Skip to content

Commit

Permalink
generalized plateau cuts
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogila committed Oct 18, 2024
1 parent 2906a32 commit fc13715
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion maat/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'''


version = 'v2.0.2'
version = 'v2.1.0'


#############################
Expand Down
4 changes: 2 additions & 2 deletions maat/deuteration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def impulse_approx(ins: Spectra,
ins.dataframe[H_df_index][ins.dataframe[H_df_index].columns[1]] = ins.dataframe[H_df_index][ins.dataframe[H_df_index].columns[1]]
ins.dataframe[D_df_index][ins.dataframe[D_df_index].columns[1]] = ins.dataframe[D_df_index][ins.dataframe[D_df_index].columns[1]]

plateau_H, plateau_H_error = plateau(ins, threshold, None, H_df_index)
plateau_D, plateau_D_error = plateau(ins, threshold, None, D_df_index)
plateau_H, plateau_H_error = plateau(ins, [threshold, None], H_df_index)
plateau_D, plateau_D_error = plateau(ins, [threshold, None], D_df_index)

plateau_H_normalized = plateau_H / material_H.mols
plateau_H_normalized_error = plateau_H_normalized * np.sqrt((plateau_H_error / plateau_H)**2 + (material_H.mols_error / material_H.mols)**2)
Expand Down
27 changes: 23 additions & 4 deletions maat/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,35 @@
from .classes import *
import scipy
import numpy as np
from copy import deepcopy


'''
This module contains functions for fitting and analyzing data.
'''


def plateau(spectra:Spectra, low_cut:float, top_cut:float, df_index:int=0):
'''Fit the mean value of a plateau and its standard deviation.'''
df = spectra.dataframe[df_index]
def plateau(spectra:Spectra, cuts, df_index:int=0):
'''
Fit the mean value of a plateau and its standard deviation.\n
`mt.fit.plateau(spectra, cuts=[low_cut, high_cut], df_index=0)`\n
`cuts`, `low_cut` and/or `top_cut` can be set to None.
'''
df = deepcopy(spectra.dataframe[df_index])
if isinstance(cuts, list):
low_cut = cuts[0]
if len(cuts) > 1:
top_cut = cuts[1]
else:
top_cut = None
elif isinstance(cuts, float): # If cuts is a float, it is considered as low_cut
low_cut = cuts
top_cut = None
elif cuts is None:
low_cut = None
top_cut = None
else:
raise ValueError("plateau: cuts must be a float for the low_cut, or a list")
if low_cut is not None:
df = df[df[df.columns[0]] >= low_cut]
if top_cut is not None:
Expand Down Expand Up @@ -45,7 +64,7 @@ def area_under_peak(spectra:Spectra, peak:list, df_index:int=0, errors_as_in_bas
baseline = peak[2] if len(peak) >= 3 else 0.0
baseline_error = peak[3] if len(peak) >= 4 else 0.0

df = spectra.dataframe[df_index]
df = deepcopy(spectra.dataframe[df_index])
df_range = df[(df[df.columns[0]] >= xmin) & (df[df.columns[0]] <= xmax)]
x = df_range[df.columns[0]].to_numpy()
y = df_range[df.columns[1]].to_numpy()
Expand Down
2 changes: 1 addition & 1 deletion maat/plot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .classes import *
from . import tools
from . import normalize


'''This module manages the plotting of data.'''
Expand Down

0 comments on commit fc13715

Please sign in to comment.