Пример #1
0
def sloanimage(img, survey='sloan', frames=[], show=False, force=False):
    import sys
    from lsc import readhdr, readkey3, deg2HMS, display_image
    if show:
        display_image(img, 1, True, '', '')
    hdr = readhdr(img)
    _ra = readkey3(hdr, 'RA')
    _dec = readkey3(hdr, 'DEC')
    _object = readkey3(hdr, 'object')
    _instrume = readkey3(hdr, 'instrume')
    _filter = readkey3(hdr, 'filter')
    _radius = 1100
    filt = {'up': 'u', 'gp': 'g', 'rp': 'r', 'ip': 'i', 'zs': 'z'}

    if _filter in filt.keys():
        _band = filt[_filter]
    else:
        _band = _filter

    if 'fs' in _instrume:
        _telescope = 'spectral'
    elif 'fl' in _instrume:
        _telescope = 'sinistro'
    elif 'kb' in _instrume:
        _telescope = 'sbig'

    print _ra, _dec, _band, _radius
    if survey == 'sloan':
        frames = downloadsdss(_ra, _dec, _band, _radius, force)
    elif survey == 'ps1':
        if len(frames) == 0:
            delta = 0.22
            DR = delta / np.cos(_dec * np.pi / 180)
            DD = delta
            f = open(_object + '_' + _band + '_ps1request.txt', 'w')
            f.write('%s   %s   %s\n' % (str(_ra), str(_dec), str(_band)))
            f.write('%s   %s   %s\n' %
                    (str(_ra + DR), str(_dec + DD), str(_band)))
            f.write('%s   %s   %s\n' %
                    (str(_ra - DR), str(_dec - DD), str(_band)))
            f.write('%s   %s   %s\n' %
                    (str(_ra + DR), str(_dec - DD), str(_band)))
            f.write('%s   %s   %s\n' %
                    (str(_ra - DR), str(_dec + DD), str(_band)))
            f.close()
            print '#' * 20
            print "Please submit file:" + _object + '_' + _band + '_ps1request  at this link (you need an account)\n'
            print "   http://psps.ifa.hawaii.edu/PSI/postage_stamp.php    "
            print "   select:\n       Survey ID:    3PI          3PI.PV3  \n  "
            print "   Image Type:       Total Stacked Image, 1 pixel 0.250 "
            print "   Method of Image Selection by:   Coordinate- Images are selected based on supplied Ra and DEC   "
            print "   Size of the Postage Stamp:   (x) Arc-Second             Width:  2000         Height: 2000    pixel"
            print "   Center Coordinate of Image  - Input coordinate From: "
            print "                  (x)  Upload File           "
            print "        Choose File:    " + _object + '_' + _band + '_ps1request.txt'
            print '#' * 20
            answ = raw_input(
                'Do you want to wait that the frames are downloded [y/n]  [y] ? '
            )
            if not answ:
                answ = 'y'
            if answ in ['Yes', 'yes', 'Y', 'y']:
                print 'Which is the last req_name at this page: '
                answ1 = raw_input(
                    'http://psps.ifa.hawaii.edu/PSI/postage_stamp_results.php ? '
                )
                if not answ1:
                    sys.exit(
                        'no name provided, no PS1 images have been downloaded')
                else:
                    print 'try download........'
                    frames = downloadPS1('./', answ1)
        else:
            frames2 = []
            for img in frames:
                if '_' + _band + '_' in img:
                    frames2.append(img)

            frames = frames2
    if len(frames):
        out, varimg = sdss_swarp(frames,
                                 _telescope,
                                 _ra,
                                 _dec,
                                 '',
                                 _object,
                                 survey,
                                 show=show)
    else:
        sys.exit('exit, no PS1 images have been downloaded')
    return out, varimg
