예제 #1
0
    def __init__(self,
                 combine='mean',
                 center='mean',
                 axis=0,
                 default=0,
                 dtype=None,
                 returnmask=False):

        self.axis = axis
        self.default = default
        self.dtype = judge_dtype(dtype)
        self.rtnmask = returnmask

        errormsg = '{0} is not impremented as {1}'

        if center == 'mean':
            self.center = lambda mean, *args: mean
        elif center == 'median':
            self.center = lambda mean, *args: self.median(*args, keepdims=True)
        else:
            raise ValueError(errormsg.format(center, 'center'))

        if combine == 'mean':
            self.combine = self.mean
        elif combine == 'median':
            self.combine = self.median
        else:
            raise ValueError(errormsg.format(combine, 'combine'))
예제 #2
0
파일: align.py 프로젝트: PepeJoseHU/Eclair
 def __init__(self, x_len, y_len, interp='spline3', dtype=None):
     self.x_len = x_len
     self.y_len = y_len
     self.dtype = judge_dtype(dtype)
     if interp == 'spline3':
         self.shift = self.__spline
         self.matx = Ms(x_len, self.dtype)
         if y_len == x_len:
             self.maty = self.matx
         else:
             self.maty = Ms(y_len, self.dtype)
     elif interp == 'poly3':
         self.shift = self.__poly
         self.mat = Mp(self.dtype)
     elif interp == 'linear':
         self.shift = self.__linear
     elif interp == 'neighbor':
         self.shift = self.__neighbor
     else:
         raise ValueError('"{}" is not inpremented'.format(interp))
예제 #3
0
파일: io.py 프로젝트: PepeJoseHU/Eclair
    def __init__(self,list,dtype=None):
        '''
        Parameters
        ----------
        list : iterable
            List of FITS file paths
            load() method refer this list to load FITS file.
            Whether path like object is supported depends on 
            the version of Python and Astropy.
        dtype : str or dtype, default None
            dtype of cupy.ndarray
            If None, this value will be usually "float32", 
            but this can be changed with eclair.set_dtype.
        '''
        self.list  = builtins.list(list)
        self.dtype = judge_dtype(dtype)

        self.slices = dict(x_start=0,x_stop=None,y_start=0,y_stop=None)
        
        self.header = [None] * len(list)
        self.data   = self.header[:]
예제 #4
0
def reduction(image, bias, dark, flat, out=None, dtype=None):
    '''
    This function is equal to the equation:
    out = (image - bias - dark) / flat, but needs less memory.
    Therefore, each inputs must be broadcastable shape.

    Parameters
    ----------
    image : ndarray
    bias : ndarray
    dark : ndarray
    flat : ndarray
    out : cupy.ndarray, default None
        Alternate output array in which to place the result. The default
        is ``None``; if provided, it must have the same shape as the
        expected output, but the type will be cast if necessary.
    dtype : str or dtype, default 'float32'
        dtype of array used internally
        If None, this value will be usually "float32", 
        but this can be changed with eclair.set_dtype.
        If the input dtype is different, use a casted copy.
    
    Returns
    -------
    out : cupy.ndarray
    '''
    dtype = common.judge_dtype(dtype)

    image = cp.asarray(image, dtype=dtype)
    bias = cp.asarray(bias, dtype=dtype)
    dark = cp.asarray(dark, dtype=dtype)
    flat = cp.asarray(flat, dtype=dtype)

    if out is None:
        out = cp.empty(cp.broadcast(image, bias, dark, flat).shape,
                       dtype=dtype)

    reduction_kernel(image, bias, dark, flat, out)

    return out
예제 #5
0
파일: io.py 프로젝트: PepeJoseHU/Eclair
def split_hdu(hdu,dtype=None,xp=cp,
        x_start=0,x_stop=None,y_start=0,y_stop=None):
    '''
    Split HDU object into header and data

    Parameters
    ----------
    hdu : astropy HDU object
    dtype : str or dtype, default None
        dtype of cupy.ndarray
        If None, this value will be usually "float32", 
        but this can be changed with eclair.set_dtype.
    xp : module object of numpy or cp, default cupy
        Whether the return value is numpy.ndarray or cupy.ndarray
    x_start : int, default 0
    x_stop : int, default None
    y_start : int, default 0
    x_stop : int, default None
        return the area of [y_start: y_stop, x_start: x_stop] in hdu.data
    
    Returns
    -------
    header : astropy.io.fits.Header
    data : ndarray
    '''

    header = hdu.header
    data = xp.asarray(
        hdu.data[y_start:y_stop,x_start:x_stop],
        dtype=judge_dtype(dtype)
    )

    try:
        header['CRPIX1'] -= x_start
        header['CRPIX2'] -= y_start
    except:
        pass

    return header, data
예제 #6
0
파일: fix.py 프로젝트: PepeJoseHU/Eclair
def fixpix(data, mask, out=None, dtype=None, fix_NaN=False):
    '''
    fill the bad pixel with mean of surrounding pixels

    Parameters
    ----------
    data : ndarray
        An array of image
        If a 3D array containing multiple images,
        the images must be stacked along the 1st dimension (axis=0).
    mask : ndarray
        An array indicates bad pixel positions
        The shape must be same as image.
        The value of bad pixel is nonzero, and the others is 0.
        If all pixels are bad, raise ValueError.
    out : cupy.ndarray, default None
        Alternate output array in which to place the result. The default
        is ``None``; if provided, it must have the same shape as the
        expected output, but the type will be cast if necessary.
    dtype : str or dtype, default 'float32'
        dtype of array used internally
        If None, this value will be usually "float32", 
        but this can be changed with eclair.set_dtype.
        If the input dtype is different, use a casted copy.
    fix_NaN : bool, default False
        If true, fix NaN pixel even if it's not bad pixel in the mask.

    Returns
    -------
    fixed : ndarray
        An array of images fixed bad pixel

    Notes
    -----
    NaN is ignored in interpolation calculations,
    but is not fixed if fix_NaN is False.
    '''
    dtype = judge_dtype(dtype)
    if data.shape[-2:] != mask.shape[-2:]:
        raise ValueError('shape differs between data and mask')
    elif mask.all():
        raise ValueError('No available pixel')

    data = cp.array(data, dtype=dtype, copy=False, ndmin=3)
    mask = cp.array(mask, dtype=dtype, copy=False, ndmin=3)

    convolution = lambda data, out: conv_kernel(data, out)

    if out is None:
        out = cp.empty_like(data)
    cp.copyto(out, data)

    filt = mask2filter(mask)
    if fix_NaN:
        filt = checkfinite(data, filt)

    out *= filt

    dconv = cp.empty_like(out)
    nconv = cp.empty_like(filt)

    while not filt.all():
        convolution(out, dconv)
        convolution(filt, nconv)
        fix_kernel(out, filt, dconv, nconv, out)
        cp.sign(nconv, out=filt)

    return cp.squeeze(out)