简体   繁体   中英

How do I import multiple tables from a single NetCDF .nc file using python xarray?

I have a dataset in both a netcdf .nc file and a .wls file. I can open the .wls file and view it with a text editor. The dataset contains a large amount of metadata and several tables. I understand that python xarray was created to work with netcdf files, but when I try to import this file as a python xarray dataset, only one of the tables is imported.

This information is copied from the text file. Each table ends with %TableEnd: , so I think the import ends there. Most of my data is in .nc files, so manually editing text files isn't an option.

%CTF: 1.00
%FileType: WVMD WVM9 "Wave History"
%UUID: 1E9EBB39-F35C-4E9B-8C4C-72945FFEA5D9
%Manufacturer: CODAR Ocean Sensors. SeaSonde
...
(trimmed for clarity)
...
%TableType: WAVL WVM9
%TableColumns: 20
%TableColumnTypes: TIME MWHT MWPD WAVB WNDB PMWH ACNT DIST RCLL WDPT MTHD FLAG WHNM WHSD TYRS TMON TDAY THRS TMIN TSEC 
%TableRows: 4459
%TableStart:
%%     Time     ----------Wave----------    Wind    WaveNF                                                             Height    Height                        
%%   FromStart   Height  Period   From      From    Height   Spectra   Distance   Range   Doppler    Wave    Vector    Valid      StdDv    Time                
%%   (seconds)     (m)     (s)   (True)    (True)     (m)     count      (km)      cell     bins    Method    Flag     points      (m)     Year Mo Dy  Hr Mn  S
             0      1.21   5.75    19.0     77.3      0.19        7    9.06088        3       20        2        0          4      0.19    2019 10 01  00 00 00
           600      1.16   5.60    17.5     75.2      0.19        7    9.06088        3       20        2        0          5      0.20    2019 10 01  00 10 00
          1200      1.16   5.60    17.5     75.2      0.19        7    9.06088        3       20        2        0          5      0.20    2019 10 01  00 20 00

...
...
       2677200      2.41   7.00   101.0    217.0      0.20        7    9.06088        3       26        2        0          5      0.13    2019 10 31  23 40 00
       2677800      2.37   7.00   101.0    217.0      0.21        7    9.06088        3       26        2        0          5      0.09    2019 10 31  23 50 00
%TableEnd:
%%
%Distance: 12.08117 km
%RangeCell: 4
%TableType: WAVL WVM9
%TableColumns: 20
%TableColumnTypes: TIME MWHT MWPD WAVB WNDB PMWH ACNT DIST RCLL WDPT MTHD FLAG WHNM WHSD TYRS TMON TDAY THRS TMIN TSEC 
%TableRows: 4459
%TableStart: 2
%%     Time     ----------Wave----------    Wind    WaveNF                                                             Height    Height                        
%%   FromStart   Height  Period   From      From    Height   Spectra   Distance   Range   Doppler    Wave    Vector    Valid      StdDv    Time                
%%   (seconds)     (m)     (s)   (True)    (True)     (m)     count      (km)      cell     bins    Method    Flag     points      (m)     Year Mo Dy  Hr Mn  S
             0    999.00 999.00     0.0     67.0      0.18        7   12.08117        4       19        2       64          0      0.00    2019 10 01  00 00 00
...
...

Here is the xarray code i tried. There should be 7 tables of 4459 values.

import xarray as xr

ds = xr.open_dataset('filename.nc')
ds.sizes

Output:
Frozen(SortedKeysDict({'time': 4459}))

The answer to my question was that the two files were different. The .nc file did not contain the same information as the txt file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM