clawpack / visclaw

Clawpack visualization tools
http://www.clawpack.org
BSD 3-Clause "New" or "Revised" License
29 stars 47 forks source link

WIP: use anim.to_jshtml if available #245

Closed rjleveque closed 4 years ago

rjleveque commented 5 years ago

This address #244, but not yet optimized. We ran into this before when trying to switch to anim.to_jshtml to make JS Animations: for some reason the resolution of the resulting animation is much worse than that of the png files being read in. Comparison of old and new below.

Maybe someone knows how to fix this?

old new
ketch commented 5 years ago

One solution is to avoid writing figure files altogether. I think this will be the most robust long-term, but I realize it may be significant work to implement.

rjleveque commented 4 years ago

I swapped the order or the try/except blocks so it first tries our original approach of using JSAnimation directly and only reverts to anim.to_jshtml if that fails, since we still haven't figured out how to make that give movies with full resolution of the png files.

Several users have run into this bug with the code in master recently and I have to tell them to merge in this PR, so I suggest we go ahead and merge it, so their code will at least produce ugly animations rather than dying.

I did try again to figure out what's going on. The problem is not the resolution of the png files being saved since opening them alone looks fine, and so does the JSAnimation version of the animation. Somehow it is in imshow. I discovered there's a figimage command that maybe does what we want better, but I couldn't get it to work.

@ketch suggested avoiding png's altogether, which for some applications would work. But it is very useful to also have the png of every frame separately and the other webpages produced with plotpages.py allow looking at these separately, so we need to generate them anyway. And for some applications (e.g. many tsunami models with huge grids and several figures for each of many frames) it can take hours to make the plots, so plotting two versions of every figure isn't viable, nor could we save them all in memory to animate directly.

donnaaboise commented 4 years ago

Thanks, Randy. I am still a bit confused as to the source of the error, because I can create plots that look fine to me, and the movies work as well. We just had problems on the Windows install. But maybe I am not up-to-date with the latest Anaconda?

rjleveque commented 4 years ago

It depends a lot on what particular version of matplotlib you have. The error you sent me by email,

 out = TextIOWrapper(BytesIO(out)).read()                                                               
TypeError: a bytes-like object is required, not 'str'                                    

is the same one encountered in https://github.com/clawpack/visclaw/issues/244, I believe, which comes up with newer versions of matplotlib when trying to use the older JSAnimation code. On the other hand sufficiently old versions of matplotlib don't have the to_jshtml function.