<commit_before>#!/usr/bin/env python
description = ">> make different image using hotpants"
usage = "%prog imagein  imagetem [options] "
import os
import lsc
from astropy.io import fits
from astropy.wcs import WCS
import numpy as np
from argparse import ArgumentParser
from PyZOGY.subtract import run_subtraction
from pyraf import iraf

def crossmatchtwofiles(img1, img2, radius=3):
    ''' This module is crossmatch two images:
        It run sextractor transform the pixels position of the the sources in coordinates and crossmatch them  
        The output is a dictionary with the objects in common
    '''

    hd1 = fits.getheader(img1)
    hd2 = fits.getheader(img2)
    wcs1 = WCS(hd1)
    wcs2 = WCS(hd2)

    xpix1, ypix1, fw1, cl1, cm1, ell1, bkg1, fl1 = lsc.lscastrodef.sextractor(img1)
    xpix2, ypix2, fw2, cl2, cm2, ell2, bkg2, fl2 = lsc.lscastrodef.sextractor(img2)
    xpix1, ypix1, xpix2, ypix2 = np.array(xpix1, float), np.array(ypix1, float), np.array(xpix2, float), np.array(ypix2, float)

    bb = wcs1.wcs_pix2world(zip(xpix1, ypix1), 1)  #   transform pixel in coordinate
    xra1, xdec1 = zip(*bb)
    bb = wcs2.wcs_pix2world(zip(xpix2, ypix2), 1)  #   transform pixel in coordinate
    xra2, xdec2 = zip(*bb)

    xra1, xdec1, xra2, xdec2 = np.array(xra1, float), np.array(xdec1, float), np.array(xra2, float), np.array(xdec2, float)
    distvec, pos1, pos2 = lsc.lscastrodef.crossmatch(xra1, xdec1, xra2, xdec2, radius)
    #dict={}
    dict = {'ra1': xra1[pos1], 'dec1': xdec1[pos1], 'ra2': xra2[pos2], 'dec2': xdec2[pos2], \
            'xpix1': xpix1[pos1], 'ypix1': ypix1[pos1], 'xpix2': xpix2[pos2], 'ypix2': ypix2[pos2]}
    np.savetxt('substamplist', zip(xpix1[pos1], ypix1[pos1]), fmt='%10.10s\t%10.10s')
    return 'substamplist', dict

###################################################
if __name__ == "__main__":
    parser = ArgumentParser(usage=usage, description=description)
    parser.add_argument("targlist", help='list of images with the target in them')
    parser.add_argument("templist", help='list of template images')
    parser.add_argument("-f", "--force", dest="force", action="store_true",
                      default=False, help=' force archiving \t\t\t [%default]')
    parser.add_argument("--show", dest="show", action="store_true",
                      default=False, help=' show result  \t\t\t [%default]')
    parser.add_argument("--fixpix", dest="fixpix", action="store_true", default=False,
                      help='Run fixpix on the images before doing the subtraction')
    parser.add_argument('--suffix', default='.diff.fits', help='suffix for difference images')

    hotpants = parser.add_argument_group("hotpants parameters")
    hotpants.add_argument("--nrxy", dest="nrxy", default='1,1',
                        help='Number of image region in x y directions \t [%default]')
    hotpants.add_argument("--nsxy", dest="nsxy", default='8,8',
                        help="Number of region's stamps in x y directions\t [%default]")
    hotpants.add_argument("--ko", dest="ko", default='2',
                        help='spatial order of kernel variation within region\t [%default]')
    hotpants.add_argument("--bgo", dest="bgo", default='2',
                        help='spatial order of background variation within region \t [%default]')
    hotpants.add_argument("--afssc", dest="afssc", default=False,
                        action="store_true", help='use selected stamps \t\t\t [%default]')
    hotpants.add_argument("--normalize", dest="normalize", default='i', choices=['i', 't'],
                        help='normalize zero point to image [i] or template [t] \t [%default]')
    hotpants.add_argument("--convolve", dest="convolve", default='', choices=['i', 't', ''],
                        help='convolve direction to image [i] or template [t] \t [%default]')
    hotpants.add_argument("--interpolation", dest="interpolation", default='drizzle',
                          choices=['drizzle', 'nearest', 'linear', 'poly3', 'poly5', 'spline3'],
                        help='interpolation algorithm  [drizzle,nearest,linear,poly3,poly5,spline3]\t [%default]')
    parser.add_argument("--difftype", type=str, default='0', help='Choose hotpants (0) or optimal (1) subtraction \t [%(default)s]')
    parser.add_argument("--unmask", action='store_false', dest='use_mask', help='do not use mask for PyZOGY gain calculation')

    args = parser.parse_args()
    imglisttar = lsc.util.readlist(args.targlist)
    imglisttemp = list.util.readlist(args.templist)

    listatar = {}
    try:<commit_msg>typo in previous commit<commit_after>#!/usr/bin/env python
