[python #JED-117964]: MetPy units and i/o question
- Subject: [python #JED-117964]: MetPy units and i/o question
- Date: Sat, 11 Apr 2020 15:58:44 -0600
Thank you for the kind words. I'm guessing right now you have something like
from metpy.units import units
vt = 310 * units.kelvin
with open('outfile.txt', 'wt') as outfile:
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:
Hope this helps,
> 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 ID: JED-117964
Department: Support Python
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.