Exemple #1
0
    def test_load_save_npy(self):
        cube1 = clfd.DataCube(self.ndarray)
        with tempfile.NamedTemporaryFile(mode="wb",
                                         suffix='.npy',
                                         delete=False) as fobj:
            fname = fobj.name

        cube1 = clfd.DataCube(self.ndarray)
        cube1.save_npy(fname)
        cube2 = clfd.DataCube.from_npy(fname)
        self.assertTrue(numpy.allclose(cube1.data, cube2.data))
        os.remove(fname)
Exemple #2
0
    def test_input_dim_errors(self):
        with self.assertRaises(ValueError,
                               msg="Input has less than 3 dimensions"):
            clfd.DataCube(self.ndarray.ravel())

        shape = self.ndarray.shape
        shape4 = tuple(list(shape) + [1])
        with self.assertRaises(ValueError,
                               msg="Input has more than 3 dimensions"):
            clfd.DataCube(self.ndarray.reshape(shape4))

        with self.assertRaises(ValueError, msg="Input has only 1 phase bin"):
            clfd.DataCube(self.ndarray[:, :, :1])

        with self.assertRaises(ValueError, msg="Input has only 1 profile"):
            clfd.DataCube(self.ndarray[:1, :1, :])
Exemple #3
0
    def test_load_save_npy(self):
        with tempfile.NamedTemporaryFile(mode="wb", suffix='.npy') as fobj:
            fname = fobj.name

            # NOTE: leaving self.ndarray untouched
            cube1 = clfd.DataCube(self.ndarray, copy=True)
            cube1.save_npy(fname)
            cube2 = clfd.DataCube.from_npy(fname)

            self.assertTrue(numpy.allclose(cube1.data, cube2.data))
Exemple #4
0
    def setUp(self):
        # Load test data
        self.npy_data_fname = os.path.join(
            get_example_data_path(), "npy_example.npy")
        self.ndarray = numpy.load(self.npy_data_fname)
        self.cube = clfd.DataCube(self.ndarray, copy=False)
        self.frequencies = numpy.linspace(1181.0, 1581.0, 128)

        self.feature_names = ["std", "ptp", "lfamp"]
        self.qmask = 2.0
        self.features = clfd.featurize(
            self.cube, 
            features=self.feature_names
            )
        
        # Run profile masking
        (self.stats, self.profmask) = clfd.profile_mask(self.features, q=self.qmask)
Exemple #5
0
    def test_time_phase_mask(self):
        q = 2.0
        zap_channels = range(10)
        all_channels = range(self.cube.num_chans)

        mask, valid_chans, repvals = clfd.time_phase_mask(
            self.cube, q=q, zap_channels=zap_channels)

        # Check that valid_chans is the complement set of zap_channels
        isect = set(zap_channels).intersection(set(valid_chans))
        union = set(zap_channels).union(set(valid_chans))
        self.assertFalse(isect)
        self.assertTrue(union == set(all_channels))

        # Check output shapes
        self.assertEqual(mask.shape,
                         (self.cube.num_subints, self.cube.num_bins))
        self.assertEqual(repvals.shape, self.cube.data.shape)

        ##### Check replacement of values behaves as expected #####
        # Once bad values have been replaced, if we call time_phase_mask() again
        # with the same params, then no previously flagged time-phase bins should be
        # flagged again.
        # NOTE: HOWEVER, new bins can still get flagged !
        # That is because once the old outliers have been replaced by "good" values,
        # the range of acceptable value is reduced which may push previously "normal" points
        # into outlier status.
        orig_data = self.cube.orig_data
        clean_data = apply_time_phase_mask(mask, valid_chans, repvals,
                                           orig_data)
        clean_cube = clfd.DataCube(clean_data)
        newmask, __, __ = clfd.time_phase_mask(clean_cube,
                                               q=q,
                                               zap_channels=zap_channels)

        # Check that no bin is flagged in both masks
        self.assertFalse(numpy.any(newmask & mask))
Exemple #6
0
 def test_input_type_errors(self):
     # Input must be numpy.ndarray
     with self.assertRaises(ValueError):
         clfd.DataCube(list(self.ndarray))
Exemple #7
0
 def test_init(self):
     clfd.DataCube(self.ndarray)
Exemple #8
0
 def test_init(self):
     # NOTE: need to leave self.ndarray untouched. It WILL be modified
     # if wrapping it in a DataCube with copy=False
     X = self.ndarray.copy()
     clfd.DataCube(X, copy=False)
     clfd.DataCube(X, copy=True)