Пример #2
0
def sloanimage(img,survey='sloan',frames=[], show=False, force=False):
   import sys
   from lsc import readhdr, readkey3,deg2HMS,display_image
   if show:
      display_image(img,1,True,'','')
   hdr = readhdr(img)
   _ra = readkey3(hdr,'RA')
   _dec = readkey3(hdr,'DEC')
   _object = readkey3(hdr,'object')
   _instrume = readkey3(hdr,'instrume')
   _filter = readkey3(hdr,'filter')
   _radius = 1100
   filt={'up':'u','gp':'g','rp':'r','ip':'i','zs':'z'}

   if _filter in filt.keys():
      _band = filt[_filter]
   else:
      _band = _filter

   if 'fs' in _instrume:
      _telescope = 'spectral'
   elif 'fl' in _instrume:
      _telescope = 'sinistro'
   elif 'fa' in _instrume:
      _telescope = 'sinistro'
   elif 'kb' in _instrume:
      _telescope = 'sbig'

   print _ra, _dec, _band, _radius
   if survey == 'sloan':
      frames =  downloadsdss(_ra, _dec, _band, _radius, force)
   elif survey == 'ps1':
      if len(frames) == 0:
         delta= 0.22
         DR = delta/np.cos(_dec*np.pi/180)
         DD = delta
         f=open(_object+'_'+_band+'_ps1request.txt','w')
         f.write('%s   %s   %s\n' %(str(_ra),str(_dec),str(_band)))
         f.write('%s   %s   %s\n' %(str(_ra+DR),str(_dec+DD),str(_band)))
         f.write('%s   %s   %s\n' %(str(_ra-DR),str(_dec-DD),str(_band)))
         f.write('%s   %s   %s\n' %(str(_ra+DR),str(_dec-DD),str(_band)))
         f.write('%s   %s   %s\n' %(str(_ra-DR),str(_dec+DD),str(_band)))
         f.close()
         print '#'*20
         print "Please submit file:"+_object+'_'+_band+'_ps1request  at this link (you need an account)\n'
         print "   http://psps.ifa.hawaii.edu/PSI/postage_stamp.php    "
         print "   select:\n       Survey ID:    3PI          3PI.PV3  \n  "
         print "   Image Type:       Total Stacked Image, 1 pixel 0.250 "
         print "   Method of Image Selection by:   Coordinate- Images are selected based on supplied Ra and DEC   "
         print "   Size of the Postage Stamp:   (x) Arc-Second             Width:  2000         Height: 2000    pixel"
         print "   Center Coordinate of Image  - Input coordinate From: "
         print "                  (x)  Upload File           "
         print "        Choose File:    "+_object+'_'+_band+'_ps1request.txt'
         print '#'*20
         answ = raw_input('Do you want to wait that the frames are downloded [y/n]  [y] ? ')
         if not answ: 
             answ= 'y'
         if answ in ['Yes','yes','Y','y']:
              print 'Which is the last req_name at this page: '
              answ1 = raw_input('http://psps.ifa.hawaii.edu/PSI/postage_stamp_results.php ? ' )
              if not answ1:  
                  sys.exit('no name provided, no PS1 images have been downloaded')
              else:
                  print 'try download........'
                  frames = downloadPS1('./',answ1)
      else:
          frames2 = []
          for img in frames:
               if '_'+_band+'_' in img:
                    frames2.append(img)

          frames = frames2
   if len(frames):
         out, varimg = sdss_swarp(frames,_telescope,_ra,_dec,'',_object, survey, show=show)
   else:
       sys.exit('exit, no PS1 images have been downloaded')
   return out, varimg
Пример #3
0
def sdss_swarp(imglist,
               _telescope='spectral',
               _ra='',
               _dec='',
               output='',
               objname='',
               survey='sloan',
               combine_type='MEDIAN',
               show=False):
    import re
    import datetime
    import lsc
    import time
    import string

    if _telescope == 'spectral':
        pixelscale = 0.30104  # 2 meter
        _imagesize = 2020
    elif _telescope == 'sbig':
        pixelscale = 0.467  # 1 meter
        _imagesize = 2030
    elif _telescope == 'sinistro':
        pixelscale = 0.387  # 1 meter
        _imagesize = 4020

    if survey == 'sloan':
        out1 = 'SDSS'
        hdr = fits.getheader(imglist[0])
        _filter = hdr.get('filter')
        _gain = hdr.get('gain')
        _ron = hdr.get('rdnoise')
        if not _ra:
            _ra = hdr.get('CRVAL1')
        if not _dec:
            _dec = hdr.get('CRVAL2')
        _saturate = hdr.get('SATURATE')
        if not _saturate:
            _saturate = 61000
        if 'day-obs' in hdr:
            _dayobs = hdr.get('day-obs')
        elif 'date-obs' in hdr:
            _dayobs = re.sub('-', '', hdr.get('date-obs'))

        if '/' in _dayobs:
            _dayobs = '19' + ''.join(string.split(_dayobs, '/')[::-1])

        try:
            _mjd = MJDnow(
                datetime.datetime(int(str(_dayobs)[0:4]),
                                  int(str(_dayobs)[4:6]),
                                  int(str(_dayobs)[6:8])))
        except:
            print 'warning, no mjd'
            _mjd = 0
            _dayobs = '19991231'

    elif survey == 'ps1':
        out1 = 'PS1'
        imglist2 = []
        for i, img in enumerate(imglist):
            print i, img
            hdr = fits.open(img)
            if os.path.isfile(re.sub('.fits', '_1.fits', img)):
                os.system('rm ' + re.sub('.fits', '_1.fits', img))
            fits.writeto(re.sub('.fits', '_1.fits', img), hdr[1].data,
                         hdr[1].header)
            imglist2.append(re.sub('.fits', '_1.fits', img))

        imglist = imglist2
        hdr = fits.getheader(imglist[0])
        _saturate = hdr.get('HIERARCH CELL.SATURATION')
        _filter = string.split(hdr.get('HIERARCH FPA.FILTER'), '.')[0]
        _gain = hdr.get('HIERARCH CELL.GAIN')
        _ron = hdr.get('HIERARCH CELL.READNOISE')
        _mjd = hdr.get('MJD-OBS')
        _dayobs = jd2date(_mjd + 2400000.5).strftime('%Y%d%m')
        if not _ra:
            _ra = hdr.get('RA_DEG')
        if not _dec:
            _dec = hdr.get('DEC_DEG')

    #  airmass
    if 'airmass' in hdr:
        _airmass = hdr.get('airmass')
    else:
        _airmass = 1

    #  filters
    filt = {
        'U': 'U',
        'B': 'B',
        'V': 'V',
        'R': 'R',
        'I': 'I',
        'u': 'up',
        'g': 'gp',
        'r': 'rp',
        'i': 'ip',
        'z': 'zs'
    }
    if _filter in filt.keys():
        _filter = filt[_filter]

    if 'date-obs' in hdr:
        _dateobs = hdr.get('date-obs')
    else:
        _dateobs = jd2date(_mjd + 2400000.5).strftime('%Y-%d-%m')

    print imglist[0]
    print _dateobs, _dayobs, _mjd, _filter

    if not output:
        output = _telescope + '_' + str(out1) + '_' + str(_dayobs) + '_' + str(
            _filter) + '_' + objname + '.fits'

    imgmask = []
    skylevel = []
    # if the template is from sloan, use mask and weight image
    if survey == 'sloan':
        welist = [i for i in imglist if '.weight.' in i]
        if len(welist):
            # if weight images provided, use them in swarp
            # and take out them from input list image
            imglist = [j for j in imglist if j not in welist]
            imgmask = welist
            for jj in imglist:
                img_data, img_header = fits.getdata(jj, header=True)
                if 'SKYLEVEL' in img_header:
                    skylevel.append(img_header['SKYLEVEL'])
    elif survey == 'ps1':
        wtlist = [i for i in imglist if '.wt_' in i]
        mklist = [i for i in imglist if '.mk_' in i]
        if len(wtlist):
            for i, name in enumerate(wtlist):
                weightimg = re.sub('.wt_', '.weight.', name)
                imgmask.append(weightimg)
                if re.sub('.wt_', '.mk_', name) in mklist:
                    weight_data, weight_header = fits.getdata(name,
                                                              header=True)
                    mask_data, mask_header = fits.getdata(re.sub(
                        '.wt_', '.mk_', name),
                                                          header=True)
                    weight_data = 1 / weight_data
                    weight_fits = fits.PrimaryHDU(header=weight_header,
                                                  data=weight_data)
                    weight_fits.writeto(weightimg,
                                        output_verify='fix',
                                        clobber=True)
                else:
                    os.system('cp ' + name + ' ' + weightimg)
        imglist = [
            j for j in imglist if (j not in wtlist) and (j not in mklist)
        ]
        # measure skylevel in all ps1 images
        for jj in imglist:
            img_data, img_header = fits.getdata(jj, header=True)
            skylevel.append(np.mean(img_data))


