Skip to main content

Small utility to transform netCDF files into (Geo)DataFrames

Project description

netcdf2dataframe

This repo contains a small utility used to transform netCDF files to geopandas.GeoDataFrames.

Why netcdf2dataframe?

⚠️ This project was initiated due to the need of colleagues. It's considered a work in progress !

Installation

pip install netcdf2dataframe

Basic usage

from netcdf2dataframe import netcdf2dataframe
path = "IMERG_total_precipitation_day_0.5x0.5_global_2021_v6.0.nc"
df = netcdf2dataframe(path, "pr")

Note that this module may end up crashing your machine, as DataFrames are not RAM-efficient objects (compared to the netCDF format). But sometimes, this is what you may need...

Full docstring:

netcdf2dataframe(path: str, target: str = 'pr', dropna: bool = True) -> geopandas.geodataframe.GeoDataFrame
    Picks a netCDF file and extracts one variable ("target") on the form of
    a GeoDataFrame.
    
    Parameters
    ----------
    path : str
        Path to netCDF file
    target : str
        Target variable. Should be any of the available variables, excepting
        the latitude, longitude or time. Please look the INFO log to now more
        on the available variables.
        Note that available variables are displayed in the log (info level).
    dropna : bool, optional
        If True, the GeoDataFrame will not contain missing values, hence
        being more frugal (less RAM consumption). The default is True.
    
    Returns
    -------
    gpd.GeoDataFrame
        GeoDataFrame of the extracted values
    
    Example
    -------
    >>> df = netcdf2dataframe(
            "IMERG_total_precipitation_day_0.5x0.5_global_2021_v6.0.nc,
            "pr",
            )
    >>> df.head()
    
             pr   time_val                      geometry
    0  0.000000 2021-01-01  POINT (-179.74998 -78.24999)
    1  0.382080 2021-01-01  POINT (-177.24998 -78.24999)
    2  1.625944 2021-01-01  POINT (-176.74998 -78.24999)
    3  1.772459 2021-01-01  POINT (-176.24998 -78.24999)
    4  1.412688 2021-01-01  POINT (-175.74998 -78.24999)

Support

In case of bugs, please open an issue on the repo.

Contribution

Any help is welcome.

This project is managed with poetry and tested with pytest. It uses black formatting with 79 characters.

Author

Thomas GRANDJEAN (DREAL Hauts-de-France, service Information, Développement Durable et Évaluation Environnementale, pôle Promotion de la Connaissance).

Licence

GPL-3.0-or-later

Project Status

Development.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netcdf2dataframe-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netcdf2dataframe-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file netcdf2dataframe-0.1.1.tar.gz.

File metadata

  • Download URL: netcdf2dataframe-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.16 Linux/6.8.0-1020-azure

File hashes

Hashes for netcdf2dataframe-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0e3e6e8487ac8ac48e47ebefcc6bf82b38767dd5367855f8e121c9c8d02dfa63
MD5 566f765becf91b56264607348d17c8b2
BLAKE2b-256 17ff90b2d7140f0b6c2e57b8122d946a067c4961e76fe85243e2e57395a79a64

See more details on using hashes here.

File details

Details for the file netcdf2dataframe-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: netcdf2dataframe-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.16 Linux/6.8.0-1020-azure

File hashes

Hashes for netcdf2dataframe-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bff48810b1df3dbe7e0e9348ad9d0ab67bd15a696cddd3726b46d54f358418c3
MD5 467478823d5e465f7b0de110a858d36d
BLAKE2b-256 220cd8c9d68e27515d741c56a4710d6dd4d5677a13f1d27c244df9d9b8564ae3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page