@@ -225,7 +225,7 @@ def _get_intra_dataset_upstream_basins(res_dict, ds) -> list[dict]:
225225 else :
226226 basin_map = ds [map_data ][:]
227227
228- # check whether the file name is in the list of resources.
228+ # check whether the basin is in the list of resources.
229229 for res in pkg .resources :
230230 if _is_basin_of_dataset (ds , res , bn_dict ):
231231 # upstream resource ID
@@ -300,6 +300,9 @@ def _is_basin_of_dataset(ds,
300300 ):
301301 """Check whether a CKAN resource is a basin for a dataset
302302
303+ Return True when `resource_basin` is a basin of `ds`
304+ as described by `basin_dict`.
305+
303306 Parameters
304307 ----------
305308 ds:
@@ -313,26 +316,30 @@ def _is_basin_of_dataset(ds,
313316 ds_runid = ds .get_measurement_identifier ()
314317 with get_dc_instance (resource_basin .id ) as ds_bn :
315318 bn_runid = ds_bn .get_measurement_identifier ()
319+ bn_runid_dict = basin_dict .get ("identifier" )
316320
317- if not bn_runid :
321+ if not bn_runid or not bn_runid_dict :
318322 # No run identifier specified -> no basin inference possible.
319323 return False
320324
325+ if bn_runid != bn_runid_dict :
326+ # Basin-resource mismatch.
327+ # This resource is not the measurement referenced in this basin.
328+ return False
329+
321330 mapping_is_same = basin_dict .get ("mapping" , "same" ) == "same"
322331
323332 if mapping_is_same and bn_runid == ds_runid :
324333 # This is an ideal case. Both run identifiers match and the mapping
325334 # is identical.
326- print (f"same { bn_runid } { ds_runid } " )
327335 return True
328336
329- elif not mapping_is_same and ds_runid .rsplit ("_" , 1 )[0 ] == bn_runid :
330- # This is a slightly more complicated cases. If you split the
331- # run identifiers with an underscore (dclab 0.65.0 and dcnum 0.25.11
332- # correctly support this), then the referrer has a run identifier
333- # that starts with that of the basin.
334- print (f"basinmap { bn_runid } { ds_runid } " )
337+ elif not mapping_is_same and ds_runid .startswith (bn_runid ):
338+ # This is a slightly more complicated cases. If the mapping
339+ # is not "same", this means that we have filtered datasets.
340+ # For a filtered dataset, the identifier is the identifier of
341+ # its basin plus a unique string.
335342 return True
336343
337- # None of the above cases matched. This is not a basin of ds.
344+ # None of the above cases matched. This is not a direct basin of ds.
338345 return False
0 commit comments