public void AvailabilityValueWritesAvailabilityProperty() { JulianDate start = new JulianDate(new GregorianDate(2012, 4, 2, 1, 2, 3)); JulianDate stop = new JulianDate(new GregorianDate(2012, 4, 3, 1, 2, 3)); m_output.WriteStartSequence(); using (PacketCesiumWriter packet = m_writer.OpenPacket(m_output)) { packet.WriteAvailability(start, stop); } using (PacketCesiumWriter packet = m_writer.OpenPacket(m_output)) { packet.WriteAvailability(new TimeInterval(start, stop)); } using (PacketCesiumWriter packet = m_writer.OpenPacket(m_output)) { var intervals = new List<TimeInterval>(); intervals.Add(new TimeInterval(start, stop)); intervals.Add(new TimeInterval(start.AddDays(2.0), stop.AddDays(2.0))); packet.WriteAvailability(intervals); } m_output.WriteEndSequence(); Assert.AreEqual("[{\"availability\":\"20120402T010203Z/20120403T010203Z\"}," + "{\"availability\":\"20120402T010203Z/20120403T010203Z\"}," + "{\"availability\":[\"20120402T010203Z/20120403T010203Z\",\"20120404T010203Z/20120405T010203Z\"]}]", m_sw.ToString()); }
public void TestParseIso8601DayOfYear() { GregorianDate iso = new GregorianDate(1985, 2, 11, 2, 0, 5.2134); GregorianDate result = GregorianDate.Parse("1985-042T02:00:05.2134"); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11, 2, 0, 5.21345); result = GregorianDate.Parse("1985-042T02:00:05.21345Z"); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11, 2, 0, 5); result = GregorianDate.Parse("1985-042T02:00:05"); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11); result = GregorianDate.Parse("1985-042"); Assert.AreEqual(iso, result); // Make sure to check each month to ensure we have it right const string first = "1986-"; const string last = "T02:01:04Z"; JulianDate baseDate = new JulianDate(new GregorianDate(1986, 1, 12, 02, 01, 4)); for (int i = 1; i < 12; i++) { string testString = string.Format(first + "{0:000}" + last, 12 + i * 30); GregorianDate expected = baseDate.AddDays(i * 30).ToGregorianDate(); Assert.AreEqual(expected, GregorianDate.Parse(testString)); } }
public void TestParseISO8601DayOfYear() { GregorianDate iso = new GregorianDate(1985, 2, 11, 2, 0, 5.2134); GregorianDate result = GregorianDate.Parse("1985-042T02:00:05.2134"); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11, 2, 0, 5.21345); result = GregorianDate.Parse("1985-042T02:00:05.21345Z"); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11, 2, 0, 5); result = GregorianDate.Parse("1985-042T02:00:05"); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11); result = GregorianDate.Parse("1985-042"); Assert.AreEqual(iso, result); // Make sure to check each month to ensure we have it right string first = "1986-"; string last = "T02:01:04Z"; JulianDate baseDate = new JulianDate(new GregorianDate(1986, 1, 12, 02, 01, 4)); for (int i = 1; i < 12; i++) { string testString = string.Format(first + "{0:000}" + last, 12 + i * 30); GregorianDate expected = baseDate.AddDays(i * 30).ToGregorianDate(); Assert.AreEqual(expected, GregorianDate.Parse(testString)); } }
public void AvailabilityValueWritesAvailabilityProperty() { JulianDate start = new JulianDate(new GregorianDate(2012, 4, 2, 1, 2, 3)); JulianDate stop = new JulianDate(new GregorianDate(2012, 4, 3, 1, 2, 3)); m_output.WriteStartSequence(); using (PacketCesiumWriter packet = m_writer.OpenPacket(m_output)) { packet.WriteAvailability(start, stop); } using (PacketCesiumWriter packet = m_writer.OpenPacket(m_output)) { packet.WriteAvailability(new TimeInterval(start, stop)); } using (PacketCesiumWriter packet = m_writer.OpenPacket(m_output)) { var intervals = new List <TimeInterval>(); intervals.Add(new TimeInterval(start, stop)); intervals.Add(new TimeInterval(start.AddDays(2.0), stop.AddDays(2.0))); packet.WriteAvailability(intervals); } m_output.WriteEndSequence(); Assert.AreEqual("[{\"availability\":\"20120402T010203Z/20120403T010203Z\"}," + "{\"availability\":\"20120402T010203Z/20120403T010203Z\"}," + "{\"availability\":[\"20120402T010203Z/20120403T010203Z\",\"20120404T010203Z/20120405T010203Z\"]}]", m_sw.ToString()); }
/// <summary> /// Tries to download from AGI's server a list of TLEs describing the satellite which has the given string /// NORAD identifier for the 24 hour period following the given date. If AGI's server is unavailable /// (i.e. if the machine on which the demo is running is not connected to the internet), /// pulls the list of TLEs from the local Data directory. /// </summary> public static List <TwoLineElementSet> GetTles(string satelliteIdentifier, JulianDate date) { try { return(TwoLineElementSet.DownloadTles(satelliteIdentifier, date, date.AddDays(1.0))); } catch (DataUnavailableException) { // Read from local data if the machine does not have access to the internet. string dataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.RelativeSearchPath ?? "", "Data"); var satelliteDatabase = new StkSatelliteDatabase(Path.Combine(dataPath, "SatelliteDatabase"), "stkSatDb"); var query = new StkSatelliteDatabaseQuery { SatelliteNumber = new Regex(satelliteIdentifier) }; foreach (var entry in satelliteDatabase.GetEntries(query)) { return(new List <TwoLineElementSet> { entry.TwoLineElementSet }); } throw new DataUnavailableException("TLE data for " + satelliteIdentifier + " could not be found in local SatelliteDatabase"); } }
public void TestAddDays() { // Make sure AddDays produces the correct answer in the correct time standard. JulianDate test = new JulianDate(2451912, 43200.0, TimeStandard.InternationalAtomicTime); JulianDate result = test.AddDays(45.5); Assert.AreEqual(TimeStandard.InternationalAtomicTime, result.Standard); Assert.AreEqual(2451958, result.Day); Assert.AreEqual(0.0, result.SecondsOfDay); }
public void TestDeletePropertyWithStartAndStop() { var start = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0)); var stop = start.AddDays(1.0); using (Packet) { Packet.WriteId("id"); using (var position = Packet.OpenPositionProperty()) using (var interval = position.OpenInterval(start, stop)) { interval.WriteDelete(true); } } Assert.AreEqual("{\"id\":\"id\",\"position\":{\"interval\":\"20120402T12Z/20120403T12Z\",\"delete\":true}}", StringWriter.ToString()); }
public void TestDeletePropertyWithStartAndStop() { var start = new JulianDate(new GregorianDate(2012, 4, 2, 12, 0, 0)); var stop = start.AddDays(1.0); using (Packet) { Packet.WriteId("id"); using (var writer = new DoubleCesiumWriter("foo")) { writer.Open(OutputStream); writer.WriteInterval(start, stop); writer.WriteDelete(true); } } Assert.AreEqual("{\"id\":\"id\",\"foo\":{\"interval\":\"20120402T12Z/20120403T12Z\",\"delete\":true}}", StringWriter.ToString()); }
/// <summary> /// Load TLEs from a satellite database and create marker primitives for each satellite /// </summary> private void CreateSatellites(string fileName) { m_satellites.Clear(); JulianDate?epoch = null; StkSatelliteDatabase db = new StkSatelliteDatabase(GetDataFilePath("SatelliteDatabase"), fileName); foreach (StkSatelliteDatabaseEntry entry in db.GetEntries()) { if (entry.TwoLineElementSet != null) { Sgp4Propagator propagator = new Sgp4Propagator(entry.TwoLineElementSet); if (epoch == null) { epoch = propagator.InitialConditions.Epoch; } Duration epochDifference = epoch.Value - propagator.InitialConditions.Epoch; if (epochDifference < Duration.FromDays(1)) { m_satellites.Add(propagator.GetEvaluator(), entry.TwoLineElementSet.Epoch); } } } SetText(m_satellites.Count); JulianDate time = epoch.Value.ToTimeStandard(TimeStandard.InternationalAtomicTime); // Set epoch time m_animation.Pause(); m_animation.StartTime = time; m_animation.EndTime = time.AddDays(1.0); m_animation.Time = time; m_animation.PlayForward(); }
public void TestAvailabilityProperty() { JulianDate start = new JulianDate(new GregorianDate(2012, 4, 2, 1, 2, 3)); JulianDate stop = new JulianDate(new GregorianDate(2012, 4, 3, 1, 2, 3)); m_outputStream.WriteStartSequence(); using (PacketCesiumWriter packet = m_writer.OpenPacket(m_outputStream)) { packet.WriteAvailability(start, stop); } using (PacketCesiumWriter packet = m_writer.OpenPacket(m_outputStream)) { packet.WriteAvailability(new TimeInterval(start, stop)); } using (PacketCesiumWriter packet = m_writer.OpenPacket(m_outputStream)) { var intervals = new List <TimeInterval> { new TimeInterval(start, stop), new TimeInterval(start.AddDays(2.0), stop.AddDays(2.0)) }; packet.WriteAvailability(intervals); } m_outputStream.WriteEndSequence(); const string expected = "[" + "{\"availability\":\"20120402T010203Z/20120403T010203Z\"}," + "{\"availability\":\"20120402T010203Z/20120403T010203Z\"}," + "{\"availability\":[\"20120402T010203Z/20120403T010203Z\",\"20120404T010203Z/20120405T010203Z\"]}" + "]"; Assert.AreEqual(expected, m_stringWriter.ToString()); }
static void Main(string[] args) { var dateTime = new DateTime(2019, 5, 20); // 时间转换为JulianDate的协调世界时(UTC), var jdUTC = new JulianDate(dateTime, TimeStandard.CoordinatedUniversalTime); Console.WriteLine("时间:{0},儒略日:{1}", jdUTC, jdUTC.TotalDays); // 时间转换为JulianDate的国际原子时(TAI), var jdTAI = new JulianDate(dateTime, TimeStandard.InternationalAtomicTime); Console.WriteLine("时间:{0},儒略日:{1}", jdTAI, jdTAI.TotalDays); // 与J2000时刻的时间差 var jdTT = new JulianDate(dateTime, TimeStandard.TerrestrialTime); Duration diff = jdTT - TimeConstants.J2000; Console.WriteLine("时间差:{0}天", diff.TotalDays); // UTC转为TAI JulianDate jdTAI2 = jdUTC.ToTimeStandard(TimeStandard.InternationalAtomicTime); Console.WriteLine("时间:{0},儒略日:{1}", jdTAI2, jdTAI2.TotalDays); // TAI转UTC JulianDate jdUTC2 = TimeStandardConverter.Convert(jdTAI2, TimeStandard.CoordinatedUniversalTime); Console.WriteLine("时间:{0},儒略日:{1}", jdUTC2, jdUTC2.TotalDays); // 加上指定天数 JulianDate jd = jdUTC.AddDays(7); Console.WriteLine("时间:{0},儒略日:{1}", jd, jd.TotalDays); Console.Read(); }
public void TestCompleteExample() { var date = new JulianDate(2451545.0); const string id = "MyID"; var availability = new TimeInterval(date, date.AddDays(2.0)); var interval1 = new TimeInterval(date, date.AddDays(1.0)); var interval1Position = new Cartesian(1.0, 2.0, 3.0); var interval1Orientation = new UnitQuaternion(1, 0, 0, 0); var interval2 = new TimeInterval(date.AddDays(1.0), date.AddDays(2.0)); var interval2SampleDates = new List <JulianDate> { date.AddDays(1.0), date.AddDays(1.5), date.AddDays(2.0) }; var interval2SamplePositions = new List <Cartographic> { Cartographic.Zero, new Cartographic(1.0, 0.0, 0.0), new Cartographic(0.0, 1.0, 0.0) }; var interval2SampleOrientations = new List <UnitQuaternion> { UnitQuaternion.Identity, new UnitQuaternion(0.0, 1.0, 0.0, 0.0), new UnitQuaternion(0.0, 0.0, 1.0, 0.0) }; const CesiumInterpolationAlgorithm orientationInterpolationAlgorithm = CesiumInterpolationAlgorithm.Linear; const int orientationInterpolationDegree = 1; var outputStream = new CesiumOutputStream(StringWriter) { PrettyFormatting = true }; var writer = new CesiumStreamWriter(); using (var packet = writer.OpenPacket(outputStream)) { packet.WriteId(id); packet.WriteAvailability(availability); using (var positionWriter = packet.OpenPositionProperty()) using (var intervalListWriter = positionWriter.OpenMultipleIntervals()) { using (var interval = intervalListWriter.OpenInterval()) { interval.WriteInterval(interval1); interval.WriteCartesian(interval1Position); } using (var interval = intervalListWriter.OpenInterval(interval2.Start, interval2.Stop)) { interval.WriteCartographicRadians(interval2SampleDates, interval2SamplePositions); } } using (var orientationWriter = packet.OpenOrientationProperty()) using (var intervalListWriter = orientationWriter.OpenMultipleIntervals()) { using (var interval = intervalListWriter.OpenInterval()) { interval.WriteInterval(interval1); interval.WriteUnitQuaternion(interval1Orientation); } using (var interval = intervalListWriter.OpenInterval(interval2.Start, interval2.Stop)) { interval.WriteInterpolationAlgorithm(orientationInterpolationAlgorithm); interval.WriteInterpolationDegree(orientationInterpolationDegree); interval.WriteUnitQuaternion(interval2SampleDates, interval2SampleOrientations); } } } Console.WriteLine(StringWriter.ToString()); }
public void Sandbox() { JulianDate date = new JulianDate(2451545.0); using (StringWriter sw = new StringWriter()) { CesiumOutputStream output = new CesiumOutputStream(sw); output.PrettyFormatting = true; CesiumStreamWriter writer = new CesiumStreamWriter(); using (PacketCesiumWriter packet = writer.OpenPacket(output)) { packet.WriteId("MyID"); packet.WriteAvailability(date, date.AddDays(1.0)); using (PositionCesiumWriter position = packet.OpenPositionProperty()) using (CesiumIntervalListWriter <PositionCesiumWriter> intervalList = position.OpenMultipleIntervals()) { using (PositionCesiumWriter interval = intervalList.OpenInterval()) { interval.WriteInterval(new TimeInterval(date, date.AddDays(1.0))); interval.WriteCartesian(new Cartesian(1.0, 2.0, 3.0)); } using (PositionCesiumWriter interval = intervalList.OpenInterval(date.AddDays(1.0), date.AddDays(2.0))) { var dates = new List <JulianDate>(); var positions = new List <Cartographic>(); dates.Add(date.AddDays(1.0)); positions.Add(Cartographic.Zero); dates.Add(date.AddDays(1.5)); positions.Add(new Cartographic(1.0, 0.0, 0.0)); dates.Add(date.AddDays(2.0)); positions.Add(new Cartographic(0.0, 1.0, 0.0)); interval.WriteCartographicRadians(dates, positions); } } using (OrientationCesiumWriter orientation = packet.OpenOrientationProperty()) using (CesiumIntervalListWriter <OrientationCesiumWriter> intervalList = orientation.OpenMultipleIntervals()) { using (OrientationCesiumWriter interval = intervalList.OpenInterval()) { interval.WriteAxes("MyMadeUpAxes"); interval.WriteInterval(new TimeInterval(date, date.AddDays(1.0))); interval.WriteUnitQuaternion(new UnitQuaternion(1, 0, 0, 0)); } using (OrientationCesiumWriter interval = intervalList.OpenInterval()) { interval.WriteInterpolationAlgorithm(CesiumInterpolationAlgorithm.Linear); interval.WriteInterpolationDegree(1); var dates = new List <JulianDate>(); var orientations = new List <UnitQuaternion>(); dates.Add(date.AddDays(1.0)); orientations.Add(UnitQuaternion.Identity); dates.Add(date.AddDays(1.5)); orientations.Add(new UnitQuaternion(0.0, 1.0, 0.0, 0.0)); dates.Add(date.AddDays(2.0)); orientations.Add(new UnitQuaternion(0.0, 0.0, 1.0, 0.0)); interval.WriteUnitQuaternion(dates, orientations); } } } Console.WriteLine(sw.ToString()); } }