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

[python #SNN-978284]: converting a gempak color table with metpy


I know it's been some time, but in case you were still hoping for some 
direction here, I wanted to reach back out to you. Our `convert_gempak_table` 
function is not built to handle paths as strings directly. So you'll have to 
create a file object from these paths yourself. Here the shortest way to 
accomplish this would be to use python's built-in `open()` function to return 
file objects for these files in the same directory you're working in. Here is a 
short demonstration,

  from metpy.plots.ctables import convert_gempak_table

  # Use `open` to 'r' read our input file and 'w' write to our output file
  # This `with` statement returns the two file objects temporarily
  with open('ir_sab.tbl', 'r') as infile, open('irtest', 'w') as outfile:
      convert_gempak_table(infile, outfile)

and there are multiple ways to manipulate more advanced paths if needed. We 
mostly use this function for internal reading of colortables, so we haven't 
designed it for more advanced user needs. `convert_gempak_table` is not a part 
of metpy.io, so doesn't follow the structure of those classes you've described. 
We have a bit of material on our training website for file input and output, 
including this link 
(https://unidata.github.io/python-training/python/basic_input_and_output/) if 
it's helpful here.

I hope this helps. If there's any further resources I can point you in the 
direction of, don't hesitate to follow up. Apologies for the long delay!

All the best,


> I have a color table I use a lot in IDV with IR imagery,
> Now I want to use it with MetPy,
> I saw there is a convert function for gempak tables in MetPy
> In IDV I exported it as a GEMPAK table (.tbl file attached below)
> So I am trying to use the following command to convert it to one MetPy can
> read:
> metpy.plots.ctables.convert_gempak_table(*infile*, *outfile*)
> my file is in the same directory that my notebook so:
> metpy.plots.ctables.convert_gempak_table('ir_sab.tbl', 'irtest')
> I think the expression file-like object is not clear for me, I understand
> that I have to put for infile the string corresponding the the filename,
> but it does not seems so from the error and the section 1.4.3 p 66 in
> documentation ("MetPyâs IO module contains classes for reading files. These
> classes are written to take both file names (for local files)or file-like
> objects; this allows reading files that are already in memory (using
> io.StringIO)")...should I use a sort of read to get a specific object or
> class... I am confused
> Any advice or documentation or even better examples I could refer to?

Ticket Details
Ticket ID: SNN-978284
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.