Skip to content

Commit 7833545

Browse files
committed
add handling of mip_scraper logs
1 parent 8362b87 commit 7833545

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

ras_stac/ras1d/converter.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, asset_paths: list, crs: str) -> None:
3434
self.assets = [generate_asset(i) for i in asset_paths]
3535
self.crs = crs
3636
[a.set_crs(crs) for a in self.assets if isinstance(a, GeometryAsset)]
37+
self.custom_properties = {}
3738

3839
def export_stac(self, output_path: str) -> None:
3940
"""Export the converted STAC item."""
@@ -129,7 +130,7 @@ def stac_properties(self):
129130
properties = {
130131
"model_name": self.idx,
131132
"ras_version": self.primary_geometry.ras_version,
132-
"ras_units": self.ras_prj_file.units,
133+
"ras_units": self.primary_geometry.units,
133134
"project_title": self.ras_prj_file.title,
134135
"plans": {a.title: a.suffix for a in self.assets if isinstance(a, PlanAsset)},
135136
"geometries": {a.title: a.suffix for a in self.assets if isinstance(a, GeometryAsset)},
@@ -139,6 +140,8 @@ def stac_properties(self):
139140
"assigned_HUC8": self.huc8,
140141
"has_2d": any([a.has_2d for a in self.assets if isinstance(a, GeometryAsset)]),
141142
}
143+
for p in self.custom_properties:
144+
properties[p] = self.custom_properties[p]
142145
return properties
143146

144147
@property
@@ -176,6 +179,22 @@ def primary_geometry(self) -> GeometryAsset:
176179
"""The geometry file listed in the primary plan"""
177180
return self.extension_dict[self.primary_plan.geometry]
178181

182+
def check_for_mip(self) -> None:
183+
mip_data = [a for a in self.assets if a.name == "mip_package_geolocation_metadata.json"]
184+
if len(mip_data) == 0:
185+
return
186+
elif len(mip_data) > 1:
187+
raise RuntimeError(
188+
f"More than one mip_package_geolocation_metadata.json found in s3 dir: {[m.title for m in mip_data]}"
189+
)
190+
else:
191+
mip_data = mip_data[0]
192+
self.assets.remove(mip_data)
193+
mip_data.download_asset_str()
194+
mip_json = json.loads(mip_data.file_str)
195+
self.custom_properties["fema_case_number"] = mip_json["case"]
196+
self.custom_properties["fema_case_counties"] = mip_json["county"]
197+
179198

180199
def from_directory(model_dir: str, crs: str) -> Converter:
181200
"""Scrape assets from directory and return Converter object."""
@@ -196,6 +215,7 @@ def ras_to_stac(ras_dir: str, crs: str):
196215
def process_in_place_s3(in_prefix: str, crs: str, out_prefix: str):
197216
"""Convert a HEC-RAS model to a STAC item and save to same directory."""
198217
converter = from_directory(in_prefix, crs)
218+
converter.check_for_mip()
199219
thumb_path = out_prefix + "Thumbnail.png"
200220
converter.export_thumbnail(thumb_path)
201221
stac_path = out_prefix + f"{converter.idx}.json"
@@ -206,5 +226,6 @@ def process_in_place_s3(in_prefix: str, crs: str, out_prefix: str):
206226
if __name__ == "__main__":
207227
ras_dir = sys.argv[1]
208228
crs = sys.argv[2]
209-
process_in_place_s3(ras_dir, crs, ras_dir)
229+
out_dir = sys.argv[3]
230+
process_in_place_s3(ras_dir, crs, out_dir)
210231
# ras_to_stac(ras_dir, crs)

0 commit comments

Comments
 (0)