Source code for mds_api.mds_measurements

"""Additional functionality for MDS: measurements"""

import json
import math
import re


from mds_api import client
from mds_api.NetworkConfiguration import NetworkConfiguration

[docs] def add_lvlh_frame_measurement(measurement_name: str, reference_sat: str, target_sat: str, description: str = "") -> bytes: """ Add LVLH measurement, which measures the target's position and veocity in LVLH frame of the reference sat. Args: measurement_name (str): Name, by which you're going to call your measurement reference_sat (str): reference satellite name, in whose frame measurements are carried out. target_sat (str): target satellite name description (str): an optional description if you want to attach it to your measurement. Defaults to just empty string. """ data = {} data["action"]="add" data["name"]=measurement_name data["kind"]="lvlh_frame" data["reference_sat"] = reference_sat data["target_sat"] = target_sat data["description"] = description json_data = json.dumps(data) response = client.update_measurement(NetworkConfiguration.MDS_HOST, NetworkConfiguration.MDS_HOST_PORT, json_data) return response
[docs] def remove_lvlh_frame_measurement(measurement_name: str) -> bytes: """ Remove LVLH frame measruement. Args: measurement_name (str): Name of the measurement you want to remove """ data = {} data["action"]="remove" data["name"]=measurement_name data["kind"]="lvlh_frame" json_data = json.dumps(data) response = client.update_measurement(NetworkConfiguration.MDS_HOST, NetworkConfiguration.MDS_HOST_PORT, json_data) return response
[docs] def retrieve_lvlh_frame_measurements(measurement_name: str | list | None = None) -> bytes: """ Retrive measurement data of one or multiple measurements. Args: measurement_name (str or List or None): Name or list of names of measurements you want to retrieve data from. If not specified, defaults to None, in which case you are going to receive data of all measurements that are there. Returns: - julian date of when the measurement was taken - a dict, representing data of measurements. You can access a particular measurement by using its name as a key. """ data = {} data["kind"]="lvlh_frame" if (measurement_name is not None): mn = measurement_name if (not isinstance(mn, list)): mn = [mn] for n in range(len(mn)): data["name"+str(n)] = mn[n] json_data = json.dumps(data) jd, json_response = client.retrieve_measurement(NetworkConfiguration.MDS_HOST, NetworkConfiguration.MDS_HOST_PORT, json_data) jsonDict = json.loads(json_response) count = int(jsonDict["Count"]) rval = {jsonDict["Keys"][n]:jsonDict["Values"][n] for n in range(count)} return jd, rval
[docs] def add_single_spacecraft_measurement(measurement_name: str, reference_sat: str, description: str = "") -> bytes: """ Add single spacecraft, which measures the target's position and veocity in LVLH frame of the reference sat. Args: measurement_name (str): Name, by which you're going to call your measurement reference_sat (str): reference satellite name, in whose frame measurements are carried out. description (str): an optional description if you want to attach it to your measurement. Defaults to just empty string. """ data = {} data["action"]="add" data["name"]=measurement_name data["kind"]="single_spacecraft" data["reference_sat"] = reference_sat data["description"] = description json_data = json.dumps(data) response = client.update_measurement(NetworkConfiguration.MDS_HOST, NetworkConfiguration.MDS_HOST_PORT, json_data) return response
[docs] def remove_single_spacecraft_measurement(measurement_name: str) -> bytes: """ Remove single spacecraft measurement. Args: measurement_name (str): Name of the measurement you want to remove """ data = {} data["action"]="remove" data["name"]=measurement_name data["kind"]="single_spacecraft" json_data = json.dumps(data) response = client.update_measurement(NetworkConfiguration.MDS_HOST, NetworkConfiguration.MDS_HOST_PORT, json_data) return response
[docs] def retrieve_single_spacecraft_measurements(measurement_name: str | list | None = None) -> bytes: """ Retrive measurement data of one or multiple measurements. Args: measurement_name (str or List or None): Name or list of names of measurements you want to retrieve data from. If not specified, defaults to None, in which case you are going to receive data of all measurements that are there. Returns: - julian date of when the measurement was taken - a dict, representing data of measurements. You can access a particular measurement by using its name as a key. """ data = {} data["kind"]="single_spacecraft" if (measurement_name is not None): mn = measurement_name if (not isinstance(mn, list)): mn = [mn] for n in range(len(mn)): data["name"+str(n)] = mn[n] json_data = json.dumps(data) jd, json_response = client.retrieve_measurement(NetworkConfiguration.MDS_HOST, NetworkConfiguration.MDS_HOST_PORT, json_data) jsonDict = json.loads(json_response) count = int(jsonDict["Count"]) rval = {jsonDict["Keys"][n]:jsonDict["Values"][n] for n in range(count)} return jd, rval