def make_cutouts_multiband(bands='r', detband='detr', 
  imagefiles=None, 
  listfile=None, format='region', width_arcsecs=10.0, 
  catfiles=None):

  """


  """

  import os, sys
  import time

  import pyfits
  import pyregion
  import cutout

  #import fits2png

  import matplotlib.pyplot as plt
  #if not interactive: matplotlib.use('Agg')

  import aplpy

  import plotid

  t0=time.time()

  base=os.path.basename(listfile)
  id=os.path.splitext(base)[0]

  weightmap = False


  # open ds9 region 
  if format == 'region':
    region = pyregion.open(listfile)

    irow=-1
    # print out the cordinates in degrees
    for rows in region:  # iterate over table rows
      irow=irow+1
      print irow+1, region[irow].coord_list[0], region[irow].coord_list[1]
  
    nrows=len(region)

  if format == 'ozdes':
    table= pyfits.getdata(listfile,1)
    ralist = table['RA']
    declist = table['Dec']
    object = table['object']
    comment = table['comment']
    redshift = table['z_fin']
    print 'ralist range: ', min(ralist), max(ralist)
    print 'declist range: ', min(declist), max(declist)
    nrows=len(ralist)

  # Read extension 2 of the catalog file
  ext=2
  catalog = pyfits.getdata(catalog_path+catalog_filename,ext)
  ra_catalog = catalog['alphawin_j2000']
  dec_catalog = catalog['deltawin_j2000']

  title=imagefiles 
  #plt.text(.5, .95, title, horizontalalignment='center') 

  # leave some space to add annotation at the top of the page
  plt.rc('figure.subplot', left=0.05, right=0.95, bottom=0.05, top=0.95, 
   wspace=0.0, hspace=0.0)

  fig=plt.figure(figsize=(12.0, 10.0))

  fig.text(0.1, 0.97, title, horizontalalignment='left', 
   color='blue', transform = plt.gcf().transFigure) 

  plt.xticks=[]
  plt.yticks=[]
  label=os.path.basename(__file__)
  plotid.plotid(label=label)

  nxplots=5
  nyplots=6

  irow=-1
  iplot=0
  

  #print plt.get_gca()
  #print plt.get_gcf()
  isource=0
  ifig=1
  #for rows in region:  # iterate over table rows

  for rows in ralist:  # iterate over table rows
    print 'Elpased time: %.2f seconds' %(time.time() - t0)
    irow=irow+1
    isource=isource+1
    print irow, ' of ', nrows
    #if irow > nxplots*nyplots: break

    if format == 'region':
      ra=region[irow].coord_list[0]
      dec=region[irow].coord_list[1]

    if format == 'ozdes':
      ra=ralist[irow]
      dec=declist[irow]

    iband=-1
    for band in bands:  # iterate over the bands  
      iband=iband+1
      iplot=iplot+1
      outfile='cutout' + str(irow+1) + band + '.fits'
      outfile=None
      verbose=True
      xc=ra
      yc=dec
      imagefile=imagefiles[iband]
      print 'input image: ', imagefile

      # width in arcsecs
      width_arcsecs=10.0
      # convert to semi-width in degrees
      xw=(0.5*width_arcsecs)/3600.0 
      yw=(0.5*width_arcsecs)/3600.0 
    
      # create cutout FITS file
      imagefile=imagefiles[iband]
      image=cutout.cutout(imagefile, xc, yc, xw=xw, yw=yw, units='wcs', 
       outfile=outfile, clobber=True, 
       useMontage=False, coordsys='celestial', verbose=verbose)
      image = image.data

      ax=fig.add_subplot(nxplots,nyplots,iplot,
       frameon=True, xticks=[], yticks=[])
      ax.imshow(image)

      if iband == 0: ax.text(0.1, 0.80, str(isource), 
       transform=plt.gca().transAxes)

      ax.text(0.9, 0.80, band, transform=plt.gca().transAxes)

      if format == 'ozdes':
        annotation=object[isource-1].strip()
        if iband == 0: ax.text(0.1, 0.02, annotation, 
          verticalalignment='baseline',
          transform=plt.gca().transAxes)

        annotation=comment[isource-1].strip()
        if iband == 0: ax.text(0.1, 0.1, annotation, 
          transform=plt.gca().transAxes)

        annotation=str(redshift[isource-1]).strip()
        if iband == 0: ax.text(0.5, 0.1, annotation, 
          transform=plt.gca().transAxes)


      if iplot == nxplots*nyplots:
        print 'nxplots, nyplots, iplot, isource: ', \
         nxplots, nyplots, iplot, isource
        iplot=0
        strfigno= '%4.4d' % (ifig)
        #plt.savefig(id+'_cutouts_multiband_' + str(ifig) + '.png', dpi=150)
        #plt.savefig(id+'_cutouts_multiband_' + strfigno + '.png', dpi=150)
        plt.savefig(id+'_cutouts_multiband_' + strfigno + '.png', dpi=100)

        if ifig == 1: plt.show()
        ifig=ifig+1
        fig=plt.figure(ifig,figsize=(12.0, 10.0))
        plotid.plotid(label=label)

  print 'nxplots, nyplots, iplot, isource: ', \
         nxplots, nyplots, iplot, isource
  iplot=0
  strfigno= '%4.4d' % (ifig)
  #plt.savefig(id+'_cutouts_multiband_' + str(ifig) + '.png', dpi=150)
  #plt.savefig(id+'_cutouts_multiband_' + strfigno + '.png', dpi=150)
  plt.savefig(id+'_cutouts_multiband_' + strfigno + '.png', dpi=100)
Exemplo n.º 2
0
  &lthead&gt
    &lttitle&gthtml网页标题&lt/title&gt
  &lt/head&gt
  &ltbody&gt
     &ltul id="img"&gt
     	&ltli&gt &ltp&gtpic1&lt/p&gt &ltimg src="/img/pic1.jpg" /&gt  &lt/li&gt
     	&ltli&gt &ltp&gtpic2&lt/p&gt &ltimg src="/img/pic2.jpg" /&gt  &lt/li&gt
     	&ltli&gt &ltp&gtpic3&lt/p&gt &ltimg src="/img/pic3.jpg" /&gt  &lt/li&gt
     &lt/ul&gt
  &lt/body&gt
&lt/html&gt
'''

# 获取网页title

title = cutout(data=datastr, start="&lttitle&gt", end="&lt/title&gt")
print(title)  #  html网页标题

# 获取图片地址

href = cutout(
    data=datastr,
    start="&ltul id=\"img\"&gt",
    end="&lt/ul&gt",
    split="&ltli&gt",  #分割
    dealwith=(
        {
            "start": "&ltp&gt",  #获取名称
            "end": "&lt/p&gt"
        },
        {
Exemplo n.º 3
0
means = np.array([0.4914, 0.4822, 0.4465])
stds = np.array([0.2470, 0.2435, 0.2616])

if not args.use_cutout:
    transform_train = transforms.Compose([
        transforms.RandomCrop(32, padding=4),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize(means, stds),
        noise_func_train,
    ])
else:
    transform_train = transforms.Compose([
        transforms.RandomCrop(32, padding=4),
        transforms.RandomHorizontalFlip(),
        cutout(args.cutout_size, args.cutout_prob, args.cutout_inside),
        transforms.ToTensor(),
        transforms.Normalize((0.4914, 0.4822, 0.4465), (0.247, 0.243, 0.261)),
        noise_func_train,
    ])

transform_test = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize((0.4914, 0.4822, 0.4465), (0.247, 0.243, 0.261)),
    noise_func_test,
])

trainset = torchvision.datasets.CIFAR10(root='./data',
                                        train=True,
                                        download=True,
                                        transform=transform_train)
Exemplo n.º 4
0
for ii in range(Nimg): # looping over images
    image   = pyfits.getdata(drzimages[ii],ext=0)  # reading image into array   [rows,columns]
    hdulist = pyfits.open(drzimages[ii])     # Load the FITS hdulist using pyfits
    hdr     = hdulist[0].header                  # get header

    if args.coords[2] == 'pixels':
        wcs = pywcs.WCS(hdr)  # Extract wcs (coordinate) information
        pix = np.array([[args.coords[0],args.coords[1]]], np.float_)
        sky = wcs.wcs_pix2sky(pix, 1)  # convert to 'sky' values. 2nd arg. is "origin": 1 = a 1-based (Fortran-like) coordinates.
        ra  = sky[0][0]
        dec = sky[0][1]
    elif args.coords[2] == 'wcs':
        ra  = float(args.coords[0])
        dec = float(args.coords[1])
    else:
        sys.exit('Coordinate units '+args.coords[2]+' not allowed --> ABORTING')

    outname = args.outputdir+'/'+args.objname+'_cutoutFROM_'+drzimages[ii].split('/')[-1]
#    pdb.set_trace()
    cutout.cutout(drzimages[ii],ra,dec,xw=args.pswidth,yw=args.pswidth,units='wcs',outfile=outname)
    if args.verbose: print 'Created the cutout '+outname
#-------------------------------------------------------------------------------------------------------------
if args.stop: pdb.set_trace()
#if args.stop: sys.exit('STOPPED PROGRAM AS REQUESTED')
if args.verbose:
    print ' '
    print ':: '+sys.argv[0]+' :: -- END OF PROGRAM -- '
    print ' '
#-------------------------------------------------------------------------------------------------------------

Exemplo n.º 5
0
  &lt/head&gt
  &ltbody&gt
     &ltul id="img"&gt
     	&ltli&gt &ltp&gtpic1&lt/p&gt &ltimg src="/img/pic1.jpg" /&gt  &lt/li&gt
     	&ltli&gt &ltp&gtpic2&lt/p&gt &ltimg src="/img/pic2.jpg" /&gt  &lt/li&gt
     	&ltli&gt &ltp&gtpic3&lt/p&gt &ltimg src="/img/pic3.jpg" /&gt  &lt/li&gt
     &lt/ul&gt
  &lt/body&gt
&lt/html&gt
'''

