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.
Metadata
Release files for netcdf2dataframe 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| netcdf2dataframe-0.1.1.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| netcdf2dataframe-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.1 kB
Release files / netcdf2dataframe-0.1.1.tar.gz
| Download URL | netcdf2dataframe-0.1.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e3e6e8487ac8ac48e47ebefcc6bf82b38767dd5367855f8e121c9c8d02dfa63
|
|
BLAKE2b-256 checksum How to use checksums |
17ff90b2d7140f0b6c2e57b8122d946a067c4961e76fe85243e2e57395a79a64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.10.16 Linux/6.8.0-1020-azure
|
Release files / netcdf2dataframe-0.1.1-py3-none-any.whl
| Download URL | netcdf2dataframe-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bff48810b1df3dbe7e0e9348ad9d0ab67bd15a696cddd3726b46d54f358418c3
|
|
BLAKE2b-256 checksum How to use checksums |
220cd8c9d68e27515d741c56a4710d6dd4d5677a13f1d27c244df9d9b8564ae3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.10.16 Linux/6.8.0-1020-azure
|