Example #1
0
def regenerateGP(server, gp_in):
    global gp_wrapper
    server.latestGP["pending"] = True

    if len(tmp_global_of_caseSpecificParams.keys()) <= 1:  # one set by default
        print(
            "This should be set as part of remote configuration &/or periodic update before GP used."
        )
        raise Exception

    curr_time_dt = datetime.now() if gp_in[0] is None else gp_in[0]

    #  get already existing sim route containers that need to be fed to the global planner
    existing_rt_conts = server.plan_db.get_filtered_sim_routes(
        curr_time_dt, filter_opt='partially_within')

    #  get the satellite states at the beginning of the planning window
    sat_state_by_id = server.plan_db.get_sat_states(curr_time_dt)

    global latest_gp_route_indx
    new_rt_conts, latest_gp_route_indx = gp_wrapper.run_gp(
        curr_time_dt, existing_rt_conts,
        tmp_global_of_caseSpecificParams['sim_case_config']['sim_gsn_ID'],
        latest_gp_route_indx, sat_state_by_id, all_windows_dict,
        tmp_global_of_caseSpecificParams)

    server.latestGP = {
        "plan": [new_rt_conts, latest_gp_route_indx],
        "windows": all_windows_dict,
        "timestamp": tt.date_string(datetime.now()),
        "pending": False
    }
Example #2
0
    def __init__(self,
                 port,
                 log_pathName=None,
                 printVerbose=PrintVerbosity.ALL):
        Thread.__init__(self)
        self.port = port

        # self.messages_to_pass = queue.Queue(0)
        self.messages_to_pass = [
            queue.Queue(0) for n in range(0, 4)
        ]  # sim, sats[live conn], local, sats[not live conn] : high to lo priority
        self.outgoingMessageQueue = {
            'sim': queue.Queue(0)
        }  # queue added for other dest-IDs when discovered

        self.printVerbose = printVerbose

        # self.queue_lock = False  For later, use this while clearing to prevent more incoming messages
        self.node_server = None
        self.SHUTDOWN_REQ = False

        self.logPathName = None
        if (log_pathName.rpartition('/')[0] != ''
                and log_pathName.rpartition('/')[2] != ''):
            if os.path.isdir(log_pathName.rpartition('/')[0]):
                self.logPathName = log_pathName
                self.__print_live("Logging at: {}".format(self.logPathName))
                logging.basicConfig(filename=self.logPathName,
                                    level=logging.DEBUG)
                logging.warn("Log started at: {}".format(self.logPathName))
        # else, log_pathName isFile

        if not self.logPathName:
            self.__print_live("Logging location invalid, NOT enabled.")

        self.latestGP = {
            "plan": None,
            "windows": None,
            "timestamp": tt.date_string(datetime.now()),
            "pending": False
        }

        self.act_timing_helper = None
        self.plan_db = None
    def get_route_string(self, time_base=None):
        #  note that this function uses the mutable start and end for all the windows.  because activity windows are shared across the whole constellation simulation, these won't necessarily be correct times for every satellite

        out_string = ""

        for wind in self.route:

            if type(wind) == ObsWindow:
                start_str = "%.0fs" % (wind.start - time_base).total_seconds(
                ) if time_base else tt.date_string(wind.start,
                                                   self.output_date_str_format)
                end_str = "%.0fs" % (wind.end - time_base).total_seconds(
                ) if time_base else tt.date_string(wind.end,
                                                   self.output_date_str_format)
                wind_type = ' inj' if wind.injected else ''
                out_string += "o%s %d s%d dv %.0f %s,%s" % (
                    wind_type, wind.window_ID, wind.sat_indx, wind.data_vol,
                    start_str, end_str)
            elif type(wind) == XlnkWindow:
                start_str = "%.0fs" % (wind.start - time_base).total_seconds(
                ) if time_base else tt.date_string(wind.start,
                                                   self.output_date_str_format)
                end_str = "%.0fs" % (wind.end - time_base).total_seconds(
                ) if time_base else tt.date_string(wind.end,
                                                   self.output_date_str_format)
                sat_indx = self.window_start_sats[wind]
                # xsat_indx=wind.xsat_indx  if self.window_start_sats[wind] == wind.sat_indx else wind.sat_indx
                xsat_indx = wind.get_xlnk_partner(self.window_start_sats[wind])
                out_string += " -> x %d s%d,xs%d dv %.0f %s,%s" % (
                    wind.window_ID, sat_indx, xsat_indx, wind.data_vol,
                    start_str, end_str)
            elif type(wind) == DlnkWindow:
                start_str = "%.0fs" % (wind.start - time_base).total_seconds(
                ) if time_base else tt.date_string(wind.start,
                                                   self.output_date_str_format)
                end_str = "%.0fs" % (wind.end - time_base).total_seconds(
                ) if time_base else tt.date_string(wind.end,
                                                   self.output_date_str_format)
                sat_indx = wind.sat_indx
                out_string += " -> d %d s%d dv %.0f %s,%s" % (
                    wind.window_ID, sat_indx, wind.data_vol, start_str,
                    end_str)

        return out_string
