Example #1
0
"""

import argparse
import numpy as np
import pylab as plt
from astropy.io import fits
from trm import doppler
import copy

parser = argparse.ArgumentParser(description=usage)

# positional
parser.add_argument('map',   help='name of the input map')
parser.add_argument('dout',  help='default output file')

# OK, done with arguments.
args = parser.parse_args()

# load map
dmap  = doppler.Map.rfits(doppler.afits(args.map))

# copy the map to compute the entropy
mcopy = copy.deepcopy(dmap)

# compute default
doppler.comdef(dmap)

# write the result to a FITS file
dmap.wfits(doppler.afits(args.dout))

Example #2
0
parser.add_argument('map',   help='name of the input map template')
parser.add_argument('data', help='data template file data template')

# optional
parser.add_argument('-n', dest='ntrial', type=int, default=1,
                    help='number of tests to carry out.')

# OK, done with arguments.
args = parser.parse_args()

if args.ntrial < 1:
    print('You must carry out at least one trial.')
    exit(1)

# load map and data
dmap = doppler.Map.rfits(doppler.afits(args.map))
ddat = doppler.Data.rfits(doppler.afits(args.data))

# make copies
cmap = copy.deepcopy(dmap)
cdat = copy.deepcopy(ddat)

for i in xrange(args.ntrial):

    # fill map with random noise
    for image in dmap.data:
        image.data = np.asarray(
            np.random.normal(size=image.data.shape),dtype=np.float32)

    #  enact opus
    doppler.comdat(dmap, cdat)
Example #3
0
parser = argparse.ArgumentParser(description=usage)

# positional
parser.add_argument('map', help='name of the input map')
parser.add_argument('vmax', type=float, help='maximum velocity (km/s)')

# optional
parser.add_argument('-n', dest='nimage', type=int, default=1,
                    help='number of the image to plot')
parser.add_argument('-s', dest='step', type=int, default=1,
                    help='pixel step to use. Make > 1 if the rendering seems slow and clunky')

# OK, done with arguments.
args = parser.parse_args()

dmap  = doppler.Map.rfits(doppler.afits(args.map))
img   = dmap.data[args.nimage-1]

# have to copy the array [perhaps to allow modification?]
data  = img.data.T[::args.step,::args.step,::args.step].copy()
nx, ny, nz = data.shape

# transform array
tr     = np.empty((12))
tr[1], tr[6], tr[11] = args.step*img.vxy, args.step*img.vxy, args.step*img.vz
tr[2] = tr[3] = tr[5] = tr[7] = tr[9] = tr[10] = 0

tr[0] =  -tr[1]*(nx-1)/2
tr[4] =  -tr[6]*(ny-1)/2
tr[8] = -tr[11]*(nz-1)/2
Example #4
0
parser = argparse.ArgumentParser(description=usage)

# positional
parser.add_argument('map',   help='name of the input map')
parser.add_argument('dtemp', help='data template file')
parser.add_argument('dout',  help='data output file')

# optional
parser.add_argument('-n', dest='noise', action='store_true',
                    help='add noise according to uncertainty array in template')

# OK, done with arguments.
args = parser.parse_args()

# load map and data
dmap  = doppler.Map.rfits(doppler.afits(args.map))
dtemp = doppler.Data.rfits(doppler.afits(args.dtemp))

flux = dtemp.data[0].flux
ferr = dtemp.data[0].ferr

# compute data
dcopy = copy.deepcopy(dtemp)
doppler.comdat(dmap, dtemp)

# optionally add noise
if args.noise:
    for spectra in dtemp.data:
        spectra.flux = np.random.normal(spectra.flux, np.abs(spectra.ferr))
else:
    chisq = 0.
Example #5
0
vy     = -50.
vz     = 0.
fwhmxy = 200.
fwhmz  = 50.
vpeak  = 550.
vout1  = 2200.
vout2  = 2400.
ipeak  = 0.5
eout   = -2.5
ein    = +3.0
"""
    with open(doppler.acfg(args.config),'w') as fout:
        fout.write(config.format(doppler.VERSION))
else:

    if not args.clobber and os.path.exists(doppler.afits(args.map)):
        print('\nERROR: ',doppler.afits(args.map),
              'already exists and will not be overwritten.')
        exit(1)

    config = ConfigParser.RawConfigParser()
    config.read(doppler.acfg(args.config))

    tver   = config.getint('main', 'version')
    if tver != doppler.VERSION:
        print('Version number in config file =',tver,
              'conflicts with version of script =',doppler.VERSION)
        print('Will continue but there may be problems')

    target = config.get('main', 'target')
    if target != 'maps':
