lgrcia / prose

Modular image processing pipelines with Python. Built for Astronomy.
https://prose.readthedocs.io
MIT License
54 stars 11 forks source link

Feat/custom region parser #95

Closed shfxia closed 1 year ago

shfxia commented 1 year ago

Description

When creating a Source, you can specify a custom region parser using the from_region method. After the default region has been parsed, the specified parser will be called if it has been set. This allows users to retrieve additional information from the original region by defining their own custom region parser. And, this may be used in issue 74

@classmethod
def from_region(cls, region, parser=None, keep_region=False, **kwargs):
        source = cls(
            # default parser
            a=region.axis_major_length / 2,
            b=region.axis_minor_length / 2,
            orientation=np.pi / 2 - region.orientation,
            coords=np.array(region.centroid_weighted[::-1]),
            peak=region.intensity_max,
            area=region.area,
            **kwargs,
        )

        # custom parser
        if parser is not None:
            parser(source, region)

        return source

Related Issue

https://github.com/lgrcia/prose/issues/74#issuecomment-1523833524

Type of Change

Checklist

lgrcia commented 1 year ago

Hi @shfxia ans thanks again for this very nice addition! I really like it.

Once we discuss the implementation a bit I am very happy to merge it to the upcoming 3.2.0.