Changeset 68


Ignore:
Timestamp:
Sep 23, 2014 1:21:28 PM (10 years ago)
Author:
JohnLightfoot
Message:

parallelized

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dirtyimage.py

    r58 r68  
    77
    88import common.commonobjects as co
     9
     10def 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)
     13
     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
    942
    1043
     
    4073        dirtybeam = np.zeros([npix, npix, len(wavenumber)], np.float)
    4174
     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 = []
    4281        for uvspectrum in uvspectra:
     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)
    4386
    44             b_x = uvspectrum.baseline_x
    45             b_y = uvspectrum.baseline_y
    46             spectrum = uvspectrum.spectrum
    47             wn_spectrum = uvspectrum.wavenumber
     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',))
    4895
    49             for iwn,wn in enumerate(wavenumber):
    50                 # must be a better way of doing this
    51                 argx = b_x * (wn * 100.0) * spatial_axis / 206265.0
    52                 argy = b_y * (wn * 100.0) * spatial_axis / 206265.0
    53                 valx = np.exp(2j * math.pi * argx)
    54                 valy = np.exp(2j * math.pi * argy)
    55 
    56                 vis = spectrum[wn_spectrum==wn]
    57 
    58                 # numpy arrays are [row,col] or here [y,x]
    59                 for iy,y in enumerate(spatial_axis):
    60                     contribution = (vis * valx * valy[iy]) + \
    61                       np.conjugate(vis * valx * valy[iy])
    62                     dirtyimage[iy,:,iwn] += contribution.real
    63                     contribution = (valx * valy[iy]) + \
    64                       np.conjugate(valx * valy[iy])
    65                     dirtybeam[iy,:,iwn] += contribution.real
    66    
    67         # normalise
    6896        for iwn,wn in enumerate(wavenumber):
    69             dirtyimage[:,:,iwn] /= np.sum(dirtybeam[:,:,iwn])
    70             dirtybeam[:,:,iwn] /= np.sum(dirtybeam[:,:,iwn])
    71 #        dirtyimage /= 2.0 * float(len(uvspectra))
    72 #        dirtybeam /= 2.0 * float(len(uvspectra))
    73         print 'sum image', np.sum(dirtyimage[:,:,0])
    74         print 'sum beam', np.sum(dirtybeam[:,:,0])
     97            # collect and store results
     98            dirtyimage[:,:,iwn], dirtybeam[:,:,iwn] = jobs[wn]()
    7599
    76100        self.result['dirtyimage'] = dirtyimage
Note: See TracChangeset for help on using the changeset viewer.