Skip to content

Commit

Permalink
some tweaks to allow Opx equilibrium + testing PyPI for Diadfit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
PennyWieser committed Sep 5, 2024
1 parent d286b53 commit 383807c
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Thermobar/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# 1) we don't load dependencies by storing it in __init__.py
# 2) we can import it in setup.py for the same reason
# 3) we can import it into your module
__version__ = '1.0.45dev'
__version__ = '1.0.46'
51 changes: 32 additions & 19 deletions src/Thermobar/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def import_lepr_file(filename):


# Loading Excel, returns a disctionry
def import_excel(file_name, sheet_name, path=None, sample_label=None, GEOROC=False, suffix=None):
def import_excel(file_name, sheet_name, path=None, sample_label=None, GEOROC=False, suffix=None, df=None):
'''
Import excel sheet of oxides in wt%, headings should be of the form SiO2_Liq (for the melt/liquid), SiO2_Ol (for olivine comps), SiO2_Cpx (for clinopyroxene compositions). Order doesn't matter
Expand All @@ -321,6 +321,9 @@ def import_excel(file_name, sheet_name, path=None, sample_label=None, GEOROC=Fa
filename: str
specifies the file name (e.g., Python_OlLiq_Thermometers_Test.xlsx)
OR
enter a dataframe instead of an excel file.
Optional:
path: provide a pathlib path to where the file is stored
Expand All @@ -344,25 +347,30 @@ def import_excel(file_name, sheet_name, path=None, sample_label=None, GEOROC=Fa
Amps=pandas dataframe of amphibole oxides
Sps=pandas dataframe of spinel oxides
'''
if path is not None:
file_path = Path(path) / file_name
else:
file_path = Path(file_name)

# Convert to string if needed
if isinstance(file_path, Path):
file_path = str(file_path)
if df is None:

# Check the file extension and read the file accordingly
if file_path.endswith('.csv'):
my_input = pd.read_csv(file_path)
elif file_path.endswith(('.xls', '.xlsx')):
if sheet_name is not None:
my_input = pd.read_excel(file_path, sheet_name=sheet_name)
if path is not None:
file_path = Path(path) / file_name
else:
my_input = pd.read_excel(file_path)
file_path = Path(file_name)

# Convert to string if needed
if isinstance(file_path, Path):
file_path = str(file_path)

# Check the file extension and read the file accordingly
if file_path.endswith('.csv'):
my_input = pd.read_csv(file_path)
elif file_path.endswith(('.xls', '.xlsx')):
if sheet_name is not None:
my_input = pd.read_excel(file_path, sheet_name=sheet_name)
else:
my_input = pd.read_excel(file_path)
else:
raise ValueError(f"Unsupported file extension: {Path(file_path).suffix}")
else:
raise ValueError(f"Unsupported file extension: {Path(file_path).suffix}")
my_input=df


if any(my_input.columns.str.startswith(' ')):
Expand Down Expand Up @@ -437,11 +445,16 @@ def import_excel(file_name, sheet_name, path=None, sample_label=None, GEOROC=Fa


# myLabels=my_input.Sample_ID
duplicates = df_ideal_exp.columns[df_ideal_exp.columns.duplicated()]

# If duplicates are found, return them to the user
if not duplicates.empty:
print("Duplicate columns found:", duplicates)
return "Duplicate columns detected. Please handle them before reindexing."

# Proceed with reindexing if no duplicates are found
Experimental_press_temp1 = my_input.reindex(df_ideal_exp.columns, axis=1)
# This deals with the fact almost everyone will enter as FeO, but the code uses FeOt for these minerals.
# E.g., if users only enter FeO (not FeOt and Fe2O3), allocates a FeOt
# column. If enter FeO and Fe2O3, put a FeOt column



if GEOROC is True:
Expand Down
81 changes: 81 additions & 0 deletions src/Thermobar/mineral_equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,87 @@ def calculate_eq_ol_content(liq_comps, Kd_model, ol_comps=None, T=None, P=None,

return Kd_out

## Same for Orhopyroxene
def calculate_eq_px_content(liq_comps,
Fe3Fet_Liq=None, px='Opx'):
'''calculates equilibrium pyroxene contents based on inputtted liquid compositions.
Parameters
-------
liq_comps: pandas.DataFrame
Liquid compositions with column headings SiO2_Ol, MgO_Ol etc.
px: 'Opx' or 'Cpx'
Fe3FeT: optional, float or int.
overwrites Fe3Fet_Liq in liq_comps DataFrame
Returns
-------
pandas DataFrame
returns equilibrium Px Mg#s (+- sigma) from Putirka 2008
'''
liq_comps_c=liq_comps.copy()
if Fe3Fet_Liq is not None:
liq_comps_c['Fe3Fet_Liq'] = Fe3Fet_Liq


liq = calculate_anhydrous_cat_fractions_liquid(liq_comps_c)
Mgno = liq['Mg_Number_Liq_Fe3']
Mgno_noFe3 = liq['Mg_Number_Liq_NoFe3']




if px == 'Opx':

# These values are 0.29+0-.06, which is from Putirka, He also gives an expression in terms of the si content of the liquid.

Eq_023 = 1 / ((0.23 / Mgno) + (1 - 0.23))
Eq_029 = 1 / ((0.29 / Mgno) + (1 - 0.29))
Eq_035 = 1 / ((0.35 / Mgno) + (1 - 0.35))


# Or calculating as a function of the Si content.
cat_frac = calculate_anhydrous_cat_fractions_liquid(liq_comps_c)
Si_mean_frac = np.nanmean(cat_frac['Si_Liq_cat_frac'])
Kd = 0.4805 - 0.3733 * Si_mean_frac
Eq_Opx = 1 / ((Kd / Mgno) + (1 - Kd))
Kd_p_1_s = Kd + 0.06
Kd_m_1_s = Kd - 0.06
Eq_Opx_p1sigma = 1 / ((Kd_p_1_s / Mgno) + (1 - Kd_p_1_s))
Eq_Opx_m1sigma = 1 / ((Kd_m_1_s / Mgno) + (1 - Kd_m_1_s))


Kd_out= pd.DataFrame(data={'Kd_XSi_P2008': Kd,
'Eq_Opx_Mg# (Kd_XSi_P2008)': Eq_Opx,
'Eq_Opx_Mg# (Kd_XSi_P2008)+0.06': Eq_Opx_p1sigma,
'Eq_Opx_Mg# (Kd_XSi_P2008)-0.06': Eq_Opx_m1sigma,
'Eq_Opx_Mg# (Kd=0.23)': Eq_023,
'Eq_Opx_Mg# (Kd=0.29)': Eq_029,
'Eq_Opx_Mg# (Kd=0.35)': Eq_035

})





Kd_out.insert(0, 'Mg#_Liq_Fe2', Mgno)
Kd_out.insert(1, 'Mg#_Liq_Fet', Mgno_noFe3)


return Kd_out

if px == 'Cpx':
raise TypeError('Penny still needs to add this, if you need it , please message me!')



def calculate_ol_rhodes_diagram_lines(
Min_Mgno, Max_Mgno, KdMin=None, KdMax=None):
Expand Down

0 comments on commit 383807c

Please sign in to comment.