'How to convert 2d lat lon netCDF file to a map
I am new in python. I have a netCDF file which contains 2d lat and lon data. Also, I have a numpy file which contains soil moisture value for each pixel. I want to convert them into a map. Actually, each pixel has different x, y, and z because the data is for a country and it is not rectangular (has its specific shape). I tried to do it with the following code but I understood that x and y are 2d and it did not work (I think it is not correct for my problem).
import netCDF4
import numpy as np
lat_lon=netCDF4.Dataset(dir)
sm=np.load(dirsm)
lat=lat_lon.variables['lat']
lon=lat_lon.variables['lon']
np.asarray(lon)
np.asarray(lat)
X, Y = np.meshgrid(lat,lon)
smNorm=(smv-smv.min())/(smv.max()-smv.min())*255
smNormUnit8=smNorm.astype(np.un)
Solution 1:[1]
Use Dask Groupby - I faced a similar issue and received about 1 order of magnitude speedup. This allows you to run across multiple CPUs rather than being single-thread bound.
https://examples.dask.org/dataframes/02-groupby.html
I would imagine there are ways to send to GPU/multi-node as well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alex D |
