def __init__(self, data_header, cube_header, ng=1, **kwargs): self.data_header = data_header self.map_header = cube_header xout = dataarray_from_header(data_header) xout[:] = 0 xin = fa.fitsarray_from_header(cube_header) xin.header = dict(xin.header) xin[:] = 0 self.xin = xin self.xout = xout def matvec(x): y = dataarray_from_header(data_header) y[:] = 0 for i in xrange(ng): yi = y[..., i::ng] yi.header = y.header[i::ng] projector4d(yi, x, **kwargs) del yi return y def rmatvec(x): y = fa.fitsarray_from_header(cube_header) y[:] = 0 for i in xrange(ng): xi = x[..., i::ng] xi.header = xi.header[i::ng] backprojector4d(xi, y, **kwargs) del xi return y lo.NDSOperator.__init__(self, xin=xin, xout=xout, matvec=matvec, rmatvec=rmatvec, dtype=xout.dtype)
def __init__(self, data_header, cube_header, **kwargs): self.data_header = data_header self.map_header = dict(cube_header) xin = fa.fitsarray_from_header(cube_header) xin.header = dict(xin.header) xin[:] = 0 xout = dataarray_from_header(data_header) xout[:] = 0 self.xin = xin self.xout = xout shapein = xin.shape shapeout = xout.shape def matvec(x): x = fa.InfoArray(data=x, header=dict(cube_header)) y = xout y[:] = 0. projector(y, x, **kwargs) return y def rmatvec(x): x = fa.InfoArray(data=x, header=data_header) y = xin y[:] = 0. backprojector(x, y, **kwargs) return y lo.NDSOperator.__init__(self, shapein, shapeout, xin=xin, xout=xout, matvec=matvec, rmatvec=rmatvec, dtype=xout.dtype)
def rmatvec(x): y = fa.fitsarray_from_header(cube_header) y[:] = 0 for i in xrange(ng): xi = x[..., i::ng] xi.header = xi.header[i::ng] backprojector4d(xi, y, **kwargs) del xi return y
def centered_image(pshape, shape, fill=0., dtype=np.float64): """ Generate a centered cubic map. Arguments --------- pshape : physical shape shape : shape in pixels Returns ------- cube: 3d FitsArray """ header = centered_image_header(pshape, shape, dtype=dtype) im = fa.fitsarray_from_header(header) im[:] = fill return im
def centered_cubic_map(pshape, shape, fill=0., dtype=np.float64): """ Generate a centered cubic map header Arguments --------- pshape : physical shape shape : shape in pixels Output ------ cube: 3d FitsArray """ header = centered_cubic_map_header(pshape, shape, dtype=dtype) # generate cube and exit map = fa.fitsarray_from_header(header) map = fa.InfoArray(data=map, header=dict(header)) map[:] = fill return map
def siddon_lo(data_header, cube_header, obstacle=None): """ A linear operator performing projection and backprojection using Siddon. """ data = dataarray_from_header(data_header) data[:] = 0 cube = fa.fitsarray_from_header(cube_header) cube[:] = 0 def matvec(x): y = dataarray_from_header(data_header) y[:] = 0 projector(y, x, obstacle=obstacle) return y def rmatvec(x): y = fa.fitsarray_from_header(cube_header) y[:] = 0 backprojector(x, y, obstacle=obstacle) return y return lo.ndsubclass(cube, data, matvec=matvec, rmatvec=rmatvec, dtype=data.dtype)
""" Regroup functions to easily perform simulations. """ import copy import numpy as np import siddon import fitsarray as fa default_image_dict = {'NAXIS':2, 'NAXIS1':1, 'NAXIS2':1, 'BITPIX':-64, 'SIMPLE':True, 'CRPIX1':0.5, 'CRPIX2':0.5, 'CDELT1':1., 'CDELT2':1., 'LON':0., 'LAT':0., 'ROL':0., 'D':1., 'M1':1., 'M2':0., 'M3':0.} image_keys = default_image_dict.keys() default_image = fa.fitsarray_from_header(default_image_dict) default_object_dict = {'NAXIS':3, 'NAXIS1':1, 'NAXIS2':1, 'NAXIS3':1, 'BITPIX':-64, 'SIMPLE':True, 'CRPIX1':0.5, 'CRPIX2':0.5, 'CRPIX3':0.5, 'CRVAL1':0., 'CRVAL2':0., 'CRVAL3':0., 'CDELT1':1., 'CDELT2':1., 'CDELT3':1., } object_keys = default_object_dict.keys() default_object = fa.fitsarray_from_header(default_object_dict) class Image(fa.InfoArray): """ A subclass of FitsArray with mandatory keywords defining an image """ def __new__(subtype, shape, data=None, dtype=float, buffer=None, offset=0, strides=None, order=None, header=None): if header is None:
def make_object(*kargs): import fitsarray as fa header = make_object_header(*kargs) return fa.fitsarray_from_header(header)
'BITPIX': -64, 'SIMPLE': True, 'CRPIX1': 0.5, 'CRPIX2': 0.5, 'CDELT1': 1., 'CDELT2': 1., 'LON': 0., 'LAT': 0., 'ROL': 0., 'D': 1., 'M1': 1., 'M2': 0., 'M3': 0. } image_keys = default_image_dict.keys() default_image = fa.fitsarray_from_header(default_image_dict) default_object_dict = { 'NAXIS': 3, 'NAXIS1': 1, 'NAXIS2': 1, 'NAXIS3': 1, 'BITPIX': -64, 'SIMPLE': True, 'CRPIX1': 0.5, 'CRPIX2': 0.5, 'CRPIX3': 0.5, 'CRVAL1': 0., 'CRVAL2': 0., 'CRVAL3': 0., 'CDELT1': 1.,
def rmatvec(x): y = fa.fitsarray_from_header(cube_header) y[:] = 0 backprojector4d(x, y, obstacle=obstacle) return y