I have a numpy array in python with size (16,250,186) representing time, latitude and longitude.
I want to convert it to a netCDF file so that I can read the data easily with co-ordinates in future.
My numpy array looks like this
RZS = np.load("/home/chandra/Data/rootzone_CHIRPS_era5_2003-2015_daily-analysis_annual-result.npy")
RZS.shape
Output: (16, 250, 186)
As you can see my above numpy array represents annual values for 16 years.
chirps_precip =xarray.open_mfdataset("/home/chandra/Data/CHIRPS/chirps-v2.0.2000.days_p25.nc")
precip = chirps_precip.precip.sel(latitude = slice(-50,12.5), longitude = slice(-81.25,-34.75))
precip[0,:,:]
Output:
<xarray.DataArray 'precip' (latitude: 250, longitude: 186)>
dask.array<shape=(250, 186), dtype=float32, chunksize=(250, 186)>
Coordinates:
* latitude (latitude) float32 -49.875 -49.625 -49.375 ... 12.125 12.375
* longitude (longitude) float32 -81.125 -80.875 -80.625 ... -35.125 -34.875
time datetime64[ns] 2000-01-01
Attributes:
units: mm/day
standard_name: convective precipitation rate
long_name: Climate Hazards group InfraRed Precipitation with St...
time_step: day
geostatial_lat_min: -50.0
geostatial_lat_max: 50.0
geostatial_lon_min: -180.0
geostatial_lon_max: 180.0
These are the co-ordinates of the chirps_precip
dataset that I want my numpy array RZS
to have with years (as 2000, 2001, .....2015) on the timestep
I have tried some methods like
# from xarray
array = xarray.DataArray(RZS, latitude = 'precip.latitude')
#from netCDF
Dataset.createVariable('rootzone storage cap', np.float32, ('time','lat','lon'))
But I am not able to do anything. I also tried to copy attrs
and coords
but that also didn't work.
It seems like I am doing this the wrong way. Can anyone suggest what am I missing.
I want my numpy array to have the same co-ordinate as the netcdf file, but with a modified time
attribute to years.