Skip to content

Commit

Permalink
Merge pull request #47 from cljdevitre/main
Browse files Browse the repository at this point in the history
Added RelaxiFi v0.0.4 to DiadFit, and modified densimeter_fitting.py to allow specifying column names and plotting x and y errors.
  • Loading branch information
PennyWieser authored Oct 13, 2023
2 parents c525250 + fb7236a commit 9e1e5da
Show file tree
Hide file tree
Showing 8 changed files with 991 additions and 15 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/DiadFit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

from DiadFit.molar_gas_proportions import *

from DiadFit.relaxifi import *

# version
from ._version import __version__

Expand Down
37 changes: 22 additions & 15 deletions src/DiadFit/densimeter_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,33 +58,40 @@ def calculate_generic_std_err_values(*, pickle_str, new_x, CI=0.67):

return df

def plot_and_save_CO2cali_pickle(*, cali_data, density_range, N_poly=3, CI=0.67, std_error=True, save_fig=False):
def plot_and_save_CO2cali_pickle(*, cali_data, CO2_dens_col='rho',Split_col='Split', split_error='split_err',CO2_dens_error='dens_err', density_range, N_poly=3, CI=0.67, std_error=True, save_fig=False):
# Define the x and y values
try:
if density_range == 'Low':
cali_data = cali_data[cali_data['rho'] < 0.17]
# print(np.min(cali_data['Split']))
# print(np.max(cali_data['Split']))
cali_data = cali_data[cali_data[CO2_dens_col] < 0.17]

prefix='Lowrho_'
elif density_range == 'Medium':
cali_data = cali_data[cali_data['rho'].between(0.12, 0.72)]
# print(np.min(cali_data['Split']))
# print(np.max(cali_data['Split']))
cali_data = cali_data[cali_data[CO2_dens_col].between(0.12, 0.72)]

prefix='Mediumrho_'
elif density_range == 'High':
cali_data = cali_data[cali_data['rho'] > 0.65]
# print(np.min(cali_data['Split']))
# print(np.max(cali_data['Split']))
cali_data = cali_data[cali_data[CO2_dens_col] > 0.65]

prefix='Highrho_'
else:
raise ValueError("Invalid density range. Please choose 'Low', 'Medium', or 'High'.")
except ValueError as e:
print(f"Warning: {e}")
return

x_all = cali_data['Split'].values
y_all = cali_data['rho'].values
x_err=cali_data['spliterr'].values
x_all = cali_data[Split_col].values
y_all = cali_data[CO2_dens_col].values

if not isinstance(split_error,str)==True:
x_err=pd.Series(split_error, index=cali_data[CO2_dens_col].index).values
else:
x_err=cali_data[split_error].values

if not isinstance(CO2_dens_error,str)==True:
y_err=pd.Series(CO2_dens_error, index=cali_data[CO2_dens_col].index).values
else:
y_err=cali_data[CO2_dens_error].values

non_nan_indices = ~np.isnan(x_all) & ~np.isnan(y_all)

# Filter out NaN values
Expand Down Expand Up @@ -119,8 +126,8 @@ def plot_and_save_CO2cali_pickle(*, cali_data, density_range, N_poly=3, CI=0.67,

# Now lets plot the confidence interval
fig, (ax1) = plt.subplots(1, 1, figsize=(10,5))
ax1.errorbar(x, y, xerr=x_err,
fmt='o', ecolor='k', elinewidth=0.8, mfc='grey', ms=5, mec='k',capsize=3,barsabove=True)
ax1.errorbar(x, y, xerr=x_err,yerr=y_err,
fmt='o', ecolor='grey', elinewidth=0.8, mfc='grey', ms=5, mec='k',capsize=3,barsabove=True)

ax1.plot(new_x_plot, new_calidf['preferred_values'], '-k', label=legend_label)
# ax1.plot(new_x_plot, new_calidf['lower_values'], ':k', label='lower vals')
Expand Down
Loading

0 comments on commit 9e1e5da

Please sign in to comment.