@@ -34,6 +34,7 @@ def __init__(self, asset_paths: list, crs: str) -> None:
34
34
self .assets = [generate_asset (i ) for i in asset_paths ]
35
35
self .crs = crs
36
36
[a .set_crs (crs ) for a in self .assets if isinstance (a , GeometryAsset )]
37
+ self .custom_properties = {}
37
38
38
39
def export_stac (self , output_path : str ) -> None :
39
40
"""Export the converted STAC item."""
@@ -129,7 +130,7 @@ def stac_properties(self):
129
130
properties = {
130
131
"model_name" : self .idx ,
131
132
"ras_version" : self .primary_geometry .ras_version ,
132
- "ras_units" : self .ras_prj_file .units ,
133
+ "ras_units" : self .primary_geometry .units ,
133
134
"project_title" : self .ras_prj_file .title ,
134
135
"plans" : {a .title : a .suffix for a in self .assets if isinstance (a , PlanAsset )},
135
136
"geometries" : {a .title : a .suffix for a in self .assets if isinstance (a , GeometryAsset )},
@@ -139,6 +140,8 @@ def stac_properties(self):
139
140
"assigned_HUC8" : self .huc8 ,
140
141
"has_2d" : any ([a .has_2d for a in self .assets if isinstance (a , GeometryAsset )]),
141
142
}
143
+ for p in self .custom_properties :
144
+ properties [p ] = self .custom_properties [p ]
142
145
return properties
143
146
144
147
@property
@@ -176,6 +179,22 @@ def primary_geometry(self) -> GeometryAsset:
176
179
"""The geometry file listed in the primary plan"""
177
180
return self .extension_dict [self .primary_plan .geometry ]
178
181
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
+
179
198
180
199
def from_directory (model_dir : str , crs : str ) -> Converter :
181
200
"""Scrape assets from directory and return Converter object."""
@@ -196,6 +215,7 @@ def ras_to_stac(ras_dir: str, crs: str):
196
215
def process_in_place_s3 (in_prefix : str , crs : str , out_prefix : str ):
197
216
"""Convert a HEC-RAS model to a STAC item and save to same directory."""
198
217
converter = from_directory (in_prefix , crs )
218
+ converter .check_for_mip ()
199
219
thumb_path = out_prefix + "Thumbnail.png"
200
220
converter .export_thumbnail (thumb_path )
201
221
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):
206
226
if __name__ == "__main__" :
207
227
ras_dir = sys .argv [1 ]
208
228
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 )
210
231
# ras_to_stac(ras_dir, crs)
0 commit comments