#    elif len(welist):
#       imglist = [j for j in imglist if j not in welist]
#       imgmask = welist

    print imgmask
    print skylevel
    sampling = 'BILINEAR'  # LANCZOS3
    line = 'swarp ' + ','.join(imglist) + ' -IMAGEOUT_NAME ' + str(output) + \
            ' -WEIGHTOUT_NAME ' + re.sub('.fits', '', output) + '.weight.fits' + \
            ' -RESAMPLE_DIR ./ -RESAMPLE_SUFFIX .swarptemp.fits -RESAMPLING_TYPE ' +sampling+ \
            ' -COMBINE Y  -COMBINE_TYPE ' + str(combine_type)+ \
            ' -VERBOSE_TYPE NORMAL -SUBTRACT_BACK Y -INTERPOLATE Y' + \
            ' -PIXELSCALE_TYPE MANUAL,MANUAL -PIXEL_SCALE ' + str(pixelscale) + ',' + str(pixelscale) + \
            ' -IMAGE_SIZE ' + str(_imagesize) + ',' + str(_imagesize) + \
            ' -CENTER_TYPE MANUAL,MANUAL -CENTER ' + str(_ra) + ',' + str(_dec) + \
            ' -GAIN_DEFAULT ' + str(_gain)

    if imgmask:
        line += ' -WEIGHT_TYPE MAP_WEIGHT -WEIGHT_IMAGE ' + ','.join(imgmask)
    print line
    os.system(line)

    # the output of swarp give the normalized weight
    # we want to store the variance image
    # we invert the normalized weight and we "de-normalized" this image
    hd = fits.getheader(output)
    ar = fits.getdata(output)
    hd2 = fits.getheader(re.sub('.fits', '', output) + '.weight.fits')
    ar2 = fits.getdata(re.sub('.fits', '', output) + '.weight.fits')
    variance = 1 / ar2
    #  this is to take in account that the weight is normalized
    variance *= (np.median(np.abs(ar - np.median(ar))) *
                 1.48)**2 / np.median(variance)
    varimg = re.sub('.fits', '', output) + '.var.fits'
    fits.writeto(varimg, variance, hd2, clobber=True)

    # put the saturation all values where the weight is zero
    ar = np.where(ar2 == 0, _saturate, ar)

    if len(skylevel):
        hd['SKYLEVEL'] = (np.mean(skylevel), 'average sky level')
    hd['L1FWHM'] = (9999, 'FHWM (arcsec) - computed with sextractor')
    hd['WCSERR'] = (0, 'error status of WCS fit. 0 for no error')
    hd['MJD-OBS'] = (_mjd, 'MJD')
    hd['RA'] = (_ra, 'RA')
    hd['DEC'] = (_dec, 'DEC')
    hd['RDNOISE'] = (_ron, 'read out noise')
    hd['PIXSCALE'] = (pixelscale, '[arcsec/pixel] Nominal pixel scale on sky')
    hd['FILTER'] = (_filter, 'filter used')
    hd['DAY-OBS'] = (_dayobs, 'day of observation')
    hd['AIRMASS'] = (_airmass, 'airmass')
    hd['DATE-OBS'] = (_dateobs, 'date of observation')
    hd['GAIN'] = (_gain, 'gain')
    hd['SATURATE'] = (_saturate, 'saturation level ')
    if objname:
        hd['OBJECT'] = (objname, 'title of the data set')
    if survey == 'sloan':
        hd['TELESCOP'] = ('SDSS', 'name of the telescope')
        hd['INSTRUME'] = ('SDSS', 'instrument used')
        hd['SITEID'] = ('SDSS', 'ID code of the Observatory site')
    elif survey == 'ps1':
        hd['TELESCOP'] = ('PS1', 'name of the telescope')
        hd['INSTRUME'] = ('PS1', 'instrument used')
        hd['SITEID'] = ('PS1', 'ID code of the Observatory site')

    ar, hdr = northupeastleft(data=ar, header=hd)
    out_fits = fits.PrimaryHDU(header=hd, data=ar)
    out_fits.writeto(output, clobber=True, output_verify='fix')
    northupeastleft(filename=varimg)
    if show:
        lsc.display_image(output, 2, True, '', '')
    return output, varimg
