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 | import pythonclean
|
---|
10 |
|
---|
11 |
|
---|
12 | class CleanImage(object):
|
---|
13 | """Class to compute clean image cube from uvspectra.
|
---|
14 | """
|
---|
15 |
|
---|
16 | def __init__(self, previous_results, job_server):
|
---|
17 | self.previous_results = previous_results
|
---|
18 | self.job_server = job_server
|
---|
19 |
|
---|
20 | self.result = collections.OrderedDict()
|
---|
21 |
|
---|
22 | def run(self):
|
---|
23 | print 'CleanImage.run'
|
---|
24 |
|
---|
25 | # get dirty image and beam info
|
---|
26 | dirty = self.previous_results['dirtyimage']
|
---|
27 | dirtyimage = dirty['dirtyimage']
|
---|
28 | dirtybeam = dirty['dirtybeam']
|
---|
29 | spatial_axis = dirty['spatial axis [arcsec]']
|
---|
30 | wavenumber = dirty['wavenumber [cm-1]']
|
---|
31 |
|
---|
32 | # clean image cube
|
---|
33 | cleanimage = np.zeros(np.shape(dirtyimage), np.float)
|
---|
34 | residualimage = np.zeros(np.shape(dirtyimage), np.float)
|
---|
35 |
|
---|
36 | # for iwn,wn in enumerate(wavenumber):
|
---|
37 | # print 'cleaning %s' % wn
|
---|
38 | # max = np.max(dirtyimage[:,:,iwn])
|
---|
39 | # components, residual = pclean.hogbom(dirty=dirtyimage[:,:,iwn],
|
---|
40 | # psf=dirtybeam[:,:,iwn],
|
---|
41 | # window=True, gain=0.1, thresh=max/100.0, niter=5000)
|
---|
42 | # cleanimage[:,:,iwn] = components
|
---|
43 | # residualimage[:,:,iwn] = residual
|
---|
44 |
|
---|
45 | # calculate clean image for each wn
|
---|
46 | jobs = {}
|
---|
47 | for iwn,wn in enumerate(wavenumber):
|
---|
48 | # submit jobs
|
---|
49 | print 'starting clean for', wn
|
---|
50 | immax = np.max(dirtyimage[:,:,iwn])
|
---|
51 | indata = (dirtyimage[:,:,iwn], dirtybeam[:,:,iwn], True, 0.1,
|
---|
52 | immax/100.0, 5000,)
|
---|
53 | jobs[wn] = self.job_server.submit(pythonclean.hogbom,
|
---|
54 | indata, (), ('numpy','pythonclean',))
|
---|
55 |
|
---|
56 | for iwn,wn in enumerate(wavenumber):
|
---|
57 | # collect and store results
|
---|
58 | cleanimage[:,:,iwn], residualimage[:,:,iwn] = jobs[wn]()
|
---|
59 |
|
---|
60 | self.result['dirtyimage'] = dirtyimage
|
---|
61 | self.result['cleanimage'] = cleanimage
|
---|
62 | self.result['residualimage'] = residualimage
|
---|
63 | self.result['spatial axis [arcsec]'] = spatial_axis
|
---|
64 | self.result['spatial axis'] = spatial_axis
|
---|
65 | self.result['wavenumber [cm-1]'] = wavenumber
|
---|
66 |
|
---|
67 | return self.result
|
---|
68 |
|
---|
69 | def __repr__(self):
|
---|
70 | return '''
|
---|
71 | CleanImage:
|
---|
72 | '''.format(
|
---|
73 | num_uvspectra=len(self.uvspectra))
|
---|
74 |
|
---|