Skip to content

Commit

Permalink
Adapted examples to pyglotaran v0.3.0 release
Browse files Browse the repository at this point in the history
Updated examples
Updated LICENSE text
Updated setup.py dependency information, authors
Updated README with basic instructions
  • Loading branch information
jsnel committed Feb 21, 2021
1 parent 76c26bf commit 956716e
Show file tree
Hide file tree
Showing 24 changed files with 158 additions and 955 deletions.
694 changes: 20 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# pyglotaran_examples

This repository hold examples showcasing the use of the pyglotaran package
This repository hold examples showcasing the use of the pyglotaran package, version 0.3.0.
Can be installed as a python package from sources, but is not released on pypi or conda.

## Installation

Prerequisites:

- Python 3.8
- Python package `pyglotaran` v0.3.0

Note for Windows Users: The easiest way to get python for Windows is via [Anaconda](https://www.anaconda.com/)

### Stable Release

To install pyglotaran_examples from sources, either clone this repository or download the latest release, then run this command in your terminal:

```shell
git clone https://github.com/glotaran/pyglotaran_examples.git
cd pyglotaran_examples
pip install -e .
```
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@
print(model.markdown(parameters=parameters))
scheme = Scheme(model, parameters, {"dataset1": dataset})
result = optimize(scheme)
# Second optimization with results of the first:
scheme2 = result.get_scheme()
result2 = optimize(scheme2)
simple_plot_overview(result.data["dataset1"], key)
simple_plot_overview(result2.data["dataset1"], key)
plt.show()
9 changes: 8 additions & 1 deletion pyglotaran_examples/ex_two_datasets/ex_two_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@
print(model.validate(parameters=parameters))

# %% Construct the analysis scheme
scheme = Scheme(model, parameters, {"dataset1": dataset1, "dataset2": dataset2})
scheme = Scheme(
model,
parameters,
{"dataset1": dataset1, "dataset2": dataset2},
maximum_number_function_evaluations=11,
non_negative_least_squares=True,
optimization_method="TrustRegionReflection",
)

# %% Optimize the analysis scheme (and estimate parameters)
result = optimize(scheme)
Expand Down
7 changes: 7 additions & 0 deletions pyglotaran_examples/ex_two_datasets/models/model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ equal_area_penalties:
target_intervals: [[300, 3000]]
parameter: area.1
weight: 0.1

# Example of weight application:
# weights:
# - datasets: [dataset1, dataset2]
# global_interval: [100, 102]
# model_interval: [301, 502]
# value: 0.95
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from glotaran.analysis.scheme import Scheme
from glotaran.io import read_data_file

DATA_PATH = "data/data.ascii"
DATA_PATH = "data/demo_data_Hippius_etal_JPCC2007_111_13988_Figs5_9.ascii"
MODEL_PATH = "models/model.yml"
PARAMETERS_FILE_PATH = "models/parameters.yml"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from glotaran.analysis.scheme import Scheme
from glotaran.io.reader import read_data_file

TARGET_MODEL = "models/co_co2_TA_model.yaml"
TARGET_PARAMS = "models/co_co2_TA_parameters.yaml"
TARGET_MODEL = "models/model_2d_co_co2.yml"
TARGET_PARAMS = "models/parameters_2d_co_co2.yml"


# %%
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 5 additions & 5 deletions pyglotaran_examples/test/simultaneous_analysis_3d_disp/model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ equal_area_penalties:
parameter: area.1
weight: 0.1

weights:
- datasets: [dataset1, dataset2, dataset3]
global_interval: [400, 450]
# model_interval: [301, 502]
value: 0.5
# weights:
# - datasets: [dataset1, dataset2, dataset3]
# global_interval: [400, 450]
# # model_interval: [301, 502]
# value: 0.5
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
rates:
- ["k1", 0.05]
- ["k2", 0.5]
- ["k3", 2.1]
- ["k1", 0.0499]
- ["k2", 2.31]
- ["k3", 0.509]
- {"vary": True,"non-negative": True}

inputs:
- ["1", 0.5, {"vary": False}]
- ["2", 0.251]
- ["3", 0.252]
- ["7", 0.21]
- ["8", 0.22]
- ["9", 0.22]
- ["10", 0.22]
- ["2", 0.180]
- ["3", 0.303]
- ["7", 0.387]
- ["8", 0.394]
- ["9", 0.288]
- ["10", 0.352]
- {"non-negative": True}

irf:
- ["center1",0.5]
- ["center2",0.5]
- ["center3",0.5]
- ["width", 0.06]
- ["center1",0.4]
- ["center2",0.41]
- ["center3",0.42]
- ["width", 0.05998]
- ['dispc',500, {vary: False}]
- ['disp1',0.01]
- ['disp2',0.001]


scale:
- ["1", 1, {"vary": False}]
- ["2", 1.3, {"vary": True}]
- ["3", 1.1, {"vary": True}]
- ["2", 1.30557, {"vary": True}]
- ["3", 1.1635, {"vary": True}]

pen:
- ["1", 1, {"vary": False}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# output folder for this specific analysis
output_folder = results_folder.joinpath("simultaneous_analysis_3d_disp")

# data inlezen
# read in data
data_path = script_folder.joinpath("equareaIRFdispscalsima.ascii")
dataset1 = gta.io.read_data_file(data_path)
# print(dataset1)
Expand All @@ -36,54 +36,53 @@

model = gta.read_model_from_yaml_file(model_path)

# if the optimized parameters from a previous run are available, use those
parameter_file = output_folder.joinpath("optimized_parameters.csv")
if parameter_file.exists():
print("Optimized parameters exists: please check")
parameter = read_parameters_from_csv_file(str(parameter_file))
parameters = read_parameters_from_csv_file(str(parameter_file))
else:
parameter = gta.read_parameters_from_yaml_file(parameters_path)
parameters = gta.read_parameters_from_yaml_file(parameters_path)

print(model.validate(parameters=parameter))
print(model.validate(parameters=parameters))

# analysis schema definieren
# define the analysis scheme to optimize
scheme = Scheme(
model,
parameter,
parameters,
{"dataset1": dataset1, "dataset2": dataset2, "dataset3": dataset3},
maximum_number_function_evaluations=5,
maximum_number_function_evaluations=99,
non_negative_least_squares=True,
# optimization_method="Levenberg-Marquardt",
)
# optimize
result = optimize(scheme)
# %%
# evt opslaan


# %% Save results
result.save(str(output_folder))
# evt plotten
# %% Set subsequent plots to the glotaran style

# %% 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=5)
fig1 = plot_overview(result_datafile1, linlog=True, linthresh=1)
fig1.savefig(
output_folder.joinpath("plot_overview_dummy1.pdf"),
output_folder.joinpath("plot_overview_sim3d_d1.pdf"),
bbox_inches="tight",
)

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

fig3 = plot_overview(result_datafile3, linlog=True, linthresh=5)
fig3 = plot_overview(result_datafile3, linlog=True, linthresh=1)
fig3.savefig(
output_folder.joinpath("plot_overview_dummy3.pdf"),
output_folder.joinpath("plot_overview_sim3d_d3.pdf"),
bbox_inches="tight",
)
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
rates:
- ["k1", 0.199]
- ["k2", 0.5]
- ["k3", 2.1]
- ["k1", 0.05]
- ["k2", 2.0]
- ["k3", 0.5]
- {"vary": True,"non-negative": True}

inputs:
- ["1", 0.5, {"vary": False}]
- ["2", 0.251]
- ["3", 0.252]
- ["7", 0.21]
- ["8", 0.22]
- ["9", 0.22]
- ["10", 0.22]
- ["2", 0.161]
- ["3", 0.311]
- ["7", 0.322]
- ["8", 0.415]
- ["9", 0.242]
- ["10", 0.363]
- {"non-negative": True}

irf:
- ["center",0.5]
- ["width", 0.1]
- ["center",0.4]
- ["width", 0.05998]

scale:
- ["1", 1, {"vary": False}]
- ["2", 0.991, {"vary": True}]
- ["3", 0.991, {"vary": True}]
- ["2", 1.27, {"vary": True}]
- ["3", 1.13, {"vary": True}]

pen:
- ["1", 1, {"vary": False}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# output folder for this specific analysis
output_folder = results_folder.joinpath("simultaneous_analysis_3d_nodisp")

# data inlezen
# read in data
data_path = script_folder.joinpath("equareaIRFsim3a.ascii")
dataset1 = gta.io.read_data_file(data_path)
# print(dataset1)
Expand All @@ -36,54 +36,53 @@

model = gta.read_model_from_yaml_file(model_path)

# if the optimized parameters from a previous run are available, use those
parameter_file = output_folder.joinpath("optimized_parameters.csv")
if parameter_file.exists():
print("Optimized parameters exists: please check")
parameter = read_parameters_from_csv_file(str(parameter_file))
parameters = read_parameters_from_csv_file(str(parameter_file))
else:
parameter = gta.read_parameters_from_yaml_file(parameters_path)
parameters = gta.read_parameters_from_yaml_file(parameters_path)

print(model.validate(parameters=parameter))
print(model.validate(parameters=parameters))

# analysis schema definieren
# define the analysis scheme to optimize
scheme = Scheme(
model,
parameter,
parameters,
{"dataset1": dataset1, "dataset2": dataset2, "dataset3": dataset3},
maximum_number_function_evaluations=5,
maximum_number_function_evaluations=99,
non_negative_least_squares=True,
# optimization_method="Levenberg-Marquardt",
)
# optimize
result = optimize(scheme)
# %%
# evt opslaan


# %% Save results
result.save(str(output_folder))
# evt plotten
# %% Set subsequent plots to the glotaran style

# %% 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=5)
fig1 = plot_overview(result_datafile1, linlog=True, linthresh=1)
fig1.savefig(
output_folder.joinpath("plot_overview_dummy1.pdf"),
output_folder.joinpath("plot_overview_sim3d_d1.pdf"),
bbox_inches="tight",
)

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

fig3 = plot_overview(result_datafile3, linlog=True, linthresh=5)
fig3 = plot_overview(result_datafile3, linlog=True, linthresh=1)
fig3.savefig(
output_folder.joinpath("plot_overview_dummy3.pdf"),
output_folder.joinpath("plot_overview_sim3d_d3.pdf"),
bbox_inches="tight",
)
Loading

0 comments on commit 956716e

Please sign in to comment.