@@ -84,7 +84,7 @@ def create_hgrid(s, inputs, logger):
8484 )
8585 small_area_param = section .get ("small_areas" )
8686 if small_area_param is not None :
87- small_area_param ["prepro_output_dir" ] = inputs ["prepro_output_dir " ]
87+ small_area_param ["prepro_output_dir" ] = inputs ["diagnostics_dir " ]
8888 # This just emits warnings unless the fail threshold is met
8989 small_areas (s .mesh , logger = logger , ** small_area_param )
9090
@@ -151,7 +151,7 @@ def create_hgrid(s, inputs, logger):
151151 s .mesh .nodes [:, 2 ] = stacked_dem_fill (
152152 dem_list ,
153153 s .mesh .nodes [:, :2 ],
154- inputs ["prepro_output_dir " ],
154+ inputs ["diagnostics_dir " ],
155155 require_all = False ,
156156 na_fill = default_depth_for_missing_dem ,
157157 negate = True ,
@@ -173,7 +173,8 @@ def create_hgrid(s, inputs, logger):
173173 smooth = href_spec .get ("smooth" , None )
174174 # reuse the exact machinery used by the 'gr3' section:
175175 s .create_node_partitioning (
176- href_path , polygons , default , smooth
176+ href_path , polygons , default , smooth ,
177+ global_imports = inputs .get ("imports" ),
177178 ) # writes GR3
178179 href_arg = href_path
179180 else :
@@ -244,7 +245,7 @@ def create_hgrid(s, inputs, logger):
244245 stacked_dem_fill (
245246 dem_list ,
246247 s .mesh .nodes [:, :2 ],
247- inputs ["prepro_output_dir " ],
248+ inputs ["diagnostics_dir " ],
248249 require_all = False ,
249250 na_fill = default_depth_for_missing_dem ,
250251 )
@@ -259,13 +260,16 @@ def create_hgrid(s, inputs, logger):
259260
260261 depth_enforce_params = section .get ("depth_enforcement" )
261262 if depth_enforce_params is not None :
263+ global_imports = inputs .get ("imports" )
262264 if "polygons" in depth_enforce_params :
263265 s .mesh .nodes [:, 2 ] = s .apply_polygons (
264- default = None , polygons = depth_enforce_params ["polygons" ]
266+ default = None , polygons = depth_enforce_params ["polygons" ],
267+ global_imports = global_imports ,
265268 )
266269 if "linestrings" in depth_enforce_params :
267270 s .mesh .nodes [:, 2 ] = s .apply_linestring_ops (
268- default = None , linestrings = depth_enforce_params ["linestrings" ]
271+ default = None , linestrings = depth_enforce_params ["linestrings" ],
272+ global_imports = global_imports ,
269273 )
270274
271275 # Write hgrid.gr3
@@ -295,6 +299,7 @@ def create_vgrid(s, inputs, logger):
295299 return
296300
297301 output_dir = inputs ["prepro_output_dir" ]
302+ diagnostics_dir = inputs ["diagnostics_dir" ]
298303
299304 # --- Resolve hgrid (shared by v1 and v2) ---
300305 if "hgrid" in section :
@@ -333,6 +338,7 @@ def create_vgrid(s, inputs, logger):
333338 )
334339 for k in stray :
335340 section .pop (k )
341+ section ["diagnostics_dir" ] = diagnostics_dir
336342 vgrid_gen (hgrid , ** section )
337343
338344 elif gen_version == "v2" :
@@ -343,6 +349,10 @@ def create_vgrid(s, inputs, logger):
343349 )
344350 # v2 passes named arguments
345351 section .pop ("hgrid" , None )
352+ # Route debug_prefix under diagnostics_dir if set
353+ debug_prefix = section .get ("debug_prefix" )
354+ if debug_prefix :
355+ debug_prefix = os .path .join (diagnostics_dir , debug_prefix )
346356 vgrid_gen_v2 (
347357 hgrid = hgrid ,
348358 vgrid_out = section ["vgrid_out" ],
@@ -353,7 +363,7 @@ def create_vgrid(s, inputs, logger):
353363 region_constraints = section .get ("region_constraints" ),
354364 constraint_taper_rings = int (section .get ("constraint_taper_rings" , 3 )),
355365 dz_scale_gr3 = section .get ("dz_scale_gr3" ),
356- debug_prefix = section . get ( " debug_prefix" ) ,
366+ debug_prefix = debug_prefix ,
357367 pileup_log = section .get ("pileup_log" ),
358368 )
359369 else :
@@ -394,6 +404,7 @@ def create_gr3_with_polygons(s, inputs, logger):
394404 if dict_gr3 is None :
395405 return
396406 logger .info ("Processing gr3 outputs..." )
407+ global_imports = inputs .get ("imports" )
397408 expected_items = ("polygons" , "default" , "smooth" )
398409 output_dir = inputs ["prepro_output_dir" ]
399410 for fname , item in dict_gr3 .items ():
@@ -419,7 +430,7 @@ def create_gr3_with_polygons(s, inputs, logger):
419430 default = item .get ("default" )
420431 logger .info ("Creating %s..." % fname )
421432 smooth = item .get ("smooth" )
422- s .create_node_partitioning (fname , polygons , default , smooth )
433+ s .create_node_partitioning (fname , polygons , default , smooth , global_imports = global_imports )
423434
424435
425436def create_prop_with_polygons (s , inputs , logger ):
@@ -428,6 +439,7 @@ def create_prop_with_polygons(s, inputs, logger):
428439 if dict_prop is None :
429440 return
430441 logger .info ("Processing prop outputs..." )
442+ global_imports = inputs .get ("imports" )
431443 expected_items = ("default" , "polygons" )
432444 output_dir = inputs ["prepro_output_dir" ]
433445 for fname , item in dict_prop .items ():
@@ -445,7 +457,7 @@ def create_prop_with_polygons(s, inputs, logger):
445457 polygons = item .get ("polygons" , [])
446458 default = item .get ("default" )
447459 logger .info ("Creating %s..." % fname )
448- s .create_prop_partitioning (fname , polygons , default )
460+ s .create_prop_partitioning (fname , polygons , default , global_imports = global_imports )
449461
450462
451463def create_structures (s , inputs , logger ):
@@ -761,6 +773,7 @@ def process_output_dir(inputs):
761773 os .mkdir (outdir )
762774 else :
763775 raise ValueError ("Output directory (output_dir) does not exist" )
776+
764777 return outdir
765778
766779
@@ -811,6 +824,7 @@ def process_prepare_yaml(in_fname, use_logging=True, write_echo=True, envvar=Non
811824 keys_top_level = [
812825 "config" ,
813826 "env" ,
827+ "imports" ,
814828 "min_schimpy_version" ,
815829 "prepro_output_dir" ,
816830 "mesh" ,
@@ -827,6 +841,11 @@ def process_prepare_yaml(in_fname, use_logging=True, write_echo=True, envvar=Non
827841 logger .info ("Processing the top level..." )
828842 check_and_suggest (list (inputs .keys ()), keys_top_level , logger )
829843
844+ # Create diagnostics subdirectory for intermediate/debug outputs
845+ diagnostics_dir = os .path .join (outdir , "diagnostics" )
846+ os .makedirs (diagnostics_dir , exist_ok = True )
847+ inputs ["diagnostics_dir" ] = diagnostics_dir
848+
830849 if write_echo :
831850 out_fname = (
832851 os .path .splitext (in_fname )[0 ] + "_echo" + os .path .splitext (in_fname )[1 ]
0 commit comments