salem icon indicating copy to clipboard operation
salem copied to clipboard

Size of subset files too large (`salem.roi`)

Open javedali99 opened this issue 2 years ago • 3 comments

Hello there! I have been trying to use salem.roi() to subset the netCDF data using a shapefile. However, I have noticed that the file size remains the same despite selecting a smaller area, and it is also taking a significantly longer time to run. Can anyone offer any assistance or advice on this matter? Your help would be greatly appreciated.

Check the code below:

for shapefile in shapefiles:
    
    # open the shapefile
    county = salem.read_shapefile(shapefile)
        
    # subset the netcdf data for the county
    county_data = data.salem.roi(shape=county)
    
    file_name = os.path.basename(shapefile)
    
    # save county netcdf file
    county_data.to_netcdf(save_path + "/" + file_name[:-4] + "_river_discharge.nc")
        
    # close the netcdf file
    county_data.close()

javedali99 avatar May 23 '23 18:05 javedali99

Hello, if you want to subset the data to should use subset, not ROI. ROI is masking the data. See:

https://salem.readthedocs.io/en/stable/xarray_acc.html#subsetting-data https://salem.readthedocs.io/en/stable/xarray_acc.html#regions-of-interest

fmaussion avatar May 24 '23 07:05 fmaussion

@fmaussion Thank you. I will try the subset function.

javedali99 avatar May 24 '23 14:05 javedali99

@fmaussion I tried it and it appears to be working, but I am getting data that falls outside the polygon of the shapefile. Is there a way to remove this data that exceeds the boundary of the shapefile? I want to select the points on land, instead of those on the sea. Any help would be appreciated.

See this figure: image

javedali99 avatar Jun 02 '23 18:06 javedali99

@javedali99 yes: subset first to make the domain smaller, then mask with region of interest (ROI). This is explained here: https://salem.readthedocs.io/en/stable/xarray_acc.html#subsetting-data

fmaussion avatar Jul 10 '24 03:07 fmaussion