Example #4
0
def recalculateLinkDatarates():
    global tmp_global_of_caseSpecificParams

    link_input_data = {
        "sim_case_config": {
            "scenario_params": {
                "start_utc":
                tt.date_string(
                    tmp_global_of_caseSpecificParams['sim_run_params']
                    ['start_utc_dt']),
                "lookup_params":
                tmp_global_of_caseSpecificParams['sim_case_config']
                ['scenario_params']['lookup_params']
            }
        },
        "orbit_prop_data":
        tmp_global_of_caseSpecificParams['orbit_prop_params']
        ['orbit_prop_data'],
        'constellation_config': {
            "constellation_definition": {
                "constellation_params": {
                    "num_satellites":
                    tmp_global_of_caseSpecificParams['orbit_prop_params']
                    ['sat_params']['num_satellites'],
                    "sat_id_prefix":
                    tmp_global_of_caseSpecificParams['orbit_prop_params']
                    ['sat_params']['sat_id_prefix'],
                    "sat_ids":
                    tmp_global_of_caseSpecificParams["orbit_prop_params"]
                    ["sat_params"]["sat_ids"],
                    "sat_id_order":
                    tmp_global_of_caseSpecificParams['orbit_prop_params']
                    ['sat_params']['sat_id_order']  # a real test vs 'default'!
                }
            }
        },
        'gs_network_config': {
            "network_definition": {
                "gs_net_params": {
                    "num_stations":
                    len(tmp_global_of_caseSpecificParams["orbit_prop_params"]
                        ["gs_params"]["stations"]),
                    "stations":
                    tmp_global_of_caseSpecificParams["orbit_prop_params"]
                    ["gs_params"]["stations"]
                }
            }
        },
        'ops_profile_config': {
            "ops_profile_params": {
                "obs_params": {
                    "num_targets":
                    len(tmp_global_of_caseSpecificParams["orbit_prop_params"]
                        ["obs_params"]["targets"]),
                },
                "link_disables": {
                    "dlnk_direc_disabled_gs_ID_by_sat_IDstr":
                    tmp_global_of_caseSpecificParams["orbit_link_params"]
                    ["link_disables"]
                    ["dlnk_direc_disabled_gs_ID_by_sat_IDstr"],
                    "xlnk_direc_disabled_xsat_ID_by_sat_IDstr":
                    tmp_global_of_caseSpecificParams["orbit_link_params"]
                    ["link_disables"]
                    ["xlnk_direc_disabled_xsat_ID_by_sat_IDstr"]
                }
            }
        },
        'sim_general_config': {
            "general_sim_params": {
                "general_link_params":
                tmp_global_of_caseSpecificParams["orbit_link_params"]
                ["general_link_params"]
            }
        },
        'sat_config':
        tmp_global_of_caseSpecificParams['sat_config']
    }

    output = simple_link_calc.py_links_wrapper(link_input_data)
    tmp_global_of_caseSpecificParams['data_rates_params'] = output[0]