Пример #4
0
def sdss_swarp(imglist,_telescope='spectral',_ra='',_dec='',output='', objname='',survey='sloan',combine_type='MEDIAN', show=False):
    import re
    import datetime
    import lsc
    import time
    import string

    if _telescope == 'spectral':
        pixelscale = 0.30104  # 2 meter
        _imagesize =  2020
    elif _telescope == 'sbig':
            pixelscale = 0.467  # 1 meter
            _imagesize =  2030
    elif _telescope == 'sinistro':
            pixelscale = 0.387  # 1 meter
            _imagesize =  4020

    if survey =='sloan':
       out1 = 'SDSS'
       hdr = fits.getheader(imglist[0])
       _filter = hdr.get('filter')
       _gain   = hdr.get('gain')
       _ron   = hdr.get('rdnoise')
       if not _ra:
          _ra = hdr.get('CRVAL1')
       if not _dec:
          _dec = hdr.get('CRVAL2')
       _saturate = hdr.get('SATURATE')
       if not _saturate:
          _saturate = 61000
       if 'day-obs' in hdr:
          _dayobs = hdr.get('day-obs')
       elif 'date-obs' in hdr:
          _dayobs = re.sub('-','',hdr.get('date-obs'))

       if '/' in _dayobs:
          _dayobs = '19'+''.join(string.split(_dayobs,'/')[::-1])

       try:
          _mjd = MJDnow(datetime.datetime(int(str(_dayobs)[0:4]),int(str(_dayobs)[4:6]),int(str(_dayobs)[6:8])))
       except:
          print 'warning, no mjd'
          _mjd = 0
          _dayobs = '19991231'

    elif survey =='ps1':
       out1 = 'PS1'
       imglist2=[]
       for i,img in enumerate(imglist):
           print i,img
           hdr = fits.open(img)
           if os.path.isfile(re.sub('.fits','_1.fits',img)):
              os.system('rm '+re.sub('.fits','_1.fits',img))
           fits.writeto(re.sub('.fits','_1.fits',img),hdr[1].data,hdr[1].header)
           imglist2.append(re.sub('.fits','_1.fits',img))

       imglist = imglist2
       hdr = fits.getheader(imglist[0])
       _saturate = hdr.get('HIERARCH CELL.SATURATION')
       _filter = string.split(hdr.get('HIERARCH FPA.FILTER'),'.')[0]
       _gain   = hdr.get('HIERARCH CELL.GAIN')
       _ron   = hdr.get('HIERARCH CELL.READNOISE')
       _mjd = hdr.get('MJD-OBS')
       _dayobs = jd2date(_mjd+2400000.5).strftime('%Y%d%m')
       if not _ra:
          _ra = hdr.get('RA_DEG')
       if not _dec:
          _dec = hdr.get('DEC_DEG')

    #  airmass
    if 'airmass' in hdr:
        _airmass = hdr.get('airmass')
    else:
        _airmass = 1

    #  filters
    filt={'U':'U','B':'B','V':'V','R':'R','I':'I','u':'up','g':'gp','r':'rp','i':'ip','z':'zs'}
    if _filter in filt.keys():
        _filter = filt[_filter]

    if 'date-obs' in hdr:
       _dateobs = hdr.get('date-obs')
    else:
       _dateobs = jd2date(_mjd+2400000.5).strftime('%Y-%d-%m')

    print imglist[0]
    print _dateobs, _dayobs, _mjd, _filter

    if not output:
       output = _telescope+'_'+str(out1)+'_'+str(_dayobs)+'_'+str(_filter)+'_'+objname +'.fits'

    imgmask = [] 
    skylevel = []
    # if the template is from sloan, use mask and weight image
    if survey =='sloan':
       welist = [i for i in imglist if '.weight.' in i]
       if len(welist):
          # if weight images provided, use them in swarp
          # and take out them from input list image
          imglist = [j for j in imglist if j not in welist]
          imgmask = welist
          for jj in imglist:
             img_data,img_header=fits.getdata(jj, header=True)
             if 'SKYLEVEL' in img_header:
                skylevel.append(img_header['SKYLEVEL'])
    elif survey=='ps1':
       wtlist = [i for i in imglist if '.wt_' in i]
       mklist = [i for i in imglist if '.mk_' in i]
       if len(wtlist):
          for i,name in enumerate(wtlist):
             weightimg = re.sub('.wt_','.weight.',name)
             imgmask.append(weightimg)
             if re.sub('.wt_','.mk_',name) in mklist:
                weight_data, weight_header = fits.getdata(name, header=True)
                mask_data, mask_header = fits.getdata(re.sub('.wt_','.mk_',name), header=True)
                weight_data = 1/weight_data 
                weight_fits = fits.PrimaryHDU(header=weight_header, data=weight_data)
                weight_fits.writeto(weightimg, output_verify='fix', overwrite=True)
             else:
                os.system('cp '+name+' '+weightimg)
       imglist = [j for j in imglist if (j not in wtlist) and (j not in mklist)]
       # measure skylevel in all ps1 images
       for jj in imglist:
          img_data,img_header=fits.getdata(jj, header=True)
          skylevel.append(np.mean(img_data))

