cp readslice.R ts_readslice.R
[wrf-fire-matlab.git] / smoke / ts_smoke.py
blobf855c49410cc88da0f684819caddc1f3e8c6e623
1 import xarray as xr
2 import numpy as np
3 import sys, os
5 pm25_vars = []
6 times_vars = []
7 lon_vars = []
8 lat_vars = []
9 new = sys.argv[-1]
11 for file_path in sys.argv[1:-1]:
13 print('Reading NetCDF file',file_path)
14 ds = xr.open_dataset(file_path)
16 # read lowest layer
17 pm25_vars.append(ds["tr17_1"].isel(bottom_top=0))
19 # Get the other variables, Times, longitude, latitude
20 times_vars.append(ds["Times"])
21 lon_vars.append(ds["XLONG"])
22 lat_vars.append(ds["XLAT"])
24 print('Concatenating the data variables along the time dimension')
25 print('pm25')
26 pm25 = xr.concat(pm25_vars, dim="Time")
27 print('times')
28 times = xr.concat(times_vars, dim="Time")
29 print('lon')
30 lon = xr.concat(lon_vars, dim="Time")
31 print('lat')
32 lat = xr.concat(lat_vars, dim="Time")
34 del pm25_vars, times_vars, lon_vars, lat_vars
36 ds_new = xr.Dataset({'pm25':pm25,'Times':times,'XLONG':lon,'XLAT':lat})
38 print('Creating new NetCDF file',new)
39 ds_new.to_netcdf(new)