Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alc and gex header fix #10

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion libaarhusxyz/alc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe split this into a separate function?

columns = clean_column_names(columns)

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")])
Expand Down
4 changes: 2 additions & 2 deletions libaarhusxyz/gex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
22 changes: 12 additions & 10 deletions libaarhusxyz/xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>",

_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", "<NA>",
"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]
Expand Down Expand Up @@ -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"]
Expand All @@ -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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose adding separate argument skip_header or somesuch, as this throws away info in a non-obvious way?

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')

Expand Down