Open paulocortes opened 2 years ago
Darn! Didn't realize yt
can't handle beam units. We might need to propose a fix upstream for that, or drop units when sending to yt.
Hi Adam, I did try to convert to to Kelvin, but failed when trying to visualize.
` In [16]: from radio_beam import Beam
In [17]: new_beam = Beam(0.4 * u.arcsec)
In [18]: new_cube = cube.with_beam(new_beam)
In [19]: kcube=new_cube.to(u.K)
In [21]: ytcube = kcube.to_yt(spectral_factor=0.5) yt : [WARNING ] 2022-01-12 14:36:46,551 Cannot find time yt : [INFO ] 2022-01-12 14:36:46,552 Detected these axes: RA---SIN DEC--SIN FREQ yt : [WARNING ] 2022-01-12 14:36:46,558 No length conversion provided. Assuming 1 = 1 cm. yt : [WARNING ] 2022-01-12 14:36:46,558 Assuming 1.0 = 1.0 s yt : [WARNING ] 2022-01-12 14:36:46,558 Assuming 1.0 = 1.0 g yt : [INFO ] 2022-01-12 14:36:46,602 Parameters: current_time = 0.0 yt : [INFO ] 2022-01-12 14:36:46,602 Parameters: domain_dimensions = [1500 1500 51] yt : [INFO ] 2022-01-12 14:36:46,603 Parameters: domain_left_edge = [0.5 0.5 0.5] yt : [INFO ] 2022-01-12 14:36:46,603 Parameters: domain_right_edge = [1500.5 1500.5 26. ] yt : [INFO ] 2022-01-12 14:36:46,603 Parameters: cosmological_simulation = 0`
AttributeError Traceback (most recent call last)
Darn! Didn't realize yt can't handle beam units.
Hi ! yt maintainer here. Note that yt (and unyt) can be taught how to handle arbitrary units at runtime. See https://unyt.readthedocs.io/en/latest/usage.html#user-defined-units
A unyt.UnitRegistry
object is attached to any yt dataset, which can be modify to include arbitrary units. I don't know much about how spectral-cube passes down data to yt but it seems likely that you can fix this issue here without needing to patch upstream :)
@neutrinoceros thanks! Any chance you could help us out with this? I would guess we want to do something like:
import unit
unit.define_unit('beam', 1)
to just create a dimensionless Beam unit (because yt
should basically ignore the beam unless it's used for some specific purposes).
Also, we could use help - maybe @jzuhone can jump back in here - to refactor the yt-related code to work with yt again? It's been too long since we used yt in practice, so it looks like there's been some code rot that led to this issue.
@paulocortes could you say something more about what you're trying to do with yt
here? Is your aim to create a visualization, or do some further analysis? I think we need a clear use case to guide our development again and build up a proper test suite.
I think what's required is to register the appropriate unit right after loading the dataset here https://github.com/radio-astro-tools/spectral-cube/blob/a5ec36019634d408289749d261688de3456b94aa/spectral_cube/spectral_cube.py#L2353
if fact there's something very similar done in a different class in yt https://github.com/yt-project/yt/blob/e76b39b8f8ed24c972e8acc1b250a5f5bbbc89a4/yt/frontends/fits/data_structures.py#L685-L699
We had a setup for a "beam" unit at some point for this very frontend--need to figure out why it isn't working now
Are you referring to the method I linked ? I'm thinking maybe it was just moved to a different class since spectral-cube was last updated ?
I'll submit a PR to spectral-cube
tomorrow to fix it
Trying to export an ALMA data cube into yt, got the following error: