This repository was archived by the owner on Aug 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRead_co2app.py
More file actions
59 lines (54 loc) · 2.47 KB
/
Copy pathRead_co2app.py
File metadata and controls
59 lines (54 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# import os
import re
# import time
# import zipfile
from datetime import datetime
# import configparser
import pandas as pd
import numpy as np
class read_file():
# Parse the system_config\co2app.conf file from the 7200 to get calibration settings
# Only an option for co2/h2o the ch4 calibration values are only saved on the LI-7000
def __init__(self,co2app_file):
self.Coef = re.search(r'Coef(.*?)\)\)\)', co2app_file).group(0)
Coef_Keys = ['CO2 ','H2O ','Pressure ','MaxRef']
Coef_Summary = pd.concat(
[self.Parse_Coef(Val) for Val in Coef_Keys],
axis=0,
ignore_index=True)
self.Calibrate = re.search(r'Calibrate(.*?)\)\)\)', co2app_file).group(0)
Calibrate_Keys = ['ZeroCO2','SpanCO2','ZeroH2O','SpanH2O'] # Span2CO2 & Span2H2O not needed
Calibrate_Summary = pd.concat(
[self.Parse_Cal(Val) for Val in Calibrate_Keys],
axis=0,
ignore_index=True)
self.Summary = pd.concat(
[Calibrate_Summary,Coef_Summary],
axis=0)
def Parse_Coef(self,key):
# Get Calibration coefficients from co2app file
Coef_Info = re.search(r''+key+'\((.*?)\)\)', self.Coef).group(1).replace(')(',' ')
Coef_Info = pd.DataFrame(np.array([v for v in Coef_Info.split(' ')]).reshape(-1,2))
Coef_Info = Coef_Info.rename(columns={0:'Attribute',1:'Value'})
Coef_Info['Attribute']=key.replace(' ','')+'_'+Coef_Info['Attribute'].astype(str)
return(Coef_Info)
def Parse_Cal(self,key):
# Get Calibration metadata from co2app file
Cal_Info = re.search(r''+key+'(.*?)\)\)', self.Calibrate).group(1)
Cal_Date = Cal_Info.split('(Date ')[-1].replace(' at ',' ')
Cal_Stats = Cal_Info.split('(Date ')[0]
Cal_Stats = re.search(r'\((.*)\)', Cal_Stats).group(1).replace(')(',' ')
Cal_Stats = pd.DataFrame(np.array([v for v in Cal_Stats.split(' ')]).reshape(-1,2))
Cal_Stats = Cal_Stats.rename(columns={0:'Attribute',1:'Value'})
Cal_Stats['Attribute']=key+'_'+Cal_Stats['Attribute'].astype(str)
try:
timestamp = datetime.strptime(Cal_Date,'%b %d %Y %H:%M:%S')
except:
timestamp = pd.Timestamp('nat')
pass
Cal_Stats = pd.concat(
[Cal_Stats,pd.DataFrame(data={'Attribute':[key+'_Timestamp'],'Value':[timestamp]},index=[0])],
axis=0,
ignore_index=True
)
return(Cal_Stats)