[64] | 1 | from __future__ import absolute_import
|
---|
| 2 |
|
---|
| 3 | import collections
|
---|
| 4 | import math
|
---|
| 5 | import numpy as np
|
---|
| 6 | import pp
|
---|
| 7 |
|
---|
| 8 | import common.commonobjects as co
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | class UVspectra(object):
|
---|
| 12 | """Class to compute spectra from each interferogram.
|
---|
| 13 | """
|
---|
| 14 |
|
---|
| 15 | def __init__(self, previous_results, job_server):
|
---|
| 16 | self.previous_results = previous_results
|
---|
| 17 | self.job_server = job_server
|
---|
| 18 |
|
---|
| 19 | self.uvspectra = []
|
---|
| 20 | self.result = collections.OrderedDict()
|
---|
| 21 |
|
---|
| 22 | def run(self):
|
---|
| 23 | print 'Uvspectra.run'
|
---|
| 24 |
|
---|
| 25 | # get observation list
|
---|
| 26 | observe = self.previous_results['observe']
|
---|
| 27 | obs_framework = observe['observed_framework']
|
---|
| 28 |
|
---|
| 29 | # and calculate the result for each configuration
|
---|
| 30 | UVspectrum = collections.namedtuple('uvspectrum', [
|
---|
| 31 | 'scan_number',
|
---|
| 32 | 'baseline_x', 'baseline_y', 'baseline_z', 'baseline_number',
|
---|
| 33 | 'interferogram', 'mirror_position', 'spectrum', 'wavenumber'],
|
---|
| 34 | verbose=False)
|
---|
| 35 |
|
---|
| 36 | fts_position = []
|
---|
| 37 | fts_data = []
|
---|
| 38 |
|
---|
| 39 | for config in obs_framework:
|
---|
| 40 | if config.fts_start:
|
---|
| 41 | if fts_data:
|
---|
| 42 | # reduce previous scan - assume symmetric -tau to +tau, so first
|
---|
| 43 | # shift 0 freq from centre of scan
|
---|
| 44 | temp = np.fft.fftshift(fts_data)
|
---|
| 45 | # spectrum is complex
|
---|
| 46 | spectrum = np.fft.fft(temp)
|
---|
| 47 | wavenumber = np.fft.fftfreq(n=spectrum.size,
|
---|
| 48 | d=2.0 * abs(fts_position[1] - fts_position[0])) / 100.0
|
---|
| 49 |
|
---|
| 50 | # save it
|
---|
| 51 | uvspectrum = UVspectrum(config.scan_number,
|
---|
| 52 | baseline[0],
|
---|
| 53 | baseline[1],
|
---|
| 54 | 0.0,
|
---|
| 55 | config.baseline_number,
|
---|
| 56 | np.array(fts_data),
|
---|
| 57 | np.array(fts_position),
|
---|
| 58 | spectrum,
|
---|
| 59 | wavenumber)
|
---|
| 60 |
|
---|
| 61 | self.uvspectra.append(uvspectrum)
|
---|
| 62 |
|
---|
| 63 | # start new scan
|
---|
| 64 | fts_position = [config.fts_nominal_position]
|
---|
| 65 | fts_data = [config.data]
|
---|
| 66 |
|
---|
| 67 | else:
|
---|
| 68 |
|
---|
| 69 | # add points to current scan
|
---|
| 70 | fts_position.append(config.fts_nominal_position)
|
---|
| 71 | fts_data.append(config.data)
|
---|
| 72 | baseline = (config.baseline_x, config.baseline_y)
|
---|
| 73 |
|
---|
| 74 | # deal with last scan
|
---|
| 75 | if fts_data:
|
---|
| 76 | temp = np.fft.fftshift(fts_data)
|
---|
| 77 | spectrum = np.fft.fft(temp)
|
---|
| 78 | wavenumber = np.fft.fftfreq(n=spectrum.size,
|
---|
| 79 | d=2.0 * abs(fts_position[1] - fts_position[0])) / 100.0
|
---|
| 80 |
|
---|
| 81 | uvspectrum = UVspectrum(config.scan_number,
|
---|
| 82 | baseline[0],
|
---|
| 83 | baseline[1],
|
---|
| 84 | 0.0,
|
---|
| 85 | config.baseline_number,
|
---|
| 86 | np.array(fts_data),
|
---|
| 87 | np.array(fts_position),
|
---|
| 88 | spectrum,
|
---|
| 89 | wavenumber)
|
---|
| 90 |
|
---|
| 91 | self.uvspectra.append(uvspectrum)
|
---|
| 92 |
|
---|
| 93 | self.result['uvspectra'] = self.uvspectra
|
---|
| 94 | return self.result
|
---|
| 95 |
|
---|
| 96 | def __repr__(self):
|
---|
| 97 | return '''
|
---|
| 98 | UVspectra:
|
---|
| 99 | #uvspectra : {num_uvspectra}
|
---|
| 100 | '''.format(
|
---|
| 101 | num_uvspectra=len(self.uvspectra))
|
---|
| 102 |
|
---|