3

I am trying to load grib2 files and I am not sure if the files are the issues or if the way I am trying to load them.

The files are extracted from here (I didn't download them from here, but copied them from a folder of a colleague that gets them from here - so really they should be the same files..., but I then also tried to insert the ftp address and got the same errors).

I tired pygrib

grbs = pygrib.open('pgbf2016060100.01.2016053100.grib2')

gets this error:

---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-20-674763ffdd1f> in <module>()
----> 1 grbs = pygrib.open('pgbf2016060100.01.2016053100.grib2')

pygrib.pyx in pygrib.open.__cinit__ (pygrib.c:2772)()

IOError: [Errno could not open %s] pgbf2016060100.01.2016053100.grib2

I tried xarray

ds = xr.open_dataset("pgbf2016060100.01.2016053100.grb2",engine='pynio')

and I get this error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/software/centos6/x86_64/canopy-1.5.2/Canopy_64bit/User/lib/python2.7/site-    packages/IPython/core/interactiveshell.pyc in run_code(self, code_obj, result)
   3081             if result is not None:
   3082                 result.error_in_exec = sys.exc_info()[1]
-> 3083             self.showtraceback()
   3084         else:
   3085             outflag = 0

/software/centos6/x86_64/canopy-1.5.2/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in showtraceback(self, exc_tuple,     filename, tb_offset, exception_only)
   1858                 return
   1859 
-> 1860             if issubclass(etype, SyntaxError):
   1861                 # Though this won't be called by syntax errors in the input
   1862                 # line, there may be SyntaxError cases with imported code.

TypeError: issubclass() arg 1 must be a class

I tried directly NIO

f = nio.open_file("pgbf2016060100.01.2016053100.grb2")

and I get the same error as the one from xarray.

Any suggestion?

Asclepius
  • 57,944
  • 17
  • 167
  • 143
claude
  • 549
  • 8
  • 25
  • 1
    Check integrity of your file by wgrib2. And check pygrib configuration files, may be grib2 support had been turn off during installation, because pygrib use grib_api and it is possible to compile grib_api library without grib2 support. – Serenity Jun 28 '16 at 03:55

1 Answers1

1

I Had this problem with pygrib. The root of the problem is the JPEG support, something was wrong with openjpeg or jasper libraries, after o many tries, I made this steps to solve this problem with the pygrib reinstalling:

  • Remove this libraries with:

    yum remove openjpeg and yum remove jasper (I use RHEL 7)

  • After reinstalling this libraries with:

    yum install openjpeg and yum install jasper

  • Make sure of grib_api or his replacement eccodes are no longer installed. After, install eccodes from the source, follow this instructions. The installation directory is vital for the next step, in my case I installed it in /usr/local/lib/eccodes (I make an empty directory called eccodes in /usr/local/lib), this directory are specify during the cmake with the argument -DCMAKE_INSTALL_PREFIX=/path/to/where/you/install/eccodes.

  • Finally install pygrib from the source following this steps, I only uncomment the line 15 in the setup.cfg and setting grib_api_dir = /usr/local/lib/eccodes (Here are the importance of the install directory). If the installation pass without problems the test.py the problem is already solved.

cmcuervol
  • 335
  • 1
  • 3
  • 11
  • Thanks! I left pygrib behind for xarray, but by any chance did you open a PR on the GitHub repo? it seems relevant. thanks! – claude Mar 06 '19 at 16:03
  • Not, I didn't open a pull request on the GitHub repository. This error is maybe for an issue in the installation of `openjpeg` or `jasper`. I will try to use `xarray`, looks awesome and simply. Thanks! – cmcuervol Mar 06 '19 at 16:51