Example #5
0
def loadFromLocalConfig(case_name="ONLINE_OPS"):

    sim_case_config_FILENAME = PATH_TO_INPUTS + '/cases/' + case_name + '/sim_case_config.json'
    constellation_config_FILENAME = PATH_TO_INPUTS + '/cases/' + case_name + '/constellation_config.json'
    gs_network_config_FILENAME = PATH_TO_INPUTS + '/cases/' + case_name + '/ground_station_network_config.json'
    opsProfile_config_FILENAME = PATH_TO_INPUTS + '/cases/' + case_name + '/operational_profile_config.json'

    sim_gen_config_FILENAME = PATH_TO_INPUTS + '/general_config/sim_general_config.json'

    # -------- CASE SPECIFIC CONFIGURATION INPUTS -------- #
    with open(sim_case_config_FILENAME, 'r') as f:
        sim_case_config = json.load(f)
    with open(constellation_config_FILENAME, 'r') as f:
        constellation_config = json.load(f)
    with open(gs_network_config_FILENAME, 'r') as f:
        gs_network_config = json.load(f)
    with open(opsProfile_config_FILENAME, 'r') as f:
        opsProfile_config = json.load(f)

    sat_ref_model_FILENAME = PATH_TO_INPUTS + '/reference_model_definitions/sat_refs/' + constellation_config[
        "constellation_definition"]["default_sat_ref_model_name"] + '.json'
    with open(sat_ref_model_FILENAME, 'r') as f:
        sat_ref_model = json.load(f)

    payload_ref_model_FILENAME = PATH_TO_INPUTS + '/reference_model_definitions/payload_refs/' + sat_ref_model[
        "sat_model_definition"]["default_payload_ref_model_name"] + '.json'
    with open(payload_ref_model_FILENAME, 'r') as f:
        payload_ref_model = json.load(f)

    # -------- General Config ------ #
    with open(sim_gen_config_FILENAME, 'r') as f:  # move to constructor
        sim_gen_config = json.load(f)

    # Peel off outer layer(s)
    scenario_params = sim_case_config['scenario_params']
    general_sim_params = sim_gen_config['general_sim_params']
    ops_profile_params = opsProfile_config['ops_profile_params']
    constellation_params = constellation_config["constellation_definition"][
        'constellation_params']
    gs_network_definition = gs_network_config['network_definition']

    sat_model_definition = sat_ref_model['sat_model_definition']
    payload_params = payload_ref_model['payload_model_definition'][
        'payload_params']

    ######### ---------- Build orbit_prop_params ---------- #########
    append_power_params_with_enumeration = {
        "power_consumption_W": {
            **sat_model_definition['sat_model_params']['power_params']["power_consumption_W"], "obs":
            payload_params["power_consumption_W"]["obs"]
        },
        "battery_storage_Wh":
        sat_model_definition['sat_model_params']['power_params']
        ["battery_storage_Wh"],
        'sat_ids':
        constellation_params['sat_ids'],
        'sat_id_prefix':
        constellation_params['sat_id_prefix'],
    }
    append_data_params_with_enumeration = {
        **sat_model_definition['sat_model_params']['data_storage_params'],
        'sat_ids':
        constellation_params['sat_ids'],
        'sat_id_prefix':
        constellation_params['sat_id_prefix'],
    }
    append_state_params_with_enumeration = {
        **sat_model_definition['sat_model_params']['initial_state'],
        'sat_ids':
        constellation_params['sat_ids'],
        'sat_id_prefix':
        constellation_params['sat_id_prefix'],
    }

    power_params_by_sat_id, all_sat_ids1 = io_tools.unpack_sat_entry_list(
        [append_power_params_with_enumeration], output_format='dict')
    data_storage_params_by_sat_id, all_sat_ids2 = io_tools.unpack_sat_entry_list(
        [append_data_params_with_enumeration], output_format='dict')
    initial_state_by_sat_id, all_sat_ids3 = io_tools.unpack_sat_entry_list(
        [append_state_params_with_enumeration], output_format='dict')

    if case_name == "ONLINE_OPS":
        scenario_params['start_utc'] = tt.date_string(datetime.now())
        scenario_params['end_utc'] = tt.date_string(datetime.now() + timedelta(
            minutes=horizon_len_m))
        print("Time range: {} -> {}".format(scenario_params['start_utc'],
                                            scenario_params['end_utc']))

    orbit_prop_params = {
        'scenario_params': {
            'start_utc': scenario_params[
                'start_utc'],  # These duplications accomodate runner_gp.py expectations
            'end_utc': scenario_params[
                'end_utc'],  # TODO - update runner_gp.py to expect non-duplicated input 
            'start_utc_dt': tt.iso_string_to_dt(scenario_params['start_utc']),
            'end_utc_dt': tt.iso_string_to_dt(scenario_params['end_utc']),
            'timestep_s': general_sim_params["timestep_s"]
        },
        'sat_params': {
            'num_sats': constellation_params['num_satellites'],
            'num_satellites': constellation_params[
                'num_satellites'],  # Duplication to accomodate downstream (runner_gp.py among others) -- TODO: cut out duplication
            'sat_id_order': constellation_params['sat_id_order'],
            'sat_id_prefix': constellation_params['sat_id_prefix'],
            'pl_data_rate': payload_params['payload_data_rate_Mbps'],
            'payload_data_rate_Mbps': payload_params[
                'payload_data_rate_Mbps'],  # Duplication to accomodate downstream (runner_gp.py among others) -- TODO: cut out duplication
            'power_params_by_sat_id': power_params_by_sat_id,
            'power_params': [
                append_power_params_with_enumeration
            ],  # Duplication to accomodate downstream (runner_gp.py among others) -- TODO: cut out duplication
            'data_storage_params_by_sat_id': data_storage_params_by_sat_id,
            'data_storage_params': [
                append_data_params_with_enumeration
            ],  # Duplication to accomodate downstream (runner_gp.py among others) -- TODO: cut out duplication 
            'initial_state_by_sat_id': initial_state_by_sat_id,
            'initial_state': [
                append_state_params_with_enumeration
            ],  # Duplication to accomodate downstream (runner_gp.py among others) -- TODO: cut out duplication 
            'activity_params': {
                **sat_model_definition['sat_model_params']["activity_params"], "min_duration_s":
                {
                    **payload_params["min_duration_s"],
                    **sat_model_definition['sat_model_params']["activity_params"]["min_duration_s"]
                },
                "intra-orbit_neighbor_direction_method":
                constellation_params["intra-orbit_neighbor_direction_method"]
            }
        },
        'gs_params': {
            'gs_network_name':
            gs_network_definition["gs_net_params"]['gs_network_name'],
            'num_stations':
            gs_network_definition["gs_net_params"]["num_stations"],
            'num_gs':
            gs_network_definition["gs_net_params"]
            ["num_stations"],  # TODO: LOL are you serious right now. Get rid of this duplication.
            'stations':
            gs_network_definition["gs_net_params"]["stations"]
        },
        'obs_params': ops_profile_params['obs_params'],
        'orbit_params': {
            'sat_ids_by_orbit_name':
            io_tools.expand_orbits_list(constellation_params['orbit_params'],
                                        constellation_params['sat_id_prefix']),
            'sat_orbital_elems':
            constellation_params['orbit_params']['sat_orbital_elems']
        },
        'orbit_prop_data':
        None  # orbit_prop_data   # now from repropagateSats()
    }

    # make the satellite ID order. if the input ID order is default, then will assume that the order is the same as all of the IDs found in the power parameters
    orbit_prop_params['sat_params'][
        'sat_id_order'] = io_tools.make_and_validate_sat_id_order(  # Pay close attention to this, because this is a mutated copy
            orbit_prop_params['sat_params']['sat_id_order'],
            orbit_prop_params['sat_params']['sat_id_prefix'],
            orbit_prop_params['sat_params']['num_sats'], all_sat_ids1)

    io_tools.validate_ids(
        validator=orbit_prop_params['sat_params']['sat_id_order'],
        validatee=all_sat_ids1)
    io_tools.validate_ids(
        validator=orbit_prop_params['sat_params']['sat_id_order'],
        validatee=all_sat_ids2)
    io_tools.validate_ids(
        validator=orbit_prop_params['sat_params']['sat_id_order'],
        validatee=all_sat_ids3)

    gs_id_order = io_tools.make_and_validate_gs_id_order(
        orbit_prop_params['gs_params'])
    orbit_prop_params['gs_params']['gs_id_order'] = gs_id_order
    orbit_prop_params['gs_params'][
        'elevation_cutoff_deg'] = gs_network_definition["gs_net_params"][
            "elevation_cutoff_deg"]

    obs_target_id_order = io_tools.make_and_validate_target_id_order(
        orbit_prop_params['obs_params'])
    orbit_prop_params['obs_params'][
        'obs_target_id_order'] = obs_target_id_order
    ######### ---------- End Build orbit_prop_params ---------- #########

    params = {
        'sim_case_config': {
            'scenario_params':
            scenario_params,  # simulation.params['sim_case_config'],
            'sim_gsn_ID': 'gsn'  # self.sim_gsn.ID
        },
        'orbit_prop_params':
        orbit_prop_params,  # simulation.params['orbit_prop_params'],
        'orbit_link_params': {
            "link_disables": ops_profile_params["link_disables"],
            "general_link_params": general_sim_params["general_link_params"]
        },
        'data_rates_params':
        None,  # simulation.params['data_rates_params'],   # now from recalculateLinkDatarates()
        'sim_run_params': {
            "start_utc_dt": tt.iso_string_to_dt(scenario_params['start_utc']),
            "end_utc_dt": tt.iso_string_to_dt(scenario_params['end_utc'])
        },
        'sat_config': {
            'sat_model_definition':
            sat_model_definition  # simulation.params['sat_config'],  # 'sat_model_definition' : data['sat_ref_model']['sat_model_definition']
        },
        'sim_gen_config':
        general_sim_params,  # simulation.params['sim_gen_config'],
        'gp_general_params': tmp_global_of_caseSpecificParams[
            'gp_general_params']  # carrying over from initial setup
    }

    return params
