Skip to content
Snippets Groups Projects
Commit 00c8be44 authored by Aaron Spring's avatar Aaron Spring
Browse files

open grb

parent 1af5cf80
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import xarray as xr
```
%% Cell type:code id: tags:
``` python
grb_path = '/work/mh1007/MPI-GE/onepct/onepct0001/outdata/echam6/onepct0001_echam6_BOT_mm_1950.grb'
```
%% Cell type:code id: tags:
``` python
!ls /work/mh1007/MPI-GE/onepct/onepct0001/outdata/echam6/onepct0001_echam6_BOT_mm_1950*
```
%% Output
/work/mh1007/MPI-GE/onepct/onepct0001/outdata/echam6/onepct0001_echam6_BOT_mm_1950.grb
%% Cell type:code id: tags:
``` python
!conda list eccodes
```
%% Output
# packages in environment at /work/mh0727/m300524/miniconda3/envs/pymistral:
#
# Name Version Build Channel
eccodes 2.14.1 hec26673_0 conda-forge
%% Cell type:code id: tags:
``` python
ds = xr.open_dataset("/work/mh1007/MPI-GE/onepct/onepct0001/outdata/echam6/onepct0001_echam6_echam_2001.grb", engine='cfgrib', backend_kwargs={"indexpath": ""})
```
%% Output
ecCodes provides no latitudes/longitudes for gridType='sh'
ecCodes provides no latitudes/longitudes for gridType='sh'
ecCodes provides no latitudes/longitudes for gridType='sh'
ecCodes provides no latitudes/longitudes for gridType='sh'
%% Cell type:code id: tags:
``` python
grb_ds = xr.open_dataset(grb_path, engine='cfgrib', backend_kwargs={"indexpath": ""})
```
%% Output
---------------------------------------------------------------------------
DatasetBuildError Traceback (most recent call last)
<ipython-input-10-444941c83cd0> in <module>
----> 1 grb_ds = xr.open_dataset(grb_path, engine='cfgrib', backend_kwargs={"indexpath": ""})
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/xarray/backends/api.py in open_dataset(filename_or_obj, group, decode_cf, mask_and_scale, decode_times, autoclose, concat_characters, decode_coords, engine, chunks, lock, cache, drop_variables, backend_kwargs, use_cftime)
518 elif engine == "cfgrib":
519 store = backends.CfGribDataStore(
--> 520 filename_or_obj, lock=lock, **backend_kwargs
521 )
522
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/xarray/backends/cfgrib_.py in __init__(self, filename, lock, **backend_kwargs)
41 lock = ECCODES_LOCK
42 self.lock = ensure_lock(lock)
---> 43 self.ds = cfgrib.open_file(filename, **backend_kwargs)
44
45 def open_store_variable(self, name, var):
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/dataset.py in open_file(path, grib_errors, indexpath, filter_by_keys, read_keys, **kwargs)
635 index_keys = sorted(ALL_KEYS + read_keys)
636 index = open_fileindex(path, grib_errors, indexpath, index_keys).subindex(filter_by_keys)
--> 637 return Dataset(*build_dataset_components(index, read_keys=read_keys, **kwargs))
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/dataset.py in build_dataset_components(index, errors, encode_cf, squeeze, log, read_keys, time_dims)
601 'encode_cf': encode_cf,
602 }
--> 603 attributes = build_dataset_attributes(index, filter_by_keys, encoding)
604 return dimensions, variables, attributes, encoding
605
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/dataset.py in build_dataset_attributes(index, filter_by_keys, encoding)
527
528 def build_dataset_attributes(index, filter_by_keys, encoding):
--> 529 attributes = enforce_unique_attributes(index, GLOBAL_ATTRIBUTES_KEYS, filter_by_keys)
530 attributes['Conventions'] = 'CF-1.7'
531 if 'GRIB_centreDescription' in attributes:
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/dataset.py in enforce_unique_attributes(index, attributes_keys, filter_by_keys)
253 fbk.update(filter_by_keys)
254 fbks.append(fbk)
--> 255 raise DatasetBuildError("multiple values for key %r" % key, key, fbks)
256 if values and values[0] not in ('undef', 'unknown'):
257 attributes['GRIB_' + key] = values[0]
DatasetBuildError: multiple values for key 'centre'
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
 
``` python
from dask.distributed import Client
import multiprocessing
ncpu = multiprocessing.cpu_count()
threads = 6
nworker = ncpu//threads
print(f'Number of CPUs: {ncpu}, number of threads: {threads}, number of workers: {nworker}')
```
 
%% Output
 
Number of CPUs: 48, number of threads: 6, number of workers: 8
 
%% Cell type:code id: tags:
 
``` python
client = Client(processes=True, threads_per_worker=threads, n_workers=nworker, memory_limit='256GB')
client
```
 
%% Cell type:markdown id: tags:
 
# Intake to load CMIP data
 
### Using intake-esm on mistral
 
- install intake-esm: https://intake-esm.readthedocs.io/en/latest/installation.html
- check the already built catalogs: `/home/mpim/m300524/intake-esm-datastore/catalogs` or `https://github.com/NCAR/intake-esm-datastore/` and skip long catalog building process of running `/home/mpim/m300524/intake-esm-datastore/builders/*.ipynb`
 
