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

[python #UJM-414395]: problem converting gempak table



Hi, thanks for reaching out!

I was able to use the code in your second link to appropriately write out your 
attached gempak color table to a new file, which can then be read back in using 
our `read_colortable` helper or just by hand, for example:

  from metpy.plots.ctables import convert_gempak_table, read_colortable
  from matplotlib.colors import ListedColormap
  
  with open("ir_upc2.tbl", "r") as infile, open("ir_upc2_converted.tbl", "w") 
as outfile:
      # read our old table and write to a new one
      convert_gempak_table(infile, outfile)
  
  with open("ir_upc2_converted.tbl", "r") as infile:
      # read in our new table!
      ctable = read_colortable(infile)
  
  cmap = ListedColormap(ctable)
  print(cmap.colors)  # just to see


What specific errors or problems are you encountering? There are some other 
code snippets here 
(https://github.com/Unidata/MetPy/issues/3243#issuecomment-1779829053) that can 
help you without saving a new file, if that's what you're looking for.

Please follow up with any tracebacks or additional errors you're receiving, and 
let me know if I can provide any more resources here! I hope this helps.


All the best,

Drew


> I have some gempak color tables (one example attached).
> I am trying to use convert_gempak_table from metpy.
> I checked the doc (
> https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.ctables.convert_gempak_table.html
> )
> and the posts (
> https://www.unidata.ucar.edu/support/help/MailArchives/python/msg00223.html)
> I have no idea how to define correctly the out_file that I would get a
> usable color table. I am sincerely lost!!! Thanks in advance for any help
> here is part of the code I wrote but seems useless
> >from metpy.plots.ctables import convert_gempak_table
> >import io
> >ir_upc2_tbl = open("ir_upc2.tbl","r")
> >our_outfile = io.StringIO()
> >convert_gempak_table(ir_upc2_tbl,our_outfile)
> >#help(convert_gempak_table)


Ticket Details
===================
Ticket ID: UJM-414395
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.