Differences between _parse_features and get_feature_parser

I came upon a version issue between different eo-learn versions. The issue was that the _parse_features function that was removed along time ago, does not function the same way as the parse_features function that was added included with the get_feature_parser:

This photo is from eo-learn 1.0.0.
It states that _parse_features was replaced with get feature_parser.

Once again I am trying to repurpose a the CloudMasking class within the tiffs_to_eopatch.py file within the field-delineation Github.

class CloudMasking(EOTask):
    """ Compute cloud mask from SH cloud probability CLP data map """
    def __init__(self, clp_feature: Tuple = (FeatureType.DATA, 'CLP'), clm_feature: Tuple = (FeatureType.MASK, 'CLM'),
                 average_over: int = 24, max_clp: float = 255.):
        """
        :param clp_feature: Feature type and name of input CLP mask
        :param clm_feature: Feature type and name of output CLM mask
        :param average_over: Parameter used ot smooth the CLP data map
        :param max_clp: Maximum value of CLP map used for normalization
        """
        # _parse_features replaced with `get feature parser`
        self.clm_feature = next(self._parse_features(iter(clm_feature))())
        self.clp_feature = next(self._parse_features(iter(clp_feature))())
        self.s2_cd = S2PixelCloudDetector(average_over=average_over)
        self.max_clp = max_clp

    def execute(self, eopatch: EOPatch) -> EOPatch:
        """ Compute and add CLM from CLP """
        clc = self.s2_cd.get_mask_from_prob(eopatch[self.clp_feature].squeeze() / self.max_clp)
        eopatch[self.clm_feature] = clc[..., np.newaxis]
        return eopatch

This code is resulting in the following error:

I am simply trying to understand the differences between the versions.

Previously each task had a _parse_features method, which, given some specification of features) created an iterator over said features. This has been more or less renamed into a get_feature_parser method, but we also added specialized methods cases such as the one in your screenshot (since they arise often).

In the CloudMasking task you only need to parse a single feature, so what you would do is use self.parse_feature(clp_feature).

Thanks so much for you help!

So instead of
self.clm_feature = next(self._parse_features(iter(clm_feature))())

I would be using the following instead?
self.clm_feature = next(self.parse_feature(clm_feature))

even simpler, just self.clm_feature = self.parse_feature(clm_feature)

1 Like