Available catalogs:
- CMIP6
- CMIP5
- MiKlip (homogenization of names across MiKlip generations needed)
- MPI Grand Ensemble
 
%% Cell type:code id: tags:
 
``` python
import intake
import xarray as xr
import numpy as np
import pandas as pd
import warnings
import matplotlib.pyplot as plt
import pprint
warnings.simplefilter("ignore")
%matplotlib inline
xr.set_options(keep_attrs=True)
import intake_esm
import pymistral
from pymistral.setup import yearmean
import cartopy.crs as ccrs
import cartopy as cp
from climpred.stats import dpp, varweighted_mean_period
```
 
%% Output
Read df from path: /home/mpim/m300524/pymistral/MPI-ESM-1-2-LR_output.csv
%% Cell type:code id: tags:
 
``` python
intake_esm.__version__
```
 
%% Output
 
'2019.10.15.post33'
 
%% Cell type:markdown id: tags:
 
# CMIP6
 
%% Cell type:code id: tags:
 
``` python
col_url = "/home/mpim/m300524/intake-esm-datastore/catalogs/mistral-cmip6.json"
col = intake.open_esm_datastore(col_url)
```
 
%% Cell type:code id: tags:
 
``` python
# example: time mean of oceanic CO2 flux in esm-piControl
variable='fgco2'
query = dict(experiment_id=['esm-piControl'], table_id='Omon',
variable_id=variable, grid_label=['gn', 'gr'])
cat = col.search(**query)
 
print(cat.df['source_id'].unique())
```
 
%% Output
 
['GFDL-ESM4' 'CanESM5' 'CESM2' 'CNRM-ESM2-1']
 
%% Cell type:markdown id: tags:
 
Credits to Julius Busecke for creating `cmip6_preprocessing`: https://github.com/jbusecke/cmip6_preprocessing
 
%% Cell type:code id: tags:
 
``` python
from cmip6_preprocessing.preprocessing import combined_preprocessing
#combined_preprocessing??
```
 
%% Cell type:code id: tags:
 
``` python
dset_dict = cat.to_dataset_dict(cdf_kwargs={'chunks': {'time': 12*50}},
preprocess=combined_preprocessing)
```
 
%% Output
 
--> The keys in the returned dictionary of datasets are constructed as follows:
'activity_id.institution_id.source_id.experiment_id.table_id.grid_label'
--> There will be 5 group(s)
 
%% Cell type:code id: tags:
 
``` python
# manually check for double entries and delete
del dset_dict['CMIP.NCAR.CESM2.esm-piControl.Omon.gn']
```
 
%% Cell type:code id: tags:
 