Example #6
0
parser = argparse.ArgumentParser(description=usage)

# positional
parser.add_argument('map',   help='name of the input map')
parser.add_argument('data',  help='data file')
parser.add_argument('scaled',  help='scaled output map')

# optional
parser.add_argument('-i', dest='iscale', action='store_true',
                    help='individual scaling (else a single global scale)')

# OK, done with arguments.
args = parser.parse_args()

# load map and data
dmap = doppler.Map.rfits(doppler.afits(args.map))
data = doppler.Data.rfits(doppler.afits(args.data))

nscale = 0
for image in dmap.data:
    nscale += len(image.wave)

if args.iscale and nscale > 1:
    # in this option we try to individually scale the images
    mtemp = copy.deepcopy(dmap)
    flux, ferr = retarr(data)
    wgt = np.empty_like(ferr)
    ok = ferr > 0
    wgt[ok] = 1./ferr[ok]**2

    # create indices to access the scale factors
Example #7
0
from astropy.io import fits
from trm import doppler

parser = argparse.ArgumentParser(description=usage)

# positional
parser.add_argument('imap',  help='name of the input map')
parser.add_argument('data',  help='data file')
parser.add_argument('niter', type=int, help='number of iterations')
parser.add_argument('caim',  type=float, help='reduced chi**2 to aim for')
parser.add_argument('omap',  help='name of the output map')

# optional
parser.add_argument('-r', dest='rmax', type=float,
                    default=0.2, help='maximum change')
parser.add_argument('-t', dest='tlim', type=float,
                    default=1.e-4, help='test limit for stopping iterations')

# OK, done with arguments.
args = parser.parse_args()

# load map and data
dmap = doppler.Map.rfits(doppler.afits(args.imap))
data = doppler.Data.rfits(doppler.afits(args.data))

# mem iterations
doppler.memit(dmap, data, args.niter, args.caim, args.tlim, args.rmax)

# write to fits file
dmap.wfits(doppler.afits(args.omap))
Example #8
0
scale1   = 1.0
wave2    = 434.0
gamma2   = 120.
scale2   = 0.6

# keywords / values for the FITS header. Optional

[fitshead]
ORIGIN = makegrid.py
OBJECT = SS433
"""
    with open(doppler.acfg(args.config),'w') as fout:
        fout.write(config.format(doppler.VERSION))
else:

    if not args.clobber and os.path.exists(doppler.afits(args.grid)):
        print('\nERROR: ',doppler.afits(args.grid),
              'already exists and will not be overwritten.')
        exit(1)

    config = ConfigParser.RawConfigParser()
    config.read(doppler.acfg(args.config))

    tver   = config.getint('main', 'version')
    if tver != doppler.VERSION:
        print('Version number in config file =',tver,
              'conflicts with version of script =',doppler.VERSION)
        print('Will continue but there may be problems')

    target = config.get('main', 'target')
    if target != 'grids':
Example #9
0
wave1  = 480.
wave2  = 500.
nwave  = 100
wrms   = 0.01
time1  = 50000.0
time2  = 50000.1
nspec  = 20
error  = 0.1
fwhm   = 100.
nsub   = 3
"""
    with open(doppler.acfg(args.config),'w') as fout:
        fout.write(config.format(doppler.VERSION))
else:

    if not args.clobber and os.path.exists(doppler.afits(args.data)):
        print('\nERROR: ',doppler.afits(args.data),
              'already exists and will not be overwritten.')
        exit(1)

    config = ConfigParser.RawConfigParser()
    config.read(doppler.acfg(args.config))

    tver   = config.getint('main', 'version')
    if tver != doppler.VERSION:
        print('Version number in config file =',tver,
              'conflicts with version of script =',version)
        print('Will continue but there may be problems')

    target = config.get('main', 'target')
    if target != 'data':
Example #10
0
parser.add_argument('flow',   type=float, help='lowest frequency to search')
parser.add_argument('fhigh',  type=float, help='highest frequency to search')
parser.add_argument('delta',  type=float, help='number of cycles change over time base per frequency step')
parser.add_argument('vgrid',  type=float, help='velocity spacing of grid')
parser.add_argument('ngrid',  type=int, help='number of gaussians along side of grid')
parser.add_argument('fratio', type=float, help='ratio FWHM/VGRID')
parser.add_argument('ofile', help='ASCII file for output')
parser.add_argument('cond',  type=float, nargs='+', help='SVD condition parameter(s)')

# optional
parser.add_argument('-n', dest='ntdiv', type=int,
                    default=11, help='spectrum sub-division factor')

