Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用pygrib访问GRIB2文件的所有参数_Python_Grib Api_Pygrib - Fatal编程技术网

Python 使用pygrib访问GRIB2文件的所有参数

Python 使用pygrib访问GRIB2文件的所有参数,python,grib-api,pygrib,Python,Grib Api,Pygrib,我正在尝试使用读取GRIB2文件。我能够毫无问题地打开文件和读取数据,但我需要自动化这个过程,不幸的是,每个文件都包含多个非常相似的字段: 1:Total Cloud Cover:% (avg):regular_ll:unknown:level 0 214:fcst time 0-1 hrs (avg):from 201705200000 2:Total Cloud Cover:% (avg):regular_ll:unknown:level 0 224:fcst time 0-1 hrs (a

我正在尝试使用读取GRIB2文件。我能够毫无问题地打开文件和读取数据,但我需要自动化这个过程,不幸的是,每个文件都包含多个非常相似的字段:

1:Total Cloud Cover:% (avg):regular_ll:unknown:level 0 214:fcst time 0-1 hrs (avg):from 201705200000
2:Total Cloud Cover:% (avg):regular_ll:unknown:level 0 224:fcst time 0-1 hrs (avg):from 201705200000
3:Total Cloud Cover:% (avg):regular_ll:unknown:level 0 234:fcst time 0-1 hrs (avg):from 201705200000
4:Total Cloud Cover:% (avg):regular_ll:unknown:level 0 10:fcst time 0-1 hrs (avg):from 201705200000
5:Total Cloud Cover:% (instant):regular_ll:unknown:level 0 244:fcst time 1 hrs:from 201705200000
6:Total Cloud Cover:% (avg):regular_ll:unknown:level 0 211:fcst time 0-1 hrs (avg):from 201705200000
这些文件的唯一区别(正如pygrib所看到的)是字段
typeOfFirstFixedSurface
,但我不知道该字段是什么(在我获取grib2文件的站点上找不到相关信息)。我查看了每条消息的所有键/值参数,没有找到任何其他有用的信息来区分字段

但是,在使用时,我会看到更多的参数,例如:

float Total_cloud_cover_convective_cloud(time=1, lat=721, lon=1440);
  :long_name = "Total cloud cover @ Convective cloud layer";
  :units = "%";
  :abbreviation = "TCDC";
  :missing_value = NaNf; // float
  :grid_mapping = "LatLon_Projection";
  :coordinates = "reftime time lat lon ";
  :Grib_Variable_Id = "VAR_0-6-1_L244";
  :Grib2_Parameter = 0, 6, 1; // int
  :Grib2_Parameter_Discipline = "Meteorological products";
  :Grib2_Parameter_Category = "Cloud";
  :Grib2_Parameter_Name = "Total cloud cover";
  :Grib2_Level_Type = "Convective cloud layer";
  :Grib2_Generating_Process_Type = "Forecast";
我可以明确地使用
long\u name
Grib\u Variable\u Id
字段来区分消息,但我无法使用pygrib访问这些“参数”


有没有一种方法可以使用pygrib访问这些参数?

我在理解这种特殊格式和工具时遇到了很多问题,这些格式和工具可以帮助我阅读/解析它。。。最后,我使用了一个非常混乱的设置。一年半前,我在Ubuntu机器上用Python2.7实现了这一点。我粘贴的步骤,我需要做的,以便安装虹膜和所有可能的依赖,希望这将是一些有用的给你,虽然可能有很多过时的版本在整个安装

祝你好运

# http://scitools.org.uk/iris/docs/latest/installing.html

# necessary steps for a clean machine
#
# sudo apt-get install gcc python-dev build-essential python-setuptools libpq-dev git unzip cmake
# pip install virtualenv
# pip install virtualenvwrapper
# mkdir ~/.virtualenvs
# nano ~/.bashrc
# export WORKON_HOME=$HOME/.virtualenvs
# source /usr/local/bin/virtualenvwrapper.sh
# . ~/.bashrc
# mkvirtualenv iris

pip install numpy
pip install biggus

sudo apt-get install libblas-dev liblapack-dev libatlas-base-dev gfortran
# OR
# sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose

pip install scipy

# cartopy dependecies
pip install cython

# https://github.com/OSGeo/proj.4
wget http://download.osgeo.org/proj/proj-4.9.1.tar.gz
tar -xzf proj-4.9.1.tar.gz
cd proj-4.9.1/
./configure
make
make install

# OR
# sudo apt-get install libproj-dev
# sudo apt-get install libgeos-dev

# http://sourceforge.net/projects/pyke/files/pyke/
wget http://sourceforge.net/projects/pyke/files/pyke/1.1.1/pyke-1.1.1.zip/download
unzip download
cd pyke-1.1.1/
python setup.py build
python setup.py install

pip install cartopy

# netcdf4 dependecies
# https://code.google.com/p/netcdf4-python/wiki/UbuntuInstall
# wget https://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.8.16.tar (??????????????)
sudo apt-get install libhdf5-dev

pip install h5py

sudo apt-get install python-netcdf libnetcdf-dev libnetcdf4

git clone https://github.com/Unidata/netcdf4-python.git
cd netcdf4-python
python setup.py build
python setup.py install


# other iris dependencies
pip install cf_units

sudo apt-get install libudunits2-dev

nano ~/.bashrc
# check where exactly xml file is
export UDUNITS2_XML_PATH=/usr/local/share/doc/udunits/udunits2.xml
. ~/.bashrc

pip install pillow

# gribapi
# https://software.ecmwf.int/wiki/display/GRIB/GRIB+API+CMake+installation
wget https://software.ecmwf.int/wiki/download/attachments/3473437/grib_api-1.14.4-Source.tar.gz?api=v2
tar -xzf grib_api-1.14.4-Source.tar.gz?api=v2
mkdir build; cd build
cmake ../grib_api-1.14.0-Source -DENABLE_PYTHON=ON
make -j4
ctest -j4
make install

# OR
# sudo apt-get install libgrib-api-dev
# sudo apt-get install openjpeg-tools

cp -R /usr/local/lib/python2.7/site-packages/grib_api ~/.virtualenvs/iristest/lib/python2.7/site-packages/

# aaaand, here we go, iris!
git clone https://github.com/SciTools/iris.git
cd iris
python setup.py build
python setup.py install
# rejoice!

# pip freeze output:
# Biggus==0.12.0
# Cartopy==0.13.0
# cf-units==1.0.0
# Cython==0.23.4
# h5py==2.5.0
# Iris==1.10.0.dev0
# netCDF4==1.2.2
# numpy==1.10.2
# Pillow==3.0.0
# pyke==1.1.1
# pyshp==1.2.3
# scipy==0.16.1
# Shapely==1.5.13
# six==1.10.0

我在弄明白这种特殊的格式和工具时遇到了很多问题,这些格式和工具可以帮助我阅读/解析它。。。最后,我使用了一个非常混乱的设置。一年半前,我在Ubuntu机器上用Python2.7实现了这一点。我粘贴的步骤,我需要做的,以便安装虹膜和所有可能的依赖,希望这将是一些有用的给你,虽然可能有很多过时的版本在整个安装

祝你好运

# http://scitools.org.uk/iris/docs/latest/installing.html

# necessary steps for a clean machine
#
# sudo apt-get install gcc python-dev build-essential python-setuptools libpq-dev git unzip cmake
# pip install virtualenv
# pip install virtualenvwrapper
# mkdir ~/.virtualenvs
# nano ~/.bashrc
# export WORKON_HOME=$HOME/.virtualenvs
# source /usr/local/bin/virtualenvwrapper.sh
# . ~/.bashrc
# mkvirtualenv iris

pip install numpy
pip install biggus

sudo apt-get install libblas-dev liblapack-dev libatlas-base-dev gfortran
# OR
# sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose

pip install scipy

# cartopy dependecies
pip install cython

# https://github.com/OSGeo/proj.4
wget http://download.osgeo.org/proj/proj-4.9.1.tar.gz
tar -xzf proj-4.9.1.tar.gz
cd proj-4.9.1/
./configure
make
make install

# OR
# sudo apt-get install libproj-dev
# sudo apt-get install libgeos-dev

# http://sourceforge.net/projects/pyke/files/pyke/
wget http://sourceforge.net/projects/pyke/files/pyke/1.1.1/pyke-1.1.1.zip/download
unzip download
cd pyke-1.1.1/
python setup.py build
python setup.py install

pip install cartopy

# netcdf4 dependecies
# https://code.google.com/p/netcdf4-python/wiki/UbuntuInstall
# wget https://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.8.16.tar (??????????????)
sudo apt-get install libhdf5-dev

pip install h5py

sudo apt-get install python-netcdf libnetcdf-dev libnetcdf4

git clone https://github.com/Unidata/netcdf4-python.git
cd netcdf4-python
python setup.py build
python setup.py install


# other iris dependencies
pip install cf_units

sudo apt-get install libudunits2-dev

nano ~/.bashrc
# check where exactly xml file is
export UDUNITS2_XML_PATH=/usr/local/share/doc/udunits/udunits2.xml
. ~/.bashrc

pip install pillow

# gribapi
# https://software.ecmwf.int/wiki/display/GRIB/GRIB+API+CMake+installation
wget https://software.ecmwf.int/wiki/download/attachments/3473437/grib_api-1.14.4-Source.tar.gz?api=v2
tar -xzf grib_api-1.14.4-Source.tar.gz?api=v2
mkdir build; cd build
cmake ../grib_api-1.14.0-Source -DENABLE_PYTHON=ON
make -j4
ctest -j4
make install

# OR
# sudo apt-get install libgrib-api-dev
# sudo apt-get install openjpeg-tools

cp -R /usr/local/lib/python2.7/site-packages/grib_api ~/.virtualenvs/iristest/lib/python2.7/site-packages/

# aaaand, here we go, iris!
git clone https://github.com/SciTools/iris.git
cd iris
python setup.py build
python setup.py install
# rejoice!

# pip freeze output:
# Biggus==0.12.0
# Cartopy==0.13.0
# cf-units==1.0.0
# Cython==0.23.4
# h5py==2.5.0
# Iris==1.10.0.dev0
# netCDF4==1.2.2
# numpy==1.10.2
# Pillow==3.0.0
# pyke==1.1.1
# pyshp==1.2.3
# scipy==0.16.1
# Shapely==1.5.13
# six==1.10.0

为了使用Anaconda分发版安装iris,我执行了以下操作:

conda install -c conda-forge iris
而且所有必需的软件包都是一次性安装的,没有任何问题。 我有水蟒3版

干杯


Pere

为了安装iris,我使用了Anaconda分发版:

conda install -c conda-forge iris
而且所有必需的软件包都是一次性安装的,没有任何问题。 我有水蟒3版

干杯


Pere

查看有关GRIB的数据,这可能会有帮助。。。我几乎把所有的精力都花在了GRIB数据上,因为文档太糟糕了:/@errata谢谢你的选择,不幸的是我试图安装
iris\u GRIB
,但没有成功,因为我没有安装
gribapi
python模块。。。令人惊讶的是,人们在创建新格式时投入了大量精力,却没有人能够使用它们,因为提议的API要么使用起来要么安装起来都是一团糟……如果您愿意,我可以与您分享安装
iris
所需的步骤。。。这完全是一团糟,就像所有与GRIB相关的东西一样:/@errata我确实设法安装了
iris
,问题是我不知道如何为python3安装
gribapi
(能够使用
iris\u GRIB
)-从源代码安装是一团糟,debian的可用软件包需要python3.5和一些python模块,这些模块的版本我无法访问。我已经找到了一种方法来处理我想要使用的文件的问题(我可以将
typeOfFirstFixedSurface
的值链接到相应的
long_name
),但也许在你的问题答案中逐步添加,这是一个好主意,我可以将这个标记为重复。我会给你写一个答案,希望能对你或其他有此问题的人有所帮助…查看有关GRIB数据的信息,可能会有所帮助。。。我几乎把所有的精力都花在了GRIB数据上,因为文档太糟糕了:/@errata谢谢你的选择,不幸的是我试图安装
iris\u GRIB
,但没有成功,因为我没有安装
gribapi
python模块。。。令人惊讶的是,人们在创建新格式时投入了大量精力,却没有人能够使用它们,因为提议的API要么使用起来要么安装起来都是一团糟……如果您愿意,我可以与您分享安装
iris
所需的步骤。。。这完全是一团糟,就像所有与GRIB相关的东西一样:/@errata我确实设法安装了
iris
,问题是我不知道如何为python3安装
gribapi
(能够使用
iris\u GRIB
)-从源代码安装是一团糟,debian的可用软件包需要python3.5和一些python模块,这些模块的版本我无法访问。我已经找到了一种方法来处理我想要使用的文件的问题(我可以将
typeOfFirstFixedSurface
的值链接到相应的
long_name
),但也许在你的问题答案中逐步添加,这是一个好主意,我可以将这个标记为重复。我会给你写一个答案,希望能对你或其他有麻烦的人有所帮助。。。