def load_and_plot_results():
    # %% Plot and save as PDF
    # This set subsequent plots to the glotaran style
    plot_style = PlotStyle()
    plt.rc("axes", prop_cycle=plot_style.cycler)

    parameter_file = output_folder.joinpath("optimized_parameters.csv")
    parameters = read_parameters_from_csv_file(str(parameter_file))
    print(f"Optimized parameters loaded:\n {parameters}")

    result1 = output_folder.joinpath("dataset1.nc")
    fig1 = plot_overview(result1, linlog=True, show_data=True)
    timestamp = datetime.today().strftime("%y%m%d_%H%M")
    fig1.savefig(output_folder.joinpath(f"plot_overview_1of2_{timestamp}.pdf"),
                 bbox_inches="tight")

    result2 = output_folder.joinpath("dataset2.nc")
    fig2 = plot_overview(result2, linlog=True)
    timestamp = datetime.today().strftime("%y%m%d_%H%M")
    fig2.savefig(output_folder.joinpath(f"plot_overview_2of2_{timestamp}.pdf"),
                 bbox_inches="tight")
    plt.show()
示例#2
0
)
# optimize
result = optimize(scheme)
# %% Save results
result.save(str(output_folder))

# %% Plot results
# Set subsequent plots to the glotaran style
plot_style = PlotStyle()
plt.rc("axes", prop_cycle=plot_style.cycler)

# TODO: enhance plot_overview to handle multiple datasets
result_datafile1 = output_folder.joinpath("dataset1.nc")
result_datafile2 = output_folder.joinpath("dataset2.nc")
result_datafile3 = output_folder.joinpath("dataset3.nc")
fig1 = plot_overview(result_datafile1, linlog=True, linthresh=1)
fig1.savefig(
    output_folder.joinpath("plot_overview_sim3d_d1.pdf"),
    bbox_inches="tight",
)

fig2 = plot_overview(result_datafile2, linlog=True, linthresh=1)
fig2.savefig(
    output_folder.joinpath("plot_overview_sim3d_d2.pdf"),
    bbox_inches="tight",
)

fig3 = plot_overview(result_datafile3, linlog=True, linthresh=1)
fig3.savefig(
    output_folder.joinpath("plot_overview_sim3d_d3.pdf"),
    bbox_inches="tight",
示例#3
0
        save_result(result_path=str(output_folder),
                    result=result,
                    format_name="yml",
                    allow_overwrite=True)
    except FileExistsError as error:
        print(f"catching error: {error}")
        timestamp = datetime.today().strftime("%y%m%d_%H%M")
        save_result(
            result_path=str(output_folder.joinpath(timestamp)),
            result=result,
            format_name="yml",
            allow_overwrite=True,
        )

# %% Plot and save as PDF
# This set subsequent plots to the glotaran style
plot_style = PlotStyle()
plt.rc("axes", prop_cycle=plot_style.cycler)

fig1 = plot_overview(result.data["dataset1"], linlog=True)
timestamp = datetime.today().strftime("%y%m%d_%H%M")
fig1.savefig(output_folder.joinpath(f"plot_overview_1of2_{timestamp}.pdf"),
             bbox_inches="tight")

fig2 = plot_overview(result.data["dataset2"], linlog=True)
timestamp = datetime.today().strftime("%y%m%d_%H%M")
fig2.savefig(output_folder.joinpath(f"plot_overview_2of2_{timestamp}.pdf"),
             bbox_inches="tight")

plt.show()
result.save(str(output_folder))
# evt plotten
# %% Set subsequent plots to the glotaran style
plot_style = PlotStyle()
plt.rc("axes", prop_cycle=plot_style.cycler)

# %%
# TODO: enhance plot_overview to handle multiple datasets
result_datafile1 = output_folder.joinpath("dataset1.nc")
result_datafile2 = output_folder.joinpath("dataset2.nc")
result_datafile3 = output_folder.joinpath("dataset3.nc")
result_datafile4 = output_folder.joinpath("dataset4.nc")
result_datafile5 = output_folder.joinpath("dataset5.nc")
result_datafile6 = output_folder.joinpath("dataset6.nc")
fig1 = plot_overview(result_datafile1, linlog=True, linthresh=5)
fig1.savefig(
    output_folder.joinpath("plot_overview_dummy1.pdf"),
    bbox_inches="tight",
)

fig2 = plot_overview(result_datafile2, linlog=True, linthresh=5)
fig2.savefig(
    output_folder.joinpath("plot_overview_dummy2.pdf"),
    bbox_inches="tight",
)

fig3 = plot_overview(result_datafile3, linlog=True, linthresh=5)
fig3.savefig(
    output_folder.joinpath("plot_overview_dummy3.pdf"),
    bbox_inches="tight",
    # %%
    start = timer()
    # Warning: this may take a while (several seconds per iteration)
    result = optimize(scheme, verbose=True)
    end = timer()
    print(f"Total time: {end - start}")

    result.save(str(output_folder))
    end2 = timer()
    print(f"Saving took: {end2 - end}")

    # %%
    print(result.markdown(True))

    # %%
    res = result.data["dataset1"]
    # Tip: print the xarray object to explore its content
    print(res)

# %% Set subsequent plots to the glotaran style
plot_style = PlotStyle()
plt.rc("axes", prop_cycle=plot_style.cycler)

# %%
fig = plot_overview(result_datafile, linlog=False)
# note species concentration plot still needs work to match styles between the two locatable axis

# %%
fig.savefig(output_folder.joinpath(f"plot_overview_{result_name}.pdf"),
            bbox_inches="tight")
parameters = read_parameters_from_yaml_file(
    script_folder.joinpath(PARAMETERS_FILE_PATH))

# %% Validate model and parameters
print(model.validate(parameters=parameters))

# %% Construct the analysis scheme
scheme = Scheme(model,
                parameters, {"dataset1": dataset},
                maximum_number_function_evaluations=10)

# %% Optimize the analysis scheme (and estimate parameters)
result = optimize(scheme)

# %% Basic print of results
print(result.markdown(True))

# %% Save the results
result.save(str(output_folder))

# %% Plot and save as PDF
# This set subsequent plots to the glotaran style
plot_style = PlotStyle()
plt.rc("axes", prop_cycle=plot_style.cycler)

fig = plot_overview(result, linlog=True)

timestamp = datetime.today().strftime("%y%m%d_%H%M")
fig.savefig(output_folder.joinpath(f"plot_overview_{timestamp}.pdf"),
            bbox_inches="tight")