# 获取网页title

title = cutout(
  data=datastr,
  start="&lttitle&gt",
  end="&lt/title&gt"
)
print(title) #  html网页标题

# 获取图片地址

href = cutout(
  data=datastr,
  start="&ltul id=\"img\"&gt",
  end="&lt/ul&gt",
  split="&ltli&gt", #分割
  dealwith=({
    "start":"&ltp&gt", #获取名称
    "end":"&lt/p&gt" 
  },{
Exemplo n.º 6
0
            pix, 1
        )  # convert to 'sky' values. 2nd arg. is "origin": 1 = a 1-based (Fortran-like) coordinates.
        ra = sky[0][0]
        dec = sky[0][1]
    elif args.coords[2] == 'wcs':
        ra = float(args.coords[0])
        dec = float(args.coords[1])
    else:
        sys.exit('Coordinate units ' + args.coords[2] +
                 ' not allowed --> ABORTING')

    outname = args.outputdir + '/' + args.objname + '_cutoutFROM_' + drzimages[
        ii].split('/')[-1]
    #    pdb.set_trace()
    cutout.cutout(drzimages[ii],
                  ra,
                  dec,
                  xw=args.pswidth,
                  yw=args.pswidth,
                  units='wcs',
                  outfile=outname)
    if args.verbose: print 'Created the cutout ' + outname
#-------------------------------------------------------------------------------------------------------------
if args.stop: pdb.set_trace()
#if args.stop: sys.exit('STOPPED PROGRAM AS REQUESTED')
if args.verbose:
    print ' '
    print ':: ' + sys.argv[0] + ' :: -- END OF PROGRAM -- '
    print ' '
#-------------------------------------------------------------------------------------------------------------
Exemplo n.º 7
0
                if not os.path.exists(directory+galaxy['ID']+'_'+filter+'.fits'):
                    if len(glob.glob("*"+galaxy['ID']+"*"+filter+"*"+"*fit*gz*")) < 1:
                        fetchsdss.main(["", "--coords="+strcoords, filter, "--output="+galaxy['ID']+'_'])

                    files = glob.glob("*"+galaxy['ID']+"*"+filter+"*"+"*fit*gz*")

                    for file in files:
                        print file
                        hdulist = fits.open(file)
                        print hdulist[0].header['filter']
                        hdulist.writeto(large_image_file, output_verify='ignore', clobber = True)

                #if not os.path.exists(stamp_name):
                if True:
                    try:
                        cutout.cutout(large_image_file, galaxy['RA'], galaxy['Dec'], 0.035, 0.035, units='wcs', outfile=stamp_name, coordsys='celestial')
                    except:
                        error_file = open(error_filename, "a")
                        error_file.write(stamp_name+"\n")
                        error_file.close()
                        error = True

                    try:
                        cutout.cutout(large_image_file, galaxy['RA'], galaxy['Dec'], 0.005, 0.005, units='wcs', outfile=mini_stamp_name, coordsys='celestial')
                    except:
                        error_file = open(error_filename, "a")
                        error_file.write(mini_stamp_name+"\n")
                        error_file.close()
                        error = True

        if error == False: