[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #JED-117964]: MetPy units and i/o question



Greetings!

Thank you for the kind words. I'm guessing right now you have something like 
the following:

    from metpy.units import units

    vt = 310 * units.kelvin
    with open('outfile.txt', 'wt') as outfile:
        outfile.write(str(vt))

to write out the value without units, you want to use the `.magnitude` 
attribute (which can also be shortened to `.m`). So you'll want to do something 
like this instead for the last line:

        outfile.write(str(vt.magnitude))

Hope this helps,

Ryan

> Dear Unidata,
> 
> First, thank you for the excellent MetPy package, and associated examples
> and documents!
> 
> I am using MetPy for some calculations, manipulating data that I'm writing
> out to initialize a research numerical model (CM1).  I am finding it
> cumbersome to write out the quantities I compute without the unit string
> attached.  This difficulty likely stems from my lack of Python knowledge,
> but my question is this:
> 
> Suppose that I have computed a virtual temperature value in Kelvins.
> How can I write just the numerical value to a text file without the pesky
> 'Kelvins' being also written to the file?
> 
> Thank you for any suggestions - hopefully this is an easy one to address!


Ticket Details
===================
Ticket ID: JED-117964
Department: Support Python
Priority: Low
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.