I’m trying to use the xr.where() function to create a binary based on multiple arrays. The code I am using is the following:
binary = xr.where((snd_nc.SNOWDP >= 0.2) & (tas_nc.tas <= 0) & (fdd_nc.fdd >= 300) & (elev_mask == 1) & (slope_mask == 1), 1, 0)
The three netCDFs are daily data for snow depth, temperature, and freezing degree days with shapes of (time = 365, lat = 50, lon = 360). The two masks are elevation and slope with shapes of (lat = 50, lon = 360). They are .gz files read in with np.loadtxt(path/to/file.gz)
.
I’ve run this code successfully before using monthly data but now that I have switched out the three variables for daily data, the code no longer works. Everything else about the input data before and after is the same except that time dimension.
When I try to run my code, I get this error: ValueError: operands could not be broadcast together with shapes (365,50,360,365) (50,360)
though I have ensured all of the shapes of the inputs are correct.
Running the code with just the two masks works just fine but when I try to run it with just the three variables (or even just two of them), the session crashes for using all available RAM on Google Colab:
binary = xr.where((snd_nc.SNOWDP >= 0.2) & (tas_nc.tas <= 0) & (fdd_nc.fdd >= 300), 1, 0)
Any ideas on what’s giving me trouble here? I’ll attach a zip with the data attached if anyone wants to take a look.
Data: https://drive.google.com/file/d/1LyCbZ5riLfQ4uKIi77xalmpEpzb0Hye3/view?usp=sharing