コード例 #1
0
ファイル: madcap.py プロジェクト: pchanial/tamasis-pacs
 def get_tod(self, unit=None):
     """
     Method to get the Tod from this observation
     """
     tod = Tod.empty((self.get_ndetectors(), np.sum(self.get_nsamples())))
     sizeofpmatrix = self.info.npixels_per_sample * tod.size
     pmatrix = np.zeros(sizeofpmatrix, dtype=int)
     status = tmf.madmap1_read_tod(self.info.todfile, self.info.invnttfile,
         self.info.convert, self.info.npixels_per_sample, 0, tod.T, pmatrix)
     if status != 0: raise RuntimeError()
     if unit is not None:
         tod.unit = unit
     return tod
コード例 #2
0
ファイル: madcap.py プロジェクト: pchanial/tamasis-pacs
 def get_tod(self, unit=None):
     """
     Method to get the Tod from this observation
     """
     tod = Tod.empty((self.get_ndetectors(), np.sum(self.get_nsamples())))
     sizeofpmatrix = self.info.npixels_per_sample * tod.size
     pmatrix = np.zeros(sizeofpmatrix, dtype=int)
     status = tmf.madmap1_read_tod(self.info.todfile, self.info.invnttfile,
                                   self.info.convert,
                                   self.info.npixels_per_sample, 0, tod.T,
                                   pmatrix)
     if status != 0: raise RuntimeError()
     if unit is not None:
         tod.unit = unit
     return tod
コード例 #3
0
def mapper_naive(tod, model, unit=None):
    """
    Returns a naive map, i.e.: map = model.T(tod) / model.T(1)

    This equation is valid for a map and a Time Ordered Data (TOD) expressed as
    a surface brightness, so when the TOD does not meet this requirement and
    is a quantity per detector, a unit conversion is attempted.

    Parameters
    ----------

    tod : Tod
        The input Time Ordered Data

    model : Operator
        The instrument model such as tod = model(map)

    unit : string
        Output map unit. By default, the output map unit is chosen to be
        compatible with the model (usually pixel^-1)
    """

    # apply mask
    if hasattr(tod, 'mask') and tod.mask is not None:
        mask = MaskOperator(tod.mask)
    else:
        mask = IdentityOperator()
    tod = mask(tod)

    # get tod units
    if not hasattr(tod, '_unit') or len(tod._unit) == 0:
        attr = {'_unit': {'?': 1.}}
        model.propagate_attributes(None, attr)
        u = getattr(attr, '_unit', {})
        if 'detector' in u and u['detector'] == -1:
            u = {'detector': -1.}
        elif u == {'?': 1.}:
            u = {}
        elif len(u) > 1:
            raise ValueError(
                'The timeline units are not known and cannot be in'
                'ferred from the model.')
        tod_du = getattr(attr, '_derived_units', {})
        tod = Tod(tod.magnitude, unit=u, derived_units=tod_du, copy=False)
    else:
        attr = {'_unit': {'?': 1}}
        model.T.propagate_attributes(None, attr)
        u = attr['_unit']
        if 'detector' not in tod._unit and 'detector' in u and u[
                'detector'] == 1:
            raise ValueError("The model is incompatible with input units '{0}'"\
                             .format(tod.unit))

    tod_unit = tod._unit
    tod_du = tod._derived_units

    # make sure the input is a surface brightness
    if 'detector' in tod._unit:
        tod.inunit(tod.unit + ' detector / arcsec^2')
    elif 'detector_reference' in tod._unit:
        tod.inunit(tod.unit + ' detector_reference / arcsec^2')

    # compute model.T(tod)/model.T(one)
    mymap = model.T(tod.magnitude)
    tod[...] = 1
    mask(tod, tod)
    map_weights = model.T(tod.magnitude)
    old_settings = np.seterr(divide='ignore', invalid='ignore')
    mymap /= map_weights
    mymap.unit = tod.unit
    np.seterr(**old_settings)
    mymap.coverage = Map(map_weights.magnitude,
                         header=mymap.header,
                         copy=False)

    if unit is not None:
        mymap.inunit(unit)
        return mymap

    # set map units according to model
    attr = {'_unit': tod_unit, '_derived_units': tod_du}
    model.T.propagate_attributes(None, attr)
    if '_derived_units' in attr:
        mymap.derived_units = attr['_derived_units']
    if '_unit' in attr:
        mymap.inunit(attr['_unit'])

    return mymap
コード例 #4
0
ファイル: test_madcap.py プロジェクト: pchanial/tamasis-pacs
tod = obs.get_tod(unit='Jy/beam')
projection = obs.get_projection_operator()
packing = PackOperator(obs.info.mapmask)

model = projection * packing
map_naive = mapper_naive(tod, model)
map_ref = pyfits.open(path + 'naivemapSpirePsw.fits')['image'].data


def test_madcap1():
    assert all_eq(map_naive, map_ref)


map_naive_1d = mapper_naive(tod, projection)
map_naive_2d = packing.T(map_naive_1d)
map_naive_2d = packing.T(projection.T(tod) / projection.T(Tod.ones(tod.shape)))
map_naive_2d[obs.info.mapmask] = np.nan


def test_madcap2():
    assert all_eq(map_naive_2d, map_ref)