``` python
fig, axarr = plt.subplots(nrows=len(dset_dict), figsize=[10,4*len(dset_dict)],
subplot_kw={'projection':ccrs.PlateCarree()}
)
for ax,(k, ds) in zip(axarr.flat,dset_dict.items()):
print(f'Processing {k}')
# do your science here
ds = ds.mean('time')
assert len(ds[variable].squeeze().dims) == 2
ds[variable].squeeze().plot(ax=ax,robust=True,transform=ccrs.PlateCarree(),
vmin=-1e-9,vmax=1e-9,cmap='RdBu_r')
# visuals
ax.set_title(k)
ax.set_global()
ax.coastlines()
ax.add_feature(cp.feature.LAND)
```
 
%% Output
 
Processing CMIP.CCCma.CanESM5.esm-piControl.Omon.gn
Processing CMIP.CNRM-CERFACS.CNRM-ESM2-1.esm-piControl.Omon.gn
Processing CMIP.NCAR.CESM2.esm-piControl.Omon.gr
Processing CMIP.NOAA-GFDL.GFDL-ESM4.esm-piControl.Omon.gr
 
 
%% Cell type:code id: tags:
 
``` python
```
 
%% Cell type:markdown id: tags:
 
# CMIP5
 
%% Cell type:code id: tags:
 
``` python
col_url = "/home/mpim/m300524/intake-esm-datastore/catalogs/mistral-cmip5.json"
col = intake.open_esm_datastore(col_url)
col.df.head()
```
 
%% Output
 
product_id institute model experiment frequency modeling_realm \
0 output1 MOHC HadGEM2-CC historical day atmos
1 output1 MOHC HadGEM2-CC historical day atmos
2 output1 MOHC HadGEM2-CC historical day atmos
3 output1 MOHC HadGEM2-CC historical day atmos
4 output1 MOHC HadGEM2-CC historical day atmos
mip_table ensemble_member variable temporal_subset version \
0 day r2i1p1 rhs 19991201-20041130 v20111129
1 day r2i1p1 rhs 20041201-20051130 v20111129
2 day r2i1p1 rhs 19791201-19841130 v20111129
3 day r2i1p1 rhs 19591201-19641130 v20111129
4 day r2i1p1 rhs 19841201-19891130 v20111129
path
0 /work/kd0956/CMIP5/data/cmip5/output1/MOHC/Had...
1 /work/kd0956/CMIP5/data/cmip5/output1/MOHC/Had...
2 /work/kd0956/CMIP5/data/cmip5/output1/MOHC/Had...
3 /work/kd0956/CMIP5/data/cmip5/output1/MOHC/Had...
4 /work/kd0956/CMIP5/data/cmip5/output1/MOHC/Had...
 
%% Cell type:code id: tags:
 
``` python
uni_dict = col.unique(['model', 'institute', 'mip_table','experiment'])
pprint.pprint(uni_dict, compact=True)
```
 
%% Output
 
