Example #1
0
def align(hduls, name="SCI", reference=None):
    """
    Aligns the source astronomical image(s) to the reference astronomical image
    \b
    :param hduls: list of fitsfiles
    :return: list of fistfiles with <name> HDU aligned
    """

    hduls_list = [hdul for hdul in hduls]
    sources = [hdul[name] for hdul in hduls_list]
    outputs = []

    if reference is None:
        reference = snr.snr(hduls_list, name)[name]
    # click.echo(reference.header["ORIGNAME"])
    # FIXME log ref name
    np_ref = to_np(
        reference,
        "Cannot align to unexpected type {}; expected numpy array or FITS HDU")

    for source in sources:
        np_src = to_np(
            source,
            "Cannot align unexpected type {}; expected numpy array or FITS HDU"
        )
        # possibly unneccessary but unsure about scoping
        output = np.array([])

        output = astroalign.register(np_src, np_ref)[0]
        if isinstance(source, HDU_TYPES):
            output = PrimaryHDU(output, source.header)
        outputs.append(HDUList([output]))

    return (hdul for hdul in outputs)
Example #2
0
def subtract(hduls):
    """
    Returns differences of a set of images from a template image
    Arguments:
        hduls --list of fits hdul's where the last image is the template 
        image that the other images will be subtracted from
    """
    hduls_list = [hdul for hdul in hduls]
    output = []
    outputs = []
    template = to_np(hduls_list[-1][0])
    for hdu in hduls[:-1]:
        diff = ois.optimal_system(image=hdu["SCI"].data,
                                  refimage=template,
                                  method='Bramich')
        output.append(diff)

    for array_set in output:
        for item in array_set:
            hdu = fits.PrimaryHDU(item)
            outputs.append(fits.HDUList([hdu]))
    return (hdul for hdul in outputs)
 def _to_np(x):
     return to_np(x)[..., 20:-20, 20:-20]
Example #4
0
 def _bm3d(x):
     res = pybm3d.bm3d.bm3d(to_np(x)[0, 0, ...], noise)
     res[np.where(np.isnan(res))] = 0
     return res[border:-border, border:-border]
Example #5
0
 def _to_np(x):
     return to_np(x)[0, 0, border:-border, border:-border]
Example #6
0
 def _bm3d(_img_n):
     return -1
     res = pybm3d.bm3d.bm3d(to_np(_img_n)[0, 0, ...], noise)
     #res[np.where(np.isnan(res))] = 0
     return res[border:-border, border:-border]
Example #7
0
 def _to_np(_img):
     return to_np(_img)[0, 0, border:-border, border:-border]