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

Livesey, Nathaniel J (US 3290) nathaniel.j.livesey at jpl.nasa.gov
Mon Jun 29 23:34:05 EDT 2020


Hi Derek,

   Many thanks indeed, that did exactly what I had in mind.  Much appreciated!

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 Jun 29, 2020, at 3:25 PM, Derek Homeier <derek at astro.physik.uni-goettingen.de> wrote:
> 
> Hi Nathaniel,
> 
>> 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:
> 
> (sub)stellar Atmospheric scientist here; although the closest I typically come to Earth atmosphere is Jupiter’s,
> that sounds like a useful unit. ;-)
> 
>> # 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?
>> 
> Yes, the problem is that -units.dex() will create a DexUnit of your inverse physical_unit rather than the unit
> on a negative log scale, so creating a custom logarithmic unit type indeed seems the way to go, e.g.
> 
> ndex = units.function.mixin.RegularFunctionUnit(['ndex'], -units.dex)                                                                                                                
> ndex._function_unit_class = units.function.logarithmic.DexUnit                                                                                                                    
> zhPa = ndex(units.hPa)
> 
> should behave as desired, though I’d let others chime in if they know of a more convenient way to define this.
> 
> HTH
> 					Derek
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy



More information about the AstroPy mailing list