Skip to content

Commit

Permalink
more review
Browse files Browse the repository at this point in the history
  • Loading branch information
cshanahan1 committed Nov 21, 2024
1 parent 3432ccf commit d21c5f5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 31 deletions.
4 changes: 4 additions & 0 deletions docs/reference/api_nuts_bolts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Utilities API
:no-inheritance-diagram:
:no-inherited-members:

.. automodapi:: jdaviz.core.custom_units_and_equivs
:no-inheritance-diagram:
:no-inherited-members:

.. automodapi:: jdaviz.models.physical_models
:no-inherited-members:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,10 @@ def _preview_x_from_extracted(self, extracted):
return extracted.spectral_axis

def _preview_y_from_extracted(self, extracted):
"""Convert y-axis units of extraction preview to display units,
if necessary."""
"""
Convert y-axis units of extraction preview to display units,
if necessary.
"""

if extracted.flux.unit != self.spectrum_y_units:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,18 +850,17 @@ def calculate_photometry(self, dataset=None, aperture=None, background=None,

phot_sum = phot_table['sum']
if include_pixarea_fac:
if phot_sum.unit != display_unit * pixarea_fac:
if phot_sum.unit != (display_unit * pixarea_fac).unit:
phot_table['sum'] = flux_conversion_general(phot_sum.value,
phot_sum.unit,
(display_unit * pixarea_fac).unit, # noqa: E501
equivs)

else:
if phot_sum.unit != display_unit:
phot_table['sum'] = flux_conversion_general(phot_sum.value,
phot_sum.unit,
display_unit,
equivs)
elif phot_sum.unit != display_unit:
phot_table['sum'] = flux_conversion_general(phot_sum.value,
phot_sum.unit,
display_unit,
equivs)

for key in ['min', 'max', 'mean', 'median', 'mode', 'std',
'mad_std', 'biweight_location']:
Expand Down
10 changes: 5 additions & 5 deletions jdaviz/configs/imviz/plugins/coords_info/coords_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,10 @@ def _image_viewer_update(self, viewer, x, y):
dq_attribute = associated_dq_layer.state.attribute
dq_data = associated_dq_layer.layer.get_data(dq_attribute)
dq_value = dq_data[int(round(y)), int(round(x))]
unit = image.get_component(attribute).units
unit = u.Unit(image.get_component(attribute).units)
elif isinstance(viewer, (CubevizImageView, RampvizImageView)):
arr = image.get_component(attribute).data
unit = image.get_component(attribute).units
unit = u.Unit(image.get_component(attribute).units)
value = self._get_cube_value(
image, arr, x, y, viewer
)
Expand All @@ -501,9 +501,9 @@ def _image_viewer_update(self, viewer, x, y):
# 'unknown' rather than surface brightness, so multiply out pix2
# and check if the numerator is a spectral/photon flux density
if check_if_unit_is_per_solid_angle(unit, return_unit=True) == PIX2:
physical_type = (u.Unit(unit) * PIX2).physical_type
physical_type = (unit * PIX2).physical_type
else:
physical_type = u.Unit(unit).physical_type
physical_type = unit.physical_type

valid_physical_types = ["spectral flux density",
"surface brightness",
Expand All @@ -523,7 +523,7 @@ def _image_viewer_update(self, viewer, x, y):
equivalencies = all_flux_unit_conversion_equivs(pixar_sr,
cube_wave)

value = flux_conversion_general(value, u.Unit(unit), u.Unit(self.image_unit),
value = flux_conversion_general(value, unit, u.Unit(self.image_unit),
equivalencies, with_unit=False)
unit = self.image_unit

Expand Down
16 changes: 0 additions & 16 deletions jdaviz/core/tests/test_validunits.py

This file was deleted.

4 changes: 3 additions & 1 deletion jdaviz/core/unit_conversion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def check_if_unit_is_per_solid_angle(unit, return_unit=False):
u.core.IrreducibleUnit)):
unit_str = unit.to_string()
elif isinstance(unit, str):
unit_str = unit
# convert string>unit>string to remove any formatting inconsistencies
unit = u.Unit(unit)
unit_str = unit.to_string()
else:
raise ValueError('Unit must be u.Unit, or string that can be converted into a u.Unit')

Expand Down

0 comments on commit d21c5f5

Please sign in to comment.