Ejemplo n.º 1
0
 def doTask(imageheaders):
   #Create image cut-outs
   for hdr in imageheaders:
     fname = '%s.png' % uuid.uuid4()
     hdr.fname = fname #This attribute links the filename to the <img src=''> tag
     if async:
       t = tasks.makeImage.delay(hdr,fname,clipSize,ra,dec,units=units)
       hdr.jobid = t.id
     else:
       tasks.makeImage(hdr,fname,clipSize,ra,dec,units=units)
Ejemplo n.º 2
0
  def get(self, request, *args, **kwargs):
    if 'OB' in kwargs:
      results = ImageHeader.objects.filter(TARGETID=kwargs['targetID'],OB=kwargs['OB'])
      if not results:
        return Http404
      results = sorted(results, key = lambda k: constants.band_sequence[k.FILTER])
      photo_objs = []
      for i in results:
        if i.FILTER in constants.optical:
          photo_objs.extend(Photometry.objects.filter(imageheader=i,BAND=i.FILTER))
      calib_schemes = [j.CALIB_SCHEME for j in photo_objs]
      griz_calib_scheme = calib_schemes[0] if len(set(calib_schemes)) == 1 else 'mixed'
      hashtable = {
        'SEEING': lambda i: round(i.imageproperties.SEEING,2),
        'LIMITING_MAG_3S_ZP': lambda i: round(i.imageproperties.LIMITING_MAG_3S_ZP,1),
        'LIMITING_MAG_3S_CALIB': lambda i: round(i.imageproperties.LIMITING_MAG_3S_CALIB,1),
        'ASTROMETRY_ACCURACY_RA': lambda i: round(i.imageproperties.ASTROMETRY_ACCURACY_RA,2),
        'ASTROMETRY_ACCURACY_DEC': lambda i: round(i.imageproperties.ASTROMETRY_ACCURACY_DEC,2),
        'APP_SIZE': lambda i: round(i.imageproperties.APP_SIZE,1),
        'MEAN_AIRMASS': lambda i: round(i.imageproperties.MEAN_AIRMASS,2),
        'date': lambda i: i.DATE_OBS.split('T')[0],
        'time': lambda i: i.DATE_OBS.split('T')[1][:-4],
        'OBTYPEID': lambda i: i.OBTYPEID,
        'fname': lambda i: tasks.makeImage(i,'%s.png' % uuid.uuid4(),None,None,None).fname,
      }
      data = {}
      for ih in results:
        data[ih.FILTER] = dict([(k,hashtable[k](ih)) for k in hashtable])
        data[ih.FILTER].update({'griz_calib_scheme':griz_calib_scheme})
      context = {'ob_data':json.dumps(data),'targetID':kwargs['targetID'],'OB':kwargs['OB'],'RA':'%0.4f' % ih.RA,'DEC':'%0.4f' %  ih.DEC}
    else:
      results = ImageHeader.objects.filter(TARGETID=kwargs['targetID'])
      if not results:
        return Http404
      hashtable = {
        'date':lambda i: i.DATE_OBS.split('T')[0],
        'time': lambda i: i.DATE_OBS.split('T')[1][:-4],
        'obtype': lambda i: i.OBTYPEID,
        'n_bands': lambda i: len(ImageHeader.objects.filter(TARGETID=i.TARGETID,OB=i.OB)),
        'mjd': lambda i: i.MJD_OBS,
        'filename': lambda i: i.PATH,
      }

      #unique_observations = set([(i.TARGETID,i.OB) for i in results])
      data = {}
      for ih in results:
        if "%s %s" % (ih.TARGETID,ih.OB) not in data:
          data["%s %s" % (ih.TARGETID,ih.OB)] = dict([(k,hashtable[k](ih)) for k in hashtable])
      context = {'field_data':json.dumps(data),'targetID':kwargs['targetID']}
    return render(request,self.template_name,context)