[58] | 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 |
|
---|
[68] | 10 | def dirty(b_x_list, b_y_list, spectra, wn_spectra, iwn, wn, spatial_axis, npix):
|
---|
| 11 | image = numpy.zeros([npix, npix], numpy.float)
|
---|
| 12 | beam = numpy.zeros([npix, npix], numpy.float)
|
---|
[58] | 13 |
|
---|
[68] | 14 | for ibx,b_x in enumerate(b_x_list):
|
---|
| 15 | b_x = b_x_list[ibx]
|
---|
| 16 | b_y = b_y_list[ibx]
|
---|
| 17 | spectrum = spectra[ibx]
|
---|
| 18 | wn_spectrum = wn_spectra[ibx]
|
---|
| 19 |
|
---|
| 20 | # must be a better way of doing this
|
---|
| 21 | argx = b_x * (wn * 100.0) * spatial_axis / 206265.0
|
---|
| 22 | argy = b_y * (wn * 100.0) * spatial_axis / 206265.0
|
---|
| 23 | valx = numpy.exp(2j * math.pi * argx)
|
---|
| 24 | valy = numpy.exp(2j * math.pi * argy)
|
---|
| 25 |
|
---|
| 26 | vis = spectrum[wn_spectrum==wn]
|
---|
| 27 |
|
---|
| 28 | # numpy arrays are [row,col] or here [y,x]
|
---|
| 29 | for iy,y in enumerate(spatial_axis):
|
---|
| 30 | contribution = (vis * valx * valy[iy]) + \
|
---|
| 31 | numpy.conjugate(vis * valx * valy[iy])
|
---|
| 32 | image[iy,:] += contribution.real
|
---|
| 33 | contribution = (valx * valy[iy]) + \
|
---|
| 34 | numpy.conjugate(valx * valy[iy])
|
---|
| 35 | beam[iy,:] += contribution.real
|
---|
| 36 |
|
---|
| 37 | # normalise
|
---|
| 38 | image /= numpy.sum(beam)
|
---|
| 39 | beam /= numpy.sum(beam)
|
---|
| 40 |
|
---|
| 41 | return image, beam
|
---|
| 42 |
|
---|
| 43 |
|
---|
[58] | 44 | class DirtyImage(object):
|
---|
| 45 | """Class to compute dirty image cube from uvspectra.
|
---|
| 46 | """
|
---|
| 47 |
|
---|
| 48 | def __init__(self, previous_results, job_server):
|
---|
| 49 | self.previous_results = previous_results
|
---|
| 50 | self.job_server = job_server
|
---|
| 51 |
|
---|
| 52 | self.result = collections.OrderedDict()
|
---|
| 53 |
|
---|
| 54 | def run(self):
|
---|
| 55 | print 'DirtyImage.run'
|
---|
| 56 |
|
---|
| 57 | # get relevant fts info
|
---|
| 58 | fts = self.previous_results['fts']
|
---|
| 59 | fts_wnmin = fts['wnmin']
|
---|
| 60 |
|
---|
| 61 | # get primary beam info
|
---|
| 62 | beamsgenerator = self.previous_results['beamsgenerator']
|
---|
| 63 | npix = beamsgenerator['npix']
|
---|
| 64 | spatial_axis = beamsgenerator['spatial axis [arcsec]']
|
---|
| 65 |
|
---|
| 66 | # get observation list
|
---|
| 67 | uvspectra = self.previous_results['uvspectra']['uvspectra']
|
---|
| 68 | wavenumber = uvspectra[0].wavenumber
|
---|
| 69 | wavenumber = wavenumber[wavenumber>fts_wnmin]
|
---|
| 70 |
|
---|
| 71 | # dirty image cube
|
---|
| 72 | dirtyimage = np.zeros([npix, npix, len(wavenumber)], np.float)
|
---|
| 73 | dirtybeam = np.zeros([npix, npix, len(wavenumber)], np.float)
|
---|
| 74 |
|
---|
[68] | 75 | # calculate dirty image for each wn
|
---|
| 76 | # uvspectrum objects don't pickle so unpack them first
|
---|
| 77 | b_x_list = []
|
---|
| 78 | b_y_list = []
|
---|
| 79 | spectra = []
|
---|
| 80 | wn_spectra = []
|
---|
[58] | 81 | for uvspectrum in uvspectra:
|
---|
[68] | 82 | b_x_list.append(uvspectrum.baseline_x)
|
---|
| 83 | b_y_list.append(uvspectrum.baseline_y)
|
---|
| 84 | spectra.append(uvspectrum.spectrum)
|
---|
| 85 | wn_spectra.append(uvspectrum.wavenumber)
|
---|
[58] | 86 |
|
---|
[68] | 87 | jobs = {}
|
---|
| 88 | for iwn,wn in enumerate(wavenumber):
|
---|
| 89 | # submit jobs
|
---|
| 90 | print 'starting dirty for', wn
|
---|
| 91 | indata = (b_x_list, b_y_list, spectra, wn_spectra, iwn, wn,
|
---|
| 92 | spatial_axis, npix,)
|
---|
| 93 | jobs[wn] = self.job_server.submit(dirty, indata, (),
|
---|
| 94 | ('numpy','math',))
|
---|
[58] | 95 |
|
---|
| 96 | for iwn,wn in enumerate(wavenumber):
|
---|
[68] | 97 | # collect and store results
|
---|
| 98 | dirtyimage[:,:,iwn], dirtybeam[:,:,iwn] = jobs[wn]()
|
---|
[58] | 99 |
|
---|
| 100 | self.result['dirtyimage'] = dirtyimage
|
---|
| 101 | self.result['dirtybeam'] = dirtybeam
|
---|
| 102 | self.result['spatial axis [arcsec]'] = spatial_axis
|
---|
| 103 | self.result['spatial axis'] = spatial_axis
|
---|
| 104 | self.result['wavenumber [cm-1]'] = wavenumber
|
---|
| 105 |
|
---|
| 106 | return self.result
|
---|
| 107 |
|
---|
| 108 | def __repr__(self):
|
---|
| 109 | return '''
|
---|
| 110 | DirtyImage:
|
---|
| 111 | '''.format(
|
---|
| 112 | num_uvspectra=len(self.uvspectra))
|
---|
| 113 |
|
---|