{'experiment': {'count': 101,
'values': ['historical', 'piControl', 'rcp85', 'midHolocene',
'rcp45', 'amip4K', 'aqua4xCO2', 'sstClim',
'sstClimAerosol', 'sstClimSulfate', 'amip4xCO2',
'amip', 'sstClim4xCO2', 'aqua4K', 'aquaControl',
'amipFuture', 'decadal2001', 'decadal1982',
'decadal1961', 'decadal2003', 'decadal1973',
'decadal1963', 'decadal1975', 'decadal1996',
'decadal2005', 'decadal2000', 'decadal1988',
'decadal2002', 'decadal1972', 'decadal1977',
'decadal2008', 'decadal1986', 'decadal1968',
'decadal1999', 'decadal1967', 'decadal1992',
'decadal1990', 'decadal1978', 'decadal1960',
'decadal1984', 'decadal1976', 'decadal1980',
'decadal1995', 'decadal1987', 'decadal1970',
'decadal1989', 'decadal2004', 'decadal1979',
'decadal1998', 'decadal1962', 'decadal2007',
'decadal1966', 'decadal1991', 'decadal1985',
'decadal1994', 'decadal2006', 'decadal1981',
'decadal1993', 'decadal1983', 'decadal1971',
'decadal1974', 'decadal1969', 'decadal1997',
'decadal1965', 'decadal2009', 'decadal1964',
'historicalNat', 'esmHistorical', 'esmFixClim1',
'esmrcp85', 'rcp60', 'rcp26', 'esmFdbk2', 'esmFdbk1',
'1pctCO2', 'historicalExt', 'abrupt4xCO2',
'esmControl', 'historicalGHG', 'esmFixClim2',
'past1000', 'lgm', 'historicalMisc', 'decadal2011',
'decadal2010', 'volcIn2010', 'decadal1959',
'sst2030', 'sst2090rcp45', 'sst2090', 'decadal2012',
'noVolc1975', 'noVolc1990', 'noVolc1970',
'noVolc2005', 'noVolc1960', 'noVolc1985',
'noVolc1995', 'noVolc1965', 'noVolc2000',
'noVolc1980']},
'institute': {'count': 28,
'values': ['MOHC', 'FIO', 'NCAR', 'NASA-GMAO', 'INM', 'CCCma',
'NASA-GISS', 'CNRM-CERFACS', 'NICAM', 'IPSL',
'CSIRO-QCCCE', 'NSF-DOE-NCAR', 'NCC', 'NOAA-NCEP',
'CSIRO-BOM', 'CMCC', 'LASG-CESS', 'LASG-IAP',
'NOAA-GFDL', 'ICHEC', 'BNU', 'COLA-CFS', 'NIMR-KMA',
'MIROC', 'BCC', 'INPE', 'MPI-M', 'MRI']},
'mip_table': {'count': 18,
'values': ['day', 'Amon', 'Omon', 'LImon', 'Lmon', 'aero',
'OImon', '6hrPlev', 'Oyr', 'fx', 'cfDay', 'cfOff',
'cfMon', 'cf3hr', 'cfSites', '3hr', '6hrLev',
'Oclim']},
'model': {'count': 62,
'values': ['HadGEM2-CC', 'HadGEM2-A', 'HadCM3', 'HadGEM2-ES',
'FIO-ESM', 'fio-esm', 'CCSM4', 'GEOS-5', 'inmcm4',
'CanESM2', 'CanCM4', 'CanAM4', 'GISS-E2-R',
'GISS-E2-R-CC', 'GISS-E2-H-CC', 'GISS-E2-H', 'CNRM-CM5',
'CNRM-CM5-2', 'NICAM-09', 'IPSL-CM5A-LR', 'IPSL-CM5A-MR',
'IPSL-CM5B-LR', 'CSIRO-Mk3-6-0', 'CESM1-CAM5',
'CESM1-CAM5-1-FV2', 'CESM1-BGC', 'CESM1-WACCM',
'CESM1-FASTCHEM', 'NorESM1-M', 'NorESM1-ME', 'CFSv2-2011',
'ACCESS1-3', 'ACCESS1-0', 'CMCC-CM', 'CMCC-CESM',
'CMCC-CMS', 'FGOALS-g2', 'FGOALS-s2', 'FGOALS-gl',
'GFDL-HIRAM-C180', 'GFDL-ESM2G', 'GFDL-CM2p1', 'GFDL-CM3',
'GFDL-ESM2M', 'GFDL-HIRAM-C360', 'EC-EARTH', 'EC-Earth',
'BNU-ESM', 'HadGEM2-AO', 'MIROC4h', 'MIROC5', 'MIROC-ESM',
'MIROC-ESM-CHEM', 'bcc-csm1-1', 'bcc-csm1-1-m',
'MPI-ESM-LR', 'MPI-ESM-MR', 'MPI-ESM-P', 'MRI-AGCM3-2H',
'MRI-CGCM3', 'MRI-ESM1', 'MRI-AGCM3-2S']}}
 
%% Cell type:code id: tags:
 
``` python
dset_dict = col.search(experiment='esmControl',variable='fgco2').to_dataset_dict(cdf_kwargs={'chunks': {'time': 12*50}})
```
 
