A python module for obtaining reduced(min,max,avg) value from netCDF file under a polygon region
Project description
pyscissor
A Python3 module for extracting data from netcdf file under a shapefile region.
Installation
pyscissor can be installed using the following commands
$ git clone https://github.com/nzahasan/pyscissor.git
$ cd pyscissor
$ python3 setup.py install
or using pip
$ pip install pyscissor
Using pyscissor
import numpy as np
from pyscissor import scissor
'''<code for reading netcdf and shapefile>'''
pys = scissor(polygon,lats,lons)
weight_grid = pys.get_masked_weight() #=> returns a masked array containing weights
# get weighted average
avg = np.average(var,weights=weight_grid)
# if only intersection mask with shape is needed use `weight_grid.mask`
A detailed use case can be found in the following notebook example_01.ipynb
Using nc2ts_by_shp.py
this package contains a nc2ts_by_shp.py
script. A command line tool that can be used to quickly extract
reduced(min/max/average/weighted average) time-series form netcdf file with shapefile
# with 3d array [data/sample_2.nc] generel case
$ nc2ts_by_shp.py -nc=sample_2.nc -nci='Y=lat;X=lon;T=time;V=tmin;' -s=shape_esri.zip \
-sp='ADM2_EN;ADM3_EN' -r=avg -o=test2.csv
# with 4d array [data/sample_1.nc]
$ nc2ts_by_shp.py -nc=sample_1.nc -nci='Y=lat;X=lon;T=time;V=temperature;slicer=[:,0,:,:]' -sf=shape_esri.zip \
-sfp='ADM2_EN;ADM3_EN' -r=wavg -o=test1.csv
Options:
-nc = netcdf file
-nci = netcdf variable and dimension information
available options:
X = x dimension variable name,
Y = y dimension variable name,
T = time dimension variable name,
V = variable name,
slicer = slicing index for obtaining 3d array [optional]
note: `slicer` is required if variable has more than three dimension
-sf = shape file ( can be zipped shapefile, shapefile or geojson )
-sfp = shapefile properties
only required when shapefile contains multiple records
-r = reducer, default is average
Available options: min,max,avg,wavg
-o = output file name
Causes of Erroneous output
- when shapefile and netcdf file have different projection
- shapefile dosen't fully reside within netcdf bounds
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
pyscissor-1.1.0.tar.gz
(9.6 kB
view hashes)
Built Distribution
pyscissor-1.1.0-py3-none-any.whl
(11.3 kB
view hashes)
Close
Hashes for pyscissor-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8b90b08691208d36d42a803b2ac588bbe6c5494e94eada3228312c5d46c0942 |
|
MD5 | f30925a555bc12ef55e8c3dd6ed72b8d |
|
BLAKE2b-256 | 9e294c12b412c43e22d5254d139f0de1865e558d8a3cdb454d409c3ceaa3f33e |