Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in calculate_area #333

Closed
fsenf opened this issue Sep 8, 2023 · 2 comments · Fixed by #378
Closed

bug in calculate_area #333

fsenf opened this issue Sep 8, 2023 · 2 comments · Fixed by #378
Assignees
Labels
bug Code that is failing or producing the wrong result
Milestone

Comments

@fsenf
Copy link
Member

fsenf commented Sep 8, 2023

The function calculate_area takes features, mask as argument. If mask is 3D (i.e. incl. time), calculate_area fails because internally calculates an area field (np.array) which is 2D. Both mask and area are provided to thescipy.ndimage function labeled_comprehension which however assumes that the 1st two arguments have the same shape. confict -> 2D != 3D

Here is part of the error

File [~/TROPOS/proj/2022-06-tobac-devel/tobac/tobac/analysis.py:960](https://file+.vscode-resource.vscode-cdn.net/home/senf/TROPOS/proj/2022-06-tobac-devel/tobac/examples/Basics/~/TROPOS/proj/2022-06-tobac-devel/tobac/tobac/analysis.py:960), in calculate_area(features, mask, method_area)
    957 else:
    958     raise ValueError("method undefined")
--> 960 feature_areas = labeled_comprehension(
    961     area, mask.data, features["feature"], np.sum, area.dtype, np.nan
    962 )
    964 features["area"] = feature_areas
    966 return features

File [~/TROPOS/proj/2022-06-tobac-devel/tobac-env-py38/lib/python3.8/site-packages/scipy/ndimage/_measurements.py:511](https://file+.vscode-resource.vscode-cdn.net/home/senf/TROPOS/proj/2022-06-tobac-devel/tobac/examples/Basics/~/TROPOS/proj/2022-06-tobac-devel/tobac-env-py38/lib/python3.8/site-packages/scipy/ndimage/_measurements.py:511), in labeled_comprehension(input, labels, index, func, out_dtype, default, pass_positions)
    509     input, labels = numpy.broadcast_arrays(input, labels)
    510 except ValueError as e:
--> 511     raise ValueError("input and labels must have the same shape "
    512                         "(excepting dimensions with width 1)") from e
    514 if index is None:
    515     if not pass_positions:

ValueError: input and labels must have the same shape (excepting dimensions with width 1)

A solution would be to care in the calculations that areahas always the same shape as mask.

As calculate_area is not included in the testing I guess it is not really used by the group, right?

@fsenf fsenf added the bug Code that is failing or producing the wrong result label Sep 8, 2023
@fsenf fsenf added this to the Version 1.6 milestone Sep 8, 2023
@w-k-jones
Copy link
Member

Good catch, we should probably allow both a 2d area calculation and volume for 3d fields

@w-k-jones
Copy link
Member

Footprint area of 3D segments is now resolved by #378 . It may be useful to add a function to calculate volume of 3D objects in future, but I will close this for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Code that is failing or producing the wrong result
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants