Esempio n. 1
0
    def convert_masks_to_ranges(self):
        """
        Converts the masks to range masks so that they take up less space.

        This is non-reversible. It is also not required, but can help save space
        on highly constrained machines before you start reading in the data.

        If you don't know what you are doing please don't use this.
        """

        if self.spatial_only:
            # We are already done!
            return
        else:
            # We must do the whole boolean mask stuff. To do that, we
            # First, convert each boolean mask into an integer mask
            # Use the accelerate.ranges_from_array function to convert
            # This into a set of ranges.

            for ptype in self.metadata.present_particle_names:
                setattr(
                    self,
                    ptype,
                    # Because it nests things in a list for some reason.
                    np.where(getattr(self, ptype))[0],
                )

                setattr(self, f"{ptype}_size", getattr(self, ptype).size)

            for ptype in self.metadata.present_particle_names:
                setattr(self, ptype, ranges_from_array(getattr(self, ptype)))

        return
Esempio n. 2
0
def test_ranges_from_array_non_contiguous():
    """
    Tests the ranges from array funciton with no contiguous input.
    """

    my_array = np.array([77, 34483, 234582, 123412341324], dtype=int)

    out = np.array([[77, 77], [34483, 34483], [234582, 234582],
                    [123412341324, 123412341324]])

    assert (ranges_from_array(my_array) == out).all()
Esempio n. 3
0
def test_ranges_from_array():
    """
    Tests ranges from array using the example given.
    """

    my_array = np.array([0, 1, 2, 3, 5, 6, 7, 9, 11, 12, 13], dtype=int)

    out = np.array([[0, 3], [5, 7], [9, 9], [11, 13]])

    assert (ranges_from_array(my_array) == out).all()

    return