Click or drag to resize

Data Interoperability

Much of the power of DME Component Libraries depends, of course, on the ability to use your own data as input to the library algorithms and to get answers back out in a useful form. This topic explains some of the techniques you can use to achieve data interoperability as well as addresses some difficulties you may encounter.

STK Data Files

DME Component Libraries provides convenient classes to read and write ephemeris and attitude data in STK *.e and *.a file formats. The following example shows how to read a *.e file and access the times, positions and velocities that it contains. It also shows how to access the interpolator that can be used to interpolate over the data in the file.

C#
using (StreamReader reader = new StreamReader(path))
{
    StkEphemerisFile ephemerisFile = StkEphemerisFile.ReadFrom(reader);
    StkEphemerisFile.EphemerisTimePosVel posVelData = ephemerisFile.Data as StkEphemerisFile.EphemerisTimePosVel;
    if (posVelData != null)
    {
        DateMotionCollection<Cartesian> ephemerisData = posVelData.EphemerisData;
        IList<JulianDate> times = ephemerisData.Dates;
        IList<Cartesian> positions = ephemerisData.Values;
        IList<Cartesian> velocities = ephemerisData.FirstDerivatives;

        TranslationalMotionInterpolator interpolator = posVelData.Interpolator;
    }
}

In addition to reading *.e files, DME Component Libraries can also write *.e files, as demonstrated in the following example:

