<commit_before>#!/usr/bin/env python
# -*- coding: utf8 -*-
# *****************************************************************
# **       AstroMagic -- the image editor for astronomers        **
# **       © Astronomical Observatory, Ghent University          **
# *****************************************************************

## \package pts.magic.basics.region Contains the Region class.

# -----------------------------------------------------------------

# Ensure Python 3 functionality
from __future__ import absolute_import, division, print_function

# Import standard modules
import numpy as np

# Import astronomical modules
import pyregion
from astropy import coordinates as coord

# Import the relevant AstroMagic classes and modules
from .vector import Extent
from .geometry import Ellipse, SkyEllipse
from .mask import Mask

# -----------------------------------------------------------------

class SkyRegion(list):

    """
    This class ...
    """

    def __init__(self):

        """
        This function ...
        :return:
        """

        # Call the constructor of the base class
        super(SkyRegion, self).__init__()

    # -----------------------------------------------------------------

    def append(self, shape):

        """
        This function ...
        :return:
        """

        # Check whether the shape is in sky coordinates
        if not isinstance(shape, SkyEllipse): raise ValueError("Shape must be of type SkyEllipse (for now)")

        # Otherwise, add the shape
        super(SkyRegion, self).append(shape)

    # -----------------------------------------------------------------

    def __mul__(self, value):

        """
        This function ...
        :param value:
        :return:
        """

        new_region = SkyRegion()

        for ellipse in self: new_region.append(ellipse * value)

        # Return the new region
        return new_region

    # -----------------------------------------------------------------

    def __div__(self, value):

        """
        This function ...
        :param value:
        :return:
        """

        new_region = SkyRegion()

        for ellipse in self: new_region.append(ellipse / value)

        # Return the new region
        return new_region

    # -----------------------------------------------------------------

    def to_image_coordinates(self, wcs):

        """
        This function ...
        :param wcs:
        :return:
        """

        # Initialize a new list contain the ellipses in image coordinates
        new_region = newRegion()

        # Fill the new list
        for i in range(len(self)): new_region.append(self[i].to_ellipse(wcs))

        # Return the list of ellipses in image coordinates
        return new_region

    # -----------------------------------------------------------------

    def to_mask(self, wcs):

        """
        This function ...
        :return:
        """

        x_size = wcs.naxis1
        y_size = wcs.naxis2

        mask = Mask(np.zeros(y_size, x_size))

        for shape in self:

            ellipse = shape.to_ellipse(wcs)
            mask += Mask.from_ellipse(x_size, y_size, ellipse)

        # Return the mask
        return mask

# -----------------------------------------------------------------

class newRegion(list):

    """
    This class ...
    """

    def __init__(self):

        """
        This function ...
        :return:
        """

        # Call the constructor of the base class
        super(newRegion, self).__init__()

    # -----------------------------------------------------------------

    def append(self, shape):

        """
        This function ...
        :param shape:
        :return:
        """

        # Check whether the shape is in sky coordinates
        if not isinstance(shape, Ellipse): raise ValueError("Shape must be of type Ellipse (for now)")

        # Otherwise, add the shape
        super(newRegion, self).append(shape)

    # -----------------------------------------------------------------

    def to_sky_coordinates(self, wcs):

        """
        This function ...
        :param wcs:
        :return:
        """

        # Initialize a new list to contain the ellipses in sky coordinates
        new_region = SkyRegion()

        # Fill the new list
        for i in range(len(self)): new_region.append(SkyEllipse.from_ellipse(self[i], wcs))

        # Return the list of ellipses in sky coordinates
        return new_region

    # -----------------------------------------------------------------

    def to_mask(self, wcs):

        """
        This function ...
        :param wcs:
        :return:
        """

        x_size = wcs.naxis1<commit_msg>Resolved small issue<commit_after>#!/usr/bin/env python
# -*- coding: utf8 -*-
# *****************************************************************
# **       AstroMagic -- the image editor for astronomers        **
# **       © Astronomical Observatory, Ghent University          **
# *****************************************************************

## \package pts.magic.basics.region Contains the Region class.

# -----------------------------------------------------------------

