@@ -90,8 +90,9 @@ def get_dimension_index_map(
9090 variable_start_indices_map = parse_start_indices_from_history_attr (datatree )
9191
9292 # Retrieve the mapping of requested variables and the corresponding dimension paths
93- variable_dimension_map = get_variable_dimension_map (granule_var_info )
94-
93+ variable_dimension_map = get_variable_dimension_map (
94+ granule_var_info , datatree , dimension_variables
95+ )
9596 # Retrieve the mapping from the dimension variable to the start index
9697 dimension_index_map = get_dim_index_from_var_dim_map (
9798 variable_dimension_map , variable_start_indices_map
@@ -125,14 +126,49 @@ def parse_start_indices_from_history_attr(datatree: xr.DataTree) -> dict[str, st
125126
126127def get_variable_dimension_map (
127128 granule_var_info : VarInfoFromNetCDF4 ,
129+ datatree : xr .DataTree ,
130+ dimension_variables : set [str ],
128131) -> dict [tuple , str ]:
129- """Return a mapping from dimensions list to a requested variable."""
132+ """Return a mapping from dimensions list to a requested variable.
133+
134+ Note that this function utilizes a temporary solution for location up-level (shared)
135+ dimension variables by updating the dimension map returned by the earthdata-varinfo
136+ method `group_variables_by_dimensions`. This should remain place until
137+ earthdata-varinfo supports up-level dimensions.
138+ """
130139 var_dim_map = {
131140 dimlist : list (varlist )[0 ]
132141 for dimlist , varlist in granule_var_info .group_variables_by_dimensions ().items ()
133142 }
134143
135- return var_dim_map
144+ # Identify dimensions that have been created up-level and update map
145+ updated_map = {}
146+ for dim_list , var_path in var_dim_map .items ():
147+ new_dim_list = []
148+ for dim in dim_list :
149+ if dim in dimension_variables :
150+ new_dim_list .append (dim )
151+ continue
152+
153+ group_path , dimension_name = os .path .split (dim )
154+ new_dim = None
155+ for parent in datatree [group_path ].parents :
156+ parent_dim_path = (
157+ f'{ parent .path } /{ dimension_name } '
158+ if parent .path != '/'
159+ else f'/{ dimension_name } '
160+ )
161+ if parent_dim_path in dimension_variables :
162+ new_dim = parent_dim_path
163+ break
164+
165+ if not new_dim :
166+ raise MissingDimensionVariable (dim )
167+ new_dim_list .append (new_dim )
168+
169+ updated_map [tuple (new_dim_list )] = var_path
170+
171+ return updated_map
136172
137173
138174def get_dim_index_from_var_dim_map (
0 commit comments