def set_pointing_track(self, param=0, sender=""):
        ### Checks if object is above x degrees over the horizon. If not telescope will not move.
        if int(param) > 0:
            star_handle = song_star_checker.star_pos(site=1)
            sun_handle = song_star_checker.sun_pos(site=1)
            ra_object = gettsi.get_object_equatorial_ra(sender="Mads")
            dec_object = gettsi.get_object_equatorial_dec(sender="Mads")

            sun_dist = float(
                str(sun_handle.sun_dist(ra_object, dec_object)).split(":")[0])
            sun_alt = float(str(sun_handle.sun_alt()).split(":")[0])

            #			if sun_alt >= 0.0 and sun_dist < 45.0:
            #				print "The Sun is too close to the pointing position... the telescope will not go there...!!!"
            #				return "Sun too close"

            object_alt = int(
                str(star_handle.star_alt(ra_object, dec_object)).split(":")[0])
            if object_alt < m_conf.telescope_min_altitude:  # Hardcoded limit... because of the cooling unit.
                return "Object too low"

        value = ''
        try:
            value = self.server.set_pointing_track(sender, param)
            if value != '':
                return_value = value
        except Exception, e:
            print 'Could not set pointing track!'
            return_value = e
    def __init__(self):
        """
			Initialization of the time checks.
		"""
        self.mon_time_value = song_monitor_config.mon_side_ports  # 1 = do things, 0 = do nothing.
        self.sun_handle = song_star_checker.sun_pos(
            site=m_conf.song_site)  # site=1: Tenerife
        self.verbose = song_monitor_config.verbose
        self.perform_actions = mon_actions.Do_Actions()
    def weather_check(self, deduced=0):
        """
         @breif: This function will return a value which corresponds to the weather conditions at the given time. 
      """
        imp.reload(song_checker_config)

        weather_value = 0

        sun_handle = song_star_checker.sun_pos(
            site=m_conf.song_site)  # site=1: Tenerife

        tmp_time_str2 = datetime.datetime.strptime(
            str(
                song_star_checker.sun_pos(
                    site=m_conf.song_site).sun_set_next()),
            "%Y/%m/%d %H:%M:%S")
        time_diff = tmp_time_str2 - datetime.datetime.utcnow()
        hours_to_next_sun_set = int(
            time_diff.days) * 24. + time_diff.seconds / (
                24. * 3600.) * 24  # Time until next sunset in seconds

        try:
            conn = psycopg2.connect(
                "host='%s' dbname='%s' user='******' password='******'" %
                (m_conf.db_host, m_conf.data_db, m_conf.db_user,
                 m_conf.db_password))
            curr = conn.cursor()
            weather_output = self.get_fields(curr, "weather_station", [
                "ins_at", "wxt520_temp1", "wxt520_humidity", "wxt520_pressure",
                "wxt520_rain_int", "drd11_rain", "wxt520_wind_speed",
                "wxt520_wind_direction", "wxt520_wind_avg",
                "wxt520_wind_avgdir", "bw_cloud_cond", "bw_rain_cond",
                "bw_sky_cond", "bw_wind_cond", "bw_delta_temp", "bw_temp_amb",
                "bw_windspeed", "bw_wetsensor", "bw_rainsensor", "bw_humidity",
                "bw_dewp_temp", "bw_temp_case", "bw_day_cond", "bw_day_inten",
                "dust_level"
            ])
            time_diff = datetime.datetime.utcnow() - weather_output["ins_at"]
            time_diff = time_diff.days * 24 * 3600 + time_diff.seconds
        except Exception, e:
            print clock.timename(), " Error: ", e
示例#4
0
    def __init__(self):

        #gc.disable()
        #gc.enable()
        #gc.get_threshold

        self.check_handle = central_song_checker.Checker(
        )  # Add posibility to select site to checker.
        self.check_star = song_star_checker.star_pos(site=conf.song_site)
        self.sun_handle = song_star_checker.sun_pos(
            site=conf.song_site)  # Tenerife sun handle
        self.hostname = socket.gethostname()
    def open_time(self, site=site_param):
        """
         @brief: This will return a value about opening time at the begining of every night.
      """
        imp.reload(song_checker_config)
        time_value = 0

        if song_star_checker.sun_pos(
                site).sun_set_next() < m_conf.side_port_open_time:
            time_value = 1

        return time_value
