diff --git a/libaarhusxyz/alc.py b/libaarhusxyz/alc.py index 76d37c3..dc84a0e 100644 --- a/libaarhusxyz/alc.py +++ b/libaarhusxyz/alc.py @@ -17,6 +17,8 @@ def parse(nameorfile, xyz_columns=None): supported_fields = ["DateTime","Date","Time","Flight","Line","GdSpeed","Alt","DEM", "Magnetic","PowerLineMonitor", + "Misc1","Misc2","Misc3","Misc4", + "Current_Ch01","Current_Ch02", "RxPitch","RxRoll","Topography","TxAltitude", "TxOffTime","TxOnTime","TxPeakTime", "TxPitch","TxRoll","TxRxHoriSep","TxRxVertSep","UTMX","UTMY", @@ -35,10 +37,19 @@ def is_supported_field(fieldname): def _dump(xyz, f, columns=None): if columns is None: columns = xyz["file_meta"]["columns"] + else: + columns_=[] + for column_name in columns: + words=re.split('\[|\]', column_name) + if len(words)==1: + columns_.append(words[0]) + else: + newname="{0}_{1:02d}".format(words[0],int(words[1])+1) + columns_.append(newname) + columns=columns_ rows = [{"canonical_name": col, "position": idx + 1} for idx, col in enumerate(columns) if is_supported_field(col)] - channels = set([row["canonical_name"][len("Gate_Ch"):].split("_")[0] for row in rows if row["canonical_name"].startswith("Gate_Ch")]) diff --git a/libaarhusxyz/gex.py b/libaarhusxyz/gex.py index ad78e5e..a1e3769 100644 --- a/libaarhusxyz/gex.py +++ b/libaarhusxyz/gex.py @@ -28,7 +28,7 @@ def split_sections(text): sectionlineidx.append(len(text)+1) sections={"header":text[0]} for k in range(len(sectionheaders)): - sections[sectionheaders[k]]=text[sectionlineidx[k]+1:sectionlineidx[k+1]-1] + sections[sectionheaders[k]]=text[sectionlineidx[k]+1:sectionlineidx[k+1]] return sections, sectionheaders def parse_parameters(textlines): @@ -64,7 +64,7 @@ def _parse(inputfile): gex={"header":sections["header"]} for header in sectionheaders: gex[header.strip("[").strip("]")]=parse_parameters(sections[header]) - print("header {} parsed".format(header)) + # print("header {} parsed".format(header)) return gex def parse(nameorfile, **kw): diff --git a/libaarhusxyz/xyz.py b/libaarhusxyz/xyz.py index 1de9c4a..cf9d140 100644 --- a/libaarhusxyz/xyz.py +++ b/libaarhusxyz/xyz.py @@ -24,14 +24,15 @@ # with the naming convention used in Aaarhus Workbench / ALC files. _RE_LAYER_COL = re.compile(r"^(.*?)[(_\[]([0-9]+)[)\]]?$") -_NA_VALUES = ["", "#N/A", "#N/A N/A", "#NA", "-1.#IND", "-1.#QNAN", "-NaN", "-nan", "1.#IND", "1.#QNAN", "", + +_NA_VALUES = [9999, 9999.9, "9999", "9999.9", "", "#N/A", "#N/A N/A", "#NA", "-1.#IND", "-1.#QNAN", "-NaN", "-nan", "1.#IND", "1.#QNAN", "", "N/A", "NA", "NULL", "NaN", "n/a", "nan", "null", "*"] def _split_layer_columns(df): per_layer_cols = [col for col in df.columns if re.match(_RE_LAYER_COL, col)] per_sounding_cols = [col for col in df.columns if not col in per_layer_cols] - + colgroups = {} for col in per_layer_cols: group = re.match(_RE_LAYER_COL, col).groups()[0] @@ -115,7 +116,7 @@ def _parse(inputfile, source=None, alcfile=None, **kw): res = {"flightlines": df, "layer_data": layer_dfs, "model_info": headers, - "file_meta": {"columns": full_df.columns}} + "file_meta": {"columns": list(full_df.columns)}} if alcdata is not None: res["alc_info"] = alcdata["meta"] @@ -142,13 +143,14 @@ def _un_split_layer_columns(data): def _dump(data, file, alcfile=None): df = _un_split_layer_columns(data) - for key, value in data['model_info'].items(): - if key != 'source': - file.write("/" + str(key) + "\n") - if isinstance(value, list): - file.write("/" + ' '.join(str(item) for item in value) + "\n") - else: - file.write("/" + str(value) + "\n") + if alcfile==None: + for key, value in data['model_info'].items(): + if key != 'source': + file.write("/" + str(key) + "\n") + if isinstance(value, list): + file.write("/" + ' '.join(str(item) for item in value) + "\n") + else: + file.write("/" + str(value) + "\n") file.write('/ ') df.to_csv(file, index=False, sep=' ', na_rep="*", encoding='utf-8')