Exemple #1
0
    def select(self, **kwargs):
        """ Select data from the BST observation file.

            :param freqrange:
                Frequency range (see :attr:`BST_Data.freqrange`).
            :type freqrange: `float`, `list`, :class:`numpy.ndarray`
                or :class:`astropy.units.Quantity`, optional
            :param timerange:
                Time range (see :attr:`BST_Data.timerange`).
            :type timerange: `str`, `list`, :class:`numpy.ndarray` or :class:`astropy.time.Time`
            :param dbeam:
                Digital beam index (see :attr:`BST_Data.dbeam`)
            :type dbeam: `int`, optional
            :param polar:
                Polarization (see :attr:`BST_Data.polar`)
            :type polar: `str`, optional

            :returns: Selected data
            :rtype: :class:`nenupy.beamlet.sdata.SData`
        """
        self._fill_attr(kwargs)
        data = self.data[np.ix_(self._time_idx, self._polar_idx,
                                self._freq_idx)]
        return SData(data=np.swapaxes(data, 1, 2),
                     time=self.time,
                     freq=self.freq,
                     polar=self.polar)
Exemple #2
0
def test_sdata_div():
    dts = TimeDelta(np.arange(2), format='sec')
    s1 = SData(
        data=np.ones((2, 3, 1)),
        time=Time('2020-04-01 12:00:00') + dts,
        freq=np.arange(3) * u.MHz,
        polar=['NE']
    )
    s2 = SData(
        data=np.ones((2, 3, 1)),
        time=Time('2020-04-01 12:00:00') + dts,
        freq=np.arange(3) * u.MHz,
        polar=['NE']
    )
    s = s1 / s2
    assert isinstance(s, SData)
    assert (s.data == 1.).all()
    s = s1 / 2
    (s.data == 0.5).all()
Exemple #3
0
def test_sdata_def_error():
    dts = TimeDelta(np.arange(2), format='sec')
    with pytest.raises(AssertionError):
        # Time shape error
        s = SData(
            data=np.ones((3, 3, 1)),
            time=Time('2020-04-01 12:00:00') + dts,
            freq=np.arange(3) * u.MHz,
            polar=['NE']
        )
    with pytest.raises(AssertionError):
        # Freq shape error
        s = SData(
            data=np.ones((2, 4, 1)),
            time=Time('2020-04-01 12:00:00') + dts,
            freq=np.arange(3) * u.MHz,
            polar=['NE']
        )
    with pytest.raises(AssertionError):
        # Polar shape error
        s = SData(
            data=np.ones((2, 3, 2)),
            time=Time('2020-04-01 12:00:00') + dts,
            freq=np.arange(3) * u.MHz,
            polar=['NE']
        )
    with pytest.raises(TypeError):
        # Time type error
        s = SData(
            data=np.ones((2, 3, 1)),
            time=np.arange(2),
            freq=np.arange(3) * u.MHz,
            polar=['NE']
        )
    with pytest.raises(TypeError):
        # Freq type error
        s = SData(
            data=np.ones((2, 3, 1)),
            time=Time('2020-04-01 12:00:00') + dts,
            freq=np.arange(3),
            polar=['NE']
        )
Exemple #4
0
def test_sdata_concat_f():
    dts = TimeDelta(np.arange(2), format='sec')
    s1 = SData(
        data=np.ones((2, 3, 1)),
        time=Time('2020-04-01 12:00:00') + dts,
        freq=np.arange(3) * u.MHz,
        polar=['NE']
    )
    with pytest.raises(TypeError):
        s = s1 & 'other'
    with pytest.raises(ValueError):
        s2 = SData(
            data=np.ones((2, 3, 1)),
            time=Time('2020-04-01 12:00:00') + dts,
            freq=(1 + np.arange(3)) * u.MHz,
            polar=['NW']
        )
        # Different polars
        s = s1 & s2
    with pytest.raises(ValueError):
        s2 = SData(
            data=np.ones((2, 3, 1)),
            time=Time('2020-04-01 13:00:00') + dts,
            freq=(1 + np.arange(3)) * u.MHz,
            polar=['NE']
        )
        # Different times
        s = s1 & s2
    s2 = SData(
        data=np.ones((2, 3, 1)),
        time=Time('2020-04-01 12:00:00') + dts,
        freq=(1 + np.arange(3)) * u.MHz,
        polar=['NE']
    )
    s = s1 & s2
    assert s.data.shape == (2, 6, 1)
