nansencenter / DAPPER

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

Reference correct example in README #89

Closed dafeda closed 2 years ago

dafeda commented 2 years ago

I think it's examples/basic_3a.py that generates one of the figures in the README.md. Or, it seems to me as if it at least generates the data that the figure is based on. Is this correct?


I have a somewhat related question.

How do I go about recreating the following figure found in the README?

Screenshot 2022-02-16 at 16 05 49

I have tried running a simple 1D advection example using the attached code, but not sure how to proceed. The xp.stats.replay() produces some plots, but eventually crashed. (I've attached the error message to the end of this post) I'm probably misunderstanding badly and any tips are appreciated.

%matplotlib notebook
from mpl_tools import is_notebook_or_qt as nb

import dapper.da_methods as da
from dapper.mods.LA.evensen2009 import HMM

xx, yy = HMM.simulate()
xp = da.EnKF('PertObs', N=100, infl=1.02)

xp.assimilate(HMM, xx, yy, liveplots=not nb)

xp.stats.replay()

Screenshot 2022-02-16 at 16 10 38


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Input In [2], in <module>
      8 xp = da.EnKF('PertObs', N=100, infl=1.02)
     10 xp.assimilate(HMM, xx, yy, liveplots=not nb)
---> 12 xp.stats.replay()

File ~/git/DAPPER/dapper/stats.py:470, in Stats.replay(self, figlist, speed, t1, t2, **kwargs)
    468 if t1 <= t <= t2:
    469     if ko is not None:
--> 470         LP.update((k, ko, 'f'), None, None)
    471         LP.update((k, ko, 'a'), None, None)
    472     LP.update((k, ko, 'u'), None, None)

File ~/git/DAPPER/dapper/tools/liveplotting.py:245, in LivePlot.update(self, key, E, P)
    242             if plt.fignum_exists(name) and \
    243                     getattr(updater, 'is_active', 1):
    244                 _ = plt.figure(name)
--> 245                 updater(key, E, P)
    246                 plot_pause(self.params['pause_'+faus])
    248 if self.run_ipdb:

File ~/git/DAPPER/dapper/tools/liveplotting.py:642, in correlations.__call__(self, key, E, P)
    640         C = np.cov(E, rowvar=False)
    641 else:
--> 642     assert P is not None
    643     C = P.full if isinstance(P, CovMat) else P
    644     C = C.copy()

AssertionError: 
patnr commented 2 years ago

I think it's examples/basic_3a.py that generates one of the figures in the README.md. Or, it seems to me as if it at least generates the data that the figure is based on. Is this correct?

basic_3{a,b}.py together generate a figure, but not the one you show. I think it's pretty clear which figure is generated when reading the rendered md on the frontpage

How do I go about recreating the following figure found in the README?

The figure you include here can be obtained by using Lorenz96/sakov08 rather than Lorenz63 in basic_1.

Anyway, it is better to obtain it via liveplotting than replays (because not all the stats are stored for later use). The error you get is because the covariances are not stored. It should be better handled, but I don't have the capacity for that right now. You can avoid it by using liveplots=["sliding_diagnostics", "spatial1d"]) in your code. Moreover, for the best liveplotting "experience", I recommend running as a script (not in jupyter).

dafeda commented 2 years ago

basic_3{a,b}.py together generate a figure, but not the one you show. I think it's pretty clear which figure is generated when reading the rendered md on the frontpage

Sorry, my writing was sloppy. I agree that it is clear which figure gets generated (the one attached to this reply), but I was not aware that I had to run both basic_3a and basic_3b to generate it.

ex3

The figure you include here can be obtained by using Lorenz96/sakov08 rather than Lorenz63 in basic_1. Anyway, it is better to obtain it via liveplotting than replays (because not all the stats are stored for later use). The error you get is because the covariances are not stored. It should be better handled, but I don't have the capacity for that right now. You can avoid it by using liveplots=["sliding_diagnostics", "spatial1d"]) in your code. Moreover, for the best liveplotting "experience", I recommend running as a script (not in jupyter).

Thank you, that is helpful.