xarray-contrib / xarray-simlab

Xarray extension and framework for computer model simulations
http://xarray-simlab.readthedocs.io
BSD 3-Clause "New" or "Revised" License
73 stars 9 forks source link

run step executed at specified times/steps only #134

Closed jeanbraun closed 4 years ago

jeanbraun commented 4 years ago

Hello @benbovy. Is it possible to perform a run_step only at times/steps specified by a given clock? As an example, I need to compute an analytical solution to compare to a numerical solution. It is quite computationally demanding so I only want to compute it at the time steps given by an "out" clock and not the master clock.

benbovy commented 4 years ago

Yes, it is possible, using on_demand variables.

Those variables have their own method, decorated with @my_var.compute, so each time they are accessed as attribute, the code within those methods is executed and a value is returned.

Then you could add those variables as output_vars in xsimlab.create_setup or Dataset.xsimlab.update_vars with any clock coordinate or None.

There is an example here.

benbovy commented 4 years ago

@jeanbraun does on_demand variables fit your use case?

I'm going to close this issue, but feel free to re-open it if that's not the case.