示例#6
0
    def __init__(self):
        """
			Initialization of the time checks.
		"""
        self.mon_time_value = song_monitor_config.mon_time  # 1 = do things, 0 = do nothing.
        self.sun_handle = song_star_checker.sun_pos(
            site=m_conf.song_site)  # site=1: Tenerife
        self.verbose = song_monitor_config.verbose
        self.perform_actions = mon_actions.Do_Actions()
        self.skycam_start = m_conf.start_skycam_movie
        self.local_mode = 0
        self.sms_send = 0
        self.check_ors = 0
        self.open_mirror_covers = 0
        self.bad_weather_sms = 0
        self.scheduler_val = 0
        self.local_mode_sms = 0
        self.x_mas_notify = 0
    def __init__(self):
        """
			Initialization of the weather checks.
		"""

        self.test = song_monitor_config.weather_test

        self.check_handle = song_checker.Checker()
        self.perform_actions = mon_actions.Do_Actions()
        self.sun_handle = song_star_checker.sun_pos(
            site=m_conf.song_site)  # site=1: Tenerife

        self.verbose = song_monitor_config.verbose  # yes or no

        try:
            value1 = self.check_weather(
                deduced_value=song_monitor_config.weather_deduced)
        except Exception, e:
            value1 = 1
    def day_check(self, site=site_param):
        """
         @brief: This function will determine whether it is day, night or twilight. 
      """
        imp.reload(song_checker_config)

        day_value = 0

        sun_alt_str = str(
            song_star_checker.sun_pos(site=m_conf.song_site).sun_alt())

        if sun_alt_str[0] == '-':
            sun_alt = float(sun_alt_str.split(':')[0]) - float(
                sun_alt_str.split(':')[1]) / 60.0 - float(
                    sun_alt_str.split(':')[2]) / 3600.0
        elif sun_alt_str[0] != '-':
            sun_alt = float(sun_alt_str.split(':')[0]) + float(
                sun_alt_str.split(':')[1]) / 60.0 + float(
                    sun_alt_str.split(':')[2]) / 3600.0

        #print "Altitude of the Sun is: %f at %s" % (sun_alt, clock.obstimeUT())

        if sun_alt < -18.0:  # Night
            day_value = -1

        if sun_alt >= -18.0 and sun_alt < -12.0:  # Astronomical twilight
            day_value = 1

        if sun_alt >= -12.0 and sun_alt < -6.0:  # Nautical twilight
            day_value = 2

        if sun_alt >= -6.0 and sun_alt < -0.5:  # Civil twilight
            day_value = 3

        if sun_alt >= -0.5:  # Day
            day_value = 4

        return day_value
示例#9
0
import send_song_mail
import get_db_values
import beating_heart
import songwriter_xmlrpcclient
import songwriter_MFA_client
import glob

import xmlrpclib

#attempt connection to server
isong_server = xmlrpclib.ServerProxy('http://%s:%s' %
                                     ("iodinepipe.kvmtenerife.prv", 8050))

clock = song_timeclass.TimeClass()

sun_handle = song_star_checker.sun_pos(
    site=m_conf.song_site)  # site=1: Tenerife

gettsi = comm2tcs_read.GET_TSI()
settsi = comm2tcs_write.SET_TSI()

pdu_handle = pdu_module.APC()


class daily_daemon(Daemon):
    """
		@brief: This class inherits Daemon from song.py and daemonizes the code.
	"""
    def run(self):
        """
			@brief: This function overwrites the run function in song.py.
		"""
示例#10
0
import time
import psycopg2
import datetime
import master_config as m_conf
import song_timeclass
import song_star_checker

clock = song_timeclass.TimeClass()
sun_handle = song_star_checker.sun_pos()

