[AstroPy] Help with negative-dex type unit

Livesey, Nathaniel J (US 3290) nathaniel.j.livesey at jpl.nasa.gov
Sat Jun 27 19:40:03 EDT 2020


Dear all,

  Apologies if this first post from an Earth Atmospheric scientist using (and really appreciating) astropy somehow fails in etiquette.  In atmospheric science, zeta=-log10(pressure/hPa) is a common vertical coordinate.  I’m finding it hard to implement the negation part (which lets
“up” be in the positive direction) in astropy.units.  The following clearly misses the mark:

import astropy.units as units

# The following is OKish, it decreases with altitude rather than increases
zhPaTrial = units.dex(units.hPa)
print ((3.0*zhPaTrial).physical)

Gives: 1000.0 hPa

# What I want is something like:
zhPaGoal = -units.dex(units.hPa)
print ((-3.0*zhPaGoal).physical)
Gives: 0.001 1 / hPa

Clearly, I’ve misunderstood “dex”. Having ended up with 0.001 1/hPa rather than 1000hPa in the second example.  Might I have to define my own unit some other way, perhaps using “RegularFunctionUnit”, the way dBs are define in the astropy.units library?

Any pointers most welcome, and sorry if this is in the documentation and I missed it.

Yours,

Nathaniel

Nathaniel Livesey
Mail Stop 183-701, Jet Propulsion Laboratory
4800 Oak Grove Drive, Pasadena, California 91109.
Phone: +1 818 354-4214   Fax: +1 818 393-5065

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20200627/e3bb17f7/attachment.html>


More information about the AstroPy mailing list