Skip to content

Commit 8c7978c

Browse files
committed
pull request changes
1 parent d76e0f9 commit 8c7978c

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

pystac/eo.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def from_item(cls, item):
7878
e.assets = item.assets
7979

8080
for k, v in item.assets.items():
81-
if v.is_eo():
81+
if is_eo(v):
8282
e.assets[k] = EOAsset.from_asset(v)
8383
e.assets[k].set_owner(e)
8484

@@ -88,7 +88,7 @@ def get_eo_assets(self):
8888
return {k: v for k, v in self.assets.items() if isinstance(v, EOAsset)}
8989

9090
def add_asset(self, key, asset):
91-
if asset.is_eo() and not isinstance(asset, EOAsset):
91+
if is_eo(asset) and not isinstance(asset, EOAsset):
9292
asset = EOAsset.from_asset(asset)
9393
asset.set_owner(self)
9494
self.assets[key] = asset
@@ -103,8 +103,8 @@ def clone(self):
103103
self.add_eo_fields_to_dict(c.properties)
104104
return EOItem.from_item(c)
105105

106-
def to_dict(self):
107-
d = super().to_dict()
106+
def to_dict(self, include_self_link=True):
107+
d = super().to_dict(include_self_link=include_self_link)
108108
if 'properties' not in d.keys():
109109
d['properties'] = {}
110110
self.add_eo_fields_to_dict(d['properties'])
@@ -251,3 +251,10 @@ def band_desc(common_name):
251251
if isinstance(r, str):
252252
return "Common name: {}".format(common_name)
253253
return "Common name: {}, Range: {} to {}".format(common_name, r[0], r[1])
254+
255+
256+
def is_eo(obj):
257+
if obj.properties:
258+
if obj.properties.get('eo:bands', None):
259+
return True
260+
return False

pystac/item.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ class MEDIA_TYPE:
189189
GEOJSON = 'application/geo+json'
190190
GEOPACKAGE = 'application/geopackage+sqlite3'
191191
HDF5 = 'application/x-hdf5' # Hierarchical Data Format version 5
192-
# Hierarchical Data Format versions 4 and earlier.
193-
HDF = 'application/x-hdf'
192+
HDF = 'application/x-hdf' # Hierarchical Data Format versions 4 and earlier.
194193

195194
def __init__(self, href, title=None, media_type=None, properties=None):
196195
self.href = href
@@ -228,8 +227,8 @@ def to_dict(self):
228227
d['title'] = self.title
229228

230229
if self.properties is not None:
231-
for k in self.properties:
232-
d[k] = self.properties[k]
230+
for k, v in self.properties.items():
231+
d[k] = v
233232

234233
return deepcopy(d)
235234

@@ -255,10 +254,4 @@ def from_dict(d):
255254
return Asset(href=href,
256255
media_type=media_type,
257256
title=title,
258-
properties=properties)
259-
260-
def is_eo(self):
261-
if self.properties:
262-
if self.properties.get('eo:bands', None):
263-
return True
264-
return False
257+
properties=properties)

tests/test_eo.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import unittest
44
from jsonschema import ValidationError
5+
from tempfile import TemporaryDirectory
56

67
from pystac import *
78
from pystac.eo import (Band, EOAsset, EOItem, band_desc, band_range, eo_key)
@@ -89,6 +90,20 @@ def test_validate_eo(self):
8990
with self.assertRaises(ValidationError):
9091
sv.validate_dict(eo_dict_2, EOItem)
9192

93+
with TemporaryDirectory() as tmp_dir:
94+
cat_dir = os.path.join(tmp_dir, 'catalog')
95+
catalog = TestCases.test_case_1()
96+
eo_item = EOItem.from_dict(self.eo_dict)
97+
catalog.add_item(eo_item)
98+
catalog.normalize_and_save(cat_dir, catalog_type=CatalogType.ABSOLUTE_PUBLISHED)
99+
100+
cat_read = Catalog.from_file(os.path.join(cat_dir, 'catalog.json'))
101+
eo_item_read = cat_read.get_item("LC08_L1TP_107018_20181001_20181001_01_RT")
102+
sv = SchemaValidator()
103+
sv.validate_object(eo_item_read)
104+
sv.validate_dict(eo_item_read.to_dict(), EOItem)
105+
106+
92107
class EOAssetTest(unittest.TestCase):
93108
def setUp(self):
94109
self.EO_ITEM_URI = TestCases.get_path(

0 commit comments

Comments
 (0)