Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added yt support #28

Merged
merged 1 commit into from
Sep 7, 2018
Merged

Added yt support #28

merged 1 commit into from
Sep 7, 2018

Conversation

jbednar
Copy link
Member

@jbednar jbednar commented Sep 6, 2018

The yt library uses Matplotlib to render one or more plots per object to PNG. Although yt objects have a _repr_html_ and can thus be displayed without any special support, the enclosing Bokeh Div does not resize appropriately to the size of the contents, which is very inconvenient. This PR adds a pane.YT class that is the same as pane.HTML except that it calculates the total height (of all stacked PNGs) and the maximum width (of all stacked PNGs) and uses those to size the Div. This implementation is somewhat inefficient, in that it renders the images to PNG just to get their sizes, but doing so seemed simpler than trying to parse them out of the HTML representation to find out their sizes. Example:

try:
    import yt
except:
    !conda install -c conda-forge yt

import os
file = "enzo_tiny_cosmology"
if not os.path.exists(file):
    !curl -sSO http://yt-project.org/data/$file.tar.gz
    !tar xzf $file.tar.gz

import yt

import panel as pp
from panel import pane
pp.extension()

ds = yt.load("enzo_tiny_cosmology/DD0046/DD0046")
p = yt.ProjectionPlot(ds, "z", ["density", "temperature"], weight_field="density")

pp.Row(p)

image
image

I don't know how to get a tiny YT data file in order to add more official tests than this.

@jbednar
Copy link
Member Author

jbednar commented Sep 6, 2018

Given that a yt object can return multiple plots and that stacking them as above could be confusing, one could consider returning a pp.Column object instead of a single pane, which would be trivial to implement given the code in this PR that already effectively generates a list of PNGs. But that would be a new behavior for Pane, so I'll leave such an implementation up to @philippjfr if he prefers it. I think yt users can simply define only a single plot per yt object if they want to use the current version in a more reasonable way.

@codecov-io
Copy link

codecov-io commented Sep 6, 2018

Codecov Report

Merging #28 into master will decrease coverage by 0.43%.
The diff coverage is 29.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #28      +/-   ##
==========================================
- Coverage   92.75%   92.32%   -0.44%     
==========================================
  Files          21       21              
  Lines        2457     2474      +17     
==========================================
+ Hits         2279     2284       +5     
- Misses        178      190      +12
Impacted Files Coverage Δ
panel/pane.py 81.81% <29.41%> (-3.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d735794...c1c8614. Read the comment docs.

@philippjfr philippjfr merged commit d42be8b into master Sep 7, 2018
@philippjfr philippjfr deleted the yt branch October 17, 2018 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants