Skip to content
Snippets Groups Projects
Commit fdde2570 authored by Jacques Grelet's avatar Jacques Grelet
Browse files

add station extraction number from file name

parent 9f15bfc7
No related branches found
No related tags found
No related merge requests found
...@@ -87,6 +87,8 @@ julianOrigin = 1 ...@@ -87,6 +87,8 @@ julianOrigin = 1
[btl] [btl]
cruisePrefix = "fr29"
stationPrefixLength = 3
typeInstrument = "SBE32 standard 24 Niskin bottles" typeInstrument = "SBE32 standard 24 Niskin bottles"
instrumentNumber = "unknown" instrumentNumber = "unknown"
titleSummary = "Water sample during PIRATA-FR32 cruise with 22 levels" titleSummary = "Water sample during PIRATA-FR32 cruise with 22 levels"
......
...@@ -246,14 +246,31 @@ class Profile: ...@@ -246,14 +246,31 @@ class Profile:
if 'julianOrigin' in cfg[device.lower()]: if 'julianOrigin' in cfg[device.lower()]:
self.__julianOrigin = cfg[device.lower()]['julianOrigin'] self.__julianOrigin = cfg[device.lower()]['julianOrigin']
# prepare the regex to extract station number from filename
# by default, station or profile number is extract from the filename
if 'cruisePrefix' in cfg[device.lower()]:
cruisePrefix = cfg[device.lower()]['cruisePrefix']
print(cruisePrefix)
if 'stationPrefixLength' in cfg[device.lower()]:
stationPrefixLength = cfg[device.lower()]['stationPrefixLength']
print(stationPrefixLength)
station_regex = re.compile(f"{cruisePrefix}(\d{{{stationPrefixLength}}})")
# read each file and extract header and data and fill sqlite tables # read each file and extract header and data and fill sqlite tables
for file in self.fname: for file in self.fname:
process_header = False process_header = False
process_data = False process_data = False
station = [] sql = {}
# by default, station or profile number is extract from the filename
if station_regex.search(file):
[station] = station_regex.search(file).groups()
sql['station'] = int(station)
logging.debug(f"Station match: {sql['station']}")
with fileinput.input( with fileinput.input(
file, openhook=fileinput.hook_encoded("ISO-8859-1")) as f: file, openhook=fileinput.hook_encoded("ISO-8859-1")) as f:
sql = {}
self.__header = '' self.__header = ''
print(f"Reading file: {file}") print(f"Reading file: {file}")
# read all lines in file # read all lines in file
...@@ -284,7 +301,7 @@ class Profile: ...@@ -284,7 +301,7 @@ class Profile:
# toml file, section [device.header] # toml file, section [device.header]
for k in self.__regex.keys(): for k in self.__regex.keys():
# extract STATION number # extract STATION number if [device][header][station] is defined
if k == "station" and self.__regex[k].search(self.__header): if k == "station" and self.__regex[k].search(self.__header):
[station] = self.__regex[k].search(self.__header).groups() [station] = self.__regex[k].search(self.__header).groups()
#print("station: {}, type: {}".format(station, type(station))) #print("station: {}, type: {}".format(station, type(station)))
......
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