All Projects → nzahasan → pyscissor

nzahasan / pyscissor

Licence: MIT license
✂️ calculate polygon mask for netCDF/GRIB/raster

Programming Languages

python
139335 projects - #7 most used programming language
Batchfile
5799 projects

Projects that are alternatives of or similar to pyscissor

Centerline
Calculate the polygon's centerline
Stars: ✭ 94 (+571.43%)
Mutual labels:  polygon, shapefile
poly-flash
Flashloan on Polygon
Stars: ✭ 233 (+1564.29%)
Mutual labels:  polygon
Netcdfjs
Read and explore NetCDF files
Stars: ✭ 86 (+514.29%)
Mutual labels:  netcdf
CosmicClone
Cosmic Clone is a utility that can backup\clone\restore a azure Cosmos database Collection. It can also anonymize cosmos documents and helps hide personally identifiable data.
Stars: ✭ 113 (+707.14%)
Mutual labels:  masking
Gdl
GDL - GNU Data Language
Stars: ✭ 104 (+642.86%)
Mutual labels:  netcdf
nctoolkit
Fast and easy analysis of netCDF data in Python
Stars: ✭ 55 (+292.86%)
Mutual labels:  netcdf
Pysat
Generalized satellite and space science data processing and file management.
Stars: ✭ 72 (+414.29%)
Mutual labels:  netcdf
matic-docs
The official documentation for all Polygon products.
Stars: ✭ 181 (+1192.86%)
Mutual labels:  polygon
nft-swap-sdk
Ethereum's missing p2p NFT and token swap library for web3 developers. Written in TypeScript. Powered by 0x.
Stars: ✭ 200 (+1328.57%)
Mutual labels:  polygon
Thredds
THREDDS Data Server v4.6
Stars: ✭ 249 (+1678.57%)
Mutual labels:  netcdf
Xarray
N-D labeled arrays and datasets in Python
Stars: ✭ 2,353 (+16707.14%)
Mutual labels:  netcdf
Nco
netCDF Operators
Stars: ✭ 105 (+650%)
Mutual labels:  netcdf
fiona
Fortran IO Netcdf Assembly
Stars: ✭ 17 (+21.43%)
Mutual labels:  netcdf
Regionmask
plotting and creation of masks of spatial regions
Stars: ✭ 97 (+592.86%)
Mutual labels:  netcdf
whitebox
White-box Analysis and Implementation Tools
Stars: ✭ 58 (+314.29%)
Mutual labels:  masking
H5netcdf
Pythonic interface to netCDF4 via h5py
Stars: ✭ 85 (+507.14%)
Mutual labels:  netcdf
Rioxarray
geospatial xarray extension powered by rasterio
Stars: ✭ 148 (+957.14%)
Mutual labels:  netcdf
gis4wrf
QGIS toolkit 🧰 for pre- and post-processing 🔨, visualizing 🔍, and running simulations 💻 in the Weather Research and Forecasting (WRF) model 🌀
Stars: ✭ 137 (+878.57%)
Mutual labels:  netcdf
Shape-Your-Music
A web application for drawing music.
Stars: ✭ 106 (+657.14%)
Mutual labels:  polygon
pydriosm
PyDriosm: an open-source tool for downloading, reading and PostgreSQL-based I/O of OpenStreetMap data
Stars: ✭ 42 (+200%)
Mutual labels:  shapefile

pyscissor

Supported Version Action: Build publish License: MIT
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 fiona
import numpy as np
from netCDF4 import Dataset
from shapely.geometry import shape
from pyscissor import scissor 


# read shapefile
sf = fiona.open('data/shape.geojson')
shapely_shp =shape(sf.get(0)['geometry'])


# read netcdf
nf = Dataset('data/sample_2.nc','r')
lats = nf.variables['lat'][:]
lons = nf.variables['lon'][:]

# create scissor object 
pys = scissor(shapely_shp,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 jupyter notebooks

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 
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].