def select_ORs(date):
	start_time = str(sun_handle.sun_rise_pre()).replace("/", "-")
	stop_time = str(sun_handle.sun_set_next()).replace("/", "-")

	try:
		conn = psycopg2.connect("host='%s' dbname='%s' user='******' password='******'" % (m_conf.db_c_host, m_conf.or_db, m_conf.db_user, m_conf.db_password))
		curr = conn.cursor()	
		curr.execute("SELECT object_name, start_window, stop_window, req_no, req_chain_previous FROM obs_request_1 WHERE start_window >= '%s' and stop_window <= '%s' AND stop_window > '%s' ORDER BY start_window ASC, req_prio DESC" % (str(start_time), str(stop_time), str(datetime.datetime.utcnow())))
		numb_of_rows = curr.rowcount
		output = curr.fetchall()
		return output, numb_of_rows
	except Exception,e:
		print e

	return 1	

def Check_Daytime(date):

	ready_ORs = select_ORs(date)
	
	if ready_ORs[1] == 0:
示例#11
0
    def run(self):
        """
		
		"""
        done_log_param = 0
        global RUNNING
        RUNNING = True

        #self.selector = selector.SELECTOR()
        #self.insertor = insertor
        self.sun_handle = song_star_checker.sun_pos(
            site=m_conf.song_site)  # Tenerife sun handle
        self.daily_update = 0
        self.daily_sun_insert = 0

        val = beating_heart.start_heartbeat(job_id=m_conf.conductor_id)

        over_all_obs_state = get_database_values(table_name='tel_dome',
                                                 fields=['extra_param_1'])

        gc.disable()

        process = psutil.Process(os.getpid())
        print("Memory used in percent : %0.3f" %
              float(process.memory_percent()))
        mem = process.memory_info()
        mem_old = (float(mem.vms) / float(2**20))

        print ""
        print clock.timename(), "The Conductor was started!\n"
        print clock.timename(
        ), "The over all observing state was: ", over_all_obs_state[
            'extra_param_1']

        while RUNNING:

            if int(
                    float(
                        datetime.datetime.strftime(
                            datetime.datetime.utcnow(),
                            "%H"))) < 9 and self.sun_handle.sun_alt(
                                unit='f') < 0.0:
                yesterday = datetime.datetime.utcnow() - datetime.timedelta(
                    days=1)
                folder_date = yesterday.strftime('%Y-%m-%d')
            else:
                folder_date = datetime.datetime.strftime(
                    datetime.datetime.utcnow(), "%Y-%m-%d")

#			print "Checking the date: %s" % (str(folder_date))

###################### DAY TIME CHECK ################################
            if int(
                    float(
                        datetime.datetime.strftime(
                            datetime.datetime.utcnow(),
                            "%H"))) < 10 and self.sun_handle.sun_alt(
                                unit='f') > 1.0:
                try:
                    daytime_obs = check_daytime.Check_Daytime(folder_date)
                except Exception, e:
                    print clock.timename(), e
                else:
                    if daytime_obs == 0 and self.daily_sun_insert == 0:
                        print clock.timename(
                        ), "The Solar observations were not inserted yet. Will do now"
                        try:
                            #insertor.insert_solar_observations()
                            insertor.insert_solar_observations_soda()
                        except Exception, e:
                            print clock.timename(
                            ), "Did not call the check-for-gaps function"
                            print clock.timename(), e
                        else:
                            self.daily_sun_insert = 1

                if conf.check_for_timecritical == "yes" and self.daily_update == 0:

                    st = datetime.datetime.utcnow()
                    se = datetime.datetime.utcnow() + datetime.timedelta(
                        days=1)
                    try:
                        selected_target = selector.SELECTOR().determine_next(
                            timegap=[st, se],
                            project_critical_type=["timecritical"])
                    except Exception, e:
                        print clock.timename(
                        ), "Problem in the selector.determine_next function..."
                        print clock.timename(), e
                    else:
                        if selected_target != None:
                            # Checking if they are already inserted:
                            ids = []
                            names = []
                            for tmp_or in selected_target:
                                ids.append(tmp_or[1])
                                names.append(tmp_or[2])
                            check_val = check_daytime.check_timecritical(
                                folder_date, ids)
                            if check_val == 0:
                                for tcrit_target in selected_target:
                                    insertor.insert_timecritical_OR(
                                        pre_obs_spec_id=tcrit_target[1])
                                try:
                                    send_song_mail.send_mail(
                                    ).sending_an_email(
                                        reciever=["mads", "frank"],
                                        sender="SONG_MS",
                                        subject="Time critical OR inserted",
                                        message=
                                        "The conductor has inserted time critical OR(s) for the coming night.\nObject(s): %s\n"
                                        % str(names))
                                except Exception, e:
                                    print "Could not send e-mail on time critical insertion..."
