@@ -293,6 +293,7 @@ def open_dataset(
293293
294294 if not silent :
295295 display_spec = {** spec , "open_kwargs" : effective_kwargs }
296+ display_spec .setdefault ("merge" , None )
296297 print (f"open_method: { display_spec !r} " )
297298
298299 if xarray_open == "datatree" :
@@ -390,6 +391,7 @@ def open_mfdataset(
390391
391392 if not silent :
392393 display_spec = {** spec , "open_kwargs" : effective_kwargs }
394+ display_spec .setdefault ("merge" , None )
393395 print (f"open_method: { display_spec !r} " )
394396
395397 result_list = results .results if isinstance (results , Plan ) else list (results )
@@ -466,10 +468,8 @@ def show_variables(
466468 If the plan contains no granules.
467469 """
468470 from point_collocation .core ._open_method import (
469- _GEOLOC_PAIRS ,
470471 _apply_coords ,
471472 _build_effective_open_kwargs ,
472- _h5py_file_info ,
473473 _merge_datatree_with_spec ,
474474 _normalize_open_method ,
475475 _open_and_merge_dataset_groups ,
@@ -515,136 +515,15 @@ def show_variables(
515515 spec = {** spec , "xarray_open" : "dataset" , "merge" : None }
516516 effective_kwargs = _build_effective_open_kwargs (spec .get ("open_kwargs" , {}))
517517
518- # Print the spec summary.
518+ # Print the spec summary. Ensure "merge" is always present so the
519+ # printed spec is unambiguous (it may be absent for the "auto" preset).
519520 display_spec = {** spec , "open_kwargs" : effective_kwargs }
521+ display_spec .setdefault ("merge" , None )
520522 print (f"open_method: { display_spec !r} " )
521523
522- def _seek_back () -> None :
523- if hasattr (file_obj , "seek" ):
524- try :
525- file_obj .seek (0 ) # type: ignore[attr-defined]
526- except Exception :
527- pass
528-
529- # ---------------------------------------------------------------
530- # Fast path: use h5py for per-group metadata inspection.
531- # ---------------------------------------------------------------
532- h5_info = _h5py_file_info (file_obj )
533- _seek_back () # ensure file_obj is at start for subsequent xarray opens
534- if h5_info is not None :
535- # Determine which groups to include based on merge spec.
536- merge = spec .get ("merge" )
537- if merge == "root" :
538- relevant_groups : set [str ] | None = {"/" }
539- elif isinstance (merge , list ):
540- relevant_groups = set (merge )
541- else :
542- # "all" or no merge key: include all discovered groups
543- relevant_groups = None
544-
545- all_var_names : set [str ] = set ()
546- merged_dims : dict [str , int ] = {}
547- merged_vars : list [str ] = []
548-
549- for group_path , vars_dict in h5_info :
550- if relevant_groups is not None and group_path not in relevant_groups :
551- continue
552-
553- print (f"\n Group { group_path } " )
554- # Collect dimension sizes from variable shapes.
555- dim_sizes : dict [str , int ] = {}
556- for vinfo in vars_dict .values ():
557- for dim , size in zip (vinfo ["dims" ], vinfo ["shape" ]):
558- if dim and dim != "?" :
559- dim_sizes .setdefault (dim , size )
560- merged_dims .setdefault (dim , size )
561- if dim_sizes :
562- print (f" Dimensions: { dim_sizes } " )
563-
564- if vars_dict :
565- var_strs = [
566- f"{ vname } { vinfo ['dims' ]} "
567- for vname , vinfo in vars_dict .items ()
568- ]
569- print (f" Variables: { ', ' .join (var_strs )} " )
570-
571- all_var_names .update (vars_dict .keys ())
572- for vname in vars_dict :
573- if vname not in merged_vars :
574- merged_vars .append (vname )
575-
576- # Flat merged summary across all relevant groups.
577- print (f"\n Dimensions: { merged_dims } " )
578- print (f"\n Variables: { merged_vars } " )
579-
580- # Geolocation detection — handles coords as dict, list, or 'auto'.
581- coords = spec .get ("coords" , "auto" )
582- set_coords_val = spec .get ("set_coords" , True )
583- if isinstance (coords , dict ):
584- lat_name = coords .get ("lat" )
585- lon_name = coords .get ("lon" )
586- if (
587- lat_name and lon_name
588- and lat_name in all_var_names
589- and lon_name in all_var_names
590- ):
591- print (f"\n Geolocation: ({ lon_name !r} , { lat_name !r} ) detected" )
592- else :
593- print (
594- f"\n Geolocation: NONE detected with "
595- f"'coords': { coords !r} , 'set_coords': { set_coords_val !r} ."
596- )
597- elif isinstance (coords , list ):
598- missing = [n for n in coords if n not in all_var_names ]
599- if not missing :
600- geo_pairs = [
601- (lon_n , lat_n )
602- for lon_n , lat_n in _GEOLOC_PAIRS
603- if lon_n in coords and lat_n in coords
604- ]
605- if geo_pairs :
606- lon_n , lat_n = geo_pairs [0 ]
607- print (f"\n Geolocation: ({ lon_n !r} , { lat_n !r} ) detected" )
608- else :
609- print (f"\n Geolocation: { coords !r} found in dataset" )
610- else :
611- print (
612- f"\n Geolocation: NONE — specified coords { missing !r} not found."
613- )
614- else :
615- # 'auto': check _GEOLOC_PAIRS
616- geo_pairs_found = [
617- (lon_n , lat_n )
618- for lon_n , lat_n in _GEOLOC_PAIRS
619- if lon_n in all_var_names and lat_n in all_var_names
620- ]
621- if geo_pairs_found :
622- lon_n , lat_n = geo_pairs_found [0 ]
623- print (f"\n Geolocation: ({ lon_n !r} , { lat_n !r} ) detected" )
624- else :
625- print (
626- f"\n Geolocation: NONE detected with "
627- f"'coords': { coords !r} , 'set_coords': { set_coords_val !r} . "
628- "Try open_method='datatree-merge' or specify "
629- "open_method={'coords': {'lat': '...', 'lon': '...'}}."
630- )
631-
632- return
633-
634524 # ---------------------------------------------------------------
635- # Fallback: use xarray to inspect the file.
525+ # Use xarray to inspect the file (same lazy path as open_dataset) .
636526 # ---------------------------------------------------------------
637- # For "auto" mode, probe the first granule to resolve which open
638- # path to use (dataset vs. datatree).
639- if xarray_open == "auto" :
640- try :
641- spec = _resolve_auto_spec (file_obj , spec )
642- xarray_open = spec ["xarray_open" ]
643- effective_kwargs = _build_effective_open_kwargs (spec .get ("open_kwargs" , {}))
644- except ValueError :
645- xarray_open = "dataset"
646- spec = {** spec , "xarray_open" : "dataset" }
647-
648527 dt = None
649528 merge = spec .get ("merge" )
650529 if xarray_open == "datatree" :
0 commit comments