description = ">> make different image using hotpants"
usage = "%prog imagein  imagetem [options] "
import os
import lsc
from astropy.io import fits
from astropy.wcs import WCS
import numpy as np
from argparse import ArgumentParser
from PyZOGY.subtract import run_subtraction
from pyraf import iraf

def crossmatchtwofiles(img1, img2, radius=3):
    ''' This module is crossmatch two images:
        It run sextractor transform the pixels position of the the sources in coordinates and crossmatch them  
        The output is a dictionary with the objects in common
    '''

    hd1 = fits.getheader(img1)
    hd2 = fits.getheader(img2)
    wcs1 = WCS(hd1)
    wcs2 = WCS(hd2)

    xpix1, ypix1, fw1, cl1, cm1, ell1, bkg1, fl1 = lsc.lscastrodef.sextractor(img1)
    xpix2, ypix2, fw2, cl2, cm2, ell2, bkg2, fl2 = lsc.lscastrodef.sextractor(img2)
    xpix1, ypix1, xpix2, ypix2 = np.array(xpix1, float), np.array(ypix1, float), np.array(xpix2, float), np.array(ypix2, float)

    bb = wcs1.wcs_pix2world(zip(xpix1, ypix1), 1)  #   transform pixel in coordinate
    xra1, xdec1 = zip(*bb)
    bb = wcs2.wcs_pix2world(zip(xpix2, ypix2), 1)  #   transform pixel in coordinate
    xra2, xdec2 = zip(*bb)

    xra1, xdec1, xra2, xdec2 = np.array(xra1, float), np.array(xdec1, float), np.array(xra2, float), np.array(xdec2, float)
    distvec, pos1, pos2 = lsc.lscastrodef.crossmatch(xra1, xdec1, xra2, xdec2, radius)
    #dict={}
    dict = {'ra1': xra1[pos1], 'dec1': xdec1[pos1], 'ra2': xra2[pos2], 'dec2': xdec2[pos2], \
            'xpix1': xpix1[pos1], 'ypix1': ypix1[pos1], 'xpix2': xpix2[pos2], 'ypix2': ypix2[pos2]}
    np.savetxt('substamplist', zip(xpix1[pos1], ypix1[pos1]), fmt='%10.10s\t%10.10s')
    return 'substamplist', dict

###################################################
if __name__ == "__main__":
    parser = ArgumentParser(usage=usage, description=description)
    parser.add_argument("targlist", help='list of images with the target in them')
    parser.add_argument("templist", help='list of template images')
    parser.add_argument("-f", "--force", dest="force", action="store_true",
                      default=False, help=' force archiving \t\t\t [%default]')
    parser.add_argument("--show", dest="show", action="store_true",
                      default=False, help=' show result  \t\t\t [%default]')
    parser.add_argument("--fixpix", dest="fixpix", action="store_true", default=False,
                      help='Run fixpix on the images before doing the subtraction')
    parser.add_argument('--suffix', default='.diff.fits', help='suffix for difference images')

    hotpants = parser.add_argument_group("hotpants parameters")
    hotpants.add_argument("--nrxy", dest="nrxy", default='1,1',
                        help='Number of image region in x y directions \t [%default]')
    hotpants.add_argument("--nsxy", dest="nsxy", default='8,8',
                        help="Number of region's stamps in x y directions\t [%default]")
    hotpants.add_argument("--ko", dest="ko", default='2',
                        help='spatial order of kernel variation within region\t [%default]')
    hotpants.add_argument("--bgo", dest="bgo", default='2',
                        help='spatial order of background variation within region \t [%default]')
    hotpants.add_argument("--afssc", dest="afssc", default=False,
                        action="store_true", help='use selected stamps \t\t\t [%default]')
    hotpants.add_argument("--normalize", dest="normalize", default='i', choices=['i', 't'],
                        help='normalize zero point to image [i] or template [t] \t [%default]')
    hotpants.add_argument("--convolve", dest="convolve", default='', choices=['i', 't', ''],
                        help='convolve direction to image [i] or template [t] \t [%default]')
    hotpants.add_argument("--interpolation", dest="interpolation", default='drizzle',
                          choices=['drizzle', 'nearest', 'linear', 'poly3', 'poly5', 'spline3'],
                        help='interpolation algorithm  [drizzle,nearest,linear,poly3,poly5,spline3]\t [%default]')
    parser.add_argument("--difftype", type=str, default='0', help='Choose hotpants (0) or optimal (1) subtraction \t [%(default)s]')
    parser.add_argument("--unmask", action='store_false', dest='use_mask', help='do not use mask for PyZOGY gain calculation')

    args = parser.parse_args()
    imglisttar = lsc.util.readlist(args.targlist)
    imglisttemp = lsc.util.readlist(args.templist)

    listatar = {}
    try:
{'fraction_non_alphanumeric': 0.1601745771958538, 'fraction_numerical': 0.025313693398799783, 'mean_word_length': 3.5376237623762377, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3787138', 'n_tokens_mistral': 3174, 'n_tokens_neox': 3073, 'n_words': 752}