Exemple #5
0
def test_sdata_attr():
    dts = TimeDelta(np.arange(2), format='sec')
    s1 = SData(
        data=np.ones((2, 3, 1)),
        time=Time('2020-04-01 12:00:00') + dts,
        freq=np.arange(3) * u.MHz,
        polar='NE'
    )
    assert s1.amp.shape == (2, 3)
    assert (s1.amp == 1.).all()
    assert s1.db.shape == (2, 3)
    assert (s1.db == 0.).all()
    assert s1.mjd.size == 2
    testmjd = np.array([0.50000, 0.50001])
    assert testmjd == pytest.approx(s1.mjd-58940, 1e-5)
    assert s1.jd.size == 2
    assert s1.datetime.size == 2
Exemple #6
0
 def time_profile(self, times, anadir, digdir=None, **kwargs):
     """
     """
     amp_list = []
     time_list = []
     # Make sure kwargs is emptied from some keywords
     for key in ['azana', 'elana', 'azdig', 'eldig']:
         try:
             del kwargs[key]
         except KeyError:
             pass
     # Instanciate the SkyModel
     if self.model == 'gsm':
         smodel = HpxGSM(freq=self.freq, resolution=self.resolution)
     elif self.model == 'lofar':
         smodel = HpxLOFAR(freq=self.freq,
                           resolution=self.resolution,
                           smooth=False)
     # Loop over times
     for i, time in enumerate(tqdm(times)):
         self._gain.beam(time=time,
                         azana=anadir[i].az.deg,
                         elana=anadir[i].alt.deg,
                         azdig=None if digdir is None else digdir[i].az,
                         eldig=None if digdir is None else digdir[i].alt,
                         freq=self.freq,
                         **kwargs)
         # Rotate the HPX mask of the GSM
         smodel.time = time
         # Multiply and sum GMS and Beam
         vmask = smodel._is_visible
         gsmcut = smodel.skymap[vmask]
         beamcut = self._gain.skymap[vmask]
         amp_list.append(ne.evaluate('sum(gsmcut*beamcut)'))
         time_list.append(time.mjd)
     return SData(data=np.expand_dims(np.array(amp_list), axis=(1, 2)),
                  time=Time(time_list, format='mjd'),
                  freq=self.freq,
                  polar=self._gain.polar)
Exemple #7
0
def test_sdata_plot(mock_show):
    dts = TimeDelta(np.arange(2), format='sec')
    s1 = SData(
        data=np.ones((2, 3, 1)),
        time=Time('2020-04-01 12:00:00') + dts,
        freq=np.arange(3) * u.MHz,
        polar=['NE']
    )
    # Default plot
    s1.plot()
    # Custom plot
    s1.plot(
        db=False,
        cmap='Blues',
        vmin=-0.1,
        vmax=0.1,
        title='test title',
        cblabel='test cblabel',
        figsize=(6, 6),
    )
Exemple #8
0
def test_sdata_add():
    dts = TimeDelta(np.arange(2), format='sec')
    s1 = SData(
        data=np.ones((2, 3, 1)),
        time=Time('2020-04-01 12:00:00') + dts,
        freq=np.arange(3) * u.MHz,
        polar=['NE']
    )
    s2 = SData(
        data=np.ones((2, 3, 1)),
        time=Time('2020-04-01 12:00:00') + dts,
        freq=np.arange(3) * u.MHz,
        polar=['NE']
    )
    s = s1 + s2
    assert isinstance(s, SData)
    assert (s.data == 2.).all()
    s = s1 + 2
    assert (s.data == 3.).all()
    s = s1 + np.ones((2, 3, 1)) * 3
    assert (s.data == 4.).all()
    # Test operation errors
    with pytest.raises(ValueError):
        # Data not same shape
        s3 = SData(
            data=np.ones((2, 4, 1)),
            time=Time('2020-04-01 12:00:00') + dts,
            freq=np.arange(4) * u.MHz,
            polar=['NE']
        )
        s = s1 + s3
    with pytest.raises(ValueError):
        # Polar not same
        s3 = SData(
            data=np.ones((2, 3, 1)),
            time=Time('2020-04-01 12:00:00') + dts,
            freq=np.arange(3) * u.MHz,
            polar=['NW']
        )
        s = s1 + s3
    with pytest.raises(ValueError):
        # Time not same
        s3 = SData(
            data=np.ones((2, 3, 1)),
            time=Time('2020-04-01 13:00:00') + dts,
            freq=np.arange(3) * u.MHz,
            polar=['NE']
        )
        s = s1 + s3
    with pytest.raises(ValueError):
        # Freq not same
        s3 = SData(
            data=np.ones((2, 3, 1)),
            time=Time('2020-04-01 12:00:00') + dts,
            freq=(np.arange(3)+1) * u.MHz,
            polar=['NE']
        )
        s = s1 + s3
    with pytest.raises(Exception):
        s = s1 + 'wrong'
    with pytest.raises(ValueError):
        s = s1 + np.ones((1, 3, 1)) * 3