C#
// Use any valid TLE to create a propagator, and use that propagator to create a MotionEvaluator.
TwoLineElementSet inputTwoLineElementSet =
    new TwoLineElementSet(@"1 20813U 90084A   07157.52757149 -.00000978  00000-0  10000-3 0  8139
                            2 20813  62.3585 177.5907 7234421 261.2958  18.3008  2.01001663122427");
Sgp4Propagator propagator = new Sgp4Propagator(inputTwoLineElementSet);
MotionEvaluator<Cartesian> motionEvaluator = propagator.GetEvaluator();

// Define start time, stop time, and time step that will be used to sample the motion evaluator for ephemeris data.
JulianDate startDate = new JulianDate(new GregorianDate(2007, 6, 1));
JulianDate stopDate = new JulianDate(new GregorianDate(2007, 6, 2));
Duration timeStep = Duration.FromSeconds(60);

// Using the MotionEvaluator created above, output ephemeris data in a format that can be processed by
// the StkEphemerisFile object. Passing null for the ITrackCalculationProgress indicates that the Evaluate step
// should not track progress.
DateMotionCollection<Cartesian> rawEphemerisData = motionEvaluator.Evaluate(startDate, stopDate, timeStep, 0, null);

// The data obtained from the MotionEvaluator is in meters.  Convert to desired units, kilometers in this case.
DateMotionCollection<Cartesian> rawEphemerisDataKm = new DateMotionCollection<Cartesian>();
double toKilometers = 1.0 / 1000.0;
for (int i = 0; i < rawEphemerisData.Count; i++)
{
    rawEphemerisDataKm.Add(rawEphemerisData.Dates[i], rawEphemerisData.Motions[i].Value * toKilometers);
}

// Once the raw data has been obtained from the MotionEvaluator and converted as necessary, place it into an StkEphemerisFile
// and specify the appropriate coordinate system.
StkEphemerisFile.EphemerisTimePos ephemerisData = new StkEphemerisFile.EphemerisTimePos
{
    CoordinateSystem = propagator.ReferenceFrame,
    EphemerisData = rawEphemerisDataKm,
};
StkEphemerisFile ephemerisFile = new StkEphemerisFile
{
    Data = ephemerisData
};

// Use the "Properties" element of the STKEphemerisFile to specify any additional supported properties
// such as the distance unit of the data.
ephemerisFile.Properties.Add("DistanceUnit", "Kilometers");

// Finally, write the StkEphemerisFile out.
using (StreamWriter ephemerisWriter = new StreamWriter(path, false, Encoding.ASCII))
{
    ephemerisFile.WriteTo(ephemerisWriter);
}

See the reference documentation for StkEphemerisFile and StkAttitudeFile for more information.

STK Database Files

It is also possible to load information from STK database files. To load positions and additional metadata for spacecraft, see the Satellite Database Files topic. To load positions and additional metadata for ground stations and other facilities, see the Facility Database Files topic. Lastly, for information on cities see the City Database Files topic.

CCSDS OEM Files

DME Component Libraries provides convenient classes to read and write ephemeris data in the Orbit Ephemeris Message (OEM) file format from The Consultative Committee for Space Data Systems (CCSDS). The following example shows how to read an OEM file and access information from the file.

C#
using (var reader = new StreamReader(path))
{
    CcsdsOrbitEphemerisMessageFile oemFile = CcsdsOrbitEphemerisMessageFile.ReadFrom(reader);

    // This particular file has only one segment at index 0. Files may contain more than one segment.
    CcsdsOrbitEphemerisMessageSegment oemSegment = oemFile[0];

    // The ephemeris and covariance data are available.
    DateMotionCollection<Cartesian> ephemeris = oemSegment.EphemerisData;
    DateMotionCollection<Matrix6By6Symmetric> covariance = oemSegment.CovarianceData;

    // The reference frame can be inferred.
    // If this or any of the other inferences fails, null is returned.
    ReferenceFrame referenceFrame = oemSegment.ReferenceFrame;

    // An interpolator can be inferred.
    TranslationalMotionInterpolator interpolator = oemSegment.Interpolator;

    // The axes in which the covariance is expressed can also be inferred.
    // These are often the same as the axes of the reference frame.
    DateMotionCollection<Axes> covarianceAxes = oemSegment.CovarianceAxes;

    // Finally, a point can be created if the ephemeris, reference frame,
    // and interpolator are not null.
    Point point = oemSegment.CreatePoint();
}

In addition to reading OEM files, DME Component Libraries can also write OEM files, as demonstrated in the following example:

C#
var oemFile = new CcsdsOrbitEphemerisMessageFile();
oemFile.Comments.Add("TLE Element Propagation.");
oemFile.Originator = "DME Component Libraries";
oemFile.Version = "2.0";

// Oem files must have at least one segment.
var oemSegment = new CcsdsOrbitEphemerisMessageSegment();

// Use any valid TLE to create a propagator, and use that propagator to create a MotionEvaluator.
TwoLineElementSet inputTwoLineElementSet =
    new TwoLineElementSet(@"1 20813U 90084A   07157.52757149 -.00000978  00000-0  10000-3 0  8139
                            2 20813  62.3585 177.5907 7234421 261.2958  18.3008  2.01001663122427");
Sgp4Propagator propagator = new Sgp4Propagator(inputTwoLineElementSet);
MotionEvaluator<Cartesian> motionEvaluator = propagator.GetEvaluator();

// Define start time, stop time, and time step that will be used to sample the motion evaluator for ephemeris data.
JulianDate startTime = new GregorianDate(2007, 6, 1).ToJulianDate();
JulianDate stopTime = new GregorianDate(2007, 6, 2).ToJulianDate();
Duration timeStep = Duration.FromSeconds(60);

// Using the MotionEvaluator created above, output ephemeris data in a format that can be processed by
// the CcsdsOrbitEphemerisMessageSegment object.
DateMotionCollection<Cartesian> rawEphemerisData = motionEvaluator.Evaluate(startTime, stopTime, timeStep, 2);
oemSegment.EphemerisData = rawEphemerisData;

oemSegment.ObjectName = "MOLNIYA 3-39";
oemSegment.ObjectId = "20813";

oemSegment.StartTime = startTime;
oemSegment.UseableStartTime = startTime;
oemSegment.UseableStopTime = stopTime;
oemSegment.StopTime = stopTime;

oemSegment.TimeStandard = TimeStandard.CoordinatedUniversalTime;
oemSegment.Center = "Earth";

// The TLE propagator uses the True Equator Mean Equinox Frame, which is abbreviated TEMEOFDATE.
oemSegment.ReferenceFrameName = "TEMEOFDATE";

// Add Covariance data at the start time in the radial, in-track, and cross-track frame,
// which is abbreviated RSW_ROTATING.
oemSegment.CovarianceData.Add(startTime, Matrix6By6Symmetric.DiagonalMatrix(100.0 * 100.0, // m^2, radial.
                                                                            1000.0 * 1000.0, // m^2, in-track.
                                                                            200.0 * 200.0, // m^2, cross-track.
                                                                            1.0, // m^2/s^2, radial velocity.
                                                                            2.0e-2 * 2.0e-2, // m^2/s^2, in-track velocity.
                                                                            1.0e-3 * 1.0e-3)); // m^2/s^2, cross-track velocity.
oemSegment.CovarianceAxesNames.Add(startTime, "RSW_ROTATING");

// Add the CCSDS segment to the CCSDS file.
oemFile.Add(oemSegment);

// The creation date will be set to DateTime.Now.
const bool overrideCreationDate = true;

// OEM files can be written and read in the ASCII KVN (key-value notation) format,
// a namespace qualified XML format (with ndm as the namespace), or
// an unqualified XML format. (NDM stands for navigation data message).
using (StreamWriter ephemerisWriter = new StreamWriter(kvnPath, false, Encoding.ASCII))
{
    oemFile.WriteTo(ephemerisWriter, new CcsdsOemFileWritingOptions(overrideCreationDate, CcsdsOemFileOutputFormat.KvnFormat));
}

using (StreamWriter ephemerisWriter = new StreamWriter(qualifiedXmlPath, false))
{
    oemFile.WriteTo(ephemerisWriter, new CcsdsOemFileWritingOptions(overrideCreationDate, CcsdsOemFileOutputFormat.NamespaceQualifiedXmlFormat));
}

using (StreamWriter ephemerisWriter = new StreamWriter(unqualifiedXmlPath, false))
{
    oemFile.WriteTo(ephemerisWriter, new CcsdsOemFileWritingOptions(overrideCreationDate, CcsdsOemFileOutputFormat.UnqualifiedXmlFormat));
}

See the reference documentation for CcsdsOrbitEphemerisMessageFile, and CcsdsOrbitEphemerisMessageSegment for more information.

Custom Data Formats

Using custom or proprietary data formats with DME Component Libraries requires a bit more work. Fundamentally, any data that can be read or accessed from .NET can be used in DME Component Libraries calculations. Whether your data is in a database or an XML file, whether it is on disk or on a web server, .NET provides plenty of support for reading and parsing nearly any type of data. Of course, it is not enough to simply read the data. You must also represent it in memory using data structures that DME Component Libraries understands. Generally, this means using DME Component Libraries primitive types such as JulianDate and Cartesian.

Dates and times in other applications and data files are represented in a variety of ways. DME Component Libraries makes it easy to convert one of these other representations to a JulianDate. One common representation is an actual Julian date. For example, the number 2454258.5 represents midnight on June 7, 2007. You can pass this number directly to the JulianDate(Double) constructor to get a JulianDate instance representing that Julian date. Be sure to consider the time standard of your data source and construct the JulianDate with the same time standard.

Your data source may contain a modified Julian date, instead. In that case, simply add ModifiedJulianDateDifference to the number read from your data source before passing it to the JulianDate constructor.

STK and other applications commonly use the notion of "epoch seconds" to describe a date and time. Essentially, an epoch is defined as a Gregorian year, month, day, hour, minute and second (and often fractions of seconds) and then each date and time is represented as the number of seconds since that epoch. Read the Gregorian epoch using the GregorianDateParse method. Then, construct a JulianDate from the parsed GregorianDate. For example:

C#
string epochAsString = "06/05/2007 12:00:00.00";
GregorianDate epochAsDateTime = GregorianDate.Parse(epochAsString);
JulianDate epoch = new JulianDate(epochAsDateTime);

Then, read each date and time by adding the number of seconds read to the epoch. For example:

C#
double secondsSinceEpoch = 123.45;
JulianDate date = epoch.AddSeconds(secondsSinceEpoch);

Reading other primitive types, such as Cartesian and Spherical vectors, is straightforward. Simply read and parse the components (X, Y, and Z for a Cartesian vector and Clock, Cone, and Magnitude for a Spherical vector) and then construct an instance of the appropriate type. DME Component Libraries has methods for converting between primitive types. The following example shows how to create a Spherical vector and then convert it to an equivalent Cartesian vector:

C#
// Initialize a set of spherical coordinates.
double clockAngle = Math.PI / 4;
double coneAngle = Math.PI / 8;
double magnitude = 100.0;
Spherical spherical = new Spherical(clockAngle, coneAngle, magnitude);

// Convert the set of spherical coordinates to a set of Cartesian coordinates.
Cartesian cartesian = new Cartesian(spherical);

Many methods in DME Component Libraries expect a Motion<Cartesian> as an input. This type holds not only a Cartesian position vector but also can optionally hold additional instantaneous derivatives of that vector, such as velocity and acceleration. See the Motion<T> and Motion<T, TDerivative> topic for more information. The following example shows how to create a Motion<Cartesian> instance from a position and velocity:

C#
Cartesian position = new Cartesian(12.0, 19.5, -6.2);
Cartesian velocity = new Cartesian(-1.2, 0.5, 2.3);
Motion<Cartesian> positionAndVelocity = new Motion<Cartesian>(position, velocity);