Ejemplo n.º 1
0
 def test_detrend_spectroscopic_data_als(self, nx, ny):
     x, spectrum = _setup_spectra(nx, ny)
     detr, _ = detrend_spectroscopic_data(x,
                                          spectrum,
                                          kind='als',
                                          outlier_purging=False)
     assert np.allclose(detr, 0., atol=1e-2)
Ejemplo n.º 2
0
def pack_data(scan, polar_dict, detrend=False):
    """Pack data into MBFITS-ready format

    Examples
    --------
    >>> scan = {'Feed0_LCP': np.arange(4), 'Feed0_RCP': np.arange(4, 8)}
    >>> polar = {'LCP': 'Feed0_LCP', 'RCP': 'Feed0_RCP'}
    >>> res = pack_data(scan, polar)
    >>> np.allclose(res, [[0, 4], [1, 5], [2, 6], [3, 7]])
    True
    >>> scan = {'Feed0_LCP': np.arange(2), 'Feed0_RCP': np.arange(2, 4),
    ...         'Feed0_Q': np.arange(4, 6), 'Feed0_U': np.arange(6, 8)}
    >>> polar = {'LCP': 'Feed0_LCP', 'RCP': 'Feed0_RCP', 'Q': 'Feed0_Q',
    ...          'U': 'Feed0_U'}
    >>> res = pack_data(scan, polar)
    >>> np.allclose(res, [[0, 2, 4, 6], [1, 3, 5, 7]])
    True
    >>> scan = {'Feed0_LCP': np.ones((2, 4)), 'Feed0_RCP': np.zeros((2, 4))}
    >>> polar = {'LCP': 'Feed0_LCP', 'RCP': 'Feed0_RCP'}
    >>> res = pack_data(scan, polar)
    >>> np.allclose(res, [[[ 1.,  1.,  1.,  1.], [ 0.,  0.,  0.,  0.]],
    ...                   [[ 1.,  1.,  1.,  1.], [ 0.,  0.,  0.,  0.]]])
    True
    """

    polar_list = list(polar_dict.keys())
    if 'LCP' in polar_list:
        data = [scan[polar_dict['LCP']], scan[polar_dict['RCP']]]
        try:
            data.append(scan[polar_dict['Q']])
            data.append(scan[polar_dict['U']])
        except KeyError:
            pass
    else:  # pragma: no cover
        raise ValueError('Polarization kind not implemented yet')

    if detrend:
        new_data = []
        for d in data:
            detr, _ = detrend_spectroscopic_data(0, d, 'als')
            new_data.append(detr)
        data = new_data
    return np.stack(data, axis=1)
Ejemplo n.º 3
0
 def test_detrend_spectroscopic_data_garbage(self, nx, ny):
     x, spectrum = _setup_spectra(nx, ny)
     detr, _ = detrend_spectroscopic_data(x, spectrum,
                                          kind='blabla')
     assert np.all(detr == spectrum)
Ejemplo n.º 4
0
 def test_detrend_spectroscopic_data(self, nx, ny):
     x, spectrum = _setup_spectra(nx, ny)
     detr, _ = detrend_spectroscopic_data(x, spectrum,
                                          kind='rough')
     assert np.allclose(detr, 0., atol=1e-3)