args = parser.parse_args()

model  = doppler.Map.rfits(doppler.afits(args.model))
if len(model.data) != 1:
    print 'precover requires just one image in the model file'
    exit(1)

data   = doppler.Data.rfits(doppler.afits(args.data))
nmonte = args.nmonte
flow   = args.flow
fhigh  = args.fhigh
delta  = args.delta
vgrid  = args.vgrid
ngrid  = args.ngrid
fratio = args.fratio
ntdiv  = args.ntdiv
ofile  = args.ofile
cond   = args.cond
Example #11
0
import argparse
import numpy as np
from trm import doppler

parser = argparse.ArgumentParser(description=usage)

# positional
parser.add_argument('grid',  help='name of the grid')
parser.add_argument('tmap',  help='template map file')
parser.add_argument('map',   help='output map')

# OK, done with arguments.
args = parser.parse_args()

# load grid and data
grid = doppler.Grid.rfits(doppler.afits(args.grid))
tmap = doppler.Map.rfits(doppler.afits(args.tmap))

nside = grid.data.shape[0]

for image in tmap.data:
    dmap = image.data
    if dmap.ndim != 2:
        print 'ERROR: Map images must be 2D for this routine.'
        exit(1)
    nvy, nvx = dmap.shape
    vx = np.linspace(-image.vxy*(nvx-1)/2., image.vxy*(nvx-1)/2., nvx)
    vy = np.linspace(-image.vxy*(nvy-1)/2., image.vxy*(nvy-1)/2., nvy)
    VX, VY = np.meshgrid(vx, vy)
    dmap[:] = 0
    efac = 1./(grid.vgrid*grid.fratio/doppler.EFAC)**2/2.
Example #12
0
user-specified fraction of the maximum.
"""

import argparse
import numpy as np
import pylab as plt
from astropy.io import fits
from trm import doppler
import copy

parser = argparse.ArgumentParser(description=usage)

# positional
parser.add_argument('inmap',   help='name of the input map')
parser.add_argument('llim', type=float,  help='lower limit as fraction of maximum')
parser.add_argument('outmap',  help='name of output map')

# OK, done with arguments.
args = parser.parse_args()

# load map
imap  = doppler.Map.rfits(doppler.afits(args.inmap))

for image in imap.data:
    fmax = image.data.max()
    image.data = np.maximum(args.llim*fmax, image.data)

# write the result to a FITS file
imap.wfits(doppler.afits(args.outmap))

Example #13
0
parser = argparse.ArgumentParser(description=usage)

# positional
parser.add_argument('grid',  help='name of the input grid')
parser.add_argument('data',   help='data file')
parser.add_argument('svd',  help='name of the SVD output file')

# optional
parser.add_argument('-n', dest='ntdiv', type=int,
                    default=11, help='spectrum sub-division factor')

# OK, done with arguments.
args = parser.parse_args()

# load grid and data
grid = doppler.Grid.rfits(doppler.afits(args.grid))
data = doppler.Data.rfits(doppler.afits(args.data))

# generate the matrix
A = doppler.genmat(grid, data, args.ntdiv)

# Carry out full SVD, returning smallest matrices possible
u, s, v = np.linalg.svd(A,full_matrices=False)

ng = grid.data.shape[0]
# Matrix v is the one we want. It should have dimensions (ng*ng) x (ng*ng) where
# N is number along each side of the grids. Need to re-shape
v = np.reshape(v, (ng*ng,ng,ng))

# now write to FITS
Example #14
0
                    help='spectrum sub-division factor for finite exposures')

# OK, done with arguments.
args = parser.parse_args()

# a few checks
if args.flow <= 0 or args.fhigh <= args.flow:
    print 'Upper frequency must excedd the lower, and both muts be > 0'
    exit(1)

if args.delta <= 0 or args.delta >=1:
    print 'Cycle change per frequency step must lie between 0 and 1.'
    exit(1)

# load map and data
grid = doppler.Grid.rfits(doppler.afits(args.grid))
data = doppler.Data.rfits(doppler.afits(args.data))

tbase  = data.data[0].time.max() - data.data[0].time.min()
nf     = int((args.fhigh-args.flow)*tbase/args.delta)
fs     = np.linspace(args.flow,args.fhigh,nf)

# a bit of header
print '# Output from the SVD routine, psearch.py'
print '#'
print '# Grid file =',args.grid
print '# Data file =',args.data
print '# Frequency range, number of frequencies =',args.flow,args.fhigh,nf
print '# Cycle change per frequency =',args.delta
print '# Condition values =',args.cond
print '#'