Ejemplo n.º 1
0
def scan_sample_data(odin_postgresql):
    backend = 'AC2'
    freqmode = 22
    scanid = 7016113563
    db_connection = DatabaseConnector(*odin_postgresql)
    scan_data_exporter = ScandataExporter(backend, db_connection)
    scan_data_exporter.get_db_data(freqmode, scanid)
    scan_data_exporter.decode_specdata()
    assert len(scan_data_exporter.spectra['stw']) == 94
    scan_data_exporter = apply_calibration_step2(db_connection,
                                                 scan_data_exporter)
    scan_data_exporter = unsplit_normalmode(scan_data_exporter)
    assert len(scan_data_exporter.spectra['stw']) == 47
    smr_lofreqcorr(scan_data_exporter)
    smr_freq_spec = Smrl1bFreqspec()
    smr_freq_sort = Smrl1bFreqsort()
    frequency_grid = smr_freq_spec.get_frequency(scan_data_exporter.spectra, 0)
    spectra = np.array(scan_data_exporter.spectra['spectrum'])
    bad_modules = get_bad_ssb_modules(scan_data_exporter.spectra['backend'][0],
                                      spectra, frequency_grid, False)
    frequency_grid = frequency_grid.flatten()
    frequency_grid, _, _, channels_id = (smr_freq_sort.get_sorted_ac_spectrum(
        frequency_grid, spectra[0], bad_modules))
    return {
        'frequency_grids': np.tile(frequency_grid, (spectra.shape[0] - 2, 1)),
        'spectra': spectra[2::, channels_id],
        'altitudes': scan_data_exporter.spectra['altitude'][2::]
    }
Ejemplo n.º 2
0
def test_get_bad_ssb_modules_for_ac2(
        scan_data_sample, frequency_grid):
    backend = 2
    bad_modules = get_bad_ssb_modules(
        backend,
        scan_data_sample['spectra'],
        frequency_grid)
    assert bad_modules == np.mean(frequency_grid, 1)[2]
Ejemplo n.º 3
0
def test_get_bad_ssb_modules_for_dead_band(
        scan_data_sample, frequency_grid):
    backend = 1
    scan_data_sample[
        'spectra'][3][112 * 2: 112 * 3] = 0
    bad_modules = get_bad_ssb_modules(
        backend,
        scan_data_sample['spectra'],
        frequency_grid)
    assert np.all(
        bad_modules ==
        np.mean(frequency_grid, 1)[0: 3])
def get_freqinfo(scangr, debug=False):
    '''add frequency info for each spectrum in scan'''
    spectra = np.array(scangr.spectra['spectrum'])
    scangr.spectra['spectrum'] = []
    scangr.spectra['frequency'] = []
    channels = []
    freqinfo = {
        'IFreqGrid': [],
        'LOFreq': [],
        'SubBandIndex': [],
        'ChannelsID': [],
        'AppliedDopplerCorr': [],
    }
    freqgr = Smrl1bFreqspec()
    freqsortgr = Smrl1bFreqsort()

    for numspec, _ in enumerate(scangr.spectra['stw']):
        freqvec = freqgr.get_frequency(scangr.spectra, numspec)
        bad_modules = get_bad_ssb_modules(scangr.spectra['backend'][numspec],
                                          spectra, freqvec, debug)
        freqvec.shape = (freqvec.shape[0] * freqvec.shape[1], )
        freqvec, tempspec, ssb, channels_id = (
            freqsortgr.get_sorted_ac_spectrum(freqvec, spectra[numspec],
                                              bad_modules))
        # correcting freqvec for Doppler
        lofreq, freqvec = doppler_corr(scangr.spectra['skyfreq'][numspec],
                                       scangr.spectra['restfreq'][numspec],
                                       scangr.spectra['lofreq'][numspec],
                                       freqvec)
        if (scangr.spectra['frontend'][0] == 3
                and (scangr.spectra['freqmode'][0] == 14
                     or scangr.spectra['freqmode'][0] == 22
                     or scangr.spectra['freqmode'][0] == 24)):
            # make a frequency adjustement of measurements from 572 frontend
            # according to Julias description in L1ATBD
            if numspec == 0:
                # get doppler corrected lo frequencies
                lo_frequencies = []
                for sky_freq, rest_freq, lo_freq in zip(
                        scangr.spectra['skyfreq'],
                        scangr.spectra['restfreq'],
                        scangr.spectra['lofreq'],
                ):
                    (lo_freq_corrected,
                     _) = doppler_corr(sky_freq, rest_freq, lo_freq, freqvec)
                    lo_frequencies.append(lo_freq_corrected)
                lo_frequencies = np.array(lo_frequencies)
                frequency_grids = (
                    np.tile(freqvec,
                            (len(scangr.spectra['altitude']) - 2, 1)) +
                    np.tile(lo_frequencies[2::],
                            (freqvec.shape[0], 1)).transpose())
                fcgr = Freqcorr572(frequency_grids, spectra[2::, channels_id],
                                   scangr.spectra['altitude'][2::])
                (
                    scan_correction_is_ok,
                    _,  # single_spectrum_correction_is_ok,
                    frequency_offset_of_scan,
                    frequencies_offset_per_spectrum
                ) = fcgr.run_frequency_correction()
            if scan_correction_is_ok:
                lofreq = lofreq - (
                    frequency_offset_of_scan +
                    frequencies_offset_per_spectrum[numspec - 2]) * 1e9
            else:
                # mark that frequency can not be trusted
                scangr.spectra['quality'][numspec] = (
                    scangr.spectra['quality'][numspec] + 0x0400)
        if numspec == 0:
            freqinfo['IFreqGrid'] = freqvec.tolist()
            freqinfo['SubBandIndex'].append(ssb[1::3])
            freqinfo['SubBandIndex'].append(ssb[2::3])
            freqinfo['ChannelsID'] = np.array(channels_id + 1).tolist()
        if numspec > 1:
            freqinfo['LOFreq'].append(lofreq)
            freqinfo['AppliedDopplerCorr'].append(
                -(scangr.spectra['skyfreq'][numspec] -
                  scangr.spectra['restfreq'][numspec]))
        channels.append(tempspec.shape[0])
        scangr.spectra['spectrum'].append(
            np.around(tempspec, decimals=3).tolist())
    scangr.spectra['frequency'] = freqinfo
    scangr.spectra['channels'] = channels
    return scangr