示例#1
0
    def resize(self,
               frames,
               shape,
               offsetsp,
               finalshape,
               window=None,
               scale=1,
               step=0):
        _logger.info('Resizing frames and masks')
        for frame, rel_offset in zip(frames, offsetsp):
            if frame.valid_target:
                region, _ = subarray_match(finalshape, rel_offset, shape)
                # Valid region
                frame.valid_region = region
                # Relative offset
                frame.rel_offset = rel_offset
                # names of frame and mask
                framen, maskn = name_redimensioned_frames(
                    frame.baselabel, step)
                frame.resized_base = framen
                frame.resized_mask = maskn
                _logger.debug('%s, valid region is %s, relative offset is %s',
                              frame.label, custom_region_to_str(region),
                              rel_offset)
                self.resize_frame_and_mask(frame, finalshape, framen, maskn,
                                           window, scale)

        return frames
示例#2
0
def resize_hdulists(hdulists, shape, offsetsp, finalshape, window=None):
    from numina.array import subarray_match
    _logger.info('Resizing frames and masks')
    rhdulist = []
    regions = []
    for hdulist, rel_offset in zip(hdulists, offsetsp):
        region, _ = subarray_match(finalshape, rel_offset, shape)
        rframe = resize_hdul(hdulist, finalshape, region)
        rhdulist.append(rframe)
        regions.append(region)
    return rhdulist, regions
示例#3
0
def resize_hdulists(hdulists, shape, offsetsp, finalshape, window=None):
    from numina.array import subarray_match
    _logger.info('Resizing frames and masks')
    rhdulist = []
    regions = []
    for hdulist, rel_offset in zip(hdulists, offsetsp):
        region, _ = subarray_match(finalshape, rel_offset, shape)
        rframe = resize_hdul(hdulist, finalshape, region)
        rhdulist.append(rframe)
        regions.append(region)
    return rhdulist, regions
示例#4
0
 def resize(self, frames, shape, offsetsp, finalshape, window=None,
            scale=1, step=0):
     self.logger.info('Resizing frames and masks')
     for frame, rel_offset in zip(frames, offsetsp):
         if frame.valid_target:
             region, _ = narray.subarray_match(finalshape, rel_offset, shape)
             # Valid region
             frame.valid_region = region
             # Relative offset
             frame.rel_offset = rel_offset
             # names of frame and mask
             framen, maskn = name_redimensioned_frames(
                 frame.label, step)
             frame.resized_base = framen
             frame.resized_mask = maskn
             self.logger.debug('%s, valid region is %s, relative offset is %s',
                           frame.label, custom_region_to_str(region),
                           rel_offset
                           )
             self.resize_frame_and_mask(
                 frame, finalshape, framen, maskn, window, scale)
示例#5
0
    def test_subarray_match(self):
        '''Test subarray_match.'''

        # Shapes don't intersect
        minor, major = array.subarray_match((3, 4, 5),
                                            (10, 10, 10),
                                            (2, 2, 2))

        #  Returns None if shapes don't intersect
        self.assertTrue(minor is None,)
        self.assertTrue(major is None)

        small = 100

        # One is contained inside the other
        minor, major = array.subarray_match((2048, 2048),
                                            (0, 0), (small, small))
        # If one array is inside the other
        # the outputs is equal to the small array
        self.assertEqual(minor, (slice(0, small, None),
                                 slice(0, small, None)))
        self.assertEqual(major, (slice(0, small, None),
                                 slice(0, small, None)))

        # One is contained inside the other, with offsets
        minor, major = array.subarray_match((2048, 2048), (30, 40),
                                            (small, small))
        # If one array is inside the other
        # the outputs is equal to the small array
        self.assertEqual(minor, (slice(30, small + 30, None),
                                 slice(40, small + 40, None)))
        self.assertEqual(major, (slice(0, small, None),
                                 slice(0, small, None)))

        # Both are equal, with offsets
        minor, major = array.subarray_match((100, 100),
                                            (30, 40), (small, small))
        # If one array is inside the other
        # the outputs is equal to the small array
        self.assertEqual(minor, (slice(30, small, None),
                                 slice(40, small, None)))
        self.assertEqual(major, (slice(0, small - 30, None),
                                 slice(0, small - 40, None)))

        # Equal offsets in both sides
        minor, major = array.subarray_match((100, 100), (30, 40),
                                            (100, 100), (30, 40))
        # If one array is inside the other
        # the outputs is equal to the small array
        self.assertEqual(minor, (slice(0, small, None),
                                 slice(0, small, None)))
        self.assertEqual(major, (slice(0, small, None),
                                 slice(0, small, None)))

        # Different offsets in both sides
        minor, major = array.subarray_match((100, 100), (31, 42),
                                            (100, 100), (10, 20))
        # If one array is inside the other
        # the outputs is equal to the small array
        self.assertEqual(minor, (slice(21, small, None),
                                 slice(22, small, None)))
        self.assertEqual(major, (slice(0, 79, None), slice(0, 78, None)))

        # If we interchange the arrays and change the sign of the offset,
        # we get the same result
        minor, major = array.subarray_match((100, 100), (10, 20),
                                            (200, 100))
        cminor, cmajor = array.subarray_match((200, 100), (-10, -20),
                                              (100, 100))
        self.assertEqual(cminor, major)
        self.assertEqual(cmajor, minor)