M = DiagonalOperator(packing(1 / map_naive.coverage))
assert np.all(np.isfinite(M.data))


class Callback:
    def __init__(self):
        self.niterations = 0
コード例 #5
0
ファイル: mappers.py プロジェクト: pchanial/tamasis-pacs
def mapper_naive(tod, model, unit=None):
    """
    Returns a naive map, i.e.: map = model.T(tod) / model.T(1)

    This equation is valid for a map and a Time Ordered Data (TOD) expressed as
    a surface brightness, so when the TOD does not meet this requirement and
    is a quantity per detector, a unit conversion is attempted.

    Parameters
    ----------

    tod : Tod
        The input Time Ordered Data

    model : Operator
        The instrument model such as tod = model(map)

    unit : string
        Output map unit. By default, the output map unit is chosen to be
        compatible with the model (usually pixel^-1)
    """

    # apply mask
    if hasattr(tod, 'mask') and tod.mask is not None:
        mask = MaskOperator(tod.mask)
    else:
        mask = IdentityOperator()
    tod = mask(tod)

    # get tod units
    if not hasattr(tod, '_unit') or len(tod._unit) == 0:
        attr = {'_unit' : {'?' : 1.}}
        model.propagate_attributes(None, attr)
        u = getattr(attr, '_unit', {})
        if 'detector' in u and u['detector'] == -1:
            u = {'detector' : -1.}
        elif u == {'?':1.}:
            u = {}
        elif len(u) > 1:
            raise ValueError('The timeline units are not known and cannot be in'
                             'ferred from the model.')
        tod_du = getattr(attr, '_derived_units', {})
        tod = Tod(tod.magnitude, unit=u, derived_units=tod_du, copy=False)
    else:
        attr = {'_unit' : {'?':1}}
        model.T.propagate_attributes(None, attr)
        u = attr['_unit']
        if 'detector' not in tod._unit and 'detector' in u and u['detector']==1:
            raise ValueError("The model is incompatible with input units '{0}'"\
                             .format(tod.unit))

    tod_unit = tod._unit
    tod_du = tod._derived_units

    # make sure the input is a surface brightness
    if 'detector' in tod._unit:
        tod.inunit(tod.unit + ' detector / arcsec^2')
    elif 'detector_reference' in tod._unit:
        tod.inunit(tod.unit + ' detector_reference / arcsec^2')

    # compute model.T(tod)/model.T(one)
    mymap = model.T(tod.magnitude)
    tod[...] = 1
    mask(tod, tod)
    map_weights = model.T(tod.magnitude)
    old_settings = np.seterr(divide='ignore', invalid='ignore')
    mymap /= map_weights
    mymap.unit = tod.unit
    np.seterr(**old_settings)
    mymap.coverage = Map(map_weights.magnitude, header=mymap.header, copy=False)
   
    if unit is not None:
        mymap.inunit(unit)
        return mymap

    # set map units according to model
    attr = {'_unit' : tod_unit, '_derived_units' : tod_du}
    model.T.propagate_attributes(None, attr)
    if '_derived_units' in attr:
        mymap.derived_units = attr['_derived_units']
    if '_unit' in attr:
        mymap.inunit(attr['_unit'])

    return mymap
コード例 #6
0
ファイル: test_madcap.py プロジェクト: pchanial/tamasis-pacs
obs.instrument.name = 'SPIRE/PSW'

tod = obs.get_tod(unit='Jy/beam')
projection = obs.get_projection_operator()
packing = PackOperator(obs.info.mapmask)

model = projection*packing
map_naive = mapper_naive(tod, model)
map_ref = pyfits.open(path+'naivemapSpirePsw.fits')['image'].data

def test_madcap1():
    assert all_eq(map_naive, map_ref)

map_naive_1d = mapper_naive(tod, projection)
map_naive_2d = packing.T(map_naive_1d)
map_naive_2d = packing.T(projection.T(tod)/projection.T(Tod.ones(tod.shape)))
map_naive_2d[obs.info.mapmask] = np.nan

def test_madcap2():
    assert all_eq(map_naive_2d, map_ref)

M = DiagonalOperator(packing(1/map_naive.coverage))
assert np.all(np.isfinite(M.data))

class Callback:
    def __init__(self):
        self.niterations = 0
    def __call__(self, x):
        self.niterations += 1
callback = Callback()
#callback = None
コード例 #7
0
def teardown():
    for file in glob.glob(filename + '*'):
        os.remove(file)


a = np.ones((4, 3))
a[1, 2] = 4
q = Quantity(a, unit='myunit', derived_units={'myunit': Quantity(2., 'Jy')})
header = create_fitsheader(fromdata=q, cdelt=0.5, crval=(4., 8.))
header['BUNIT'] = 'myunit'
f = FitsArray(q, header=header)
m = Map(f, origin='upper', error=a * 2, coverage=a * 3)
mask = np.zeros((4, 3), np.bool8)
mask[0, 2] = True
t = Tod(f, mask=mask)
del mask


def test_copy_false_subok_true():
    def func(obj1, t):
        obj2 = t(obj1, copy=False, subok=True)
        if isinstance(obj, t):
            assert obj1 is obj2
        else:
            assert obj1 is not obj2
            assert_equal(obj1, obj2)

    for obj in [q, f, m, t]:
        for ty in types:
            yield func, obj, ty