[AstroPy] [EXTERNAL] Help with negative-dex type unit

Livesey, Nathaniel J (US 3290) nathaniel.j.livesey at jpl.nasa.gov
Mon Jul 20 23:41:14 EDT 2020


Hi Derek,

   Thanks for this pointer.  I’m afraid, in the end, I opted not to follow your initially very helpful suggestion.  While that approach (and the one below) did exactly what I'd been seeking, it also behaved more logarithmically than I’d bargained for.  

   Specifically, in using it as a vertical coordinate, I wanted addition and other operators to work in an essentially linear sense.  For example, given z=-3zhPa (1000hPa, Earth’s surface, more or less), I wanted to be able to add 1zhPa to it to get -2zhPa (100hPa, ~16km altitude).  However, and completely correctly from a mathematical point of view, we actually get:

>>> -3*zhPa + 1*zhPa
<LogQuantity -2. -1 dex(hPa2)>

(note the hPa-squared).  However, all was far from lost, as astropy.unit’s equivalencies came to my aid.  I instead defined:

zUnit = units.def_unit("-log(p/hPa")
zetaEquivalencies = [(pUnit, zUnit, lambda p: -np.log10(p), lambda z: 10.0**(-z))]

This has worked fine for me thus far.

   Many thanks to you, and to all involved in putting together a really nicely put together toolset.

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

> On Jul 18, 2020, at 9:12 AM, Derek Homeier <derek at astro.physik.uni-goettingen.de> wrote:
> 
> Hi Nathaniel,
> 
>> On 30 Jun 2020, at 5:34 am, Livesey, Nathaniel J (US 3290) <nathaniel.j.livesey at jpl.nasa.gov> wrote:
>> 
>> Many thanks indeed, that did exactly what I had in mind.  Much appreciated!
> 
> by way of a late follow-up, this topic just came up again amidst some more general discussion on logarithmic units.
> 
> Summary: there is a 1-step recommended alternative
> 
> zhPa = u.LogUnit(u.hPa, '-1 dex')
> 
> More details on
> https://github.com/astropy/astropy/issues/10577
> 
> – suggestions for how to better document this are very welcome.
> 
> Cheers,
> 					Derek
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy



More information about the AstroPy mailing list