STmag and ABmag conversions give ValueError
See original GitHub issueThe conversion test was done slightly differently in #5017, so this was not caught. Conversion works when .to()
is invoked from the unit, not does not work when invoked from the Quantity
but only if it was initialized using Quantity
. Example below:
>>> from astropy import units as u
>>> wave = u.Quantity([4956.8, 4959.55, 4962.3], u.AA)
>>> flux_stmag = [12.41858665, 12.38919182, 12.41764379]
>>> photlam = u.photon / (u.cm ** 2 * u.s * u.AA)
>>> u.STmag.to(photlam, flux_stmag, u.spectral_density(wave))
array([ 0.0097654 , 0.01003896, 0.00978473])
>>> q = flux_stmag * u.STmag
>>> q
<Magnitude [ 12.41858665, 12.38919182, 12.41764379] mag(ST)>
>>> q.to(photlam, u.spectral_density(wave))
<Quantity [ 0.0097654 , 0.01003896, 0.00978473] ph / (Angstrom cm2 s)>
>>> q = u.Quantity(flux_stmag, u.STmag)
>>> q
<Quantity [ 12.41858665, 12.38919182, 12.41764379] mag(ST)>
>>> q.to(photlam, u.spectral_density(wave))
.../astropy/units/quantity.py in to(self, unit, equivalencies)
707 unit = Unit(unit)
708 new_val = self.unit.to(unit, self.view(np.ndarray),
--> 709 equivalencies=equivalencies)
710 return self._new_view(new_val, unit)
711
.../astropy/units/core.py in to(self, other, value, equivalencies)
--> 997 return self._get_converter(other, equivalencies=equivalencies)(value)
998
999 def in_units(self, other, value=1.0, equivalencies=[]):
.../astropy/units/core.py in _get_converter(self, other, equivalencies)
1740 raise ValueError(
1741 "The unit {0!r} is unrecognized. It can not be converted "
-> 1742 "to other units.".format(self.name))
1743
1744 def get_format_name(self, format):
ValueError: The unit 'mag(ST)' is unrecognized. It can not be converted to other units.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
ivs.units.conversions
Some of the many possibilities include (see convert for an extensive set of examples): ... ABmag = AB magnitude = Units of frequency...
Read more >Source code for synphot.units
Raises ------ astropy.units.UnitsError Conversion failed. synphot.exceptions.SynphotError Area or Vega spectrum is not given when needed.
Read more >5.1 Photometry - HST User Documentation - HDox
STMAG and ABMAG. These two similar photometric systems are also flux-based systems. The conversion is chosen such that the magnitude in V corresponds...
Read more >Trying to put together a test that shows input spectra are being ...
given countrates in ADU/sec rather than e-/sec. ... elif magnitude_system == 'stmag': ... raise ValueError(("AB mag to countrate conversion failed.".
Read more >Astronomical Magnitude Systems
Ramirez et al. give B-V = 0.65 which agrees with the Binney & Merrifield B-V above ... Conversion from STMAG magnitudes to Johnson...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pllim - see #5183.
And great to know that the magnitude code is being used so well, so that the bugs get shaken out!
@mhvk , no problem. I’ll open new issue if need be. Currently, I can work around the quirks.