Examples¶
Subsetting and selecting data¶
Let’s open a WRF model output file:
In [1]: import salem
In [2]: from salem.utils import get_demo_file
In [3]: ds = salem.open_xr_dataset(get_demo_file('wrfout_d01.nc'))
Let’s take a time slice of the variable T2
for a start:
In [4]: t2 = ds.T2.isel(Time=2)
In [5]: t2.salem.quick_map()
Out[5]: <salem.graphics.Map at 0x7f15c5a26588>
Although we are on a Lambert Conformal projection, it’s possible to subset the file using longitudes and latitudes:
In [6]: t2_sub = t2.salem.subset(corners=((77., 20.), (97., 35.)), crs=salem.wgs84)
In [7]: t2_sub.salem.quick_map()
I am densified (external_values, 49 elements)
Out[7]: <salem.graphics.Map at 0x7f15c5851a20>
It’s also possible to use geometries or shapefiles to subset your data:
In [8]: shdf = salem.read_shapefile(get_demo_file('world_borders.shp'))
In [9]: shdf = shdf.loc[shdf['CNTRY_NAME'].isin(['Nepal', 'Bhutan'])] # GeoPandas' GeoDataFrame
In [10]: t2_sub = t2_sub.salem.subset(shape=shdf, margin=2) # add 2 grid points
I am densified (external_values, 2 elements)
In [11]: t2_sub.salem.quick_map()