Skip to content
Snippets Groups Projects
Commit d58df64f authored by jacques.grelet_ird.fr's avatar jacques.grelet_ird.fr
Browse files

first test with XBT

parent 2dec9f6d
No related branches found
No related tags found
No related merge requests found
......@@ -31,13 +31,19 @@ D={}
D={'un': 1, "deux: 2}
D['un']
1
D.has_key('deux')
'deux' in D
True
D.keys()
['un', 'deux']
D.values()
[1,2]
len(D)
Return the number of items in the dictionary d.
d[key]
Return the item of d with key key. Raises a KeyError if key is not in the map.
d[key] = value
Set d[key] to value.
......
......@@ -13,27 +13,35 @@ class FileExtractor:
'''
This class read multiple ASCII file, extract physical parameter from ROSCOP codification at the given column
and fill arrays
and fill arrays.
Parameters
----------
fname : file, str, pathlib.Path, list of str
File, filename, or list to read.
skip_header : int, optional
The number of lines to skip at the beginning of the file.
'''
# constructor with values by default
def __init__(self, files):
def __init__(self, fname, skip_header=0):
# attibutes
# public:
self.files = files
self.fname = fname
self.n = 0
self.m = 0
# replace this constante with roscop fill value
self.FillValue = 1e36
# private:
self.__headeer = {}
self.skip_header = skip_header
self.__header = {}
self.__data = {}
# overloading operators
def __str__(self):
''' overload string representation '''
return 'Class FileExtractor, file: %s, size = %d' % (self.files, len(self))
return 'Class FileExtractor, file: %s, size = %d' % (self.fname, len(self))
def disp(self, keys):
# for key in keys:
......@@ -47,11 +55,17 @@ class FileExtractor:
# first pass on file(s)
def firstPass(self):
'''
Returns
------
out : [n,m]
The size of array.
'''
lineRead = 0
filesRead = 0
indMax = 0
for file in self.files:
for file in self.fname:
with fileinput.input(
file, openhook=fileinput.hook_encoded("ISO-8859-1")) as f:
filesRead += 1
......@@ -73,13 +87,32 @@ class FileExtractor:
self.m = indMax
return self.n, self.m
# second pass, extract data from roscop code in files and fill array
def secondPass(self, keys, cfg, type):
# second pass, extract data from roscop code in fname and fill array
def secondPass(self, keys, cfg, device):
'''
Read the file to its internal dict
Parameters
----------
keys: sequence, a list of physical parameter to read.
ex: ['PRES', 'TEMP', 'PSAL']
cfg: toml.load() instance, configuration file
device: str, instrument
ex: CTD,XBT or LADCP
'''
n = 0
m = 0
# get the dictionary from toml block, type instrument is in lower case
hash = cfg['split'][type.lower()]
#print(device, cfg[device.lower()])
print(device)
# set skip_header is declared in toml section, 0 by default
if 'skikHeader' in cfg[device.lower()]:
self.skip_header = cfg[device.lower()]['skipHeader']
#
logging.debug(self.skip_header)
# get the dictionary from toml block, device must be is in lower case
hash = cfg['split'][device.lower()]
# initialize arrays, move at the end of firstPass ?
for key in keys:
......@@ -87,10 +120,12 @@ class FileExtractor:
# the shape parameter has to be an int or sequence of ints
self.__data[key] = np.ones((self.n, self.m)) * self.FillValue
for file in self.files:
for file in self.fname:
with fileinput.input(
file, openhook=fileinput.hook_encoded("ISO-8859-1")) as f:
for line in f:
if f.filelineno() < self.skip_header + 1:
continue
if line[0] == '#' or line[0] == '*':
continue
# split the line
......@@ -129,7 +164,7 @@ if __name__ == "__main__":
default='tests/test.toml')
parser.add_argument('-k', '--key', nargs='+', default=['PRES', 'TEMP', 'PSAL'],
help='display dictionary for key(s), (default: %(default)s)')
parser.add_argument('files', nargs='*',
parser.add_argument('fname', nargs='*',
help='cnv file(s) to parse, (default: data/cnv/dfr29*.cnv)')
# display extra logging info
......@@ -140,8 +175,8 @@ if __name__ == "__main__":
logging.basicConfig(
format='%(levelname)s:%(message)s', level=logging.DEBUG)
fe = FileExtractor(args.files)
print("File(s): {}, Config: {}".format(args.files, args.config))
fe = FileExtractor(args.fname)
print("File(s): {}, Config: {}".format(args.fname, args.config))
cfg = toml.load(args.config)
[n, m] = fe.firstPass()
print("Indices:", n, m)
......
......@@ -51,13 +51,17 @@ def process(args, cfg, ti):
if __name__ == "__main__":
'''
usage:
> python oceano.py data/cnv/dfr2900[1-3].cnv -d
> python oceano.py data/cnv/dfr2900[1-3].cnv -k PRES TEMP PSAL DOX2 DENS
> python oceano.py data/cnv/dfr29*.cnv -d
> python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -d
> python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -k PRES TEMP PSAL DOX2 DENS
> python oceano.py data/CTD/cnv/dfr29*.cnv -d
'''
parser = argparse.ArgumentParser(
description='This program read multiple ASCII file, extract physical parameter \
following ROSCOP codification at the given column, fill arrays, write header file',
following ROSCOP codification at the given column, fill arrays, write header file ',
usage='\npython oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD -d\n'
'python oceano.py data/CTD/cnv/dfr2900[1-3].cnv -i CTD -k PRES TEMP PSAL DOX2 DENS\n'
'python oceano.py data/CTDcnv/dfr29*.cnv -d\n'
'python oceano.py data/XBT/T7_000*.cnv -i XBT -k DEPTH TEMP SVEL\n',
epilog='J. Grelet IRD US191 - March 2019')
parser.add_argument('-d', '--debug', help='display debug informations',
action='store_true')
......@@ -83,8 +87,9 @@ if __name__ == "__main__":
# read config Toml file and get the physical parameter list (Roscop code) for the specified instrument
cfg = toml.load(args.config)
instru = args.instrument[0]
keys = cfg['split'][instru.lower()].keys()
device = str(args.instrument[0]) # convert one element list to str
print(device)
keys = cfg['split'][device.lower()].keys()
# test arguements from sys.argv, args is never to None with default option set
if args.gui or len(sys.argv) == 1:
......@@ -99,11 +104,9 @@ if __name__ == "__main__":
enable_events=True),
sg.FilesBrowse(key='_HIDDEN_',
tooltip='Choose one or more files',
initial_folder='data/{}'.format(ti[instru]),
file_types=(("{} files".format(ti[instru]), "*.{}".format(ti[instru])),))],
[sg.Input(key='_COMBO_', visible=False,
enable_events=True),
sg.Combo(['CTD', 'XBT', 'LADCP', 'TSG'],
initial_folder='data/{}'.format(ti[device]),
file_types=(("{} files".format(ti[device]), "*.{}".format(ti[device])),))],
[sg.Combo(ti.keys(), enable_events=True,
key='_COMBO_', tooltip='Select the instrument')],
* [[sg.Checkbox(k, key=k,
tooltip='Select the extract the physical parameter {}'.format(k))] for k in keys],
......@@ -119,7 +122,7 @@ if __name__ == "__main__":
while True:
# display the main windows
event, values = window.Read()
print(event, values)
# print(event, values)
if event is 'Cancel' or event == None:
raise SystemExit("Cancelling: user exit")
......@@ -128,8 +131,14 @@ if __name__ == "__main__":
break
if event is '_COMBO_':
window.FindElement('_HIDDEN_').File_types = (
("{} files".format(ti[values['_COMBO_']]), "*.{}".format(ti[values['_COMBO_']])),)
e = window.Rows[1][2]
# print(e.FileTypes)
e.FileTypes = (("{} files".format(
ti[values['_COMBO_']]), "*.{}".format(ti[values['_COMBO_']])),)
window.Finalize
# print(e.FileTypes)
# window.FindElement('_HIDDEN_').File_types = (
# ("{} files".format(ti[values['_COMBO_']]), "*.{}".format(ti[values['_COMBO_']])),)
if event is '_HIDDEN_':
window.Element('_IN_').Update(
......@@ -177,6 +186,6 @@ if __name__ == "__main__":
parser.print_help(sys.stderr)
sys.exit(1)
# in command line mode (console)
fe, n, m = process(args, cfg, ti[instru])
fe, n, m = process(args, cfg, device)
print("Dimensions: {} x {}".format(m, n))
print(fe.disp(args.key))
......@@ -41,7 +41,7 @@ comment = "CTD bottles water sampling with temperature, salinity and oxyg
cruisePrefix = "fr29"
stationPrefixLength = 3
header = 40
skipHeader = 40
acquisitionSoftware = "WinMK21"
acquisitionVersion = "2.10.1"
processingSoftware = ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment