Ejemplo n.º 1
0
    def test_get_random_state(self):
        # Life, Universe and Everything
        lue = 42
        random_state = np.random.RandomState(lue)

        assert utils.get_random_state(None) is np.random.mtrand._rand
        assert np.all(utils.get_random_state(lue).randn(lue) == np.random.RandomState(lue).randn(lue))
        assert np.all(utils.get_random_state(np.random.RandomState(lue)).randn(lue) == np.random.RandomState(lue).randn(lue))

        with pytest.raises(ValueError):
            utils.get_random_state('foobar')
Ejemplo n.º 2
0
    def test_get_random_state(self):
        # Life, Universe and Everything
        lue = 42
        random_state = np.random.RandomState(lue)

        assert utils.get_random_state(None) is np.random.mtrand._rand
        assert np.all(utils.get_random_state(lue).randn(lue) == np.random.RandomState(lue).randn(lue))
        assert np.all(utils.get_random_state(np.random.RandomState(lue)).randn(lue) == np.random.RandomState(lue).randn(lue))

        with pytest.raises(ValueError):
            utils.get_random_state('foobar')
Ejemplo n.º 3
0
    def __init__(self,
                 dt,
                 N,
                 mean,
                 rms,
                 red_noise=1,
                 random_state=None,
                 tstart=0.0):
        self.dt = dt

        if not isinstance(N, (int, np.integer)):
            raise ValueError("N must be integer!")

        self.N = N

        if mean == 0:
            warnings.warn("Careful! A mean of zero is unphysical!" + \
                          "This may have unintended consequences!")
        self.mean = mean
        self.nphot = self.mean * self.N
        self.rms = rms
        self.red_noise = red_noise
        self.tstart = tstart
        self.time = dt * np.arange(N) + self.tstart

        # Initialize a tuple of energy ranges with corresponding light curves
        self.channels = []

        self.random_state = utils.get_random_state(random_state)

        assert rms <= 1, 'Fractional rms must be less than 1.'
        assert dt > 0, 'Time resolution must be greater than 0'
Ejemplo n.º 4
0
    def __init__(self, dt=1, N=1024, mean=0, rms=1, red_noise=1,
                 random_state=None, tstart=0.0):
        self.dt = dt
        self.N = N
        self.mean = mean
        self.rms = rms
        self.red_noise = red_noise
        self.tstart = tstart
        self.time = dt*np.arange(N) + self.tstart

        # Initialize a tuple of energy ranges with corresponding light curves
        self.channels = []

        self.random_state = utils.get_random_state(random_state)

        assert rms<=1, 'Fractional rms must be less than 1.'
        assert dt>0, 'Time resolution must be greater than 0'
Ejemplo n.º 5
0
    def __init__(self, dt=1, N=1024, mean=0, rms=1, red_noise=1,
                 random_state=None, tstart=0.0):

        self.dt = dt
        self.N = N
        self.mean = mean
        self.rms = rms
        self.red_noise = red_noise
        self.tstart = tstart
        self.time = dt*np.arange(N) + self.tstart

        # Initialize a tuple of energy ranges with corresponding light curves
        self.channels = []

        self.random_state = utils.get_random_state(random_state)

        assert rms<=1, 'Fractional rms must be less than 1.'
        assert dt>0, 'Time resolution must be greater than 0'
Ejemplo n.º 6
0
    def __init__(self,
                 dt=1,
                 N=1024,
                 mean=0,
                 rms=1,
                 red_noise=1,
                 random_state=None):
        """
        Methods to simulate and visualize light curves.

        Parameters
        ----------
        dt: int, default 1
            time resolution of simulated light curve
        N: int, default 1024
            bins count of simulated light curve
        mean: float, default 0
            mean value of the simulated light curve
        rms: float, default 1
            fractional rms of the simulated light curve,
            actual rms is calculated by mean*rms
        red_noise: int, default 1
            multiple of real length of light curve, by
            which to simulate, to avoid red noise leakage
        seed: int, default None
            seed value for random processes
        """

        self.dt = dt
        self.N = N
        self.mean = mean
        self.rms = rms
        self.red_noise = red_noise
        self.time = dt * np.arange(N)

        # Initialize a tuple of energy ranges with corresponding light curves
        self.channels = []

        self.random_state = utils.get_random_state(random_state)

        assert rms <= 1, 'Fractional rms must be less than 1.'
        assert dt > 0, 'Time resolution must be greater than 0'
Ejemplo n.º 7
0
    def __init__(self, dt=1, N=1024, mean=0, rms=1, red_noise=1,
                 random_state=None):
        """
        Methods to simulate and visualize light curves.

        Parameters
        ----------
        dt : int, default 1
            time resolution of simulated light curve
        N : int, default 1024
            bins count of simulated light curve
        mean : float, default 0
            mean value of the simulated light curve
        rms : float, default 1
            fractional rms of the simulated light curve,
            actual rms is calculated by mean*rms
        red_noise : int, default 1
            multiple of real length of light curve, by
            which to simulate, to avoid red noise leakage
        random_state : int, default None
            seed value for random processes
        """

        self.dt = dt
        self.N = N
        self.mean = mean
        self.rms = rms
        self.red_noise = red_noise
        self.time = dt*np.arange(N)

        # Initialize a tuple of energy ranges with corresponding light curves
        self.channels = []

        self.random_state = utils.get_random_state(random_state)

        assert rms<=1, 'Fractional rms must be less than 1.'
        assert dt>0, 'Time resolution must be greater than 0'