#    elif len(welist):
#       imglist = [j for j in imglist if j not in welist]
#       imgmask = welist


    print imgmask
    print skylevel
    sampling = 'BILINEAR' # LANCZOS3
    line = 'swarp ' + ','.join(imglist) + ' -IMAGEOUT_NAME ' + str(output) + \
            ' -WEIGHTOUT_NAME ' + re.sub('.fits', '', output) + '.weight.fits' + \
            ' -RESAMPLE_DIR ./ -RESAMPLE_SUFFIX .swarptemp.fits -RESAMPLING_TYPE ' +sampling+ \
            ' -COMBINE Y  -COMBINE_TYPE ' + str(combine_type)+ \
            ' -VERBOSE_TYPE NORMAL -SUBTRACT_BACK Y -INTERPOLATE Y' + \
            ' -PIXELSCALE_TYPE MANUAL,MANUAL -PIXEL_SCALE ' + str(pixelscale) + ',' + str(pixelscale) + \
            ' -IMAGE_SIZE ' + str(_imagesize) + ',' + str(_imagesize) + \
            ' -CENTER_TYPE MANUAL,MANUAL -CENTER ' + str(_ra) + ',' + str(_dec) + \
            ' -GAIN_DEFAULT ' + str(_gain)

    if imgmask:
       line += ' -WEIGHT_TYPE MAP_WEIGHT -WEIGHT_IMAGE ' +  ','.join(imgmask)
    print line
    os.system(line)

    # the output of swarp give the normalized weight 
    # we want to store the variance image
    # we invert the normalized weight and we "de-normalized" this image
    hd = fits.getheader(output)
    ar = fits.getdata(output)
    hd2 = fits.getheader(re.sub('.fits', '', output) + '.weight.fits')
    ar2 = fits.getdata(re.sub('.fits', '', output) + '.weight.fits')
    variance = 1 / ar2
    #  this is to take in account that the weight is normalized
    variance *= (np.median(np.abs(ar - np.median(ar)))*1.48)**2/np.median(variance)
    varimg = re.sub('.fits', '', output) + '.var.fits'
    fits.writeto(varimg, variance, hd2, overwrite=True)

    # put the saturation all values where the weight is zero 
    ar = np.where(ar2 == 0, _saturate, ar)

    if len(skylevel):
        hd['SKYLEVEL'] = (np.mean(skylevel), 'average sky level')
    hd['L1FWHM']   = (9999,       'FHWM (arcsec) - computed with sextractor')
    hd['WCSERR']   = (0,          'error status of WCS fit. 0 for no error')
    hd['MJD-OBS']  = (_mjd,       'MJD')
    hd['RA']       = (_ra,        'RA')
    hd['DEC']      = (_dec,       'DEC')
    hd['RDNOISE']  = (_ron,       'read out noise')
    hd['PIXSCALE'] = (pixelscale, '[arcsec/pixel] Nominal pixel scale on sky')
    hd['FILTER']   = (_filter,    'filter used')
    hd['DAY-OBS']   = (_dayobs,    'day of observation')
    hd['AIRMASS']  = (_airmass,   'airmass')
    hd['DATE-OBS'] = (_dateobs,   'date of observation')
    hd['GAIN']     = (_gain,      'gain')
    hd['SATURATE'] = (_saturate,  'saturation level ')
    if objname:
        hd['OBJECT'] = (objname, 'title of the data set')
    if survey == 'sloan':
        hd['TELESCOP'] = ('SDSS', 'name of the telescope')
        hd['INSTRUME'] = ('SDSS', 'instrument used')
        hd['SITEID'] = ('SDSS', 'ID code of the Observatory site')
    elif survey == 'ps1':
        hd['TELESCOP'] = ('PS1', 'name of the telescope')
        hd['INSTRUME'] = ('PS1', 'instrument used')
        hd['SITEID'] = ('PS1', 'ID code of the Observatory site')

    ar, hdr = northupeastleft(data=ar, header=hd)
    out_fits = fits.PrimaryHDU(header=hd, data=ar)
    out_fits.writeto(output, overwrite=True, output_verify='fix')
    northupeastleft(filename=varimg)
    if show:
       lsc.display_image(output,2,True,'','')
    return output, varimg