Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Sep 27, 2024
1 parent c805453 commit 3250230
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
from specutils import Spectrum1D

from jdaviz.core.custom_units import PIX2
from jdaviz.core.validunits import locally_defined_flux_units


def cubeviz_wcs_dict():
# returns a WCS obj and dictionary used for cubeviz tests here
# returns a WCS obj and dictionary used for cubeviz tests
wcs_dict = {"CTYPE1": "WAVE-LOG", "CTYPE2": "DEC--TAN", "CTYPE3": "RA---TAN",
"CRVAL1": 4.622e-7, "CRVAL2": 27, "CRVAL3": 205,
"CDELT1": 8e-11, "CDELT2": 0.0001, "CDELT3": -0.0001,
Expand All @@ -18,6 +19,38 @@ def cubeviz_wcs_dict():
return w, wcs_dict


@pytest.mark.skip(reason="Unskip after JDAT 4785 resolved.")
@pytest.mark.parametrize("angle_unit", [u.sr, PIX2])
def test_basic_unit_conversions(cubeviz_helper, angle_unit):
"""
Basic test for changing flux units for a cube loaded in Jy to
all available flux units. Checks that the the conversion does
not produce any tracebacks. Tests conversions between all units
in :
['Jy', 'mJy', 'uJy', 'MJy', 'W / (Hz m2)', 'eV / (Hz s m2)',
'erg / (Hz s cm2)', 'erg / (Angstrom s cm2)',
'ph / (Angstrom s cm2)', 'ph / (Hz s cm2)']
Parametrized over both available solid angle units (pix2 and sr).
"""

# load cube with flux units of MJy
w, wcs_dict = cubeviz_wcs_dict()
flux = np.zeros((30, 20, 3001), dtype=np.float32)
cube = Spectrum1D(flux=flux * u.MJy / angle_unit, wcs=w, meta=wcs_dict)
cubeviz_helper.load_data(cube, data_label="test")

# get all available flux units for translation. Since cube is loaded
# in Jy, this will be all items in 'locally_defined_flux_units'

all_flux_units = locally_defined_flux_units()

uc_plg = cubeviz_helper.plugins['Unit Conversion']

for flux_unit in all_flux_units:
uc_plg.flux_unit = flux_unit


@pytest.mark.parametrize("angle_unit", [u.sr, PIX2])
def test_unit_translation(cubeviz_helper, angle_unit):
# custom cube so PIXAR_SR is in metadata, and Flux units, and in MJy
Expand Down

0 comments on commit 3250230

Please sign in to comment.