[ncl-talk] read multiple nc files

yang yang yang.yang816 at gmail.com
Tue Jul 26 21:26:23 MDT 2022


Dear Sir/Madam:

I met a problem when I read multiple nc files in Python. I am wondering if
anyone here can help sort this out. Many thanks in advance.

Cheers!
Ed

The errors are:
(ncl_to_python)yangy at w-nwp01 $python read_nc_1.py
Traceback (most recent call last):
  File
"/scale_wlg_nobackup/filesets/nobackup/niwa00004/yangy/Ln-Python/read_nc_1.py",
line 5, in <module>
    f = nc.MFDataset(file_list)
  File "src/netCDF4/_netCDF4.pyx", line 6552, in
netCDF4._netCDF4.MFDataset.__init__
OSError: master dataset
/nesi/nobackup/niwa00004/yangy/output/DATA-cylc-run/NZLAM_rerun/
umnsaa_pa000.nc does not have a aggregation dimension


The script is listed below:
import netCDF4 as nc
#-- list of files
file_list = "umnsaa*.nc"
#-- open file
f = nc.MFDataset(file_list)
#-- read variable
var = f.variables['air_press']
print(var.dimensions)
#-- read dimension time variable
time = f.variables['time0']
print(time0[:])
#-- read dimensions lat and lon variables
lat = f.variables['latitude']
print(lat[:])
lon = f.variables['longitude']
print(lon[:])
exit()

ncdump -h of this file shows:
netcdf umnsaa_pa000 {
dimensions:
        time0 = 7 ;
        time1 = 1 ;
        time2 = 1 ;
        ntb = 2 ;
        rlat = 324 ;
        rlon = 324 ;
        nllb = 4 ;
        hybridr70 = 70 ;
        hybridt70 = 70 ;
        pressure22 = 22 ;
        num_etaT_levels = 71 ;
        num_etaR_levels = 70 ;
variables:
        float time0(time0) ;
                time0:standard_name = "time" ;
                time0:long_name = "forecast period" ;
                time0:calendar = "gregorian" ;
                time0:units = "hours since 2014-06-28 12:00:00" ;
                time0:axis = "T" ;
        float time1(time1) ;
                time1:standard_name = "time" ;
                time1:long_name = "forecast period" ;
                time1:calendar = "gregorian" ;
                time1:units = "hours since 2014-06-28 12:00:00" ;
                time1:axis = "T" ;
        float time2(time2) ;
                time2:standard_name = "time" ;
                time2:long_name = "forecast period (end of reporting
period)" ;
                time2:calendar = "gregorian" ;
                time2:units = "hours since 2014-06-28 12:00:00" ;
                time2:axis = "T" ;
                time2:bounds = "time2_bnds" ;
        float time2_bnds(time2, ntb) ;
        float rlat(rlat) ;
                rlat:standard_name = "grid_latitude" ;
                rlat:long_name = "latitude on rotated pole grid at cell
centres" ;
                rlat:units = "degrees" ;
                rlat:axis = "Y" ;
                rlat:valid_min = -90.f ;
                rlat:valid_max = 90.f ;
        float rlon(rlon) ;
                rlon:standard_name = "grid_longitude" ;
                rlon:long_name = "longitude on rotated pole grid at cell
centres" ;
                rlon:units = "degrees" ;
                rlon:axis = "X" ;
                rlon:valid_min = 0.f ;
                rlon:valid_max = 360.f ;
        float latitude(rlat, rlon) ;
                latitude:standard_name = "latitude" ;
                latitude:long_name = "geographic latitude at cell centres" ;
                latitude:units = "degrees_north" ;
                latitude:valid_min = -90.f ;
                latitude:valid_max = 90.f ;
                latitude:bounds = "latitude_bnds" ;
        float longitude(rlat, rlon) ;
                longitude:standard_name = "longitude" ;
                longitude:long_name = "geographic longitude at cell
centres" ;
                longitude:units = "degrees_east" ;
                longitude:valid_min = 0.f ;
                longitude:valid_max = 360.f ;
                longitude:bounds = "longitude_bnds" ;
        float latitude_bnds(rlat, rlon, nllb) ;
        float longitude_bnds(rlat, rlon, nllb) ;
        char rotated_pole ;
                rotated_pole:grid_mapping_name =
"rotated_latitude_longitude" ;
                rotated_pole:grid_north_pole_latitude = 50.1515f ;
                rotated_pole:grid_north_pole_longitude = 172.5319f ;
                rotated_pole:north_pole_grid_longitude = 0.f ;
        float hybridr70(hybridr70) ;
                hybridr70:long_name = "height above sea level (rho levels
used)" ;
                hybridr70:units = "meters" ;
                hybridr70:positive = "up" ;
                hybridr70:axis = "Z" ;
.....................................
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20220727/9bf0687b/attachment.htm>


More information about the ncl-talk mailing list