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)
20 new_ds
= new_ds
.drop_vars('XTIME')
22 print('Create new NetCDF file',new
,'and write the dataseet to it')