From ec27640293c7e0b3fe6e24b965c7b38455a55ef1 Mon Sep 17 00:00:00 2001 From: msalzm Date: Tue, 20 May 2025 12:36:55 +0200 Subject: [PATCH] Fixed halflife retrieval, added rate constant retrieval & fixed some addinfo bugs --- enviPath_python/objects.py | 404 +++++++++++++++++++++++-------------- 1 file changed, 257 insertions(+), 147 deletions(-) diff --git a/enviPath_python/objects.py b/enviPath_python/objects.py index d7d8d81..b70f3ce 100644 --- a/enviPath_python/objects.py +++ b/enviPath_python/objects.py @@ -1924,12 +1924,37 @@ def get_halflifes(self) -> List['HalfLife']: :return: List of HalfLife objects """ - # TODO are they equal to HLs attached to CompoundStructure? + # TODO are they equal to HLs attached to CompoundStructure? res = [] for hl in self._get('halflifes'): - res.append(HalfLife(scenarioId=hl['scenarioId'], scenarioName=hl['scenarioName'], hl=hl['hl'], - hl_comment=hl['hlComment'], hl_fit=hl['hlFit'], hl_model=hl['hlModel'], - source=hl['source'])) + res.append(HalfLife( + scenarioId=hl.get('scenarioId'), + scenarioName=hl.get('scenarioName'), + hl=hl.get('hl'), + hl_comment=hl.get('hlComment'), + hl_fit=hl.get('hlFit'), + hl_model=hl.get('hlModel'), + source=hl.get('source') + )) + return res + + def get_rateconstants(self) -> List['RateConstant']: + """ + Retrieves the rate constants of the Compound contained in Node object + + :return: List of RateConstant objects + """ + res = [] + for hl in self._get('halflifes'): + res.append(RateConstant( + correction=hl.get('correction'), + scenarioId=hl.get('scenarioId'), + scenarioName=hl.get('scenarioName'), + rateconstant=hl.get('rateconstant'), + hl_comment=hl.get('hlComment'), + hl_model=hl.get('hlModel'), + unit=hl.get('unit') + )) return res def get_proposed_values_scenarios(self) -> List['Scenario']: @@ -2678,6 +2703,7 @@ def create(self, **kwargs): ################## HalfLife = namedtuple('HalfLife', 'scenarioName, scenarioId, hl, hl_comment, hl_fit, hl_model, source') +RateConstant = namedtuple('RateConstant', 'correction, scenarioName, scenarioId, rateconstant, hl_comment, hl_model, unit') ModelStatus = namedtuple('ModelStatus', 'progress, status, statusMessage') @@ -2768,8 +2794,8 @@ def set_oxygendemandType(self, value): 'Biological Oxygen Demand (BOD5)'. :type value: str """ - if value not in self.allowed_types: - raise ValueError(f"The value {value} does not belong to the set of allowed values {self.allowed_types}") + # if value not in self.allowed_types: + # raise ValueError(f"The value {value} does not belong to the set of allowed values {self.allowed_types}") self.params["oxygendemandType"] = value def set_oxygendemandInfluent(self, value): @@ -2780,7 +2806,7 @@ def set_oxygendemandInfluent(self, value): :type value: float """ - self.params["oxygendemandInfluent"] = float(value) + self.params["oxygendemandInfluent"] = value def set_oxygendemandEffluent(self, value): """ @@ -2790,7 +2816,7 @@ def set_oxygendemandEffluent(self, value): :type value: float """ - self.params["oxygendemandEffluent"] = float(value) + self.params["oxygendemandEffluent"] = value # Getter def get_oxygendemandType(self): @@ -2863,7 +2889,7 @@ def set_DissolvedoxygenconcentrationLow(self, value): :param value: The lower limit of dissolved oxygen concentration, measured in mg/L. :type value: float """ - self.params["DissolvedoxygenconcentrationLow"] = float(value) + self.params["DissolvedoxygenconcentrationLow"] = value def set_DissolvedoxygenconcentrationHigh(self, value): """ @@ -2872,7 +2898,7 @@ def set_DissolvedoxygenconcentrationHigh(self, value): :param value: The upper limit of dissolved oxygen concentration, measured in mg/L. :type value: float """ - self.params["DissolvedoxygenconcentrationHigh"] = float(value) + self.params["DissolvedoxygenconcentrationHigh"] = value # Getter def get_DissolvedoxygenconcentrationLow(self): @@ -2998,7 +3024,7 @@ def set_oxygenuptakerateStart(self, value): :param value: The start value of the oxygen uptake rate, measured in mg/L/hr. :type value: float """ - self.params["oxygenuptakerateStart"] = float(value) + self.params["oxygenuptakerateStart"] = value def set_oxygenuptakerateEnd(self, value): """ @@ -3007,7 +3033,7 @@ def set_oxygenuptakerateEnd(self, value): :param value: The end value of the oxygen uptake rate, measured in mg/L/hr. :type value: float """ - self.params["oxygenuptakerateEnd"] = float(value) + self.params["oxygenuptakerateEnd"] = value # Getter def get_oxygenuptakerateStart(self): @@ -3055,7 +3081,7 @@ class AerationTypeAdditionalInformation(AdditionalInformation): """ name = "aerationtype" mandatories = ['aerationtype'] - allowed_types = ["stirring", "shaking", "bubbling air", "bubbling air and stirring", "other"] + #allowed_types = ["stirring", "shaking", "bubbling air", "bubbling air and stirring", "other"] # Setter def set_aerationtype(self, value): @@ -3066,8 +3092,8 @@ def set_aerationtype(self, value): "bubbling air and stiring", "other" otherwise it could cause an error. :type value: str """ - if value not in self.allowed_types: - raise ValueError(f"The value {value} is not one of the allowed values {self.allowed_types}") + #if value not in self.allowed_types: + # raise ValueError(f"The value {value} is not one of the allowed values {self.allowed_types}") self.params["aerationtype"] = value # Getter @@ -3115,7 +3141,7 @@ def set_phosphoruscontentInfluent(self, value): :type value: float """ - self.params["phosphoruscontentInfluent"] = float(value) + self.params["phosphoruscontentInfluent"] = value def set_phosphoruscontentEffluent(self, value): """ @@ -3125,7 +3151,7 @@ def set_phosphoruscontentEffluent(self, value): :type value: float """ - self.params["phosphoruscontentEffluent"] = float(value) + self.params["phosphoruscontentEffluent"] = value # Getter def get_phosphoruscontentInfluent(self): @@ -3176,7 +3202,7 @@ class MinorMajorAdditionalInformation(AdditionalInformation): """ name = "minormajor" mandatories = ['radiomin'] - allowed_values = ["minor", "major"] + #allowed_values = ["minor", "major", "neither"] # Setter def set_radiomin(self, value): @@ -3186,8 +3212,8 @@ def set_radiomin(self, value): :param value: a text value similar to 'minor' or 'major' :type value: str """ - if value.lower() not in self.allowed_values: - raise ValueError(f"{value} is not one the allowed_values {self.allowed_values}") + #if value.lower() not in self.allowed_values: + #raise ValueError(f"{value} is not one the allowed_values {self.allowed_values}") self.params["radiomin"] = value.lower().capitalize() # Getter @@ -3242,7 +3268,7 @@ def set_sludgeretentiontime(self, value): :param value: The sludge retention time, given in days. :type value: float """ - self.params["sludgeretentiontime"] = float(value) + self.params["sludgeretentiontime"] = value # Getter def get_sludgeretentiontimeType(self): @@ -3441,7 +3467,7 @@ def set_sand(self, value): :param value: The sand percentage, measured in %. :type value: float """ - self.params["sand"] = float(value) + self.params["sand"] = value def set_silt(self, value): """ @@ -3450,7 +3476,7 @@ def set_silt(self, value): :param value: The silt percentage, measured in %. :type value: float """ - self.params["silt"] = float(value) + self.params["silt"] = value def set_clay(self, value): """ @@ -3459,7 +3485,7 @@ def set_clay(self, value): :param value: The clay percentage, measured in %. :type value: float """ - self.params["clay"] = float(value) + self.params["clay"] = value # Getter def get_sand(self): @@ -3604,7 +3630,7 @@ def set_temperatureMin(self, value): :param value: The minimum temperature, measured in degrees Celsius. :type value: float """ - self.params["temperatureMin"] = float(value) + self.params["temperatureMin"] = value def set_temperatureMax(self, value): """ @@ -3613,7 +3639,7 @@ def set_temperatureMax(self, value): :param value: The maximum temperature, measured in degrees Celsius. :type value: float """ - self.params["temperatureMax"] = float(value) + self.params["temperatureMax"] = value # Getter def get_temperatureMin(self): @@ -3666,7 +3692,7 @@ def set_totalorganiccarbonStart(self, value): :type value: float :raises ValueError: If the value is not a float. """ - self.params["totalorganiccarbonStart"] = float(value) + self.params["totalorganiccarbonStart"] = value def set_totalorganiccarbonEnd(self, value): """ @@ -3676,7 +3702,7 @@ def set_totalorganiccarbonEnd(self, value): :type value: float :raises ValueError: If the value is not a float. """ - self.params["totalorganiccarbonEnd"] = float(value) + self.params["totalorganiccarbonEnd"] = value # Getter def get_totalorganiccarbonStart(self): @@ -3818,7 +3844,7 @@ def set_omcontentInOM(self, value): :param value: The OM content measured in organic matter. :type value: float """ - self.params["omcontentInOM"] = float(value) + self.params["omcontentInOM"] = value def set_omcontentINOC(self, value): """ @@ -3827,7 +3853,7 @@ def set_omcontentINOC(self, value): :param value: The OM content, measured in organic carbon. :type value: float """ - self.params["omcontentINOC"] = float(value) + self.params["omcontentINOC"] = value # Getter def get_omcontentInOM(self): @@ -3899,7 +3925,7 @@ def set_TOC_low(self, value): :param value: The low value of TOC, measured in mg/L. :type value: float """ - self.params["TOC_low"] = float(value) + self.params["TOC_low"] = value def set_TOC_high(self, value): """ @@ -3909,7 +3935,7 @@ def set_TOC_high(self, value): :param value: The high value of TOC, measured in mg/L. :type value: float """ - self.params["TOC_high"] = float(value) + self.params["TOC_high"] = value def set_DOC_low(self, value): """ @@ -3919,7 +3945,7 @@ def set_DOC_low(self, value): :param value: The low value of DOC, measured in mg/L. :type value: float """ - self.params["DOC_low"] = float(value) + self.params["DOC_low"] = value def set_DOC_high(self, value): """ @@ -3929,7 +3955,7 @@ def set_DOC_high(self, value): :param value: The high value of DOC, measured in mg/L. :type value: float """ - self.params["DOC_high"] = float(value) + self.params["DOC_high"] = value # Getter def get_TOC_low(self): @@ -3982,10 +4008,13 @@ def parse(cls, data_string): res = {} parts = data_string.split(";") if parts[0] != "NA": - res["TOC_low"], res["TOC_high"] = parts[0].split(" - ") + res["TOC_low"] = parts[0].split(" - ")[0].replace(",", ".") + res["TOC_high"] = parts[0].split(" - ")[1].replace(",", ".") + if parts[1] != "NA": - res["DOC_low"], res["DOC_high"] = parts[1].split(" - ") - + res["DOC_low"] = parts[1].split(" - ")[0].replace(",", ".") + res["DOC_high"] = parts[1].split(" - ")[1].replace(",", ".") + return cls(**res) @@ -4008,7 +4037,7 @@ def set_OC_content_low(self, value): :param value: The low value of OC content. :type value: float """ - self.params["OC_content_low"] = float(value) + self.params["OC_content_low"] = value def set_OC_content_high(self, value): """ @@ -4017,7 +4046,7 @@ def set_OC_content_high(self, value): :param value: The high value of OC content. :type value: float """ - self.params["OC_content_high"] = float(value) + self.params["OC_content_high"] = value def set_OM_content_low(self, value): """ @@ -4026,7 +4055,7 @@ def set_OM_content_low(self, value): :param value: The low value of OM content. :type value: float """ - self.params["OM_content_low"] = float(value) + self.params["OM_content_low"] = value def set_OM_content_high(self, value): """ @@ -4035,7 +4064,7 @@ def set_OM_content_high(self, value): :param value: The high value of OM content. :type value: float """ - self.params["OM_content_high"] = float(value) + self.params["OM_content_high"] = value # Getter def get_OC_content_low(self): @@ -4089,10 +4118,13 @@ def parse(cls, data_string): res = {} parts = data_string.split(";") if parts[0] != "NA": - res["OC_content_low"], res["OC_content_high"] = parts[0].split(" - ") + res["OC_content_low"] = parts[0].split(" - ")[0].replace(",", ".") + res["OC_content_high"] = parts[0].split(" - ")[1].replace(",", ".") + if parts[1] != "NA": - res["OM_content_low"], res["OM_content_high"] = parts[1].split(" - ") - + res["OM_content_low"] = parts[1].split(" - ")[0].replace(",", ".") + res["OM_content_high"] = parts[1].split(" - ")[1].replace(",", ".") + return cls(**res) @@ -4201,7 +4233,7 @@ def set_dissolvedorganiccarbonStart(self, value): :param value: The starting value of dissolved organic carbon, measured in mg C/L. :type value: float """ - self.params["dissolvedorganiccarbonStart"] = float(value) + self.params["dissolvedorganiccarbonStart"] = value def set_dissolvedorganiccarbonEnd(self, value): """ @@ -4210,7 +4242,7 @@ def set_dissolvedorganiccarbonEnd(self, value): :param value: The ending value of dissolved organic carbon, measured in mg C/L. :type value: float """ - self.params["dissolvedorganiccarbonEnd"] = float(value) + self.params["dissolvedorganiccarbonEnd"] = value # Getter def get_dissolvedorganiccarbonStart(self): @@ -4274,7 +4306,7 @@ def set_nitrogencontentInfluent(self, value): :param value: The nitrogen content in the influent, measured in mg/L. :type value: float """ - self.params["nitrogencontentInfluent"] = float(value) + self.params["nitrogencontentInfluent"] = value def set_nitrogencontentEffluent(self, value): """ @@ -4283,7 +4315,7 @@ def set_nitrogencontentEffluent(self, value): :param value: The nitrogen content in the effluent, measured in mg/L. :type value: float """ - self.params["nitrogencontentEffluent"] = float(value) + self.params["nitrogencontentEffluent"] = value # Getter def get_nitrogencontentType(self): @@ -4496,7 +4528,7 @@ def set_lower(self, value): :param value: The lower bound of the half-life, measured in days. :type value: float """ - self.params["lower"] = float(value) + self.params["lower"] = value def set_upper(self, value): """ @@ -4505,7 +4537,7 @@ def set_upper(self, value): :param value: The upper bound of the half-life, measured in days. :type value: float """ - self.params["upper"] = float(value) + self.params["upper"] = value def set_comment(self, value): """ @@ -4519,12 +4551,12 @@ def set_comment(self, value): def set_source(self, value): """ Sets the source of the half-life information. - + :param value: The source of the half-life information. :type value: str """ - if value not in self.allowed_values: - raise ValueError(f"{value} is not an allowed source value") + # if value not in self.allowed_values: + # raise ValueError(f"{value} is not an allowed source value") self.params["source"] = value def set_firstOrder(self, value): @@ -4598,7 +4630,7 @@ def get_fit(self): :return: The fit value of the half-life if set; otherwise, None. :rtype: str """ - return self.params.get("fit", False) + return self.params.get("fit", None) # Parser @classmethod @@ -4614,8 +4646,13 @@ def parse(cls, data_string): """ parts = data_string.split(';') dt50 = parts[3] + if parts[0] == 'SFO': + SFO = True + else: + SFO = False + res = { - 'firstOrder': True if parts[0] == 'SFO' else False, + 'firstOrder': SFO, 'fit': parts[1], 'comment': parts[2], 'lower': float(dt50.split(' - ')[0]), @@ -4644,7 +4681,7 @@ def set_total_low(self, value): :param value: The total low half-life value, meaured in days. :type value: float """ - self.params["total_low"] = float(value) + self.params["total_low"] = value def set_total_high(self, value): """ @@ -4653,7 +4690,7 @@ def set_total_high(self, value): :param value: The total high half-life value, meaured in days. :type value: float """ - self.params["total_high"] = float(value) + self.params["total_high"] = value def set_water_low(self, value): """ @@ -4662,7 +4699,7 @@ def set_water_low(self, value): :param value: The water low half-life value, meaured in days. :type value: float """ - self.params["water_low"] = float(value) + self.params["water_low"] = value def set_water_high(self, value): """ @@ -4671,7 +4708,7 @@ def set_water_high(self, value): :param value: The water high half-life value, meaured in days. :type value: float """ - self.params["water_high"] = float(value) + self.params["water_high"] = value def set_sediment_low(self, value): """ @@ -4680,7 +4717,7 @@ def set_sediment_low(self, value): :param value: The sediment low half-life value, meaured in days. :type value: float """ - self.params["sediment_low"] = float(value) + self.params["sediment_low"] = value def set_sediment_high(self, value): """ @@ -4689,7 +4726,7 @@ def set_sediment_high(self, value): :param value: The sediment high half-life value, meaured in days. :type value: float """ - self.params["sediment_high"] = float(value) + self.params["sediment_high"] = value def set_fit_ws(self, value): """ @@ -4726,8 +4763,8 @@ def set_source_ws(self, value): :param value: The source of the water and sediment half-life information. :type value: str """ - if value not in self.allowed_values: - raise ValueError(f"{value} is not an allowed source value") + # if value not in self.allowed_values: + # raise ValueError(f"{value} is not an allowed source value") self.params["source_ws"] = value # Getter @@ -4834,21 +4871,30 @@ def parse(cls, data_string): :rtype: HalfLifeWaterSedimentAdditionalInformation """ parts = data_string.split(';') - dt50_total = parts[3].split(' - ') - dt50_water = parts[4].split(' - ') - dt50_sediment = parts[5].split(' - ') + dt50_total = parts[3] + dt50_water = parts[4] + dt50_sediment = parts[5] + res = { 'model_ws': parts[0], 'fit_ws': parts[1], 'comment_ws': parts[2], - 'source_ws': parts[6], + 'total_low': float(dt50_total.split(' - ')[0].replace(",", ".")), + 'total_high': float(dt50_total.split(' - ')[1].replace(",", ".")), + 'source_ws': parts[6] + } - if not dt50_total: res.update({'total_low': float(dt50_total[0]), 'total_high': float(dt50_total[1])}) - if not dt50_water: res.update({'water_low': float(dt50_water[0]), 'water_high': float(dt50_water[1])}) - if not dt50_sediment: res.update({'sediment_low': float(dt50_sediment[0]), - 'sediment_high': float(dt50_sediment[1])}) + if dt50_water.strip() != '-': + res['water_low'] = float(dt50_water.split(' - ')[0].replace(",", ".")) + res['water_high'] = float(dt50_water.split(' - ')[1].replace(",", ".")) + + if dt50_sediment.strip() != '-': + res['sediment_low'] = float(dt50_sediment.split(' - ')[0].replace(",", ".")) + res['sediment_high'] = float(dt50_sediment.split(' - ')[1].replace(",", ".")) + + return cls(**res) @@ -4869,7 +4915,7 @@ def set_expHumid(self, value): :param value: The experimental humidity value, represented as a percentage. :type value: float """ - self.params["expHumid"] = float(value) + self.params["expHumid"] = value def set_humConditions(self, value): """ @@ -4935,7 +4981,7 @@ def set_initial_mass_sediment(self, value): :param value: The initial mass of sediment, measured in g. :type value: float """ - self.params["initial_mass_sediment"] = float(value) + self.params["initial_mass_sediment"] = value def set_wet_or_dry(self, value): """ @@ -4978,7 +5024,13 @@ def parse(cls, data_string): :return: An instance of InitialMassSedimentAdditionalInformation populated with the parsed data. :rtype: InitialMassSedimentAdditionalInformation """ - return cls._parse_default(data_string, ['initial_mass_sediment', 'wet_or_dry']) + parts = data_string.split(";") + res = { + "initial_mass_sediment": float(parts[0].replace(",", ".").replace("ca.", "")), + "wet_or_dry": parts[1] + } + + return cls(**res) class InitialVolumeWaterAdditionalInformation(AdditionalInformation): @@ -4998,7 +5050,7 @@ def set_initialvolumewater(self, value): :param value: The initial volume of water, measured in mL. :type value: float """ - self.params["initialvolumewater"] = float(value) + self.params["initialvolumewater"] = value # Getter def get_initialvolumewater(self): @@ -5022,7 +5074,10 @@ def parse(cls, data_string): :rtype: InitialVolumeWaterAdditionalInformation :raises ValueError: If the provided value is not a float. """ - return cls._parse_default(data_string, ['initialvolumewater']) + res = { + "initialvolumewater": float(data_string.replace(",", ".").replace("ca.", "")), + } + return cls(**res) class InitiatingOrganismAdditionalInformation(AdditionalInformation): @@ -5085,7 +5140,7 @@ def set_lagphase(self, value): :param value: The lag phase value, represented in minutes. :type value: float """ - self.params["lagphase"] = float(value) + self.params["lagphase"] = value # Getter def get_lagphase(self): @@ -5214,7 +5269,7 @@ def set_volatilettsStart(self, value): :param value: The start value of volatile TSS, measured in g/L. :type value: float """ - self.params["volatilettsStart"] = float(value) + self.params["volatilettsStart"] = value def set_volatilettsEnd(self, value): """ @@ -5223,7 +5278,7 @@ def set_volatilettsEnd(self, value): :param value: The end value of volatile TSS, measured in g/L. :type value: float """ - self.params["volatilettsEnd"] = float(value) + self.params["volatilettsEnd"] = value # Getter def get_volatilettsStart(self): @@ -5282,7 +5337,7 @@ def set_wst(self, value): :type value: float """ - self.params["wst"] = float(value) + self.params["wst"] = value def set_maximumWaterstoragecapacity(self, value): """ @@ -5292,7 +5347,7 @@ def set_maximumWaterstoragecapacity(self, value): :type value: float """ - self.params["maximumWaterstoragecapacity"] = float(value) + self.params["maximumWaterstoragecapacity"] = value def set_wstConditions(self, value): """ @@ -5528,7 +5583,7 @@ def set_bioreactorsize(self, value): :type value: float """ - self.params["bioreactorsize"] = float(value) + self.params["bioreactorsize"] = value # Getter def get_bioreactortype(self): @@ -5589,7 +5644,7 @@ def set_biomassStart(self, value): :param value: A numeric value representing the starting microbial biomass, measured in μg C/g soil """ - self.params["biomassStart"] = float(value) + self.params["biomassStart"] = value def set_biomassEnd(self, value): """ @@ -5597,7 +5652,7 @@ def set_biomassEnd(self, value): :param value: A numeric value representing the ending microbial biomass, measured in μg C/g soil """ - self.params["biomassEnd"] = float(value) + self.params["biomassEnd"] = value # Getter def get_biomassStart(self): @@ -5649,7 +5704,7 @@ def set_start_water_cells(self, value): :param value: The starting cell count for microbial biomass in water, measured in cells/mL. :type value: int """ - self.params["start_water_cells"] = float(value) + self.params["start_water_cells"] = value def set_end_water_cells(self, value): """ @@ -5658,7 +5713,7 @@ def set_end_water_cells(self, value): :param value: The ending cell count for microbial biomass in water, measured in cells/mL :type value: int """ - self.params["end_water_cells"] = float(value) + self.params["end_water_cells"] = value def set_start_sediment_cells(self, value): """ @@ -5667,7 +5722,7 @@ def set_start_sediment_cells(self, value): :param value: The starting cell count for microbial biomass in sediment, measured in cells/g. :type value: int """ - self.params["start_sediment_cells"] = float(value) + self.params["start_sediment_cells"] = value def set_end_sediment_cells(self, value): """ @@ -5676,7 +5731,7 @@ def set_end_sediment_cells(self, value): :param value: The ending cell count for microbial biomass in sediment, measured in cells/g. :type value: int """ - self.params["end_sediment_cells"] = float(value) + self.params["end_sediment_cells"] = value def set_start_sediment_mg(self, value): """ @@ -5685,7 +5740,7 @@ def set_start_sediment_mg(self, value): :param value: The starting microbial biomass mass in sediment, measured in mg C/g. :type value: float """ - self.params["start_sediment_mg"] = float(value) + self.params["start_sediment_mg"] = value def set_end_sediment_mg(self, value): """ @@ -5694,7 +5749,7 @@ def set_end_sediment_mg(self, value): :param value: The ending microbial biomass mass in sediment, measured in mg C/g. :type value: float """ - self.params["end_sediment_mg"] = float(value) + self.params["end_sediment_mg"] = value # Getter def get_start_water_cells(self): @@ -5769,15 +5824,16 @@ def parse(cls, data_string): for i in range(len(parts)): if parts[i] != "NA": vals = parts[i].split(" - ") + if i == 0: - res["start_water_cells"] = float(vals[0]) - res['end_water_cells'] = float(vals[1]) + res["start_water_cells"] = vals[0].replace(",", ".") + res['end_water_cells'] = vals[1].replace(",", ".") elif i == 1: - res["start_sediment_cells"] = float(vals[0]) - res['end_sediment_cells'] = float(vals[1]) + res["start_sediment_cells"] = vals[0].replace(",", ".") + res['end_sediment_cells'] = vals[1].replace(",", ".") elif i == 2: - res["start_sediment_mg"] = float(vals[0]) - res['end_sediment_mg'] = float(vals[1]) + res["start_sediment_mg"] = vals[0].replace(",", ".") + res['end_sediment_mg'] = vals[1].replace(",", ".") return cls(**res) @@ -5799,7 +5855,7 @@ def set_bulkdensity(self, value): :param value: The bulk density value, measured in g/cm3. :type value: float """ - self.params["bulkdensity"] = float(value) + self.params["bulkdensity"] = value # Getter def get_bulkdensity(self): @@ -5822,7 +5878,11 @@ def parse(cls, data_string): :return: An instance of BulkDensityAdditionalInformation populated with the parsed data. :rtype: BulkDensityAdditionalInformation """ - return cls._parse_default(data_string, ['bulkdensity']) + val = data_string + res = { + "bulkdensity": float(val.replace(",", ".")) + } + return cls(**res) class CECAdditionalInformation(AdditionalInformation): @@ -5842,7 +5902,7 @@ def set_cecdata(self, value): :param value: The cation exchange capacity data, measured in mEq/100g. :type value: float """ - self.params["cecdata"] = float(value) + self.params["cecdata"] = value # Getter def get_cecdata(self): @@ -5885,7 +5945,7 @@ def set_column_height_water(self, value): :param value: The column height in water, measured in cm. :type value: float """ - self.params["column_height_water"] = float(value) + self.params["column_height_water"] = value def set_column_height_sediment(self, value): """ @@ -5894,7 +5954,7 @@ def set_column_height_sediment(self, value): :param value: The column height in sediment, measured in cm. :type value: float """ - self.params["column_height_sediment"] = float(value) + self.params["column_height_sediment"] = value # Getter def get_column_height_water(self): @@ -5947,7 +6007,7 @@ def set_finalcompoundconcentration(self, value): :type value: float :raises ValueError: If the provided value is not a float. """ - self.params["finalcompoundconcentration"] = float(value) + self.params["finalcompoundconcentration"] = value # Getter def get_finalcompoundconcentration(self): @@ -6108,7 +6168,7 @@ def set_rateconstantlower(self, value): :param value: The lower rate constant value. :type value: float """ - self.params["rateconstantlower"] = float(value) + self.params["rateconstantlower"] = value def set_rateconstantupper(self, value): """ @@ -6117,7 +6177,7 @@ def set_rateconstantupper(self, value): :param value: The upper rate constant value. :type value: float """ - self.params["rateconstantupper"] = float(value) + self.params["rateconstantupper"] = value def set_rateconstantorder(self, value): """ @@ -6127,10 +6187,8 @@ def set_rateconstantorder(self, value): "Second order", "Pseudo first order". :type value: str """ - if value.lower().capitalize() not in self.allowed_order: - raise ValueError(f"{value} is not a permitted rateconstant order. " - f"Only permitted order are : {self.allowed_order}") - self.params["rateconstantorder"] = value.lower().capitalize() + + self.params["rateconstantorder"] = value def set_rateconstantcorrected(self, value): """ @@ -6140,9 +6198,9 @@ def set_rateconstantcorrected(self, value): "abiotic degradation corrected", "sorption corrected & abiotic degradation corrected". :type value: str """ - if value not in self.allowed_corrected: - raise ValueError(f"{value} is not a permitted rateconstant corrected. " - f"Only permitted order are : {self.allowed_corrected}") + # if value not in self.allowed_corrected: + # raise ValueError(f"{value} is not a permitted rateconstant corrected. " + # f"Only permitted order are : {self.allowed_corrected}") self.params["rateconstantcorrected"] = value def set_rateconstantcomment(self, value): @@ -6377,10 +6435,23 @@ def parse(cls, data_string): :rtype: SolventForCompoundSolutionAdditionalInformation """ solvents = data_string.split(';') - if len(solvents) == 1: return cls._parse_default(data_string, ["solventforcompoundsolution1"]) - res = {"proportion": solvents.pop(-1)} - for i in range(len(solvents)): - res['solventforcompoundsolution' + str(i+1)] = solvents[i] + if len(solvents) == 1: + res = { + 'solventforcompoundsolution1': solvents[0] + + } + if len(solvents) == 3: + res = { + 'solventforcompoundsolution1': solvents[0], + 'solventforcompoundsolution2': solvents[1], + 'proportion': solvents[2] + } + if len(solvents) == 4: + res = { + 'solventforcompoundsolution1': solvents[0], + 'solventforcompoundsolution2': solvents[1], + 'solventforcompoundsolution3': solvents[2], + 'proportion': solvents[3] } return cls(**res) @@ -6555,7 +6626,7 @@ def set_spikeConcentration(self, value): :param value: The spike concentration value. :type value: float """ - self.params["spikeConcentration"] = float(value) + self.params["spikeConcentration"] = value def set_spikeconcentrationUnit(self, value): """ @@ -6615,7 +6686,7 @@ def set_originalsludgeamount(self, value): :param value: The original sludge amount, measured in mL. :type value: float """ - self.params["originalsludgeamount"] = float(value) + self.params["originalsludgeamount"] = value # Getter def get_originalsludgeamount(self): @@ -6660,7 +6731,7 @@ def set_oxygen_content_water_low(self, value): :param value: The low oxygen content in water, measured in mg/L. :type value: float """ - self.params["oxygen_content_water_low"] = float(value) + self.params["oxygen_content_water_low"] = value def set_oxygen_content_water_high(self, value): """ @@ -6669,7 +6740,7 @@ def set_oxygen_content_water_high(self, value): :param value: The high oxygen content in water, measured in mg/L. :type value: float """ - self.params["oxygen_content_water_high"] = float(value) + self.params["oxygen_content_water_high"] = value def set_oxygen_content_sediment_low(self, value): """ @@ -6678,7 +6749,7 @@ def set_oxygen_content_sediment_low(self, value): :param value: The low oxygen content in sediment, given in percentage. :type value: float """ - self.params["oxygen_content_sediment_low"] = float(value) + self.params["oxygen_content_sediment_low"] = value def set_oxygen_content_sediment_high(self, value): """ @@ -6687,7 +6758,7 @@ def set_oxygen_content_sediment_high(self, value): :param value: The high oxygen content in sediment, given in percentage. :type value: float """ - self.params["oxygen_content_sediment_high"] = float(value) + self.params["oxygen_content_sediment_high"] = value # Getter def get_oxygen_content_water_low(self): @@ -6740,11 +6811,21 @@ def parse(cls, data_string): parts = data_string.split(";") res = {} - if parts[0] != 'NA': - res["oxygen_content_water_low"], res["oxygen_content_water_high"] = parts[0].split(" - ") - if parts[1] != 'NA': - res["oxygen_content_sediment_low"], res["oxygen_content_sediment_high"] = parts[1].split(" - ") - + for i, part in enumerate(parts): + if i == 0: + name = "water" + else: + name = "sediment" + if part == 'NA': + res[f"oxygen_content_{name}_low"] = 'NA' + res[f"oxygen_content_{name}_high"] = 'NA' + else: + low, high = part.split(" - ") + high = high.replace(',', '.') + low = low.replace(',', '.') + res[f"oxygen_content_{name}_low"] = float(high) if high != "NA" else 'NA' + res[f"oxygen_content_{name}_high"] = float(low) if low != "NA" else 'NA' + return cls(**res) @@ -6756,7 +6837,7 @@ class TypeOfAerationAdditionalInformation(AdditionalInformation): """ name = "typeofaeration" mandatories = ['typeofaeration'] - allowed_values = ["stirring", "shaking", "bubbling air", "bubbling air and stirring", "other"] + #allowed_values = ["stirring", "shaking", "bubbling air", "bubbling air and stirring", "other"] # Setter def set_typeofaeration(self, value): @@ -6767,8 +6848,8 @@ def set_typeofaeration(self, value): :param value: The type of aeration. :type value: str """ - if value not in self.allowed_values: - raise ValueError(f"The value {value} is not in the set of allowed values {self.allowed_values}") + # if value not in self.allowed_values: + # raise ValueError(f"The value {value} is not in the set of allowed values {self.allowed_values}") self.params["typeofaeration"] = value # Getter @@ -6804,7 +6885,7 @@ class AcidityAdditionalInformation(AdditionalInformation): """ name = "acidity" mandatories = ['lowPh'] - allowed_values = ['', 'WATER', 'KCL', 'CACL2', 'CACL₂'] + #allowed_values = ['', 'WATER', 'KCL', 'CACL2', 'CACL₂'] # Setter def set_lowPh(self, value): @@ -6814,7 +6895,7 @@ def set_lowPh(self, value): :param value: The low pH value. :type value: float """ - self.params["lowPh"] = float(value) + self.params["lowPh"] = value def set_highPh(self, value): """ @@ -6823,7 +6904,7 @@ def set_highPh(self, value): :param value: The high pH value. :type value: float """ - self.params["highPh"] = float(value) + self.params["highPh"] = value def set_acidityType(self, value): """ @@ -6832,8 +6913,8 @@ def set_acidityType(self, value): :param value: The type of acidity. Either '','WATER', 'KCL', 'CACL2'. :type value: str """ - if value.upper() not in self.allowed_values: - raise ValueError(f"The value {value} is not in the set of allowed values {self.allowed_values}") + # if value.upper() not in self.allowed_values: + # raise ValueError(f"The value {value} is not in the set of allowed values {self.allowed_values}") self.params["acidityType"] = value.upper() # Getter @@ -6909,7 +6990,7 @@ def set_pH_water_low(self, value): :param value: The low pH value for water. :type value: float """ - self.params["pH_water_low"] = float(value) + self.params["pH_water_low"] = value def set_pH_water_high(self, value): """ @@ -6918,7 +6999,7 @@ def set_pH_water_high(self, value): :param value: The high pH value for water. :type value: float """ - self.params["pH_water_high"] = float(value) + self.params["pH_water_high"] = value def set_pH_sediment_low(self, value): """ @@ -6927,8 +7008,7 @@ def set_pH_sediment_low(self, value): :param value: The low pH value for sediment. :type value: float """ - self.params["pH_sediment_low"] = float(value) - + self.params["pH_sediment_low"] = value def set_pH_sediment_high(self, value): """ Sets the high pH value for sediment. @@ -6936,7 +7016,7 @@ def set_pH_sediment_high(self, value): :param value: The high pH value for sediment. :type value: float """ - self.params["pH_sediment_high"] = float(value) + self.params["pH_sediment_high"] = value def set_acidityType(self, value): """ @@ -7089,7 +7169,7 @@ def set_lowPotentialWater(self, value): :param value: The low potential value for water, measured in mV. :type value: float """ - self.params["lowPotentialWater"] = float(value) + self.params["lowPotentialWater"] = value def set_highPotentialWater(self, value): """ @@ -7098,7 +7178,7 @@ def set_highPotentialWater(self, value): :param value: The high potential value for water, measured in mV. :type value: float """ - self.params["highPotentialWater"] = float(value) + self.params["highPotentialWater"] = value def set_lowPotentialSediment(self, value): """ @@ -7107,7 +7187,7 @@ def set_lowPotentialSediment(self, value): :param value: The low potential value for sediment, measured in mV. :type value: float """ - self.params["lowPotentialSediment"] = float(value) + self.params["lowPotentialSediment"] = value def set_highPotentialSediment(self, value): """ @@ -7116,7 +7196,7 @@ def set_highPotentialSediment(self, value): :param value: The high potential value for sediment, measured in mV. :type value: float """ - self.params["highPotentialSediment"] = float(value) + self.params["highPotentialSediment"] = value # Getter def get_lowPotentialWater(self): @@ -7230,7 +7310,7 @@ class SamplingDepthAdditionalInformation(AdditionalInformation): This class represents additional information about sampling depths. """ name = "samplingdepth" - mandatories = ["samplingDepthMin"] + mandatories = [] # "samplingDepthMin" # Setter def set_samplingDepthMin(self, value): @@ -7240,7 +7320,7 @@ def set_samplingDepthMin(self, value): :param value: The minimum sampling depth, measured in cm. :type value: float """ - self.params["samplingDepthMin"] = float(value) + self.params["samplingDepthMin"] = value def set_samplingDepthMax(self, value): """ @@ -7249,7 +7329,7 @@ def set_samplingDepthMax(self, value): :param value: The maximum sampling depth, measured in cm. :type value: float """ - self.params["samplingDepthMax"] = float(value) + self.params["samplingDepthMax"] = value # Getter def get_samplingDepthMin(self): @@ -7312,7 +7392,7 @@ def set_sedimentporosity(self, value): :param value: The sediment porosity. :type value: float """ - self.params["sedimentporosity"] = float(value) + self.params["sedimentporosity"] = value # Getter def get_sedimentporosity(self): @@ -7336,3 +7416,33 @@ def parse(cls, data_string): :rtype: SedimentPorosityAdditionalInformation """ return cls._parse_default(data_string, ['sedimentporosity']) + +class PFASManufacturingCategoryAdditionalInformation(AdditionalInformation): + """ + Creates a PFAS manufacturing category additional information object. + + This class represents additional information about the manufacturing category of PFAS. + """ + name = "pfasmanufacturingcategory" + mandatories = ["pfasmanufacturingcategory"] + allowed_values = ["Electrochemical Fluorination (ECF)", "Fluorotelomerization (FT)", "Other"] + + # Setter + def set_pfasmanufacturingcategory(self, value): + """ + Sets the PFAS manufacturing category. + + :param value: The PFAS manufacturing category. + :type value: str + """ + self.params["pfasmanufacturingcategory"] = value + + # Getter + def get_PFASmanufacturingcategory(self): + """ + Get the PFAS manufacturing category. + + :return: The PFAS manufacturing category, or None if not set. + :rtype: str or None + """ + return self.params.get("pfasmanufacturingcategory") \ No newline at end of file