3232logger = logging .getLogger (__name__ )
3333
3434FREQUENCIES = {
35- "P1M" : "mon" ,
3635 "P1D" : "day" ,
36+ "P1M" : "mon" ,
37+ "P1Y" : "yr" ,
3738}
3839
3940
@@ -113,6 +114,9 @@ def to_iris(self) -> iris.cube.CubeList:
113114 return dataset_to_iris (dataset )
114115
115116
117+ _DATASETS_LOGGED : set [str ] = set ()
118+
119+
116120@dataclass
117121class XCubeDataSource (esmvalcore .io .protocol .DataSource ):
118122 """Data source for finding files on a local filesystem."""
@@ -168,6 +172,13 @@ def find_data(self, **facets: FacetValue) -> list[XCubeDataset]: # noqa: C901,P
168172 if isinstance (requested_datasets , str | int | float ):
169173 requested_datasets = [str (requested_datasets )]
170174 available_datasets = store .list_data_ids ()
175+ if self .data_store_id not in _DATASETS_LOGGED :
176+ _DATASETS_LOGGED .add (self .data_store_id )
177+ logger .debug (
178+ "Available datasets in %s are:\n %s" ,
179+ self .data_store_id ,
180+ "\n " .join (sorted (available_datasets )),
181+ )
171182
172183 for data_id in available_datasets :
173184 for dataset_pattern in requested_datasets :
@@ -185,8 +196,10 @@ def find_data(self, **facets: FacetValue) -> list[XCubeDataset]: # noqa: C901,P
185196 "No variable matching % found in %s. Available variables are: %s" ,
186197 requested_short_names ,
187198 data_id ,
188- available_short_names ,
199+ ", " . join ( sorted ( available_short_names )) ,
189200 )
201+ continue
202+
190203 # TODO: Maybe this is too complicated and we should only
191204 # decide which variables to keep/drop after load and conversion
192205 # to iris cube.
@@ -215,37 +228,28 @@ def find_data(self, **facets: FacetValue) -> list[XCubeDataset]: # noqa: C901,P
215228 "-" ,
216229 "" ,
217230 )
218- native_frequency = description .attrs [
219- "time_coverage_resolution"
220- ]
221- frequency = FREQUENCIES .get (
222- native_frequency ,
223- native_frequency ,
224- )
225-
226231 dataset = XCubeDataset (
227232 name = data_id ,
228233 facets = {
229234 "dataset" : data_id ,
230- "short_name" : short_names
231- if len (short_names ) > 1
232- else short_names [0 ],
233- "frequency" : frequency ,
235+ "short_name" : (
236+ short_names [0 ]
237+ if len (short_names ) == 1
238+ else short_names
239+ ),
234240 "timerange" : timerange ,
235241 },
236242 store = store ,
237243 open_params = open_params ,
238244 )
245+ frequency = FREQUENCIES .get (
246+ description .attrs .get ("time_coverage_resolution" , "" ),
247+ )
248+ if frequency :
249+ # Assign the frequency facet if it is a known frequency.
250+ dataset .facets ["frequency" ] = frequency
239251 dataset .attributes = description .attrs
240252
241253 result .append (dataset )
242254
243- if not result :
244- logger .debug (
245- "No datasets matching %s found in %s. Available datasets are: %s" ,
246- requested_datasets ,
247- self .data_store_id ,
248- available_datasets ,
249- )
250-
251255 return result
0 commit comments