tobac icon indicating copy to clipboard operation
tobac copied to clipboard

3D feature detection with min_distance fails if dz is not provided

Open w-k-jones opened this issue 11 months ago • 0 comments

If dz is not given, filter_min_distance tries to find the vertical coordinate from the dataframe but as this occurs before coordinate interpolate it fails, causing an error.

Easiest solution is to move this after coordinate interpolation I think

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[22], line 1
----> 1 features_w = tobac.feature_detection_multithreshold(
      2     w_iris, **parameters_features
      3 )

File ~/python/tobac/tobac/utils/decorators.py:168, in xarray_to_iris.<locals>.wrapper(*args, **kwargs)
    165             output = xarray.DataArray.from_iris(output)
    167 else:
--> 168     output = func(*args, **kwargs)
    169 # print(output)
    170 return output

File ~/python/tobac/tobac/feature_detection.py:1375, in feature_detection_multithreshold(field_in, dxy, threshold, min_num, target, position_threshold, sigma_threshold, n_erosion_threshold, n_min_threshold, min_distance, feature_number_start, PBC_flag, vertical_coord, vertical_axis, detect_subset, wavelength_filtering, dz, strict_thresholding, statistic)
   1372     # Loop over DataFrame to remove features that are closer than distance_min to each
   1373     # other:
   1374     if min_distance > 0:
-> 1375         features_thresholds = filter_min_distance(
   1376             features_thresholds,
   1377             dxy=dxy,
   1378             dz=dz,
   1379             min_distance=min_distance,
   1380             z_coordinate_name=vertical_coord,
   1381             target=target,
   1382             PBC_flag=PBC_flag,
   1383             min_h1=0,
   1384             max_h1=hdim1_max,
   1385             min_h2=0,
   1386             max_h2=hdim2_max,
   1387         )
   1388 list_features_timesteps.append(features_thresholds)
   1390 logging.debug(
   1391     "Finished feature detection for " + time_i.strftime("%Y-%m-%d_%H:%M:%S")
   1392 )

File ~/python/tobac/tobac/feature_detection.py:1492, in filter_min_distance(features, dxy, dz, min_distance, x_coordinate_name, y_coordinate_name, z_coordinate_name, target, PBC_flag, min_h1, max_h1, min_h2, max_h2)
   1489 is_3D = "vdim" in features
   1491 if is_3D and dz is None:
-> 1492     z_coordinate_name = internal_utils.find_dataframe_vertical_coord(
   1493         features, z_coordinate_name
   1494     )
   1496 # Check if both dxy and their coordinate names are specified.
   1497 # If they are, warn that we will use dxy.
   1498 if dxy is not None and (
   1499     x_coordinate_name in features and y_coordinate_name in features
   1500 ):

File ~/python/tobac/tobac/utils/internal/basic.py:187, in find_dataframe_vertical_coord(variable_dataframe, vertical_coord)
    185     return vertical_coord
    186 else:
--> 187     raise ValueError("Please specify vertical coordinate")

ValueError: Please specify vertical coordinate
  • [x] Have you searched the issue tracker for the same problem?
  • [x] Have you checked if you're using the latest version? If not, which version are you using?
  • [x] Have you mentioned the steps to reproduce the issue?
  • [x] Have you, if applicable, included error messages?

w-k-jones avatar Mar 07 '24 11:03 w-k-jones