miniufo / xgrads

Parse and read ctl and associated binary file commonly used by GrADS into xarray
https://xgrads.readthedocs.io/
MIT License
71 stars 27 forks source link

Error while opening .grb2 #24

Closed Manuelch94 closed 3 years ago

Manuelch94 commented 3 years ago

I am using the following code for opening a .ctl .grb2 .idx files using xgrads:

In the current directory: 202104120000_arw_wrfout_d01.grb2 202104120000_arw_wrfout_d01.idx 202104120000_arw_wrfout_d01.ctl

from xgrads import CtlDescriptor, open_CtlDataset
dset = open_CtlDataset('202104120000_arw_wrfout_d01.ctl')

And I get the following error:

IndexError                                Traceback (most recent call last)
<ipython-input-3-42a243af2d2f> in <module>
      1 # ctl = CtlDescriptor(file='202104120000_arw_wrfout_d01.ctl')
----> 2 dset = open_CtlDataset('202104120000_arw_wrfout_d01.ctl')

~/anaconda3/lib/python3.7/site-packages/xgrads/io.py in open_CtlDataset(desfile, returnctl, encoding)
    100         raise Exception('unsupported file, suffix should be .ctl')
    101 
    102     ctl = CtlDescriptor(encoding=encoding, file=desfile)
    103 
    104     if ctl.template:

~/anaconda3/lib/python3.7/site-packages/xgrads/core.py in __init__(self, encoding, **kwargs)
    124                         print(dirname)
    125 
    126                         if dirname[-1] != '/':
    127                             fileContent[i] = line.replace('^',
    128                                                os.path.dirname(abspath) + '/')

IndexError: string index out of range

What can I do?

miniufo commented 3 years ago

Sorry that currently xgrads only support the raw binary file stored in a sequence of t, z, y, x... For grib2 format, I think a better way is to use cfgrid or eccodes.

Since there are specific tools for grib and netcdf decoding, support for formats like grib, netcdf etc may not be my primary targets. Thanks for your interests in xgrads.

Manuelch94 commented 3 years ago

Thank you very much!