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

Debug unit conv ap phot #3132

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,7 @@ jobs:
strategy:
matrix:
include:
- name: Code style checks
os: ubuntu-latest
python: 3.x
toxenv: codestyle
allow_failure: false

- name: PEP 517
os: ubuntu-latest
python: 3.x
toxenv: pep517
allow_failure: false

- name: Security audit
os: ubuntu-latest
python: 3.x
toxenv: securityaudit
allow_failure: false

- name: Python 3.11 with coverage checking, all deps, and remote data
os: ubuntu-latest
python: '3.11'
toxenv: py311-test-alldeps-cov
toxposargs: --remote-data --run-slow
allow_failure: false

- name: OS X - Python 3.12
os: macos-latest
python: '3.12'
toxenv: py312-test
allow_failure: false

- name: Windows - Python 3.10
os: windows-latest
python: '3.10'
toxenv: py310-test
allow_failure: false

# This also runs on cron but we want to make sure new changes
# won't break this job at the PR stage.
- name: Python 3.12 with latest dev versions of key dependencies, and remote data
os: ubuntu-latest
python: '3.12'
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Cubeviz

- Background subtraction support within Spectral Extraction. [#2859]

- Aperture photometry plugin now listens to changes in display unit. [#3118]

Imviz
^^^^^

Expand Down
74 changes: 74 additions & 0 deletions jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pytest
from astropy import units as u
from astropy.table import Table
from astropy.tests.helper import assert_quantity_allclose
from astropy.utils.exceptions import AstropyUserWarning
from numpy.testing import assert_allclose
Expand Down Expand Up @@ -192,3 +193,76 @@ def test_cubeviz_aperphot_cube_orig_flux_mjysr(cubeviz_helper, spectrum1d_cube_c
assert_allclose(row["mean"], 5 * (u.MJy / u.sr))
# TODO: check if slice plugin has value_unit set correctly
assert_quantity_allclose(row["slice_wave"], 0.46236 * u.um)


def test_cubeviz_aperphot_unit_conversion(cubeviz_helper, spectrum1d_cube_custom_fluxunit):
"""Make sure outputs of the aperture photometry plugin in Cubeviz
reflect the correct choice of display units from the Unit
Conversion plugin.
"""

# create cube with units of MJy / sr
mjy_sr_cube = spectrum1d_cube_custom_fluxunit(fluxunit=u.MJy / u.sr,
shape=(5, 5, 4))

# create apertures for photometry and background
aper = RectanglePixelRegion(center=PixCoord(x=2, y=3), width=1, height=1)
bg = RectanglePixelRegion(center=PixCoord(x=1, y=2), width=1, height=1)

cubeviz_helper.load_data(mjy_sr_cube, data_label="test")
cubeviz_helper.load_regions([aper, bg])

ap = cubeviz_helper.plugins['Aperture Photometry']._obj

ap.dataset_selected = "test[FLUX]"
ap.aperture_selected = "Subset 1"
ap.background_selected = "Subset 2"
ap.vue_do_aper_phot()

uc = cubeviz_helper.plugins['Unit Conversion']._obj

# check that initial units are synced between plugins
assert uc.flux_unit.selected == 'MJy'
assert uc.angle_unit.selected == 'sr'
assert ap.display_flux_or_sb_unit == 'MJy / sr'
assert ap.flux_scaling_display_unit == 'MJy'

# and defaults for inputs are in the correct unit
assert ap.flux_scaling == 0.003631
assert ap.background_value == 46

# test output of default curve of growth plot
# not sure how to access this from the figure
# ap_phot.plot.figure.marks[0].???

# output table in original units to compare to
# outputs after converting units
orig_tab = Table(ap.results)

# change SB units since data is in SB
uc.flux_unit.selected = 'Jy'

# make sure inputs were re-computed in new units
# after the unit change
assert ap.flux_scaling == 3631
assert ap.background_value == 4.6e7

# re-do photometry and make sure table is in new units
# and consists of the same results as before converting units
ap.vue_do_aper_phot()
new_tab = Table(ap.results)

# compare tables across units
for i, row in enumerate(orig_tab):
new_unit = new_tab[i]['unit'] or '-'
orig_unit = row['unit'] or '-'
if new_unit != '-' and orig_unit != '-':

new_unit = u.Unit(new_unit)
new = float(new_tab[i]['result']) * new_unit

orig_unit = u.Unit(orig_unit)
orig = float(row['result']) * orig_unit

orig_converted = orig.to(new_unit)
assert_quantity_allclose(orig_converted, new)
Loading
Loading