import daily_logging_handler
import datetime
import master_config as m_conf
import beating_heart
import red_ccd_config as conf
import andorsetup
import numpy
import multiprocessing
import threading
import datasave

global cam
ac_one_im = ImageClass.imClass()
cam_functions = ccd_functions.CamFunctions()
clock = song_timeclass.TimeClass()
sun_handle = song_star_checker.sun_pos(site=m_conf.song_site)

class RequestHandler(SimpleXMLRPCRequestHandler):
   """
      Some XMLPRC-magic here. This is needed, and cannot be left out. Check the documentation?
   """
   rpc_paths = ('/RPC2')

def is_alive():
   """
      The PING function
   """
   return 1

def get_settings(id):
   """
示例#13
0
                     weather_output["wxt520_temp1"]
                 ) <= song_checker_config.min_temp:  # Temperature from WXT520
            weather_value = weather_value + 1
        if float(weather_output["wxt520_humidity"]
                 ) >= song_checker_config.max_hum:  # Humidity from WXT520.
            weather_value = weather_value + 2
        if float(
                weather_output["wxt520_wind_avg"]
        ) >= song_checker_config.max_w_speed:  # Wind speed from WXT520.
            weather_value = weather_value + 4
        elif song_checker_config.use_bw_for_wind == "yes" and float(
                weather_output["bw_windspeed"]
        ) >= song_checker_config.max_w_speed_into:
            weather_value = weather_value + 4

        sun_alt_str = str(song_star_checker.sun_pos().sun_alt())

        if sun_alt_str[0] == '-':
            sun_alt = float(sun_alt_str.split(':')[0]) - float(
                sun_alt_str.split(':')[1]) / 60.0 - float(
                    sun_alt_str.split(':')[2]) / 3600.0
        elif sun_alt_str[0] != '-':
            sun_alt = float(sun_alt_str.split(':')[0]) + float(
                sun_alt_str.split(':')[1]) / 60.0 + float(
                    sun_alt_str.split(':')[2]) / 3600.0

##### I am using the telescope azimuth in stead of dome azimuth since I am not sure this only goes from 0 to 360. ####
        if float(
                weather_output["wxt520_wind_avg"]
        ) >= song_checker_config.max_w_speed_into and (
                numpy.abs(
示例#14
0
        ################################ If the acquisition is a test no connection to the database is made ##################
        else:
            epoch = 2000
            magnitude = 00
            observer = 'Unknown'
            project_name = 'Unknown'
            project_id = 0
            obs_mode = 'Unknown'
            site_value = 1
            site_name = "Observatorio del Teide"
            site_lat = m_conf.lat_obs
            site_lon = m_conf.lon_obs
            site_elev = m_conf.elev_obs
            site_note = "Node 1"
            sun_handle = song_star_checker.sun_pos(site=site_value)
            sun_ra = sun_handle.sun_ra()
            sun_dec = sun_handle.sun_dec()
            object_name = 'Unknown'
            ra_pm = 0.0
            dec_pm = 0.0

            if obj_ra == '':
                obj_ra = "00:00:00"
            if obj_dec == '':
                obj_dec = "00:00:00"
            ra_object = str(obj_ra)  #'06:44:8.9'
            dec_object = str(obj_dec)  #-16:42:58'
            ra_h = str(obj_ra).split(":")[0]
            ra_m = str(obj_ra).split(":")[1]
            ra_s = str(obj_ra).split(":")[2]