wrf-python
wrf-python copied to clipboard
Dataset read muti-time data in one file
I have a wrfout data with 24h data dimensions(sizes): Time(24), DateStrLen(19), west_east(87), south_north(74), bottom_top(23), bottom_top_stag(24), soil_layers_stag(4), west_east_stag(88), south_north_stag(75) ncfile = Dataset("wrfout_d01_2019-03-22_00:00:00")
Extract the pressure, geopotential height, and wind variables p = getvar(ncfile, "pressure") z = getvar(ncfile, "z", units="dm") ua = getvar(ncfile, "ua", units="kt") va = getvar(ncfile, "va", units="kt") wspd = getvar(ncfile, "wspd_wdir", units="kts")[0,:] p just have 3 dims <xarray.DataArray 'pressure' (bottom_top: 23, south_north: 74, west_east: 87)>
wher I use ncfiles=MFDataset("wrfout_d01_2019-03-22_00:00:00") p = getvar(ncfiles, "pressure") z = getvar(ncfiles, "z", units="dm") ua = getvar(ncfiles, "ua", units="kt") va = getvar(ncfiles, "va", units="kt") wspd = getvar(ncfiles, "wspd_wdir", units="kts")[0,:]
RuntimeError: NetCDF: Not a valid ID
The netcdf4-python MFDataset isn't currently supported. If all of your times are in one file, then just use the regular Dataset object. If you want your values computed across all times, pass in wrf.ALL_TIMES as your timeidx parameter. WRF-Python includes the logic to aggregate the data across time Time index.
(Note: In the future, the front end to WRF-Python will be changed to support xarray Datasets, so this issue will go away when that happens).