def move_motors(imagetype="", obs_mode="", iodine_cell=3): ### Check which obs mode the OR defines and move motors... # Check if motors are moving: output = get_db_values.db_connection().get_fields_site01("coude_unit", fields=["calib_mirror_pos", "iodine_pos", "filter_pos", "mirror_slide", "spectrograph_foc", "slit_pos"]) timeout = time.time() + 20 for motor in output: if float(output[motor]) == 0.0: time.sleep(1) output_motor = get_db_values.db_connection().get_fields_site01("coude_unit", fields=[motor]) while float(output_motor[motor]) == 0.0: time.sleep(1) output_motor = get_db_values.db_connection().get_fields_site01("coude_unit", fields=[motor]) if time.time() > timeout: break try: if imagetype.lower() == 'thar': try: lamp.Lamp(lamp='thar').set_on() # Might change Lamp to LAMP at some point lamp.Lamp(lamp='halo').set_off() # Might change Lamp to LAMP at some point except Exception,e: print clock.timename(), "One of the lamps was not switched correctly" pst.PST().move(3,2) # Move IODINE cell out of path pst.PST().move(4,3) # Move Calibration mirror to ThAr position elif imagetype.lower() == 'sun': try: lamp.Lamp(lamp='thar').set_off() # Might change Lamp to LAMP at some point lamp.Lamp(lamp='halo').set_off() # Might change Lamp to LAMP at some point except Exception,e: print clock.timename(), "One of the lamps was not switched correctly"
def focus_the_spectrograph(): ############################################################################## # Paths to motor controller and Andor CCD programs. DMC_PATH = "/home/obs/programs/DMC" ANDOR_PATH = "/home/madsfa/subversion/trunk/spec_ccd" SLIT_PATH = "/home/obs/programs/guiders/slit" ############################################################################## # Import the PST module, so we can read what the initial focus value was, # and return to this when we are done. The focus motor is nr. 5 sys.path.append(DMC_PATH) import pst dum, focval0 = pst.PST().where( 5) # Get the current state of the CCD camera focus. ############################################################################## # 8 7 6 5 4 3 2 #width = [25.0, 30.0, 36.0, 45.0, 60.0, 100.0, 20.0 ] width = [0, 0, 20.0, 100.0, 60.0, 45.0, 36.0, 30.0, 25.0] slit = daily_config.focus_slit # name = 'focus' + str( daily_config.focus_slit) + '_' # Image basename for FITS file. flatname = 'FOCUS_FLAT' + str(daily_config.focus_slit) + '.fits' flatname = 'FOCUS_FLAT.fits' scale = 25.0 / width[slit] exp_time_thar = scale * 2.0 # The exposure time in seconds. exp_time_flat = scale * 2.0 # The exposure time in seconds. b0 = 166000 # Start value for focus sequence b = 4000 # Step value i = 1 # Number of 1st exposure MAX = 13 # Number of last exposure ext = '.fits' # Extension of imagename imtype = 'FOCUS' # Set a keyvord in the header for Imagetype. imtypeflat = 'FLAT' # Set a keyvord in the header for Imagetype. pre_amp_gain = 2 # [0,1,2] = [x1, x2, x4] readoutspeed = 1 # [0,1,2,3] = [5MHz, 3MHz, 1MHz, 0.05MHz] ############################################################################## # Start the guiders and set M8 in right position # os.system( SLIT_PATH + "/slit_guider.py -t") # Stop the slit guider # os.system( "sleep 5" ) # Wait till it is initialized # os.system( SLIT_PATH + "/slit_guider.py -s") # Start the slit guider # os.system( "sleep 5" ) # Wait till it is initialized #os.system( SLIT_PATH + "/sigu.py display on") # Enable the display os.system(SLIT_PATH + "/sigu.py pause") # Do not enable the guiding #os.system( "sleep 2" ) # Wait till it is initialized #os.system( SLIT_PATH + "/sigu.py start") # Start showing the image #os.system( SLIT_PATH + "/sigu.py texp manual") # Set exposure time manually #os.system( SLIT_PATH + "/sigu.py texp 0.05") # ############################################################################## ############################################################################## # Setup and take a flat field - assume we have close to the right focus and # that we use the same slit af for the ThAr exposures. os.system(DMC_PATH + "/pst.py move -m 2 -p 3" ) # Make sure we get light to slit, not acq mirror. os.system(DMC_PATH + "/pst.py move -m 3 -p 2") # Move Iodine-cell to free. os.system(DMC_PATH + "/lamp.py halo on") # Turn on the halogen lamp os.system(DMC_PATH + "/pst.py move -m 4 -p 2") # Move input to flat field lamp os.system("%s/pst.py move -m6 -p%s" % (DMC_PATH, str(slit))) # Move slit Set_M8.set_m8_pos() # Get the M8 to the right position # Take flat field spectrum os.system("%s/c_acq.py -p%i -r%i -e%f -t%s -f%s" % (ANDOR_PATH, pre_amp_gain, readoutspeed, exp_time_flat, imtypeflat, flatname)) os.system(DMC_PATH + "/lamp.py halo off") # Turn off the halogen lamp ############################################################################## # Get the ThAr ready os.system(DMC_PATH + "/lamp.py thar on") # Turn on the ThAr lamp os.system(DMC_PATH + "/pst.py move -m 4 -p 3") # Move input to ThAr fibre. Set_M8.set_m8_pos() # Get the M8 ready for ThAr #os.system( SLIT_PATH + "/sigu.py texp 0.10") # ############################################################################## # Execute loop to take ThAr exposures at each focus value. while i <= MAX: focval = b0 + (i - 1) * b filename = "%s%04i.fits" % (name, i) os.system("%s/pst.py move -m5 -p%s" % (DMC_PATH, str(focval))) os.system("%s/c_acq.py -p%i -r%i -e%f -t%s -f%s" % (ANDOR_PATH, pre_amp_gain, readoutspeed, exp_time_thar, imtype, filename)) i = i + 1 # same as i += i.... but this is tooooo fancy! ############################################################################## # Finish off. os.system(DMC_PATH + "/lamp.py thar off") # Turn-off the ThAr lamp os.system(SLIT_PATH + "/slit_guider.py -t") # Stop the slit guider os.system("%s/pst.py move -m5 -p%s" % (DMC_PATH, str(focval0))) # Return to start focus value #os.system( DMC_PATH + "/pst.py move -m 4 -p 1") # Move to 'telescope' position ############################################################################## # Call the script that calcullates the optimum focus: return "done"
def check_pst_regexs(self, regexs, search_extensions, hunt_type, gauge_update_function=None): """ Searches a pst file for regular expressions in messages and attachments using regular expressions""" all_extensions = search_extensions['TEXT'] + search_extensions[ 'ZIP'] + search_extensions['SPECIAL'] if not gauge_update_function: pbar_widgets = [ '%s Hunt %s: ' % (hunt_type, unicode2ascii(self.filename)), progressbar.Percentage(), ' ', progressbar.Bar(marker=progressbar.RotatingMarker()), ' ', progressbar.ETA(), progressbar.FormatLabel(' %ss:0' % hunt_type) ] pbar = progressbar.ProgressBar(widgets=pbar_widgets).start() else: gauge_update_function(caption='%s Hunt: ' % hunt_type) try: apst = pst.PST(self.path) total_messages = apst.get_total_message_count() total_attachments = apst.get_total_attachment_count() total_items = total_messages + total_attachments items_completed = 0 for folder in apst.folder_generator(): for message in apst.message_generator(folder): if message.Subject: message_path = os.path.join(folder.path, message.Subject) else: message_path = os.path.join(folder.path, u'[NoSubject]') if message.Body: self.check_text_regexs(message.Body, regexs, message_path) if message.HasAttachments: for subattachment in message.subattachments: if get_ext(subattachment.Filename ) in search_extensions[ 'TEXT'] + search_extensions['ZIP']: attachment = message.get_attachment( subattachment) self.check_attachment_regexs( attachment, regexs, search_extensions, message_path) items_completed += 1 items_completed += 1 if not gauge_update_function: pbar_widgets[6] = progressbar.FormatLabel( ' %ss:%s' % (hunt_type, len(self.matches))) pbar.update(items_completed * 100.0 / total_items) else: gauge_update_function(value=items_completed * 100.0 / total_items) apst.close() except IOError: self.set_error(sys.exc_info()[1]) except pst.PSTException: self.set_error(sys.exc_info()[1]) if not gauge_update_function: pbar.finish() return self.matches
if imagetype.lower() == 'thar': try: lamp.Lamp(lamp='thar').set_on() # Might change Lamp to LAMP at some point lamp.Lamp(lamp='halo').set_off() # Might change Lamp to LAMP at some point except Exception,e: print clock.timename(), "One of the lamps was not switched correctly" pst.PST().move(3,2) # Move IODINE cell out of path pst.PST().move(4,3) # Move Calibration mirror to ThAr position elif imagetype.lower() == 'sun': try: lamp.Lamp(lamp='thar').set_off() # Might change Lamp to LAMP at some point lamp.Lamp(lamp='halo').set_off() # Might change Lamp to LAMP at some point except Exception,e: print clock.timename(), "One of the lamps was not switched correctly" pst.PST().move(3,2) # Move IODINE cell out of path pst.PST().move(4,4) # Move Calibration slide to Sun Fibre position elif imagetype.lower() == 'suni2': try: lamp.Lamp(lamp='thar').set_off() # Might change Lamp to LAMP at some point lamp.Lamp(lamp='halo').set_off() # Might change Lamp to LAMP at some point except Exception,e: print clock.timename(), "One of the lamps was not switched correctly" pst.PST().move(3,iodine_cell) # Move IODINE cell into light path pst.PST().move(4,4) # Move Calibration mirror to Sun Fiber position ### These are the same for all types of observations... pst.PST().move(1,4) # Move Filter wheel to position 4 (Free) pst.PST().move(6,8) # Move slit to right position