@@ -156,10 +156,17 @@ def read(self, data):
156156class SchismPolygonYamlReader (SchismPolygonIo ):
157157 """Read polygons from a SCHISM YAML polygon file"""
158158
159- def read (self , fpath ):
159+ def read (self , fpath , yaml_root = None ):
160160 if os .path .exists (fpath ):
161161 with open (fpath , "r" ) as f_in :
162162 raw = schism_yaml .load_raw (f_in )
163+ if yaml_root is not None :
164+ for key in yaml_root .split ("." ):
165+ if not isinstance (raw , dict ) or key not in raw :
166+ raise ValueError (
167+ f"yaml_root key '{ key } ' not found in YAML structure"
168+ )
169+ raw = raw [key ]
163170 return SchismPolygonDictConverter ().read (raw )
164171 else :
165172 raise ValueError ("File not found" )
@@ -326,10 +333,19 @@ def get_writer(self, name):
326333 raise ValueError ("Not in the SchismPolygonIoFactory" )
327334
328335
329- def read_polygons (fpath ):
330- """Read a polygon file"""
336+ def read_polygons (fpath , yaml_root = None ):
337+ """Read a polygon file
338+
339+ Parameters
340+ ----------
341+ fpath : str
342+ Path to the polygon file (YAML or Shapefile).
343+ yaml_root : str, optional
344+ Dot-separated path to navigate into a nested YAML structure
345+ before reading polygons (e.g., 'mesh.depth_enforcement').
346+ """
331347 if fpath .endswith (".yaml" ):
332- return SchismPolygonIoFactory ().get_reader ("yaml" ).read (fpath )
348+ return SchismPolygonIoFactory ().get_reader ("yaml" ).read (fpath , yaml_root = yaml_root )
333349 elif fpath .endswith (".shp" ):
334350 return SchismPolygonIoFactory ().get_reader ("shp" ).read (fpath )
335351 else :
0 commit comments