@@ -101,12 +101,21 @@ def _hack_structured_grid_dims(
101101 "nlay" : range (structured_grid_dims ["nlay" ]),
102102 "ncpl" : range (structured_grid_dims ["ncpl" ]),
103103 }
104+ else :
105+ # No structured grid decomposition available — keep nodes dim as-is.
106+ return value
104107
105108 if "nper" in value .dims :
106109 shape .insert (0 , value .sizes ["nper" ])
107110 dims .insert (0 , "nper" )
108111 coords = {"nper" : value .coords ["nper" ], ** coords }
109112
113+ if "naux" in value .dims :
114+ naux = value .sizes ["naux" ]
115+ shape .append (naux )
116+ dims .append ("naux" )
117+ coords ["naux" ] = range (naux )
118+
110119 return xr .DataArray (
111120 value .data .reshape (shape ),
112121 dims = dims ,
@@ -352,12 +361,31 @@ def _unstructure_array_component(value: Component) -> dict[str, Any]:
352361 for kper , block in period_blocks .items ():
353362 key = f"period { kper + 1 } "
354363 for arr_name , val in block .items ():
355- if not np .all (val == FILL_DNODATA ):
364+ # G/A variant aux: split naux-dimensioned array into one readarray
365+ # block per auxiliary variable, named by value.auxiliary.
366+ if arr_name == "aux" and isinstance (val , xr .DataArray ) and "naux" in val .dims :
367+ _aux = getattr (value , "auxiliary" , None )
368+ if _aux is not None and hasattr (_aux , "values" ):
369+ aux_names = [str (n ) for n in _aux .values .tolist ()]
370+ else :
371+ aux_names = list (_aux or [])
372+ for k in range (val .sizes ["naux" ]):
373+ aux_slice = val .isel (naux = k )
374+ if not np .all (aux_slice .values == FILL_DNODATA ):
375+ if key not in blocks :
376+ blocks [key ] = {}
377+ name = aux_names [k ] if k < len (aux_names ) else f"aux{ k } "
378+ blocks [key ][name ] = aux_slice
379+ elif not np .all (val == FILL_DNODATA ):
356380 if key not in blocks :
357381 blocks [key ] = {}
358382 blocks [key ][arr_name ] = val
359383
360- return {name : block for name , block in blocks .items () if name != "period" }
384+ return {
385+ name : block
386+ for name , block in blocks .items ()
387+ if name != "period" and not name .startswith ("__" )
388+ }
361389
362390
363391# Block names that MF6 rejects if present but empty.
@@ -467,6 +495,17 @@ def _unstructure_component(value: Component) -> dict[str, Any]:
467495 if block_name in _LIST_BLOCK_NAMES :
468496 current_block = blocks .get (block_name , {})
469497 if current_block :
498+ # Expand any 2D DataArrays (e.g. aux with shape (nlakes, naux)) into
499+ # separate per-column 1D DataArrays so the Dataset stays uniformly 1D.
500+ expanded : dict [str , Any ] = {}
501+ for name , v in current_block .items ():
502+ if isinstance (v , xr .DataArray ) and v .ndim == 2 :
503+ for j in range (v .shape [1 ]):
504+ expanded [f"{ name } _{ j } " ] = v .isel ({v .dims [1 ]: j })
505+ else :
506+ expanded [name ] = v
507+ current_block = expanded
508+
470509 das = [v for v in current_block .values () if isinstance (v , xr .DataArray )]
471510 if das and len (das ) == len (current_block ):
472511 first_dim = das [0 ].dims [0 ] if das [0 ].dims else None
0 commit comments