working
[wrf-fire-matlab.git] / python / surface_slice.py
blob56cfcec22a8d3cc0a06813c948b37d7074d06d0b
1 import xarray as xr
3 file='wrfout.nc'
4 new ='smoke.nc'
6 print('Open the original NetCDF file',file)
7 ds = xr.open_dataset(file)
9 print('Read 2d slices from the last fram')
10 pm25 = ds['tr17_1'][-1,0,:,:]
11 lon = ds['XLONG'][-1,:,:]
12 lat = ds['XLAT'][-1,:,:]
14 print('Create a new dataset with 2d slices')
15 new_ds = xr.Dataset({'pm25':pm25, 'lat':lon, 'lat':lat})
17 # Remove the time dimension from the new dataset
18 new_ds = new_ds.squeeze(drop=True)
19 if 'XTIME' in new_ds:
20 new_ds = new_ds.drop_vars('XTIME')
22 print('Create new NetCDF file',new,'and write the dataseet to it')
23 new_ds.to_netcdf(new)