Example #6
0
 def __repr__(self):
     wind_type = 'inj ' if self.injected else ''
     return  "(ObsWindow id %d %ssat %d dv %f targs %s %s,%s)" % (self.window_ID, wind_type, self.sat_indx,  self.data_vol,str(self.target_IDs),tt.date_string(self.start,self.output_date_str_format),tt.date_string(self.end,self.output_date_str_format))
Example #7
0
 def __repr__(self):
     return  "(EclipseWindow id %d %s,%s)" % ( self.window_ID,tt.date_string(self.start,self.output_date_str_format),tt.date_string(self.end,self.output_date_str_format))
Example #8
0
 def __repr__(self):
     if self.symmetric:
         return  "(XlnkWindow id %d sym. sats %d<->%d dv %f %s,%s)" % (self.window_ID,self.sat_indx, self.xsat_indx,self.data_vol, tt.date_string(self.start,self.output_date_str_format),tt.date_string(self.end,self.output_date_str_format))
     else:
         return  "(XlnkWindow id %d uni. sats %d->%d dv %f %s,%s)" % (self.window_ID,self.tx_sat, self.get_xlnk_partner(self.tx_sat),self.data_vol, tt.date_string(self.start,self.output_date_str_format),tt.date_string(self.end,self.output_date_str_format))
Example #9
0
 def __repr__(self):
     return  "(DlnkWindow id %d sat %d dv %f gs %d %s,%s)" % (self.window_ID,self.sat_indx,  self.data_vol, self.gs_indx,tt.date_string(self.start,self.output_date_str_format),tt.date_string(self.end,self.output_date_str_format))