# Ensure Python 3 functionality
from __future__ import absolute_import, division, print_function

# Import standard modules
import numpy as np

# Import astronomical modules
import pyregion
from astropy import coordinates as coord

# Import the relevant AstroMagic classes and modules
from .vector import Extent
from .geometry import Ellipse, SkyEllipse
from .mask import Mask

# -----------------------------------------------------------------

class SkyRegion(list):

    """
    This class ...
    """

    def __init__(self):

        """
        This function ...
        :return:
        """

        # Call the constructor of the base class
        super(SkyRegion, self).__init__()

    # -----------------------------------------------------------------

    def append(self, shape):

        """
        This function ...
        :return:
        """

        # Check whether the shape is in sky coordinates
        if not isinstance(shape, SkyEllipse): raise ValueError("Shape must be of type SkyEllipse (for now)")

        # Otherwise, add the shape
        super(SkyRegion, self).append(shape)

    # -----------------------------------------------------------------

    def __mul__(self, value):

        """
        This function ...
        :param value:
        :return:
        """

        new_region = SkyRegion()

        for ellipse in self: new_region.append(ellipse * value)

        # Return the new region
        return new_region

    # -----------------------------------------------------------------

    def __div__(self, value):

        """
        This function ...
        :param value:
        :return:
        """

        new_region = SkyRegion()

        for ellipse in self: new_region.append(ellipse / value)

        # Return the new region
        return new_region

    # -----------------------------------------------------------------

    def to_image_coordinates(self, wcs):

        """
        This function ...
        :param wcs:
        :return:
        """

        # Initialize a new list contain the ellipses in image coordinates
        new_region = newRegion()

        # Fill the new list
        for i in range(len(self)): new_region.append(self[i].to_ellipse(wcs))

        # Return the list of ellipses in image coordinates
        return new_region

    # -----------------------------------------------------------------

    def to_mask(self, wcs):

        """
        This function ...
        :return:
        """

        x_size = wcs.naxis1
        y_size = wcs.naxis2

        mask = Mask(np.zeros(y_size, x_size))

        for shape in self:

            ellipse = shape.to_ellipse(wcs)
            mask += Mask.from_ellipse(x_size, y_size, ellipse)

        # Return the mask
        return mask

# -----------------------------------------------------------------

class newRegion(list):

    """
    This class ...
    """

    def __init__(self):

        """
        This function ...
        :return:
        """

        # Call the constructor of the base class
        super(newRegion, self).__init__()

    # -----------------------------------------------------------------

    def append(self, shape):

        """
        This function ...
        :param shape:
        :return:
        """

        # Check whether the shape is in sky coordinates
        if not isinstance(shape, Ellipse): raise ValueError("Shape must be of type Ellipse (for now)")

        # Otherwise, add the shape
        super(newRegion, self).append(shape)

    # -----------------------------------------------------------------

    def __mul__(self, value):

        """
        This function ...
        :param value:
        :return:
        """

        new_region = newRegion()

        for ellipse in self: new_region.append(ellipse * value)

        # Return the new region
        return new_region

    # -----------------------------------------------------------------

    def __div__(self, value):

        """
        This function ...
        :param value:
        :return:
        """

        new_region = newRegion()

        for ellipse in self: new_region.append(ellipse / value)

        # Return the new region
        return new_region

    # -----------------------------------------------------------------

    def to_sky_coordinates(self, wcs):

        """
        This function ...
        :param wcs:
        :return:
        """

        # Initialize a new list to contain the ellipses in sky coordinates
        new_region = SkyRegion()

        # Fill the new list
        for i in range(len(self)): new_region.append(SkyEllipse.from_ellipse(self[i], wcs))

        # Return the list of ellipses in sky coordinates
        return new_region

    # -----------------------------------------------------------------

    def to_mask(self, wcs):

        """
        This function ...
        :param wcs:
        :return:
        """

        x_size = wcs.naxis1
{'fraction_non_alphanumeric': 0.2586223838066228, 'fraction_numerical': 0.000982607841210573, 'mean_word_length': 1.2106863596872286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5902899', 'n_tokens_mistral': 2514, 'n_tokens_neox': 2355, 'n_words': 715}