I took the proposed solution from this question (How to mask NetCDF time series data from a shapefile in Python?) and tried to implement it. However, whenever I apply this solution it seems to set all of my values to NaNs and doesn't mask. Anyone know what's going on here? All of the data details below.
#load in precipitation data data=xr.open_dataset('/Volumes/Ext HDD 1/Python_data/ERA_precip/data/SA_last10yrs_oct1_nov11/adaptor.mars.internal-1605293227.6880476-7726-17-60b7b292-7985-46a5-ac6e-d3ad5469e87a.nc')
I perform some calculations and up with this percent of normal dataarray that only contains latitude and longitude. It looks like this (pon):
Now, I have a shapefile, which is a list of points in southern Brazil. It looks like this and contains about 2500 points (south_bra_shape):
0 POINT (-50.70833 -26.20833) 1 POINT (-50.79167 -26.20833) 2 POINT (-50.79167 -26.12500) 3 POINT (-54.20833 -25.20833) 4 POINT (-50.95833 -26.20833)
Then I try the solution offered by the previous post:
pon.rio.set_spatial_dims(x_dim="longitude", y_dim="latitude", inplace=True) pon.rio.write_crs("epsg:32663", inplace=True) south_bra_shape=gpd.read_file('/Users/eli.turaskyriskpulse.com/Documents/shapefiles/brazil/SC_RGDS_PAR_brazil_soybeans/SC_RGDS_PAR_brazil_soybeans.shp',crs="epsg:32663") clipped=pon.rio.clip(south_bra_shape.geometry.apply(mapping), south_bra_shape.crs, drop=False)
However, here is the result of clipped:
I do not understand what is happening here or what I am doing wrong.