Skip to content

Commit

Permalink
IC to DIC. Labels on figures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ge0rges committed Apr 11, 2023
1 parent 15da3da commit b69eb4c
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
Binary file not shown.
Binary file modified Results/all_model_outputs.pdf
Binary file not shown.
Binary file modified Results/all_model_outputs_just_cells.pdf
Binary file not shown.
Binary file modified Results/hypothetical_growth.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def run_model(scenario: Scenario):
result = ModelResult()
result.pOC = P
result.dOC = D
result.IC = I
result.DIC = I
result.cells = N
result.t = t

Expand Down
4 changes: 2 additions & 2 deletions model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function run_model(p, u0)
prob = ODEProblem(model, u0[1:end-1], (0.0, last(u0)), p)
sol = solve(prob, Rosenbrock23(), callback=cbs, maxiters=1e6)

# Return the solution array - [pOC, dOC, IC, Cells, t]
# Return the solution array - [pOC, dOC, DIC, Cells, t]
return [[x[1] for x in sol.u], [x[2] for x in sol.u], [x[3] for x in sol.u], [x[4] for x in sol.u], sol.t]
end

Expand Down Expand Up @@ -88,7 +88,7 @@ function make_callbacks(;sensitivity_analysis=false, p=nothing)
eea_min_condition(u, t, integrator) = integrator.p[10] * u[4] - u[1]
eea_min_cb = ContinuousCallback(eea_min_condition, do_nothing)

# Min condition for IC fixation rate
# Min condition for DIC fixation rate
ic_min_condition(u, t, integrator) = integrator.p[8] - u[3]
ic_min_cb = ContinuousCallback(ic_min_condition, do_nothing)

Expand Down
16 changes: 10 additions & 6 deletions plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def plot_one_analysis(analysis: Analysis):
"""
# Make seaborn data frame
data = analysis.model_result.get_dataframe(analysis.scenario.title, analysis._variable_title)
melted = pd.melt(data, id_vars="Years from start", value_vars=("POC", "DOC", "IC", "Cells"), var_name="Variable",
melted = pd.melt(data, id_vars="Years from start", value_vars=("POC", "DOC", "DIC", "Cells"), var_name="Variable",
value_name="femtograms C/mL or cells/mL")

# Make figure
Expand Down Expand Up @@ -61,7 +61,7 @@ def plot_all_scenarios_all_analyses(analyses: [Analysis], color_cycle: int = Non
all_data = pd.concat([all_data, data]).reset_index(drop=True)

melted_data = all_data.melt(id_vars=["Years from start", "Scenario", "Analysis type"],
value_vars=["POC", "DOC", "IC", "Cells"], var_name="Data type")
value_vars=["POC", "DOC", "DIC", "Cells"], var_name="Data type")

# Plot
grid = sns.relplot(data=melted_data, x="Years from start", y="value", palette=cp, aspect=1,
Expand Down Expand Up @@ -91,8 +91,12 @@ def plot_all_scenarios_all_analyses(analyses: [Analysis], color_cycle: int = Non
ax.set_ylim(lim)
ax.set_xlim([0.01, 10 ** 5])

# Add panel title to row
if i % 4 == 0:
ax.text(-0.1, 1.1, string.ascii_uppercase[i//4], tr ansform=ax.transAxes, size=20, weight='bold')

grid.tight_layout()
grid.fig.subplots_adjust(hspace=0.2, wspace=0.4)
grid.fig.subplots_adjust(hspace=0.3, wspace=0.4)

return grid

Expand All @@ -118,7 +122,7 @@ def plot_multiple_scenarios_one_row(analyses: [Analysis], color_cycle: int = Non
all_data = pd.concat([all_data, data]).reset_index(drop=True)

melted_data = all_data.melt(id_vars=["Years from start", "Scenario", "Analysis type"],
value_vars=["POC", "DOC", "IC", "Cells"], var_name="Data type")
value_vars=["POC", "DOC", "DIC", "Cells"], var_name="Data type")

# Plot
grid = sns.relplot(data=melted_data, x="Years from start", y="value", palette=cp, aspect=1,
Expand Down Expand Up @@ -190,7 +194,7 @@ def plot_one_result_type_all_analyses(analyses: [Analysis], data_type: str, main
ax.text(-0.1, 1.1, string.ascii_uppercase[i], transform=ax.transAxes, size=20, weight='bold')

grid.tight_layout()
grid.fig.subplots_adjust(wspace=0.4)
grid.fig.subplots_adjust(wspace=0.2)

return grid

Expand Down Expand Up @@ -243,7 +247,7 @@ def hypothetical_growth_scenarios():
y_rapid = 10**5 + 10**8 / (1 + np.exp(-(x-10)))
y_cyclic = 10**5 + (10**8 - 10**5)/2 + np.sin(x/4244.1333333333 + 1.5*np.pi) * (10**8 - 10**5)/2

axis.loglog(x, y_ng, label='No growth', color="brown", linestyle='dashed')
axis.loglog(x, y_ng, label='No growth', color="purple", linestyle='dashed')
axis.loglog(x, y_slow, label='Slow growth', color="green")
axis.loglog(x, y_rapid, label='Rapid growth, no decline', color="blue")
axis.loglog(x, y_cyclic, label='Growth, decline, OC added', color="red")
Expand Down
10 changes: 5 additions & 5 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SensitivityResult:
first_order_sobol_indices: [float] = None
total_conf_int: [[float]] = None
first_order_conf_int: [[float]] = None
variables: [str] = ["POC", "DOC", "IC", "Cells", "Mean"]
variables: [str] = ["POC", "DOC", "DIC", "Cells", "Mean"]

def get_dataframe(self, scenario):
"""
Expand Down Expand Up @@ -74,21 +74,21 @@ class ModelResult:
"""
pOC: [float] = None
dOC: [float] = None
IC: [float] = None
DIC: [float] = None
cells: [float] = None
t: [float] = None

def get_dataframe(self, scenario, variable_title):
"""
Returns model results as a dataframe. Removes duplicate values (e.g. discontinuities).
"""
data = [self.t/365.25, self.pOC, self.dOC, self.IC, self.cells, [scenario]*len(self.t), [variable_title]*len(self.t)]
data = [self.t/365.25, self.pOC, self.dOC, self.DIC, self.cells, [scenario]*len(self.t), [variable_title]*len(self.t)]
df = pandas.DataFrame(data=np.column_stack(data),
columns=["Years from start", "POC", "DOC", "IC", "Cells", "Scenario", "Analysis type"])
columns=["Years from start", "POC", "DOC", "DIC", "Cells", "Scenario", "Analysis type"])

df.drop_duplicates(subset=["Years from start", "Scenario", "Analysis type"], keep="last", inplace=True)

return df.astype({"Years from start": float, "POC": float, "DOC": float, "IC": float, "Cells": float,
return df.astype({"Years from start": float, "POC": float, "DOC": float, "DIC": float, "Cells": float,
"Scenario": str, "Analysis type": str})


Expand Down

0 comments on commit b69eb4c

Please sign in to comment.