nansencenter / DAPPER

Data Assimilation with Python: a Package for Experimental Research
https://nansencenter.github.io/DAPPER
MIT License
348 stars 122 forks source link

copy method in HMM #22

Closed yumengch closed 3 years ago

yumengch commented 3 years ago

The pull request relates directly to the issue #20

Key changes:

Response to some comments;

  • You'd probably need to use deepcopy, though. Otherwise the changes in eg dapper.mods.Lorenz63.wiljes2017 to HMM.t will also be present in the copy of the HMM.

Done

  • IIRC, copying can run into trouble because objects cannot be pickled. However, this is already a consideration for multiprocessing, and hasn't yielded much trouble ever since I started using dill (via multiprocessing_on_dill).

copy indeed relies on pickling. However, as far as I can see, current use of HMM doesn't run into such problem. If any issues arise in the future, I think we can always use a customised copy. For the time being, I think the copy module is sufficient.

  • This might have the unintended consequence that changing the forcing (e.g dapper/mods/Lorenz96/pinheiro2019.py) does not take effect. I'm not sure though.

I'm not so sure about the problem, but I checked that the following short test run uses F=8.17.

from dapper.mods.Lorenz96.sakov2008 import HMM as _HMM
import dapper.da_methods as da
import dapper.mods.Lorenz96 as model
HMM = _HMM.copy()
model.Force = 8.17
xx, yy = HMM.simulate()

I hope this resolves your concern? The real issue for the model force, I think. is that we always have to manually reset the force if we change it. I think this might be an argument for using an OOP style model...

patnr commented 3 years ago

Excellent!

I hope this resolves your concern? The real issue for the model force, I think. is that we always have to manually reset the force if we change it. I think this might be an argument for using an OOP style model...

Yes, pretty much. And yes, OOP is more flexible & robust. But also more daunting for a beginner. I think L63 and L96 should not use OOP.

Related: I will add this TODO: Move documentation from L63 and L96, which is in the form of code comments, into its own doc page (maybe mods/__init__.py).