[AstroPy] got flux-conservative rebinning?

David Berry d.berry at jach.hawaii.edu
Thu Apr 19 16:42:49 EDT 2012


On 19 April 2012 18:50, Marshall Perrin <mperrin at stsci.edu> wrote:
>
>
> While we're fishing for useful algorithms, does anyone have a convenient
> implementation of flux-conservative rebinning? The image interpolations in
>  scipy.ndimage are not conservative.  Montage can do this, of course, but
> that seems like overkill (and adds a lot of interface complexity) if I just
> want to scale an image by 75% while conserving energy...  Thanks in
> advance,
>
>  - Marshall
>

The pyast package (https://github.com/timj/starlink-pyast) can do
this. Specifically, see the rebin
(http://dsberry.github.com/starlink/node1.html#Rebin) and resample
(http://dsberry.github.com/starlink/node1.html#Resample) methods. For
instance:

import starlink.Ast

# Create an object describing the mathematical transformation between
the position
# of a value in the input array and its corresponding position in the
output array. Here,
# a simple mapping that zooms by a factor of 0.75 about the origin of
a 2D coordinate
# system. AST can do create many other forms of mapping, including compound
# mappings formed by combining simpler mappings.
zoommap = starlink.Ast.ZoomMap( 2, 0.75 )

# Create the 2D array to use as a test of the rebinning.
data_in = numpy.array(   .......    )

# Paste the elements of this array into another array, using "zoommap" to
# describe the transformation from the position of each sample in the input
# array to its position in the output array. u/lbnd_in gives the
dimensions of the input
# array to be rebinned. Divide each input value up linearly between
# the neighbouring output values (other schemes are available too). Any input
#  values equal to starlink.AST.BAD are ignored (useful for flagging
missing data).
# The output array is created and returned as the method value, and
has dimensions
# given by lbnd_out/ubnd_out.

out = zoommap.rebin( 0.5, lbnd_in, ubnd_in, data_in, None, starlink.Ast.LINEAR,
                                       starlink.Ast.USEBAD , 0.0, 100,
starlink.AST.BAD, lbnd_out,
                                       ubnd_out, lbnd, ubnd )


If an array holding the variance of each input value is available,
these methods can also calculate the variance of each output value.

David



More information about the AstroPy mailing list