Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Maginor committed Aug 13, 2024
1 parent 29b2e89 commit e586474
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
18 changes: 15 additions & 3 deletions docs/mobipydocs/mobipy.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,30 @@ You can also look at some more [example notebooks](https://github.com/NIVANorge/

## Basic usage

It is useful to look at the [central model concepts](../mobius2docs/central_concepts.html) to understand what we mean by certain concepts below like ("parameter", "state variable", "identifier", etc.).
It is useful to look at the [central model concepts](../mobius2docs/central_concepts.html) to understand what we mean by certain terms below like ("parameter", "state variable", "identifier", etc.).

First you need to load a model application using
```python
app = mobipy.Model_Application.build_from_model_and_data_file("model_file_path.txt", "data_file_path.txt")
app = mobipy.Model_Application.build_from_model_and_data_file(
"path/to/model.txt",
"path/to/data.dat")
```
To be able to extract any results you need to run the model, using
```python
app.run()
```

It is important to note that the `Model_Application` object is not serializable in a python sense, so its state is not stored in Jupyter notebooks. This means that if you use a notebook, the entire state is lost if the kernel is restarted. Moreover, operations done on the `app` in later cells can effect the outcome if you run earlier cells.
It is important to note that the `Model_Application` object is not python-serializable, so you can not access the same app object across multiple processes. Using multiple threads works fine, just note that operations modifying the state of the app (running the model, modifying parameters, etc.) are not thread safe. If you want to run the model in several parallel instances, you can make copies of the working dataset as seen below.

```python
# This is a thread safe way to run a model instance in parallel.
def run_model_instance(app) :
data = app.copy()
#modify_some_parameters(data)
data.run()
#do_something_with_the_data(data)
del data
```

### Acessing model entities

Expand Down
9 changes: 6 additions & 3 deletions docs/mobius_jl_doc/mobius_jl.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ nav_order: 5

# mobius.jl

mobius.jl is a package for the [Julia programming language](https://julialang.org/). It has similar functionality to [mobipy](../mobipydocs/mobipy.html).
mobius.jl is a package for the [Julia programming language](https://julialang.org/). It has similar functionality to [mobipy](../mobipydocs/mobipy.html), including

This package is currently not fully featured, but allows you to run a model and extract result series.
- Running the model.
- Editing parameter values.
- Extracting result time series.

See [an example here](https://github.com/NIVANorge/Mobius2/blob/main/example_notebooks/basic_julia.ipynb).

To use mobius.jl you need to first follow the installation procedure for mobipy, that is you need to download mobipy/c_abi.dll from ftp://mobiserver.niva.no/Mobius2 and put it in your local Mobius2/mobipy folder.
To use mobius.jl you need to follow the installation procedure for mobipy:
- Download mobipy/c_abi.dll from ftp://mobiserver.niva.no/Mobius2 and put it in your local Mobius2/mobipy folder.
23 changes: 15 additions & 8 deletions docs/mobiviewdocs/plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,33 @@ has_children: true

You can use the plot to visualize inputs and results of the model. Time series can be selected in the result and model input trees to the left of the plot.

If you want multiple plot axes displayed at the same time, you need to open the [additional plot window](additionalplots.html) by clicking ![Additional plots](../img/toolbar/ViewMorePlots.png) in the toolbar.

The time series info box will display statistics about the selected time series. It can also display [goodness-of-fit statistics](statistics.html). Remember that you can load whatever time series data you want in the [data file](../datafiledocs/datafiles.md). This is useful for loading observation series that you want to compare to the model results.

The plot will automatically update itself every time you run the model ![Run](../img/toolbar/Run.png) to reflect any changes in the result time series.

## Series selection

![Series selecter](../img/mobiview/series_selection.png)

### Tree structure

Series are organized in a tree structure according to their [location](../mobius2docs/central_concepts.html#components-and-locations). For instance, the soil water organic carbon is found under `Soil->Water->Organic carbon`. Non-primary state variables are instead organized under the location that makes the most sense, for instance a flux is organized under its source location if it is valid, otherwise its target location.

For model result series, you can also go to the "By quantity" tab to view series as organized by their final location component instead, so for instance soil water organic carbon is found there as `Organic carbon->Soil->Water`.

The "Quick select" tab only has content if the loaded data set has [`quick_select` declarations](../datafiledocs/new_project.html#quick-select). These can be set up to make it faster to select series you want to view often.

If you write text in the search bar under the series selecter, it will collapse all top nodes of the tree that don't match the search term. You can only search for the top node.

### Selecting and removing multiple series

- You can select multiple time series at one time by ctrl-clicking (or shift-clicking) them.
- You can remove a selected time series by ctrl-clicking it.
- If a time series varies over one or more index sets, you can select indexes from the lists below the plot. You can do multiselection (ctrl-click) here too.
- If you write text in the search bar under the series selecter, it will collapse all top nodes of the tree that don't match the search term. You can only search for the top node.

If you want multiple plot axes displayed at the same time, you need to open the [additional plot window](additionalplots.html) by clicking ![Additional plots](../img/toolbar/ViewMorePlots.png) in the toolbar.

The time series info box will display statistics about the selected time series. It can also display [goodness-of-fit statistics](statistics.html). Remember that you can load whatever time series data you want in the [data file](../datafiledocs/datafiles.md). This is useful for loading observation series that you want to compare to the model results.

The plot will automatically update itself every time you run the model ![Run](../img/toolbar/Run.png) to reflect any changes in the result time series.

## Navigation
## Plot navigation (scroll and zoom)

In many of the plot modes you can scroll and zoom the plot.

Expand Down
7 changes: 5 additions & 2 deletions mobipy/optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def sample_fun(n_run) :

return par_data, stats

def run_minimizer(app, params, set_params, residual_fun, method='nelder', run_timeout=-1, disp=False) :
def run_minimizer(app, params, set_params, residual_fun, method='nelder', use_init=True, run_timeout=-1, disp=False) :

def get_residuals(pars) :

Expand All @@ -182,6 +182,9 @@ def get_residuals(pars) :

options = {'disp' : disp}

res = mi.minimize(method=method, params=params, options=options)
init = None
if use_init : init = params

res = mi.minimize(method=method, params=init, options=options)

return res
6 changes: 6 additions & 0 deletions mobipy/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ def plot_target(app, target, ax) :
simname, simidx, obsname, obsidx, *wgt = target
app.var(simname)[simidx].loc[sl].plot(ax=ax)
app.var(obsname)[obsidx].loc[sl].plot(ax=ax, marker='o')

ymin, ymax = ax.get_ylim()
if ymin > 0 :
ax.set_ylim(0, ymax)

ax.legend()


fig, axs = plt.subplots(len(targets), figsize=(width, height_per*len(targets)))

Expand Down

0 comments on commit e586474

Please sign in to comment.