I've been trying to multiply several netCDF files with each other for in-place calculations such as raster multiplication, but I keep getting different errors, and I was hoping I could get some help.
My bands have the following information (ignoring Attributes for clarity, I can add it if needed):
>>> precds
<xarray.Dataset>
Dimensions: (bnds: 2, lat: 360, lon: 720, time: 1827)
Coordinates:
* lon (lon) float32 -179.75 -179.25 -178.75 ... 178.75 179.25 179.75
* lat (lat) float32 -89.75 -89.25 -88.75 -88.25 ... 88.75 89.25 89.75
* time (time) datetime64[ns] 2016-01-01T12:00:00 ... 2020-12-31T12:00:00
Dimensions without coordinates: bnds
Data variables:
time_bnds (time, bnds) datetime64[ns] dask.array<chunksize=(10, 2), meta=np.ndarray>
prAdjust (time, lat, lon) float32 dask.array<chunksize=(10, 360, 720), meta=np.ndarray>
>>> wsxr
<xarray.DataArray (band: 1, y: 2160, x: 4320)>
[9331200 values with dtype=float32]
Coordinates:
* band (band) int64 1
* y (y) float64 89.96 89.87 89.79 89.71 ... -89.71 -89.79 -89.88 -89.96
* x (x) float64 -180.0 -179.9 -179.8 -179.7 ... 179.7 179.8 179.9 180.0
>>> tempds
<xarray.Dataset>
Dimensions: (bnds: 2, lat: 360, lon: 720, time: 1827)
Coordinates:
* lon (lon) float32 -179.75 -179.25 -178.75 ... 178.75 179.25 179.75
* lat (lat) float32 -89.75 -89.25 -88.75 -88.25 ... 88.75 89.25 89.75
* time (time) datetime64[ns] 2016-01-01T12:00:00 ... 2020-12-31T12:00:00
Dimensions without coordinates: bnds
Data variables:
time_bnds (time, bnds) datetime64[ns] dask.array<chunksize=(10, 2), meta=np.ndarray>
tasAdjust (time, lat, lon) float32 dask.array<chunksize=(10, 360, 720), meta=np.ndarray>
height float64 ...
Here, precds
and tempds
can multiply successfully, but I can't seem to multiply tempds
and wsxr
or precds
and wsxr
without getting some form of error.
Here's what I've tried:
>>> multiplied = precds_var1 * cotton_dask500_ds
>>> multiplied.to_netcdf('multiplied.nc')
Error:
MemoryError: Unable to allocate array with shape (1827, 360, 720, 1, 2160, 500) and data type float32
This is weird, cuz we're using a system that has 256GB of RAM installed, and even after trying this or using just one band, the error message didn't change.
Then, thinking that it might be because of the different names, we changed the names of the bands, but that too didn't work. Going to try to make sure that they have the same types as well (tho, float32
and float64
should still work right?)
We also tried to apply the squeeze
function to reduce the total number of dimensions (might need to verify this, cuz my co-worker worked on this not me), but this is the error message that popped up for me:
>>> precipitation_slice_squeeze = precipitation_slice.squeeze()
>>> precipitation_slice_squeeze
<xarray.DataArray 'prAdjust' (lat: 360, lon: 720)>
dask.array<getitem, shape=(360, 720), dtype=float32, chunksize=(360, 720), chunktype=numpy.ndarray>
Coordinates:
* lon (lon) float32 -179.75 -179.25 -178.75 ... 178.75 179.25 179.75
* lat (lat) float32 -89.75 -89.25 -88.75 -88.25 ... 88.75 89.25 89.75
time datetime64[ns] 2019-01-01T12:00:00
>>> precipitation_slice_squeeze * wsxr_renamed_squeeze
ValueError: zero-size array to reduction operation minimum which has no identity
Clearly, we're doing something really really wrong. We're fairly new to XArray and don't have a lot of experience with them. Our main goal is to perform in-place raster calculation, so any and all help would be appreciated!