%% Output
 
--> The keys in the returned dictionary of datasets are constructed as follows:
'institute.model.experiment.mip_table'
--> There will be 14 group(s)
 
%% Cell type:code id: tags:
 
``` python
# example: take a single dataset out of dict
ds = dset_dict['MPI-M.MPI-ESM-LR.esmControl.Omon']['fgco2'].squeeze().load()
```
 
%% Cell type:markdown id: tags:
 
# MiKlip
MiKlip data is cmorized based on `CMIP5` conventions.
The following catalog `col` contains output from 5 `generation`s of MiKlip output from `/work/bmx828/miklip-ces/data4miklip/model/global/miklip/`.
 
- Marotzke, Jochem, Wolfgang A. Müller, Freja S. E. Vamborg, Paul Becker, Ulrich Cubasch, Hendrik Feldmann, Frank Kaspar, et al. “MiKlip: A National Research Project on Decadal Climate Prediction.” Bulletin of the American Meteorological Society 97, no. 12 (June 17, 2016): 2379–94. https://doi.org/10/gddfck.
 
%% Cell type:code id: tags:
 
``` python
col_url = "/home/mpim/m300524/intake-esm-datastore/catalogs/mistral-miklip.json"
col = intake.open_esm_datastore(col_url)
col.df.head()
```
 
%% Output
 
generation product_id institute model experiment frequency \
0 baseline0 output1 MPI-M MPI-ESM-LR decadal2001 day
1 baseline0 output1 MPI-M MPI-ESM-LR decadal2001 day
2 baseline0 output1 MPI-M MPI-ESM-LR decadal2001 day
3 baseline0 output1 MPI-M MPI-ESM-LR decadal2001 day
4 baseline0 output1 MPI-M MPI-ESM-LR decadal2001 day
modeling_realm mip_table ensemble_member variable temporal_subset \
0 atmos day r2i1p1 sfcWind 20020101-20111231
1 atmos day r2i1p1 tas 20020101-20111231
2 atmos day r2i1p1 psl 20020101-20111231
3 atmos day r2i1p1 pr 20020101-20111231
4 atmos day r2i1p1 tasmin 20020101-20111231
version path
0 v20111122 /work/bmx828/miklip-ces/data4miklip/model/glob...
1 v20111122 /work/bmx828/miklip-ces/data4miklip/model/glob...
2 v20111122 /work/bmx828/miklip-ces/data4miklip/model/glob...
3 v20111122 /work/bmx828/miklip-ces/data4miklip/model/glob...
4 v20111122 /work/bmx828/miklip-ces/data4miklip/model/glob...
 
%% Cell type:code id: tags:
 
``` python
col.df.nunique()
```
 
%% Output
 
generation 6
product_id 4
institute 4
model 5
experiment 402
frequency 8
modeling_realm 7
mip_table 21
ensemble_member 93
variable 276
temporal_subset 2727
version 22
path 1773282
dtype: int64
 
%% Cell type:code id: tags:
 
``` python
import pprint
uni_dict = col.unique(['generation', 'product_id'])
pprint.pprint(uni_dict, compact=True)
```
 
%% Cell type:code id: tags:
 
``` python
# example: comparing inits from 1991 from two generations
cat = col.search(model='MPI-ESM-LR',variable='tas',frequency='mon',
ensemble_member=['r1i1p1','r2i1p1','r3i1p1'],
experiment=['decs4e1991','decs4e1992','decadal1991','decadal1992'])
```
 
%% Cell type:code id: tags:
 
``` python
dset_dict = cat.to_dataset_dict(cdf_kwargs={'chunks': {'time': 12*5}})
```
 
%% Output
 
--> The keys in the returned dictionary of datasets are constructed as follows:
'institute.model.experiment.mip_table'
--> There will be 4 group(s)
 
%% Cell type:code id: tags:
 
``` python
ds = xr.concat([i['tas'].squeeze().mean('ensemble_member') for i in dset_dict.values()],'run')
ds['run']=list(dset_dict.keys())
```
 
