Skip to content

moa_ratio and nmi in the shapes module are the same thing, and should yield the same result #404

@leehach

Description

@leehach

The shapes module has 'moa_ratio()andnmi()` functions. They are short, and their docstrings are relevant, so I am reproducing them in their entirety here.

def moa_ratio(collection):
    """
    Computes the ratio of the second moment of area (like Li et al (2013)) to
    the moment of area of a circle with the same area.
    """
    ga = _cast(collection)
    r = shapely.length(ga) / (2 * numpy.pi)
    return (numpy.pi * 0.5 * r**4) / second_areal_moment(ga)


def nmi(collection):
    """
    Computes the Normalized Moment of Inertia from Li et al (2013), recognizing
    that it is the relationship between the area of a shape squared divided by
    its second moment of area.
    """
    ga = _cast(collection)
    return shapely.area(ga) ** 2 / (2 * second_areal_moment(ga) * numpy.pi)

From the cited Li, et al. (2013):

The shape index base upon MI, CMI , is calculated as the ratio of the MI of a circle of the
same area about its center, to the MI of the shape about its centroid.

This is implemented as moa_ratio(), as explained in the docstring.

However, Li, et al. (2013) go on to say:

Mathematically, it can be expressed as:

$$ C_{MI} = \frac{A^2}{2 \pi I_g}$$

This is implemented as nmi(). $I_g$ was previously defined in the article as the moment of inertia about the centroid, which is calculated in the function by second_areal_moment(ga). Substituting in, you can see that nmi() faithfully captures this equation.

The problem is that Li, et al. (2013) makes clear that these are the same thing. Only one formula is given, and that formula is correctly represented by nmi(). There is no second formula in the article that is the basis for moa_ratio(). The module should probably only have one function, but the two functions should produce the exact same, which they do not.

I recommend that moa_ratio() be removed. For now, it could be changed to merely call nmi() with a deprecation warning, and in the future it should be removed.

If this is acceptable to implement, please assign to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions