From 1d8290ab2e6a5fafa8a005e28eb8b4c696e5981b Mon Sep 17 00:00:00 2001 From: Joris Snellenburg Date: Wed, 9 Nov 2022 00:27:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AAProject=20API=20Tryout=20-=20Fluore?= =?UTF-8?q?scence=20example=20=F0=9F=9A=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Converted the "study_fluoresnce" example into a project API example --- .gitignore | 2 ++ .../data/{data.ascii => dataset1.ascii} | 0 .../models/{model.yaml => model.yml} | 0 .../parameters-target.yaml | 0 .../parameters.yml} | 2 +- .../study_fluorescence/project.gta | 1 + .../study_fluorescence/scheme.yml | 13 +++++++ .../target_analysis_script.py | 8 ++--- .../study_fluorescence/tryout_project_api.py | 36 +++++++++++++++++++ 9 files changed, 57 insertions(+), 5 deletions(-) rename pyglotaran_examples/study_fluorescence/data/{data.ascii => dataset1.ascii} (100%) rename pyglotaran_examples/study_fluorescence/models/{model.yaml => model.yml} (100%) rename pyglotaran_examples/study_fluorescence/{models => parameters}/parameters-target.yaml (100%) rename pyglotaran_examples/study_fluorescence/{models/parameters.yaml => parameters/parameters.yml} (87%) create mode 100644 pyglotaran_examples/study_fluorescence/project.gta create mode 100644 pyglotaran_examples/study_fluorescence/scheme.yml create mode 100644 pyglotaran_examples/study_fluorescence/tryout_project_api.py diff --git a/.gitignore b/.gitignore index ebbab78..6ba5d15 100644 --- a/.gitignore +++ b/.gitignore @@ -138,3 +138,5 @@ plot_results # DOAS data file !pyglotaran_examples/ex_doas_beta/data/2008Polli_betacar_chex_sim.nc + +pyglotaran_examples/study_fluorescence/results/* diff --git a/pyglotaran_examples/study_fluorescence/data/data.ascii b/pyglotaran_examples/study_fluorescence/data/dataset1.ascii similarity index 100% rename from pyglotaran_examples/study_fluorescence/data/data.ascii rename to pyglotaran_examples/study_fluorescence/data/dataset1.ascii diff --git a/pyglotaran_examples/study_fluorescence/models/model.yaml b/pyglotaran_examples/study_fluorescence/models/model.yml similarity index 100% rename from pyglotaran_examples/study_fluorescence/models/model.yaml rename to pyglotaran_examples/study_fluorescence/models/model.yml diff --git a/pyglotaran_examples/study_fluorescence/models/parameters-target.yaml b/pyglotaran_examples/study_fluorescence/parameters/parameters-target.yaml similarity index 100% rename from pyglotaran_examples/study_fluorescence/models/parameters-target.yaml rename to pyglotaran_examples/study_fluorescence/parameters/parameters-target.yaml diff --git a/pyglotaran_examples/study_fluorescence/models/parameters.yaml b/pyglotaran_examples/study_fluorescence/parameters/parameters.yml similarity index 87% rename from pyglotaran_examples/study_fluorescence/models/parameters.yaml rename to pyglotaran_examples/study_fluorescence/parameters/parameters.yml index cf6626b..8996aa8 100644 --- a/pyglotaran_examples/study_fluorescence/models/parameters.yaml +++ b/pyglotaran_examples/study_fluorescence/parameters/parameters.yml @@ -13,4 +13,4 @@ kinetic: - 0.07 - 0.02 - 0.00016 - - {non-negative: true} + # - {non-negative: true} diff --git a/pyglotaran_examples/study_fluorescence/project.gta b/pyglotaran_examples/study_fluorescence/project.gta new file mode 100644 index 0000000..434b2f4 --- /dev/null +++ b/pyglotaran_examples/study_fluorescence/project.gta @@ -0,0 +1 @@ +version: 0.7.0.dev0 diff --git a/pyglotaran_examples/study_fluorescence/scheme.yml b/pyglotaran_examples/study_fluorescence/scheme.yml new file mode 100644 index 0000000..3e45008 --- /dev/null +++ b/pyglotaran_examples/study_fluorescence/scheme.yml @@ -0,0 +1,13 @@ +model: models/model.yml +parameters: parameters/parameters.yml +data: + dataset1: dataset1.nc +clp_link_tolerance: 0.0 +clp_link_method: nearest +maximum_number_function_evaluations: null +add_svd: true +ftol: 1e-08 +gtol: 1e-08 +xtol: 1e-08 +optimization_method: TrustRegionReflection +result_path: null diff --git a/pyglotaran_examples/study_fluorescence/target_analysis_script.py b/pyglotaran_examples/study_fluorescence/target_analysis_script.py index 3d2b574..abf7d34 100644 --- a/pyglotaran_examples/study_fluorescence/target_analysis_script.py +++ b/pyglotaran_examples/study_fluorescence/target_analysis_script.py @@ -14,10 +14,10 @@ from pyglotaran_extras.plotting.plot_overview import plot_overview from pyglotaran_extras.plotting.style import PlotStyle -GLOBAL_MODEL = "models/model.yaml" -GLOBAL_PARAMS = "models/parameters.yaml" +GLOBAL_MODEL = "models/model.yml" +GLOBAL_PARAMS = "parameters/parameters.yml" TARGET_MODEL = "models/model-target.yaml" -TARGET_PARAMS = "models/parameters-target.yaml" +TARGET_PARAMS = "parameters/parameters-target.yaml" SKIP_FIT = False # %% @@ -26,7 +26,7 @@ # %% -data_path = script_folder.joinpath("data/data.ascii") +data_path = script_folder.joinpath("data/dataset1.ascii") # model_path = script_folder.joinpath(GLOBAL_MODEL) # parameter_path = script_folder.joinpath(GLOBAL_PARAMS) model_path = script_folder.joinpath(TARGET_MODEL) diff --git a/pyglotaran_examples/study_fluorescence/tryout_project_api.py b/pyglotaran_examples/study_fluorescence/tryout_project_api.py new file mode 100644 index 0000000..b822e39 --- /dev/null +++ b/pyglotaran_examples/study_fluorescence/tryout_project_api.py @@ -0,0 +1,36 @@ +from pathlib import Path +from timeit import default_timer as timer + +import matplotlib.pyplot as plt # 3.3 or higher +from glotaran.project.project import Project +from pyglotaran_extras.plotting.plot_overview import plot_overview + +if __name__ == "__main__": + project_file = Path(".") / "project.gta" + project_folder = project_file.parent + project = Project.open(project_file) + + project.load_data("dataset1.ascii") + # Would prefer to decouple dataset label and filename + + start = timer() + project.optimize( + # model_name="model.yml", # note if you use 'model' it will pick the wrong file + # parameters_name="parameters.yml", + model_name="model-target.yaml", + parameters_name="parameters-target.yaml", + maximum_number_function_evaluations=100, + result_name="dummy", + ) + end = timer() + print(f"Total time: {end - start}") + + result = project.load_latest_result("dummy") + + print(result.markdown(True)) + + res = result.data["dataset1"] + print(res) + + fig, _ = plot_overview(result, linlog=False, figure_only=False) + plt.show(block=True)