%% Cell type:code id: tags:
 
``` python
# plot one target timestep: Feb 93
ds.sel(time='1993-02').squeeze().plot(col='run',col_wrap=2,robust=True,figsize=(12,8))
```
 
%% Output
 
<xarray.plot.facetgrid.FacetGrid at 0x2b3f1ed62710>
 
 
%% Cell type:code id: tags:
 
``` python
```
 
%% Cell type:markdown id: tags:
 
# MPI Grand Ensemble
 
%% Cell type:markdown id: tags:
 
Max Planck Institute Grand Ensemble (Maher et al. 2019 https://doi.org/10/gf3kgt) cmorized by CMIP5-standards accessible on the DKRZ's MISTRAL disk storage system in /work/mh1007/CMOR/MPI-GE.
 
%% Cell type:code id: tags:
 
``` python
col_url = "/home/mpim/m300524/intake-esm-datastore/catalogs/mistral-MPI-GE.json"
col = intake.open_esm_datastore(col_url)
col.df.head()
```
 
%% Output
 
product_id institute model experiment frequency modeling_realm mip_table \
0 output1 MPI-M MPI-ESM piControl mon atmos Amon
1 output1 MPI-M MPI-ESM piControl mon atmos Amon
2 output1 MPI-M MPI-ESM piControl mon atmos Amon
3 output1 MPI-M MPI-ESM piControl mon atmos Amon
4 output1 MPI-M MPI-ESM piControl mon atmos Amon
ensemble_member variable temporal_subset version \
0 1 prsn 310001-319912 v20190123
1 1 prsn 380001-385012 v20190123
2 1 prsn 230001-239912 v20190123
3 1 prsn 280001-289912 v20190123
4 1 prsn 190001-199912 v20190123
path
0 /work/mh1007/CMOR/MPI-GE/output1/MPI-M/MPI-ESM...
1 /work/mh1007/CMOR/MPI-GE/output1/MPI-M/MPI-ESM...
2 /work/mh1007/CMOR/MPI-GE/output1/MPI-M/MPI-ESM...
3 /work/mh1007/CMOR/MPI-GE/output1/MPI-M/MPI-ESM...
4 /work/mh1007/CMOR/MPI-GE/output1/MPI-M/MPI-ESM...
 
%% Cell type:code id: tags:
 
``` python
# example: GMST for three members in historical with all scenarios
cat = col.search(variable='tas',mip_table='Amon',
ensemble_member=[1,50,100],
experiment=['historical','rcp26','rcp45','rcp85'])
```
 
%% Cell type:code id: tags:
 
``` python
dset_dict = cat.to_dataset_dict(cdf_kwargs={'chunks': {'time': 12*20}})
```
 
%% Output
 
--> The keys in the returned dictionary of datasets are constructed as follows:
'institute.model.experiment.mip_table'
--> There will be 4 group(s)
 
%% Cell type:code id: tags:
 
``` python
dset_dict.keys()
```
 
%% Output
 
dict_keys(['MPI-M.MPI-ESM.historical.Amon', 'MPI-M.MPI-ESM.rcp26.Amon', 'MPI-M.MPI-ESM.rcp45.Amon', 'MPI-M.MPI-ESM.rcp85.Amon'])
 
%% Cell type:code id: tags:
 
``` python
ds = xr.merge([list(dset_dict.values())[0],xr.concat(list(dset_dict.values())[1:],'experiment')])
```
 
%% Cell type:code id: tags:
``` python
ds['experiment'] = ['RCP2.6','RCP4.5','RCP8.5']
```
 
%% Cell type:code id: tags:
 
``` python
gmst = ds.mean(['lon','lat'])['tas']
```
 
%% Cell type:code id: tags:
 
``` python
gmst = gmst.groupby('time.year').mean('time')
del gmst['height']
```
 
%% Cell type:code id: tags:
 
``` python
for member in gmst.ensemble_member:
gmst.sel(ensemble_member=member).plot.line(hue='experiment')
plt.title('MPI Grand Ensemble: GMST')
```
 
%% Output
 
Text(0.5, 1.0, 'MPI Grand Ensemble: GMST')
 
 
%% Cell type:code id: tags:
 
``` python
```
......
%% Cell type:code id: tags:
``` python
import xarray as xr
```
%% Cell type:code id: tags:
``` python
path='/work/bk1099/data/sf00_MM/2000-2009/E5sf00_MM_2000-2009.grb'
```
%% Cell type:code id: tags:
``` python
ds = xr.open_dataset(path, engine='cfgrib',backend_kwargs={"indexpath": ""})
```
%% Output
---------------------------------------------------------------------------
PermissionError Traceback (most recent call last)
<ipython-input-27-0f3f2f20f4e0> in <module>
----> 1 ds = xr.open_dataset(path, engine='cfgrib',backend_kwargs={"indexpath": ""})
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/xarray/backends/api.py in open_dataset(filename_or_obj, group, decode_cf, mask_and_scale, decode_times, autoclose, concat_characters, decode_coords, engine, chunks, lock, cache, drop_variables, backend_kwargs, use_cftime)
518 elif engine == "cfgrib":
519 store = backends.CfGribDataStore(
--> 520 filename_or_obj, lock=lock, **backend_kwargs
521 )
522
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/xarray/backends/cfgrib_.py in __init__(self, filename, lock, **backend_kwargs)
41 lock = ECCODES_LOCK
42 self.lock = ensure_lock(lock)
---> 43 self.ds = cfgrib.open_file(filename, **backend_kwargs)
44
45 def open_store_variable(self, name, var):
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/dataset.py in open_file(path, grib_errors, indexpath, filter_by_keys, read_keys, **kwargs)
634 """Open a GRIB file as a ``cfgrib.Dataset``."""
635 index_keys = sorted(ALL_KEYS + read_keys)
--> 636 index = open_fileindex(path, grib_errors, indexpath, index_keys).subindex(filter_by_keys)
637 return Dataset(*build_dataset_components(index, read_keys=read_keys, **kwargs))
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/dataset.py in open_fileindex(path, grib_errors, indexpath, index_keys)
621 ):
622 stream = messages.FileStream(path, message_class=cfmessage.CfMessage, errors=grib_errors)
--> 623 return stream.index(index_keys, indexpath=indexpath)
624
625
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/messages.py in index(self, index_keys, indexpath)
235 def index(self, index_keys, indexpath='{path}.{short_hash}.idx'):
236 # type: (T.List[str], str) -> FileIndex
--> 237 return FileIndex.from_indexpath_or_filestream(self, index_keys, indexpath)
238
239
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/messages.py in from_indexpath_or_filestream(cls, filestream, index_keys, indexpath, log)
303 # Reading and writing the index can be explicitly suppressed by passing indexpath==''.
304 if not indexpath:
--> 305 return cls.from_filestream(filestream, index_keys)
306
307 hash = hashlib.md5(repr(index_keys).encode('utf-8')).hexdigest()
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/messages.py in from_filestream(cls, filestream, index_keys)
263 count_offsets = {} # type: T.Dict[int, int]
264 header_values_cache = {}
--> 265 for message in filestream:
266 header_values = []
267 for key in index_keys:
/work/mh0727/m300524/miniconda3/envs/pymistral/lib/python3.7/site-packages/cfgrib/messages.py in __iter__(self)
208 def __iter__(self):
209 # type: () -> T.Generator[Message, None, None]
--> 210 with open(self.path, 'rb') as file:
211 valid_message_found = False
212 while True:
PermissionError: [Errno 13] Permission denied: '/work/bk1099/data/sf00_MM/2000-2009/E5sf00_MM_2000-2009.grb'
%% Cell type:code id: tags:
``` python
ds
```
%% Output
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-26-6f4a4004dcca> in <module>
----> 1 ds
NameError: name 'ds' is not defined
%% Cell type:code id: tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment