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

Update volume rendering code to work with more modern yt installations #586

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

jzuhone
Copy link
Contributor

@jzuhone jzuhone commented Oct 17, 2019

The API for yt's volume rendering has changed completely. This PR updates the volume rendering code for spectral cubes to reflect this.

I haven't tested this yet, so I'm marking it as WIP until I can. In the meantime, I wanted to put it up for @trhunter to play with.

Closes Issue #571.

@coveralls
Copy link

coveralls commented Oct 17, 2019

Coverage Status

Coverage decreased (-3.7%) to 84.309% when pulling 72dd5ac on jzuhone:fix_yt_camera into 31b0b51 on radio-astro-tools:master.

@jzuhone
Copy link
Contributor Author

jzuhone commented Oct 17, 2019

Ok, it runs, but the images are blank. This will probably take a little while to dig out of.

@jzuhone
Copy link
Contributor Author

jzuhone commented Oct 18, 2019

@keflavich do you have a favorite VR example that we could try out?

@keflavich
Copy link
Contributor

Not really... the GRS l=49 data were pretty good though:

https://spectral-cube.readthedocs.io/en/latest/yt_example.html#sketchfab-isosurface-contours

@jzuhone
Copy link
Contributor Author

jzuhone commented Oct 18, 2019

Is this the L1448_13CO.fits file?

@keflavich
Copy link
Contributor

No but that one is totally fine if it looks OK

@jzuhone
Copy link
Contributor Author

jzuhone commented Oct 19, 2019

So this is working now. But I'd like to add some tests and change the docs before we merge it.

@jzuhone
Copy link
Contributor Author

jzuhone commented Oct 22, 2019

Hi @keflavich this is ready to go except I cannot get the test data I generated to compare to (as .npz files) to copy correctly when installed. I've tried several of the normal tricks but nothing seems to work. Any idea what's going on here?

@jzuhone jzuhone changed the title [WIP] Update volume rendering code to work with more modern yt installations Update volume rendering code to work with more modern yt installations Oct 22, 2019
@keflavich
Copy link
Contributor

in tests/setup_package.py, you need to add *npz

@astrofrog
Copy link
Member

@jzuhone - would you be able to rebase this? If you don't have time, I'm happy to take over the PR to clean it up.

@jzuhone
Copy link
Contributor Author

jzuhone commented Jan 14, 2020

@astrofrog I can rebase it. I had trouble getting the tests to pass before, but I'll see what happens now.

@astrofrog
Copy link
Member

@jzuhone - thanks! When you rebase can you also set the minimum yt version in setup.cfg? If there are any issues with the tests I'm happy to investigate.

@keflavich
Copy link
Contributor

The failure last time was related: https://travis-ci.org/github/radio-astro-tools/spectral-cube/jobs/640107285#L635

We'll need another rebase, and maybe another small correction, to get this fixed.

@HealthyPear
Copy link

If it can help, I tested this PR with a following file from this radio CO survey

in a conda env with

yt                        4.3.1           py310hfd37619_2    conda-forge
yt-idv                    0.4.1                    pypi_0    pypi

with this test code

from spectral_cube import SpectralCube
import yt

input_file = "./FGN00000XXX" # change XXX with your file ID

cube = SpectralCube.read(input_file)

ytcube = cube.to_yt(spectral_factor=0.5)
ds = ytcube.dataset

# add rest of test code from example in the docs of this PR

I also tried directly the interactive renderer (which is what I would like to use together with isosurfaces)

import yt_idv
rc = yt_idv.render_context(height=800, width=800, gui=True)
sg = rc.add_scene(ds, "flux", no_ghost=True)
rc.run()

in both cases I get

yt : [WARNING  ] 2024-10-18 15:31:05,935 Cannot find time
yt : [INFO     ] 2024-10-18 15:31:05,935 Detected these axes: GLON-SFL GLAT-SFL VRAD
yt : [WARNING  ] 2024-10-18 15:31:05,937 No length conversion provided. Assuming 1 = 1 cm.
yt : [WARNING  ] 2024-10-18 15:31:05,937 Assuming 1.0 = 1.0 s
yt : [WARNING  ] 2024-10-18 15:31:05,937 Assuming 1.0 = 1.0 g
yt : [INFO     ] 2024-10-18 15:31:05,963 Parameters: current_time              = 0.0
yt : [INFO     ] 2024-10-18 15:31:05,963 Parameters: domain_dimensions         = [848 848 462]
yt : [INFO     ] 2024-10-18 15:31:05,963 Parameters: domain_left_edge          = [0.5 0.5 0.5]
yt : [INFO     ] 2024-10-18 15:31:05,964 Parameters: domain_right_edge         = [848.5 848.5 231.5]
yt : [INFO     ] 2024-10-18 15:31:05,964 Parameters: cosmological_simulation   = 0
Setting position 1320.0 320.0
yt : [INFO     ] 2024-10-18 15:31:06,406 Adding field flux to the list of fields.
Traceback (most recent call last):
  File "/Users/michele/Software/3D_rendering_radio_data/test_spectral_cube_from_yt.py", line 78, in <module>
    sg = rc.add_scene(ds, "flux", no_ghost=True)
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt_idv/rendering_contexts/base_context.py", line 34, in add_scene
    self.scene = SceneGraph.from_ds(ds, field, no_ghost=no_ghost)
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt_idv/scene_graph.py", line 271, in from_ds
    scene.add_volume(data_source, field, no_ghost=no_ghost)
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt_idv/scene_graph.py", line 61, in add_volume
    self.data_objects[-1].add_data(field_name, no_ghost=no_ghost)
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt_idv/scene_data/block_collection.py", line 40, in add_data
    self.data_source.tiles.set_fields([field], [False], no_ghost=no_ghost)
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/utilities/amr_kdtree/amr_kdtree.py", line 232, in set_fields
    for b in self.traverse():
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/utilities/amr_kdtree/amr_kdtree.py", line 250, in traverse
    yield self.get_brick_data(node)
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/utilities/amr_kdtree/amr_kdtree.py", line 339, in get_brick_data
    vcd = grid.get_vertex_centered_data(
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/data_objects/index_subobjects/grid_patch.py", line 288, in get_vertex_centered_data
    old_field = np.asarray(self[field], dtype="=f8")
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/data_objects/index_subobjects/grid_patch.py", line 75, in __getitem__
    tr = super().__getitem__(key)
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/data_objects/data_containers.py", line 235, in __getitem__
    self.get_data(f)
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/data_objects/selection_objects/data_selection_objects.py", line 204, in get_data
    read_fluids, gen_fluids = self.index._read_fluid_fields(
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/geometry/geometry_handler.py", line 241, in _read_fluid_fields
    fields_to_return = self.io._read_fluid_selection(
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/frontends/fits/io.py", line 96, in _read_fluid_selection
    ind += g.select(selector, data.astype("float64"), rv[field], ind)
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer_yt_pr586/lib/python3.10/site-packages/yt/data_objects/index_subobjects/grid_patch.py", line 413, in select
    dest[offset : offset + count, i] = source[tuple(sl)][np.squeeze(mask)]
IndexError: boolean index did not match indexed array along dimension 2; dimension is 5 but corresponding boolean dimension is 64

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.

5 participants