I'm having problems correctly using a sidecar file for a gridded dataset (IMERG). Here is the generalized problem.
- I make a sidecar file for IMERG using STAREMaster_py ...
$ python create_sidecar_files.py --workers 4 --grid IMERG
IMERG_stare.nc
>>>> ulong STARE_index(i=1800, j=3600);
And this matches up with the dataset I'm aiming to pod:
DYAMONDv2_PE3600x1800-DE.prectot.20200116_0000z.nc4
>>>> float PRECTOT(time=1, lat=1800, lon=3600);
- But when I attempt to form a STAREPandas dataframe using it as so...
gdf = starepandas.read_granule(granule_path, sidecar=True,
latlon=False, read_timestamp=False,
sidecar_path=sidecar_path,
add_sids=False, adapt_resolution=True)
I get an error which leads me to that think I'm likely evoking the starepandas.read_granule() method incorrectly for this kind of sidecar (gridded data). Inside said method, I see that it gets the correct sidecar info, although the self.nom_res = None parameter might be an issue.
granule.read_sidecar_index():
ds = <class 'netCDF4._netCDF4.Dataset'>
ds.dimensions = 'i' : size = 1800
'j' : size = 3600
'l' : size = 8
ds.variables = 'STARE_index': uint64 STARE_index(i, j)
'STARE_cover': uint64 STARE_cover(l)
self.nom_res = None
Here is where the error is raised (in starepandas.read_granule()).
try:
self.sids = ds['STARE_index_{}'.format(self.nom_res)][:, :].astype(numpy.int64)
except IndexError:
# If we don't have a nomres?
>>>> 'STARE_index{}'.format(self.nom_res) = 'STARE_indexNone'
self.sids = ds['STARE_index{}'.format(self.nom_res)][:, :].astype(numpy.int64)
>>>> STAREPandas/starepandas/io/granules/granule.py", line 66, in read_sidecar_index
>>>> self.sids = ds['STARE_index{}'.format(self.nom_res)][:, :].astype(numpy.int64)
>>>> IndexError: STARE_indexNone not found in /
Any suggestions? Thanks.
Note, starepandas.read_granule() is inherited from the Granule class via a class I created) as should be clear from the code snippet below.
STAREPandas/starepandas/io/granules/
__init__.py:
from .imergl3 import L3IMERG, DYAMONDv2
Added
'L3IMERG': L3IMERG,
'DYAMONDv2': DYAMONDv2
to granule_factory_library
imergl3.py:
# Standard Imports
import os
import datetime
# Third-Party Imports
import numpy
# STARE Imports
from starepandas.io.granules.granule import Granule
import starepandas
class L3IMERG(Granule):
def __init__(self, file_path, sidecar_path=None):
# Use Granule.__init__() for this instance (self)
super().__init__(file_path, sidecar_path)
##
# Opens file_path using netCDF4
self.netcdf = starepandas.io.s3.nc4_dataset_wrapper(self.file_path, 'r', format='NETCDF4')
# Not implemented yet
# def read_timestamps(self):
# self.ts_start = self.netcdf.time_coverage_start
# self.ts_end = self.netcdf.time_coverage_end
def read_latlon(self):
self.lat = self.netcdf['lat'][:].astype(numpy.double)
self.lon = self.netcdf['lon'][:].astype(numpy.double)
class DYAMONDv2(L3IMERG):
"""Special case for IMREG precip files with file names like
DYAMONDv2_PE3600x1800-DE.prectot.20200116_0000z.nc4
"""
def __init__(self, file_path, sidecar_path=None):
# Use L3IMERG.__init__(), which calls Granule.__init__() for this instance (self)
super().__init__(file_path, sidecar_path=sidecar_path)
Then in my code:
from STAREpodder.cfg.def_IMERGPF import IMERGPF
starepandas.io.granules.granule_factory_library['DYAMONDv2'] = IMERGPF
gdf = starepandas.read_granule(granule_path, sidecar=True,
latlon=False, read_timestamp=False,
sidecar_path=sidecar_path,
add_sids=False, adapt_resolution=True)
I should add some potential dependency issues that might be at work here (e.g., Pandas 2.0).
| Name |
Version |
| astropy |
5.2.2 |
| cartopy |
0.21.1 |
| gdal |
3.6.3 |
| geopandas |
0.12.2 |
| geopandas-base |
0.12.2 |
| geos |
3.11.2 |
| h5py |
3.8.0 |
| hdf4 |
4.2.15 |
| hdf5 |
1.12.2 |
| hdfeos2 |
2.20 |
| matplotlib |
3.7.1 |
| numpy |
1.24.2 |
| pandas |
2.0.0 |
| proj |
9.1.1 |
| pygeos |
0.14 |
| pyhdf |
0.10.5 |
| pyproj |
3.5.0 |
| pyshp |
2.3.1 |
| pytest |
7.3.1 |
| python |
3.11.3 |
| shapely |
2.0.1 |
| STARE |
Installs |
| pystare |
0.8.12 STARE |
| staremaster |
0.0.4 STARE |
| starepandas |
0.6.6 STARE |
I'm having problems correctly using a sidecar file for a gridded dataset (IMERG). Here is the generalized problem.
And this matches up with the dataset I'm aiming to pod:
I get an error which leads me to that think I'm likely evoking the
starepandas.read_granule()method incorrectly for this kind of sidecar (gridded data). Inside said method, I see that it gets the correct sidecar info, although theself.nom_res = Noneparameter might be an issue.Here is where the error is raised (in
starepandas.read_granule()).Any suggestions? Thanks.
Note,
starepandas.read_granule()is inherited from theGranuleclass via a class I created) as should be clear from the code snippet below.Then in my code:
I should add some potential dependency issues that might be at work here (e.g., Pandas 2.0).