Skip to content

Commit

Permalink
Merge pull request #95 from Solid-Energy-Systems/ndc_14_filetype_5
Browse files Browse the repository at this point in the history
Adds aux temperature support for ndc version 14
  • Loading branch information
d-cogswell authored Dec 2, 2024
2 parents 9986229 + a520361 commit 295e71f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions NewareNDA/NewareNDAx.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ def read_ndax(file, software_cycle_number=False, cycle_mode='chg'):
except Exception:
pass

# Read aux channel mapping from TestInfo.xml
aux_ch_dict = {}
try:
step = zf.extract('TestInfo.xml', path=tmpdir)
with open(step, 'r', encoding='gb2312') as f:
config = ET.fromstring(f.read()).find('config')

for child in config.find("TestInfo"):
aux_ch_dict.update({int(child.attrib['RealChlID']): int(child.attrib['AuxID'])})

except Exception:
pass

# Try to read data.ndc
if 'data.ndc' in zf.namelist():
data_file = zf.extract('data.ndc', path=tmpdir)
Expand Down Expand Up @@ -90,11 +103,21 @@ def read_ndax(file, software_cycle_number=False, cycle_mode='chg'):
# Read and merge Aux data from ndc files
aux_df = pd.DataFrame([])
for f in zf.namelist():
m = re.search(".*_([0-9]+)[.]ndc", f)

# If the filename contains a channel number, convert to aux_id
m = re.search("data_AUX_([0-9]+)_[0-9]+_[0-9]+[.]ndc", f)
if m:
ch = int(m[1])
aux_id = aux_ch_dict[ch]
else:
m = re.search(".*_([0-9]+)[.]ndc", f)
if m:
aux_id = int(m[1])

if m:
aux_file = zf.extract(f, path=tmpdir)
aux = read_ndc(aux_file)
aux['Aux'] = int(m[1])
aux['Aux'] = aux_id
aux_df = pd.concat([aux_df, aux], ignore_index=True)
if not aux_df.empty:
aux_df = aux_df.astype(
Expand Down Expand Up @@ -408,6 +431,25 @@ def _read_ndc_14_filetype_1(mm):
return df


def _read_ndc_14_filetype_5(mm):
record_len = 4096
header = 4096

# Read data records
aux = []
mm.seek(header)
while mm.tell() < mm.size():
bytes = mm.read(record_len)
for i in struct.iter_unpack('<f', bytes[132:-4]):
aux.append(i[0])

# Create DataFrame
aux_df = pd.DataFrame(aux, columns=['T'])
aux_df['Index'] = aux_df.index + 1

return aux_df


def _read_ndc_14_filetype_7(mm):
return _read_ndc_11_filetype_7(mm)

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 295e71f

Please sign in to comment.