Exemplo n.º 1
0
def peak(so, mapdir):
    src = '{}/{}.cnt'.format(mapdir, so)
    for li in ['ll.nocal', 'rr.nocal', 'll.nopol', 'rr.nopol']:
        miriad.maxfit({
            'in': '{}.{}.cm'.format(src, li),
            'log': 'maxfit_{}.{}'.format(so, li)
        })
    miriad.maxfit({
        'in': '{}.i.cm'.format(src),
        'log': 'maxfit_{}.stokesI'.format(so)
    })
Exemplo n.º 2
0
def getMapData(uncorrectedMap,
               correctedMap,
               line,
               stokes,
               peakStokes,
               regionWidth=1,
               useFull=True,
               imspectOptions={},
               maxfitOptions={}):
    """
	Returns two numpy arrays representing the uncorrected and corrected spectra for each given stokes
	these arrays in turn are of length 2*len(stokes).

	ex:
	```
	freqs, amps = getMapData('/path/to/uncorrected/map', '/path/to/corrected/map', 'co3-2', ['i', 'v'], 'v', regionWidth=1)
	# freqs[0], amps[0] is the frequency vs. amplitude for the uncorrected map of stokes i through the max peak of stokes i
	# since getMapData was called with stokes = ['i', 'v'] len(freqs) = 4 and len(amps) = 4
	```

	"""
    corrText = ['uncorr', 'corr']
    frequencies = []
    amplitudes = []
    for i, mapdir in enumerate([uncorrectedMap, correctedMap]):
        if useFull:
            peakLineMap = (mapdir + '.' + peakStokes + '.full.cm').replace(
                'usb', line)
        else:
            peakLineMap = (mapdir + '.' + peakStokes + '.cm').replace(
                'usb', line)

        try:
            maxPixel = miriad.maxfit({
                **{
                    'in': peakLineMap
                },
                **maxfitOptions
            },
                                     stdout=subprocess.PIPE).stdout
            maxPixel = str(maxPixel).split('\\n')[4]
            maxPixel = maxPixel[maxPixel.find('(') +
                                1:maxPixel.find(')')].split(',')[0:2]
            maxPixel = list(map(int, maxPixel))
        except:
            maxPixel = [64, 64]
            if 'OrionKL' in correctedMap:
                maxPixel = [90, 111]

        if 'sio' in line and 'OrionKL' in correctedMap:
            maxPixel = [124, 75]

        # make a box around the peak (by finding a bottom left corner 'blc' and top right corner 'trc')
        blc = (maxPixel[0] - regionWidth / 2, maxPixel[1] - regionWidth / 2)
        blc = tuple(map(int, blc))
        trc = (maxPixel[0] + regionWidth / 2, maxPixel[1] + regionWidth / 2)
        trc = tuple(map(int, trc))
        region = 'abspixel,box({},{},{},{})'.format(blc[0], blc[1], trc[0],
                                                    trc[1])
        print(peakLineMap)
        print('peak at:', str(maxPixel))

        # save overlay file
        overlayFile = '{}.{}.cmap.olay'.format(
            mapdir.split('/')[1], peakStokes)
        output = 'star abspix abspix Peak_V yes {} {} 6 6'.format(
            maxPixel[0], maxPixel[1])
        with open(overlayFile, 'w') as f:
            f.write('color 1\n')
            f.write(output)

        for stk in stokes:
            mapsuffix = '.{}.full.cm'.format(stk)
            mappath = mapdir + mapsuffix

            miriad.velsw({'in': mappath, 'axis': 'FREQ'})

            # get i and v spectra through the point where v peaks in the line map
            imspectDefaults = {
                'in': mappath,
                'region': region,
            }
            x, y, _ = miriad.dumpImspect(mappath,
                                         options={
                                             **imspectDefaults,
                                             **imspectOptions
                                         })
            frequencies.append(x)
            amplitudes.append(y)

    return frequencies, amplitudes