Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix window #104

Merged
merged 18 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
- reworked `ModisSmoothH5` class with inheritance from HDF5Base and single smoothing method which covers all Whittaker options
- enable check on last_collected
- fail if smoothing from non-initialized sgrid is requested (#80)
- Reworked mosaicing to GeoTiff from HDF5 (#104)
- new executable script
- reworked `ModisMosaic` leveraging `gdal` VRT and in-memory rasters for performing the mosaicing
- Warping can now be performed to user defined target spatial reference instead of just EPSG:4326
- Optional clipping is now performed after warp, generating coherent results independent of the medthod (#85)
- Improved control over gdal's `creationOptions`, including ability to pass kwargs directly to `gdal.Translate` (#89)
- Optional clipping to valid data range or MODIS NDVI and LST (#88)
- Optional rounding of integers to exponents of 10 (#88)

- ## v 0.3
- #### v 0.3.0:
Expand Down
5 changes: 5 additions & 0 deletions modape/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@
5: "p",
10: "d",
}

DATE_LABELS = {
5: dict(zip([3, 8, 13, 18, 23, 28], ['p1', 'p2', 'p3', 'p4', 'p5', 'p6'])),
10: dict(zip([5, 15, 25], ['d1', 'd2', 'd3']))
}
3 changes: 3 additions & 0 deletions modape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ class HDF5WriteError(Exception):
class SgridNotInitializedError(Exception):
"""Exception when requiring non existing sgrid"""
pass

class HDF5MosaicError(Exception):
"""Exception when mosaicing incompatible HDF5s"""
4 changes: 2 additions & 2 deletions modape/modis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
from .collect import ModisRawH5
from .download import ModisQuery
from .smooth import ModisSmoothH5
from .window import ModisMosaic, modis_tiles
from .window import ModisMosaic

__all__ = ['ModisRawH5', 'ModisQuery', 'ModisSmoothH5', 'ModisMosaic', 'modis_tiles']
__all__ = ['ModisRawH5', 'ModisQuery', 'ModisSmoothH5', 'ModisMosaic']
14 changes: 14 additions & 0 deletions modape/modis/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def __init__(self,

tempinfo = TEMPORAL_DICT[self.product[:5]]

self.globalproduct = False
self.temporalresolution = tempinfo["temporalresolution"]
self.tshift = tempinfo["tshift"]
self.nfiles = len(self.files)
Expand All @@ -177,6 +178,9 @@ def __init__(self,
version = REGEX_PATTERNS["version"].findall(refname)
tile_version = '.'.join(tile + version)

if not tile:
self.globalproduct = True

filename = f"{self.targetdir}/{fn_code}/{self.product}.{tile_version}.{fn_code}.h5"

super().__init__(filename=filename)
Expand Down Expand Up @@ -241,10 +245,20 @@ def create(self,
# reference metadata
dset.attrs.update(ref_metadata)

if self.vam_product_code == "VIM":
valid_range = (-2000, 10000)
elif self.vam_product_code in ["LTD", "LTN"]:
valid_range = (7500, 65535)
else:
pass

# teporal information
dset.attrs.update({
"temporalresolution": self.temporalresolution,
"tshift": self.tshift,
"globalproduct": self.globalproduct,
"vamcode": self.filename.name.split('.')[-2],
"valid_range": valid_range,
})

self.exists = True
Expand Down
4 changes: 2 additions & 2 deletions modape/modis/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _get_reference_metadata(reference_file: str,
if sds_filter is None:
sds = sds_all[0][0]
else:
sds, = [x[0] for x in sds_all if sds_filter in x[0]]
sds = [x[0] for x in sds_all if sds_filter in x[0]][0]

sds_open = gdal.Open(sds)
c, a, b, f, d, e = sds_open.GetGeoTransform()
Expand Down Expand Up @@ -267,7 +267,7 @@ def _gen_sds_handle(x: str, sds: str):
for xx in x:
try:
ds = gdal.Open(xx)
ds_sds, = [x[0] for x in ds.GetSubDatasets() if sds in x[0]]
ds_sds = [x[0] for x in ds.GetSubDatasets() if sds in x[0]][0]
yield gdal.Open(ds_sds)
ds = None

Expand Down
Loading