cedadev / nappy

NASA Ames Processing in PYthon (NAPPy) - a Python library for reading, writing and converting NASA Ames files.
BSD 3-Clause "New" or "Revised" License
9 stars 13 forks source link

support NDACC based 2160 files #10

Closed tomkralidis closed 5 years ago

tomkralidis commented 6 years ago

The Network for the Detection of Atmospheric Composition Change (NDACC) project has a 2160 variation which adds a line at the beginning of the file.

Snippet from ftp://ftp.cpc.ncep.noaa.gov/ndacc/station/alert/ames/o3sonde/al000106.b23:

FAST H.             O3SONDE     ALERT NWT   OZONE       06-Jan-2000 23:00:0007-Jan-2000 02:00:000001
54 2160 
Jonathan Davies
AES
Ozonesonde
ARQX OZONE PROGRAM
1 1 
2000  1  6  2000  1  7 
0 
40 
Pressure at observation (hPa) 
Station name

Running against master results in the following traceback

>>> from nappy import openNAFile
WARNING:nappy.nappy_api:You cannot use nappy NetCDF conversion tools as your system does not have CDMS installed, or it is not in your sys.path.
>>> n = openNAFile('al000106.b23')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "nappy/nappy_api.py", line 163, in openNAFile
    ffi = readFFI(filename)
  File "nappy/utils/common_utils.py", line 43, in readFFI
    ffi = text_parser.readItemsFromLine(topline, 2, int)[-1]
  File "nappy/utils/text_parser.py", line 48, in readItemsFromLine
    raise Exception("Incorrect number of items (%s) found in line: \n'%s'" % (nitems, line))
Exception: Incorrect number of items (2) found in line:
'FAST H.             O3SONDE     ALERT NWT   OZONE       06-Jan-2000 23:00:0007-Jan-2000 02:00:000001
'
>>>
agstephens commented 6 years ago

@tomkralidis: We could add an argument in the openNAFile() call such as ignore_header_lines=<n> that will ignore any number of initial lines (default: 0). Would that give you what you needed to use nappy for this context?

tomkralidis commented 6 years ago

thanks @agstephens. That would be really valuable. Can we also carry the ignored header lines as a property? Example:

>>> n = openNAFile('al000106.b23', ignore_header_lines=1)
# and then the resulting object would have a header_lines (list) property
>>> n.ignore_header_lines
['FAST H.             O3SONDE     ALERT NWT   OZONE       06-Jan-2000 23:00:0007-Jan-2000 02:00:000001']

Then the downstream application can have this information on hand (and be responsbile for processing).

cc'ing @acapparelli for further comments.