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

setting up na_screening analysis and linting of data scripts #30

Merged
merged 3 commits into from
Jul 2, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.py[cod]
*.egg-info
*.eggs
*.ipynb_checkpoint/

dist
.cache
Expand Down
3 changes: 3 additions & 0 deletions mibipret/analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""mibipret module for data analysis."""


3 changes: 3 additions & 0 deletions mibipret/analysis/sample/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""mibipret module for data analysis performed on each sample."""


141 changes: 141 additions & 0 deletions mibipret/analysis/sample/properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Properties for Natural Attenuation Screening.

File containing name specifications of quantities and parameters measured in
groundwater samples useful for biodegredation and bioremediation analysis

@author: A. Zech
"""
from mibipret.data.names import name_benzene
from mibipret.data.names import name_ethylbenzene
from mibipret.data.names import name_indane
from mibipret.data.names import name_indene
from mibipret.data.names import name_ironII
from mibipret.data.names import name_naphthalene
from mibipret.data.names import name_nitrate
from mibipret.data.names import name_o_xylene
from mibipret.data.names import name_oxygen
from mibipret.data.names import name_pm_xylene
from mibipret.data.names import name_sulfate
from mibipret.data.names import name_toluene
from mibipret.data.names import name_xylene

#name_phosphate,name_nitrite
#name_sulfide,name_ammonium,name_methane,name_manganese,

properties = dict()

properties[name_benzene]=dict(
chemical_formula = 'c6h6',
molecular_mass = 78.,
cs = 6,
factor_stoichiometry = 30.,
thresholds_for_intervention_NL = 30,
other_names = ["Benzene", "benzene", "C6H6", "c6h6", "Benzeen", "benzeen", "Benzol", "benzol"],
)

properties[name_toluene]=dict(
chemical_formula = 'c6h5ch3',
molecular_mass = 106.,
cs = 7.,
factor_stoichiometry = 36.,
thresholds_for_intervention_NL = 1000,
other_names = ["toluene", "Toluene","Tolueen", "tolueen", "C7H8", "c7h8","C6H5CH3",'c6h5ch3'],
)

properties[name_ethylbenzene]=dict(
chemical_formula = 'c6h5ch2ch3',
molecular_mass = 106.,
cs = 8.,
factor_stoichiometry = 42.,
thresholds_for_intervention_NL = 150.,
other_names = ["C6H5CH2CH3","c6h5ch2ch3","ethylbenzene","Ethylbenzene","ethylbenzeen","Ethylbenzeen"],
)

properties[name_pm_xylene]=dict(
chemical_formula = "c6h4ch3ch3",
molecular_mass = 106.,
cs = 8.,
factor_stoichiometry = 42.,
thresholds_for_intervention_NL = 70.,
other_names = ["pm-xylene","PM-Xylene","pm_xylene","PM_Xylene","p/m xylene","P/M Xylene", "c6h4ch3ch3",\
"C6H4CH3CH3","c6h4c2h6","C6H4C2H6","c8h14","C8H14"],
)

properties[name_o_xylene]=dict(
chemical_formula = "c6h4ch3ch3" ,
molecular_mass = 106.,
cs = 8.,
factor_stoichiometry = 42.,
thresholds_for_intervention_NL = 70.,
other_names = ["o-xylene", "O-Xylene", "O xylene", "O Xylene", "c6h4ch3ch3","C6H4CH3CH3","c6h4c2h6",\
"C6H4C2H6","c8h14","C8H14"],
)

properties[name_xylene]=dict(
chemical_formula = "c6h4ch3ch3",
molecular_mass = 106.,
cs = 8.,
factor_stoichiometry = 42.,
thresholds_for_intervention_NL = 70.,
other_names = ["xylene", "Xylene", "c6h4ch3ch3","C6H4CH3CH3","c6h4c2h6","C6H4C2H6","c8h14","C8H14"],
)

properties[name_indene]=dict(
chemical_formula = "c9h8",
molecular_mass = 116.,
cs = 9.,
factor_stoichiometry = 44.,
thresholds_for_intervention_NL = 70.,
other_names = ["indene", "Indene", "c9h8", "C9H8"],
)

properties[name_indane]=dict(
chemical_formula = "c9h10",
molecular_mass = 118.,
cs = 9.,
factor_stoichiometry = 46.,
thresholds_for_intervention_NL = 70.,
other_names = ["indane", "Indane", "c9h10", "C9H10"],
)

properties[name_naphthalene]=dict(
chemical_formula = "c10h8",
molecular_mass = 128,
cs = 10.,
factor_stoichiometry = 48.,
thresholds_for_intervention_NL = 70.,
other_names = ["naphthalene","Naphthalene","c10h8","C10H8"],
)

properties[name_oxygen]=dict(
chemical_formula = 'o2',
molecular_mass = 32.,
factor_stoichiometry = 4.,
other_names = ["oxygen","Oxygen","o2","O2"] ,
)

properties[name_nitrate]=dict(
chemical_formula = 'no3',
molecular_mass = 62.,
factor_stoichiometry = 5.,
other_names = ["nitrate","Nitrate","NO3","no3"],
)
properties[name_sulfate]=dict(
chemical_formula = "so42-",
molecular_mass = 96.1,
factor_stoichiometry = 8.,
other_names = ["sulfate", "Sulfate","so4", "so42-", "SO4", "SO42-"],
)
properties[name_ironII]=dict(
chemical_formula = "fe2+",
molecular_mass = 106.,
factor_stoichiometry = 1,
other_names = ["Iron","iron","Fe","fe","Fe II","fe II","FeII","feII",\
"Fe_II","fe_II","Fe2",'fe2',"Fe 2","fe 2","Fe_2","fe_2",\
"Fe2+",'fe2+',"Fe 2+","fe 2+","Iron2","iron2","Iron 2",\
"iron 2","Iron2+","iron2+","Iron 2+","iron 2+","IronII",\
"ironII","Iron II","iron II"],
)

59 changes: 59 additions & 0 deletions mibipret/analysis/sample/screening_NA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Routines for calculating natural attenuation potential.

@author: alraune
"""

import pandas as pd
import mibipret.data.names as ean
from .properties import properties


def reductors(
data,
verbose = True,
**kwargs,
):
"""Calculate the amount of electron reductors [mmol e-/l].

making use of imported molecular mass values for quantities in [mg/mmol]

Input
-----
electron_acceptors: dict
concentration values of electron acceptors in [mg/l]

Output
------
tot_reduct: float
Total amount of electrons needed for reduction in [mmol e-/l]
"""
tot_reduct = 0.
if isinstance(data, pd.DataFrame):
cols = data.columns.to_list()
elif isinstance(data, pd.Series):
cols = [data.name]
else:
raise ValueError("Calculation of total amount of electron reductors \
not possible with given data. Data has to be a \
panda-DataFrame or Series but is given as \
type {}".format(type(data)))

for ea in [ean.name_oxygen,ean.name_nitrate, ean.name_sulfate, ean.name_ironII]:

if ea in cols:
tot_reduct += properties[ea]['factor_stoichiometry']* \
pd.to_numeric(data[ea]) / properties[ea]['molecular_mass']

else:
print("WARNING: No data on {} given, zero concentration assumed.".format(ea))

if isinstance(tot_reduct, float):
print("\nWARNING: No data on electron acceptor concentrations given.")
return False
elif isinstance(tot_reduct, pd.Series):
tot_reduct.rename("total_reductors",inplace = True)
if verbose:
print("Total amount of electron reductors per column in [mmol e-/l] is:\n{}".format(tot_reduct))
return tot_reduct
Loading
Loading