<commit_before>def aperture(img):
    # print "LOGX:: Entering `aperture` method/function in %(__file__)s" %
    # globals()
    from astropy.io import fits as pyfits
    import re
    import os

    hdr = pyfits.open(img)[0].header
    xmax = hdr['NAXIS1']
    center = float(xmax) / 2.
    xmin = -500
    img2 = re.sub('.fits', '', img)
    line = "# Sun 13:10:40 16-Jun-2013\nbegin	aperture " + img2 + " 1 " + str(center) + "  500.0\n" + \
           "	 image	" + img2 + "\n	aperture	1\n	beam	1\n	center	" + str(center) + "  500.0\n" + \
           "	 low	-450. " + str(xmin) + "\n	high	450. " + str(xmax) + "\n" \
        "	 background\n	 xmin -850.\n" + \
           "	 xmax 850.\n	 function chebyshev\n		order 1\n		sample *\n" + \
           "	 naverage -3\n	 niterate 0\n		low_reject 3.\n		high_reject 3.\n" + \
           "	 grow 0.\n	 axis	1\n	 curve	5\n		2.\n		1.\n" + \
           "	 1.\n		1020.\n		0\n"
    if not os.path.isdir('database/'):
        os.mkdir('database/')

    f = open('database/ap' + img2, 'w')
    f.write(line)
    f.close()

##########################################################################


def choseflat(obj, listflat, setup, _JD0, _interactive):
    # print "LOGX:: Entering `choseflat` method/function in %(__file__)s" %
    # globals()
    import ntt
    import numpy as np

    differences = []
    obidflat = []
    flatgood = []
    _OBID = ntt.util.readkey3(ntt.util.readhdr(obj), 'esoid')
    listflat = ntt.sofiphotredudef.sortbyJD(listflat)
    for flat in listflat:
        hdrf = ntt.util.readhdr(flat)
        _JDf = ntt.util.readkey3(hdrf, 'JD')
        differences.append(np.abs(float(_JD0) - float(_JDf)))
        obidflat.append(ntt.util.readkey3(hdrf, 'esoid'))
    if _interactive:
        for flat in listflat:
            _JDf = ntt.util.readkey3(ntt.util.readhdr(flat), 'JD')
            ntt.util.display_image(flat, 1, '', '', False)
            answ = raw_input(
                '### good/bad/stop(enough files, go on) [[g],b,s]')
            if not answ:
                answ = 'g'
            if answ in ['G', 'g', 'good', 'Good']:
                flatgood.append(flat)
            elif answ in ['stop', 'S', 'Stop', 's']:
                break
    else:
        if obidflat.count(_OBID) >= 3:
            flatgood = list(np.compress(np.array(obidflat) == _OBID, listflat))
            print '### Flat field in the same OB !!'
        else:
            print '### ', str(_OBID)
            inds = np.array(differences).argsort()
            for i in range(0, 3):
                flatgood.append(listflat[inds[i]])
    return flatgood


def continumsub(imagefile, _order1, _order2):
    # print "LOGX:: Entering `continumsub` method/function in %(__file__)s" %
    # globals()
    import ntt
    from pyraf import iraf
    iraf.noao(_doprint=0)
    iraf.imred(_doprint=0)
    iraf.specred(_doprint=0)
    toforget = ['specred.continuum']
    for t in toforget:
        iraf.unlearn(t)
    ntt.util.delete('tsky.fits')
    iraf.specred.continuum(imagefile, output='tsky.fits', type='difference',
                           interact='no', function='legendre', niterat=300, low_rej=3, high_re=2, sample='*',
                           order=_order1, ask='YES')
    ntt.util.delete(imagefile)
    iraf.continuum('tsky.fits', output=imagefile, type='difference',
                   interact='no', function='spline1', overrid='yes', niterat=10, low_rej=3, high_re=1, sample='*',
                   order=_order2, ask='YES')
    ntt.util.delete('tsky.fits')
    return imagefile


def skyfrom2d(fitsfile, skyfile, interac=True):
    # print "LOGX:: Entering `skyfrom2d` method/function in %(__file__)s" %
    # globals()
    import ntt
    from astropy.io import fits as pyfits
    import numpy as np

    yy1 = pyfits.open(fitsfile)[0].data[:, :].mean(1)
    crval2 = pyfits.open(fitsfile)[0].header.get('CRVAL2')
    cd2 = pyfits.open(fitsfile)[0].header.get('CD2_2')

    ntt.util.delete('new3.fits')
    hdu = pyfits.PrimaryHDU(yy1)
    hdulist = pyfits.HDUList([hdu])
    hdulist[0].header.update('CRVAL1', crval2)
    hdulist[0].header.update('CD1_1', cd2)
    hdulist.writeto('new3.fits')
    hdulist.close()

    fitsfile = ntt.efoscspec2Ddef.continumsub('new3.fits', 6, 1)
    yy1 = pyfits.open(fitsfile)[0].data<commit_msg>change in efoscspec2Ddef to update header<commit_after>def aperture(img):
    # print "LOGX:: Entering `aperture` method/function in %(__file__)s" %
    # globals()
    from astropy.io import fits as pyfits
    import re
    import os

    hdr = pyfits.open(img)[0].header
    xmax = hdr['NAXIS1']
    center = float(xmax) / 2.
    xmin = -500
    img2 = re.sub('.fits', '', img)
    line = "# Sun 13:10:40 16-Jun-2013\nbegin	aperture " + img2 + " 1 " + str(center) + "  500.0\n" + \
           "	 image	" + img2 + "\n	aperture	1\n	beam	1\n	center	" + str(center) + "  500.0\n" + \
           "	 low	-450. " + str(xmin) + "\n	high	450. " + str(xmax) + "\n" \
        "	 background\n	 xmin -850.\n" + \
           "	 xmax 850.\n	 function chebyshev\n		order 1\n		sample *\n" + \
           "	 naverage -3\n	 niterate 0\n		low_reject 3.\n		high_reject 3.\n" + \
           "	 grow 0.\n	 axis	1\n	 curve	5\n		2.\n		1.\n" + \
           "	 1.\n		1020.\n		0\n"
    if not os.path.isdir('database/'):
        os.mkdir('database/')

    f = open('database/ap' + img2, 'w')
    f.write(line)
    f.close()

##########################################################################


def choseflat(obj, listflat, setup, _JD0, _interactive):
    # print "LOGX:: Entering `choseflat` method/function in %(__file__)s" %
    # globals()
    import ntt
    import numpy as np

    differences = []
    obidflat = []
    flatgood = []
    _OBID = ntt.util.readkey3(ntt.util.readhdr(obj), 'esoid')
    listflat = ntt.sofiphotredudef.sortbyJD(listflat)
    for flat in listflat:
        hdrf = ntt.util.readhdr(flat)
        _JDf = ntt.util.readkey3(hdrf, 'JD')
        differences.append(np.abs(float(_JD0) - float(_JDf)))
        obidflat.append(ntt.util.readkey3(hdrf, 'esoid'))
    if _interactive:
        for flat in listflat:
            _JDf = ntt.util.readkey3(ntt.util.readhdr(flat), 'JD')
            ntt.util.display_image(flat, 1, '', '', False)
            answ = raw_input(
                '### good/bad/stop(enough files, go on) [[g],b,s]')
            if not answ:
                answ = 'g'
            if answ in ['G', 'g', 'good', 'Good']:
                flatgood.append(flat)
            elif answ in ['stop', 'S', 'Stop', 's']:
                break
    else:
        if obidflat.count(_OBID) >= 3:
            flatgood = list(np.compress(np.array(obidflat) == _OBID, listflat))
            print '### Flat field in the same OB !!'
        else:
            print '### ', str(_OBID)
            inds = np.array(differences).argsort()
            for i in range(0, 3):
                flatgood.append(listflat[inds[i]])
    return flatgood


def continumsub(imagefile, _order1, _order2):
    # print "LOGX:: Entering `continumsub` method/function in %(__file__)s" %
    # globals()
    import ntt
    from pyraf import iraf
    iraf.noao(_doprint=0)
    iraf.imred(_doprint=0)
    iraf.specred(_doprint=0)
    toforget = ['specred.continuum']
    for t in toforget:
        iraf.unlearn(t)
    ntt.util.delete('tsky.fits')
    iraf.specred.continuum(imagefile, output='tsky.fits', type='difference',
                           interact='no', function='legendre', niterat=300, low_rej=3, high_re=2, sample='*',
                           order=_order1, ask='YES')
    ntt.util.delete(imagefile)
    iraf.continuum('tsky.fits', output=imagefile, type='difference',
                   interact='no', function='spline1', overrid='yes', niterat=10, low_rej=3, high_re=1, sample='*',
                   order=_order2, ask='YES')
    ntt.util.delete('tsky.fits')
    return imagefile


def skyfrom2d(fitsfile, skyfile, interac=True):
    # print "LOGX:: Entering `skyfrom2d` method/function in %(__file__)s" %
    # globals()
    import ntt
    from astropy.io import fits as pyfits
    import numpy as np

    yy1 = pyfits.open(fitsfile)[0].data[:, :].mean(1)
    crval2 = pyfits.open(fitsfile)[0].header.get('CRVAL2')
    cd2 = pyfits.open(fitsfile)[0].header.get('CD2_2')

    ntt.util.delete('new3.fits')
    hdu = pyfits.PrimaryHDU(yy1)
    hdulist = pyfits.HDUList([hdu])
#    hdulist[0].header.update('CRVAL1', crval2)
#    hdulist[0].header.update('CD1_1', cd2)
    hdulist[0].header['CRVAL1']= crval2
    hdulist[0].header['CD1_1'] = cd2
    hdulist.writeto('new3.fits')
    hdulist.close()

    fitsfile = ntt.efoscspec2Ddef.continumsub('new3.fits', 6, 1)
    yy1 = pyfits.open(fitsfile)[0].data
{'fraction_non_alphanumeric': 0.1728536949775888, 'fraction_numerical': 0.027583036432593955, 'mean_word_length': 2.3689508323654667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4716463', 'n_tokens_mistral': 3429, 'n_tokens_neox': 3218, 'n_words': 632}