Ejemplo n.º 1
0
def index(request):
   only_visible = None
   ha_high = settings.HA_SOFT_LIMIT
   epoch = None
   rating_low = None
   new_window = False
   tz_offset = 0
   #Default:  nothing posted and no session info
   cur_tel_obj = request.session.get('cur_tel_obj', 'Park')
   prev_tel_obj = request.session.get('prev_tel_obj', 'Park')
   selected_tab = request.session.get('selected_tab', 'table')
   show_types = None
   form = FilterForm()

   if request.method == "POST":
      if request.POST.get('action','') == 'Update':
         form = FilterForm(request.POST)
         # save this form info into the session cache
         request.session['object_list_form'] = request.POST.copy()
      elif request.POST.get('action','') == 'Park':
         request.session['cur_tel_obj'] = 'Park'
         cur_tel_obj = 'Park'
      else:
         # The reset button was called
         form = FilterForm()
         if 'object_list_form' in request.session:
            del request.session['object_list_form']
   if 'object_list_form' in request.session:
      form = FilterForm(request.session['object_list_form'])

   if form.is_valid():
      only_visible = form.cleaned_data.get('only_visible',None)
      ha_high = form.cleaned_data.get('ha_high',settings.HA_SOFT_LIMIT)
      show_types = form.cleaned_data.get('show_types', None)
      rating_low = form.cleaned_data.get('rating_low',None)
      epoch = form.cleaned_data.get('epoch',None)
      tz_offset =form.cleaned_data.get('tz_offset', 0)
      new_window = form.cleaned_data.get('new_window',False)

   if tz_offset is None:
      tz_offset = 0
   if epoch:  
      date = ephem.Date(epoch) - tz_offset*ephem.hour
   else:
      date = ephem.now()

   # Now deal with telescope position
   tel_RA,tel_DEC,tel_ha,tel_alt,tel_az = telescope_position(cur_tel_obj, date)
   # Also see if window is to be displayed:
   module_display = request.session.get('module_display', {});

   obs = genMWO(date)
   sid_time = str(obs.sidereal_time())
   obj_list = Object.objects.all()
   for obj in obj_list:
      obj.epoch = date
      obj.tel_az = float(tel_az)
   obj_list = sorted(obj_list, key=lambda a: float(a.PrecRAh()))

   new_list = []
   for obj in obj_list:  
      #obj.epoch = date
      if only_visible is not None and only_visible and not obj.visible():
         continue
      if ha_high is not None and \
         abs(obj.hour_angle()) > ha_high:
         continue
      if rating_low is not None and obj.rating < rating_low:
         continue
      if show_types is not None and obj.type not in show_types:
         continue
      new_list.append(obj)
   obj_list = new_list

   if epoch:
      sdate = epoch.strftime('%m/%d/%y %H:%M:%S')
   else:
      sdate = ephem.Date(ephem.now()+tz_offset*ephem.hour)
      sdate = sdate.datetime().strftime('%m/%d/%y %H:%M:%S')
   if tz_offset != 0:
      stz_offset = "%.1f" % (tz_offset)
   else:
      stz_offset = ""

   embed_image = plot_skyview.plot_sky_map(obj_list, date=date, 
         tel_az=tel_az, tel_alt=tel_alt)
   alt_plot = plot_objs.plot_alt_map(obj_list, date=date, toff=tz_offset) 
   t = loader.get_template('navigator/object_list.sortable.html')
   c = RequestContext(request, {
      'object_list': obj_list, 'form':form, 'date':sdate,
      'method':request.method, 'new_window':new_window, 'tz_offset':stz_offset,
      'tel_RA':tel_RA,'tel_DEC':tel_DEC,'tel_ha':tel_ha,'tel_alt':tel_alt,
      'tel_az':tel_az,'sid_time':sid_time,'embed_image':embed_image,
      'module_display':module_display, 'alt_plot':alt_plot, 
      'selected_tab':selected_tab,
      })
   return HttpResponse(t.render(c))
Ejemplo n.º 2
0
def detail(request, object_id):
   obj = Object.objects.get(id=object_id)
   message = None
   error = None
   extras = "?"
   epoch = None
   tz_offset = 0
   if 'object_list_form' in request.session:
      tz_offset = float(request.session['object_list_form']['tz_offset'])
      if tz_offset is None:
         tz_offset = 0

   date = get_current_time(request)
   obj.epoch = date
   

   if request.method == 'POST':
      if 'action' in request.POST:
         if request.POST['action'] == 'GOTO':
            request.session['prev_tel_obj'] = request.session.get('cur_tel_obj',
                                                                  'Park')
            request.session['cur_tel_obj'] = obj.name
            request.session['tel_status'] = 'SLEW'
         elif request.POST['action'] == "Sync":
            request.session['prev_tel_obj'] = request.session.get('cur_tel_obj',
                                                                  'Park')
            request.session['tel_status'] = 'IDLE'
         elif request.POST['action'] == "Cancel":
            request.session['cur_tel_obj'] = request.session.get('prev_tel_obj',
                                                                 'Park')
            request.session['tel_status'] = 'IDLE'
         elif request.POST['action'] == "Update":
            comments = request.POST['comments']
            rating = int(request.POST.get('rating',0))
            obj.comments = comments
            obj.rating = rating
            obj.save()

      elif 'eyepiece' in request.POST:
         request.session['cur_eye'] = request.POST['eyepiece']

   cur_tel_obj = request.session.get('cur_tel_obj', 'Park')
   prev_tel_obj = request.session.get('prev_tel_obj', 'Park')
   tel_status = request.session.get('tel_status', 'IDLE')

   eyepiece = request.session.get('cur_eye', None)
   if eyepiece is not None:
      FOV = settings.fovs[eyepiece]
   else:
      FOV = settings.FINDER_SIZE

   if FOV != settings.FINDER_BASE_SIZE:
      extras += "size=%d&" % (FOV)
   if settings.FINDER_REVERSE:
      extras += "reverse=1&"
   if settings.FINDER_LOW:
      extras += "low=%d&" % (settings.FINDER_LOW)
   if settings.FINDER_HIGH:
      extras += "high=%d&" % (settings.FINDER_HIGH)
   extras = extras[:-1]     # cleanup trailing & or ?
   t = loader.get_template('navigator/object_detail.html')

   # Now deal with telescope position
   if tel_status == "SLEW":
      tel_RA,tel_DEC,tel_ha,tel_alt,tel_az = telescope_position(prev_tel_obj, date)
      new_RA,new_DEC,new_ha,new_alt,new_az = telescope_position(cur_tel_obj, date)
      # Now we move the dome
      delta_az = float(new_az) - float(tel_az)
      if delta_az < -180:
         delta_az += 360
      elif delta_az > 180:
         delta_az -= 360
      if delta_az > 0:
         az_move = "Dome Right %.2f" % (delta_az)
      else:
         az_move = "Dome Left %.2f" % (-delta_az)

      # Now we move in RA
      delta_ra = (ephem.hours(new_RA) - ephem.hours(tel_RA))/pi*12.
      if delta_ra < 0:
         ra_move = "Slew West %.2f h" % (abs(delta_ra))
      else:
         ra_move = "Slew East %.2f h" % (abs(delta_ra))

      # Now we move in DEC
      delta_dec = (ephem.degrees(new_DEC) - ephem.degrees(tel_DEC))/pi*180
      if delta_dec < -180:  delta_dec += 180
      if delta_dec > 180: delta_dec -= 180
      if delta_dec < 0:
         dec_move = "Slew South %.2f" % (abs(delta_dec))
      else:
         dec_move = "Slew North %.2f" % (abs(delta_dec))


   else:
      az_move = None
      ra_move = None
      dec_move = None
      tel_RA,tel_DEC,tel_ha,tel_alt,tel_az = telescope_position(cur_tel_obj, date)
   embed_plot = plot_objs.plot_alt_map([obj], date=date, toff=tz_offset) 
   c = RequestContext(request, {
      'object':obj, 'extras':extras, 
      'finder_orientation':settings.FINDER_ORIENTATION, 
      'finder_size':FOV,
      'eyepieces':settings.fovs,'cur_eyepiece':eyepiece,
      'message':message, 'error':error, 'epoch':epoch,
      'tel_RA':tel_RA,'tel_DEC':tel_DEC,'tel_ha':tel_ha,'tel_alt':tel_alt,
      'tel_az':tel_az, 'tel_status':tel_status, 'az_move':az_move,
      'ra_move':ra_move, 'dec_move':dec_move, 'embed_plot':embed_plot,
      })
   return HttpResponse(t.render(c))