def interpolate_ephemeris(source_frame, times, states, num_points, dest_frame, interp_start, interp_end, step_size): """ Interpolates the given state vectors. Args: source_frame: Source reference frame ("EME2000", "GCRF", "ICRF", "ITRF", "MOD", "TOD", or "TEME"). times: Time strings of state vectors to interpolate. states: State vectors to interpolate. num_points: Number of states to use for interpolation. dest_frame: Destination reference frame ("EME2000", "GCRF", "ICRF", "ITRF", "MOD", "TOD", or "TEME"). interp_start: Interpolation start time. interp_end: Interpolation end time. step_size: Interpolation step size [s]. Returns: Interpolated time strings and state vectors. """ state_list = [] for s in states: da = messages_pb2.DoubleArray() da.array.MergeFrom(s) state_list.append(da) with RemoteServer.channel() as chan: stub = utilities_pb2_grpc.UtilitiesStub(chan) resp = stub.interpolateEphemeris(messages_pb2.InterpolateEphemerisInput( source_frame = source_frame, time = times, ephem = state_list, num_points = num_points, dest_frame = dest_frame, interp_start = interp_start, interp_end = interp_end, step_size = step_size)) return([r.time, list(r.state)] for r in resp.array)
def determine_orbit(config, meas, output_file = None): """ Performs orbit determination given config and measurements. Args: config: OD configuration (Dictionary, file name, text file-like object, or JSON encoded string). meas: List of measurements (List, file name, text file-like object, or JSON encoded string). output_file: If specified, the orbit fit will be written to the file name or text file-like object given. Returns: Orbit determination results in the same format as config (Dictionary or JSON encoded string). """ with RemoteServer.channel() as chan: stub = estimation_pb2_grpc.EstimationStub(chan) resp = stub.determineOrbit(messages_pb2.DetermineOrbitInput( config = build_settings(config), measurements = build_measurements(meas))) fitdata = convert_estimation(resp.array) if (output_file): write_output_file(output_file, fitdata) return(fitdata)
def transform_frame(srcframe, time, pva, destframe): """ Transforms a state vector from one frame to another. Args: srcframe: Source reference frame ("EME2000", "GCRF", "ITRF", "MOD", "TOD", or "TEME"). time: State vector epoch (ISO-8601 formatted UTC string). pva: State vector to transform [m, m, m, m/s, m/s, m/s] or [m, m, m, m/s, m/s, m/s, m/s^2, m/s^2, m/s^2]. destframe: Destination reference frame ("EME2000", "GCRF", "ITRF", "MOD", "TOD", or "TEME").. Returns: State vector transformed to the destination frame. """ with RemoteServer.channel() as chan: stub = conversion_pb2_grpc.ConversionStub(chan) resp = stub.transformFrame( messages_pb2.TransformFrameInput(src_frame=srcframe, time=time, pva=pva, dest_frame=destframe)) return (list(resp.array))
def propagate_orbits(config_list, output_file=None): """ Propagates the given objects in parallel. Args: config_list: List of configurations (each a dictionary, file name, text file-like object, or JSON encoded string). output_file: If specified, the output will be written to the file name or text file-like object given. Returns: Propagated state vectors at desired time intervals (List of dictionaries). """ with RemoteServer.channel() as chan: stub = propagation_pb2_grpc.PropagationStub(chan) resp = stub.propagate( messages_pb2.SettingsArray( array=[build_settings(p) for p in config_list])) propdata = convert_propagation(resp.array) if (output_file): write_output_file(output_file, propdata) return (propdata)
def import_TDM(file_name, file_format): with RemoteServer.channel() as chan: stub = utilities_pb2_grpc.UtilitiesStub(chan) resp = stub.importTDM( messages_pb2.ImportTDMInput(file_name=file_name, file_format=file_format)) marr = list(resp.array) return ([ convert_measurements(list(marr[idx].array)) for idx in range(len(marr)) ])
def determine_orbit(config, meas, output_file=None): """ Performs orbit determination given config and measurements. Args: config: OD configuration (Dictionary, file name, text file-like object, or JSON encoded string). meas: List of measurements (List, file name, text file-like object, or JSON encoded string). output_file: If specified, the orbit fit will be written to the file name or text file-like object given. Returns: Orbit determination results. """ if (isinstance(config, list)): od_output = [] else: od_output = None config = [config] if (od_output is None): meas = [meas] if (output_file and not isinstance(output_file, list)): output_file = [output_file] with RemoteServer.channel() as channel: stub = estimation_pb2_grpc.EstimationStub(channel) requests = [ stub.determineOrbit.future( messages_pb2.DetermineOrbitInput( config=build_settings(c), measurements=build_measurements(m))) for c, m in zip(config, meas) ] for idx, req in enumerate(requests): try: fit_data = convert_estimation(req.result().array) except Exception as exc: fit_data = format_exc() if (od_output is None): od_output = fit_data else: od_output.append(fit_data) if (output_file): write_output_file(output_file[idx], fit_data) return (od_output)
def determine_orbit(config, meas, output_file=None, async_callback=None, async_extra=None): """ Performs orbit determination given config and measurements. Args: config: OD configuration (Dictionary, file name, text file-like object, or JSON encoded string). meas: List of measurements (List, file name, text file-like object, or JSON encoded string). output_file: If specified, the orbit fit will be written to the file name or text file-like object given. async_callback: Callback function to invoke asynchronously when results become available. Processing is done synchronously by default. async_extra: Data to pass to the callback function in addition to the estimation results. Returns: Orbit determination results in the same format as config (Dictionary or JSON encoded string) or None in asynchronous mode. """ def async_helper(resp): fit_data = convert_estimation(resp.result().array) if (output_file): write_output_file(output_file, fit_data) channel.close() if (async_callback): async_callback(fit_data, async_extra) return (fit_data) channel = RemoteServer.channel() stub = estimation_pb2_grpc.EstimationStub(channel) resp = stub.determineOrbit.future( messages_pb2.DetermineOrbitInput( config=build_settings(config), measurements=build_measurements(meas))) if (async_callback): resp.add_done_callback(async_helper) return (None) return (async_helper(resp))
def propagate_orbits(config_list, output_file=None, async_callback=None, async_extra=None): """ Propagates the given objects in parallel. Args: config_list: List of configurations (each a dictionary, file name, text file-like object, or JSON encoded string). output_file: If specified, the output will be written to the file name or text file-like object given. async_callback: Callback function to invoke asynchronously when results become available. Processing is done synchronously by default. async_extra: Data to pass to the callback function in addition to the propagation results. Returns: Propagated state vectors at desired time intervals (List of dictionaries) or None in asynchronous mode. """ def async_helper(resp): prop_data = convert_propagation(resp.result().array) if (output_file): write_output_file(output_file, prop_data) channel.close() if (async_callback): async_callback(prop_data, async_extra) return (prop_data) channel = RemoteServer.channel() stub = propagation_pb2_grpc.PropagationStub(channel) resp = stub.propagate.future( messages_pb2.SettingsArray( array=[build_settings(p) for p in config_list])) if (async_callback): resp.add_done_callback(async_helper) return (None) return (async_helper(resp))
def simulate_measurements(config, output_file=None): """ Simulates measurement data given a configuration. Args: config: Simulation configuration (Dictionary, file name, text file-like object, or JSON encoded string). output_file: If specified, the measurements will be written to the file name or text file-like object given. Returns: Simulated measurements. """ if (isinstance(config, list)): sim_output = [] else: sim_output = None config = [config] if (output_file and not isinstance(output_file, list)): output_file = [output_file] with RemoteServer.channel() as channel: stub = simulation_pb2_grpc.SimulationStub(channel) requests = [ stub.simulateMeasurements.future(build_settings(c)) for c in config ] for idx, req in enumerate(requests): try: sim_data = convert_measurements(req.result().array) except Exception as exc: sim_data = format_exc() if (sim_output is None): sim_output = sim_data else: sim_output.append(sim_data) if (output_file): write_output_file(output_file[idx], sim_data) return (sim_output)
def simulate_measurements(config, output_file=None, async_callback=None, async_extra=None): """ Simulates measurement data given a configuration. Args: config: Simulation configuration (Dictionary, file name, text file-like object, or JSON encoded string). output_file: If specified, the measurements will be written to the file name or text file-like object given. async_callback: Callback function to invoke asynchronously when results become available. Processing is done synchronously by default. async_extra: Data to pass to the callback function in addition to the simulation results. Returns: Simulated measurements in the same format as config (Dictionary or JSON encoded string) or None in asynchronous mode. """ def async_helper(resp): sim_data = convert_measurements(resp.result().array) if (output_file): write_output_file(output_file, sim_data) channel.close() if (async_callback): async_callback(sim_data, async_extra) return (sim_data) channel = RemoteServer.channel() stub = simulation_pb2_grpc.SimulationStub(channel) resp = stub.simulateMeasurements.future(build_settings(config)) if (async_callback): resp.add_done_callback(async_helper) return (None) return (async_helper(resp))
def simulate_measurements(config, output_file=None): """ Simulates measurement data given a configuration. Args: config: Simulation configuration (Dictionary, file name, text file-like object, or JSON encoded string). output_file: If specified, the measurements will be written to the file name or text file-like object given. Returns: Simulated measurements in the same format as config (Dictionary or JSON encoded string). """ with RemoteServer.channel() as chan: stub = simulation_pb2_grpc.SimulationStub(chan) resp = stub.simulateMeasurements(build_settings(config)) simdata = convert_measurements(resp.array) if (output_file): write_output_file(output_file, simdata) return (simdata)
Symmetric matrix as a list of lists or None on error. """ m = (sqrt(8 * len(lower_triangle) + 1) - 1) / 2 n = int(m) if (m == n): k, matrix = 0, [[0] * n for _ in range(n)] for i in range(n): for j in range(i + 1): matrix[i][j], matrix[j][i] = lower_triangle[k], lower_triangle[ k] k += 1 return (matrix) return (None) if (__name__ != '__main__'): __pdoc__ = { m: False for m in ("Facet", "Maneuver", "Measurement", "Parameter", "Settings", "Station", "TDMFileFormat", "rpc", "version") } _root_dir = path.dirname(path.abspath(path.realpath(__file__))) _libs_dir = path.join(_root_dir, "target") _jar_file = path.join(_libs_dir, "orbdetpy-server-{}.jar".format(__version__)) _data_dir = path.join(_root_dir, "orekit-data") stat(_jar_file) stat(_data_dir) RemoteServer.connect(_data_dir, _jar_file)
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from typing import List from orbdetpy.rpc.messages_pb2 import Settings, SettingsArray from orbdetpy.rpc.propagation_pb2_grpc import PropagationStub from orbdetpy.rpc.server import RemoteServer def propagate_orbits(cfg_list: List[Settings]): """Propagate orbits and optionally simulate measurements. Parameters ---------- cfg_list: List of Settings objects. Returns ------- Propagated state vectors and simulated measurements. """ resp = _propagation_stub.propagate(SettingsArray(array=[p for p in cfg_list])) return(resp.array) if (__name__ != '__main__'): __pdoc__ = {m: False for m in ("Settings", "SettingsArray")} _propagation_stub = PropagationStub(RemoteServer.channel())
Parameters ---------- drag_model : Atmospheric drag model; a constant from DragModel. time : Offset in TT from J2000 epoch [s]. Give a list for bulk calculations. lla : WGS-84 latitude, longitude, altitude. Give a list of lists for bulk calculations. Returns ------- Atmospheric neutral density [kg/m^3] at the specified coordinates. """ if (isinstance(time, float) or isinstance(time, str)): time, lla = [time], [lla] if (isinstance(time[0], float)): resp = _utilities_stub.getDensity( TransformFrameInput(time=time, pva=[DoubleArray(array=x) for x in lla], dest_frame=str(drag_model))) else: resp = _utilities_stub.getDensity( TransformFrameInput(UTC_time=time, pva=[DoubleArray(array=x) for x in lla], dest_frame=str(drag_model))) return (resp.array) if (__name__ != '__main__'): __pdoc__ = {m: False for m in ("DoubleArray", "InterpolateEphemerisInput")} _utilities_stub = UtilitiesStub(RemoteServer.channel())
data = json.loads(param) elif (isinstance(param, io.TextIOBase)): data = json.load(param) else: data = param return (data) def write_output_file(outfile, data): if (isinstance(outfile, str)): with open(outfile, "w") as fp: if (isinstance(data, str)): fp.write(data) else: json.dump(data, fp) elif (isinstance(outfile, io.TextIOBase)): if (isinstance(data, str)): outfile.write(data) else: json.dump(data, outfile) if (__name__ != '__main__'): _rootdir = path.dirname(path.abspath(__file__)) _datadir = path.join(_rootdir, "data") _libsdir = path.join(_rootdir, "target") _jarfile = path.join(_libsdir, "orbdetpy-server-{}.jar".format(__version__)) RemoteServer.connect(_datadir, _jarfile)
Parameters ---------- utc : ISO-8601 formatted UTC string or list of strings. Returns ------- Offset in TT from J2000 epoch [s] or list of offsets. """ resp = _conversion_stub.getJ2000EpochOffset(StringValue(value=utc if isinstance(utc, str) else " ".join(utc))) return(resp.array[0] if (len(resp.array) == 1) else resp.array) def get_epoch_difference(from_epoch: int, to_epoch: int)->str: """Get the constant time difference between two epochs. Parameters ---------- from_epoch : From epoch; a value from the Epoch enumeration. to_epoch : To epoch; a value from the Epoch enumeration. Returns ------- to_epoch - from_epoch in seconds. """ return(_conversion_stub.getEpochDifference(IntegerArray(array=[from_epoch, to_epoch])).value) if (__name__ != '__main__'): __pdoc__ = {m: False for m in ("AnglesInput", "DoubleArray", "IntegerArray", "TransformFrameInput")} _conversion_stub = ConversionStub(RemoteServer.channel())
fit_data = format_exc() od_output.append(fit_data) return(od_output) def iod_laplace(frame: int, lat: float, lon: float, alt: float, time: Tuple[float, float, float], ra: Tuple[float, float, float], dec: Tuple[float, float, float])->List[float]: """Estimate orbit from 3 RA/Dec angles using the Laplace method. Parameters ---------- frame : Estimation reference frame; a constant from Frame. lat : Observer WGS-84 latitude [rad]. lon : Observer WGS-84 longitude [rad]. alt : Observer height above WGS-84 reference ellipsoid [m]. time : Times [t1, t2, t3]; each a TT offset from J2000 epoch [s]. ra : List of 3 Right Ascensions. dec : List of 3 Declinations. Returns ------- Position and velocity estimate at time t2. """ resp = _estimation_stub.iodLaplace(AnglesInput(time=time, angle1=ra, angle2=dec, latitude=lat, longitude=lon, altitude=alt, frame=frame)) return(resp.array) if (__name__ != '__main__'): __pdoc__ = {m: False for m in ("AnglesInput", "DetermineOrbitInput", "Settings")} _estimation_stub = EstimationStub(RemoteServer.channel())