Simplifying the code structure... Primarily combining the two separate data frames for data and flows to make analysis less complex and cumbersome.
This commit is contained in:
1 parent
71843f710a
commit
09a245bc2f
3 files changed
+82
-26
No files matched your search
+78
-20
@@ -196,10 +196,11 @@ class OFRSample:
|
||||
|
||||
class OFRAnalyser:
|
||||
|
||||
def __init__(self, data_source_file, sample_number_list, data_separator = ',') -> None:
|
||||
def __init__(self, data_source_file, flows_source_file, sample_number_list, data_separator = ',') -> None:
|
||||
|
||||
self.data_source_file = data_source_file
|
||||
self.flow_source_file = None
|
||||
self.flows_source_file = flows_source_file
|
||||
self.sample_number_list = sample_number_list
|
||||
self.__data_separator = data_separator
|
||||
|
||||
with open(self.data_source_file, 'r', errors = 'ignore') as file:
|
||||
@@ -211,14 +212,12 @@ class OFRAnalyser:
|
||||
continue
|
||||
|
||||
self.max_samples = max_sample_number
|
||||
self.sample_number_list = sample_number_list
|
||||
|
||||
self.data = None
|
||||
self.flow_data = None
|
||||
|
||||
|
||||
def __sample_number_list_check(self, sample_number_list) -> None:
|
||||
|
||||
# TODO: implement a similar check for the flow data file!
|
||||
|
||||
last_sample = sample_number_list[-1]
|
||||
|
||||
if last_sample > self.max_samples:
|
||||
@@ -228,24 +227,83 @@ class OFRAnalyser:
|
||||
|
||||
self.__sample_number_list_check(self.sample_number_list)
|
||||
|
||||
numbers = []
|
||||
lengths = []
|
||||
surfaces = []
|
||||
volumes = []
|
||||
densities = []
|
||||
masses = []
|
||||
times = []
|
||||
numbers_of_sample = []
|
||||
number_concentrations = []
|
||||
length_concentrations = []
|
||||
surface_concentrations = []
|
||||
volume_concentrations = []
|
||||
aerosol_densities = []
|
||||
mass_concentrations = []
|
||||
starting_times = []
|
||||
stopping_times = []
|
||||
sampling_times = []
|
||||
dry_air_flows = []
|
||||
ozone_flows = []
|
||||
species_flows = []
|
||||
total_flows = []
|
||||
cnc_flows = []
|
||||
|
||||
for sample_number in self.sample_number_list:
|
||||
sample = OFRSample(source_file=self.data_source_file, sample_number = sample_number, data_separator = self.__data_separator)
|
||||
|
||||
numbers.append(sample.Count.integrate())
|
||||
lengths.append(sample.Length.integrate() / 1E6)
|
||||
surfaces.append(sample.Surface.integrate() / 1E12)
|
||||
volumes.append(sample.Volume.integrate() / 1E9)
|
||||
densities.append(sample.SOA_density)
|
||||
masses.append(sample.Mass.integrate() / 1E12)
|
||||
times.append(sample_number * sample.sample_time)
|
||||
numbers_of_sample.append(sample_number)
|
||||
number_concentrations.append(sample.Count.integrate())
|
||||
length_concentrations.append(sample.Length.integrate() / 1E6)
|
||||
surface_concentrations.append(sample.Surface.integrate() / 1E12)
|
||||
volume_concentrations.append(sample.Volume.integrate() / 1E9)
|
||||
aerosol_densities.append(sample.SOA_density)
|
||||
mass_concentrations.append(sample.Mass.integrate() / 1E12)
|
||||
|
||||
if sample_number == 1:
|
||||
starting_times.append(0.00)
|
||||
stopping_times.append(sample.sample_time)
|
||||
|
||||
starting_times.append(stopping_times[-1])
|
||||
stopping_times.append(stopping_times[-1] + sample.sample_time)
|
||||
|
||||
local_dry_air_flows = []
|
||||
local_ozone_flows = []
|
||||
local_species_flows = []
|
||||
local_cpc_flows = []
|
||||
|
||||
out_flag = False
|
||||
|
||||
with open(self.flow_source_file, 'r', errors='ignore') as file:
|
||||
for line_counter, line in enumerate(file.readlines()):
|
||||
|
||||
if out_flag == True:
|
||||
continue
|
||||
|
||||
i = 0
|
||||
|
||||
if line_counter == 6:
|
||||
items = line.split()
|
||||
|
||||
while i <= items:
|
||||
pass
|
||||
|
||||
dry_air_flows.append(float(items[0]))
|
||||
species_flows.append(float(items[1]))
|
||||
ozone_flows.append(float(items[2]))
|
||||
cnc_flows.append(float(items[-1]))
|
||||
starts.append(0)
|
||||
stops.append(float(items[3]) * float(items[4]))
|
||||
smpls.append(float(items[4]))
|
||||
i += 1
|
||||
elif line_counter > 6 and not line.startswith('-'):
|
||||
items = line.split()
|
||||
dry_air_flows.append(float(items[0]))
|
||||
species_flows.append(float(items[1]))
|
||||
ozone_flows.append(float(items[2]))
|
||||
cnc_flows.append(float(items[-1]))
|
||||
starts.append(stops[i-1])
|
||||
stops.append(stops[i-1] + float(items[3]) * float(items[4]))
|
||||
smpls.append(float(items[4]))
|
||||
i += 1
|
||||
if line_counter > 6 and line.startswith('-'):
|
||||
out_flag = True
|
||||
else:
|
||||
continue
|
||||
|
||||
self.data = pd.DataFrame({'Sample': self.sample_number_list,
|
||||
'Number (#/cm^3)': numbers,
|
||||
|
||||
@@ -7,13 +7,11 @@ from pathlib import Path
|
||||
|
||||
# Path to the source file
|
||||
source_file = Path(r"C:\Users\tschan_d\Documents\data_local\20260612_SET02_EXP01_full.txt")
|
||||
flow_source_file = Path(r"C:\Users\tschan_d\Documents\data_local\20260612_SET02_EXP01_full_flows.txt")
|
||||
flows_source_file = Path(r"C:\Users\tschan_d\Documents\data_local\20260612_SET02_EXP01_full_flows.txt")
|
||||
|
||||
analyser = OFRAnalyser(data_source_file=source_file, sample_number_list=range(1, 157))
|
||||
analyser = OFRAnalyser(data_source_file=source_file, flows_source_file=flows_source_file, sample_number_list=range(1, 157))
|
||||
analyser.GetData()
|
||||
analyser.GetFlowData(flow_source_file=flow_source_file)
|
||||
print(analyser.flow_data)
|
||||
analyser.GetMassProductionRates()
|
||||
print(analyser.data)
|
||||
|
||||
|
||||
# %%
|
||||
@@ -91,7 +91,7 @@
|
||||
"id": "041fc7b6",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Now let's load the data for the entire sampling experiment:"
|
||||
"## Now let's load the data for the entire sampling experiment and process it!"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user