Skip to content

Commit

Permalink
Merge pull request #16 from tcpalmer/feature/plot-model2
Browse files Browse the repository at this point in the history
Feature/plot model2
  • Loading branch information
tcpalmer authored Dec 5, 2022
2 parents e74515b + 5912321 commit fd9d9d5
Show file tree
Hide file tree
Showing 36 changed files with 1,675 additions and 119 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Target Planning

## 1.0.0.X - 2022-xx-xx
## 1.1.0.0 - 2022-12-06
* Added Imaging Season chart
* Fixed bug that caused >24h imaging session in some cases
* Added annotations to the Annual Chart

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,86 @@ namespace TargetPlanning.NINAPlugin.Test.Astrometry {

public class AltitudesTest {

[Test]
public void TestFindMax() {
List<AltitudeAtTime> alts = new List<AltitudeAtTime>();
DateTime dt = DateTime.Now;
alts.Add(new AltitudeAtTime(1, 180, dt));
alts.Add(new AltitudeAtTime(2, 180, dt.AddMinutes(1)));
alts.Add(new AltitudeAtTime(3, 180, dt.AddMinutes(2)));
alts.Add(new AltitudeAtTime(2, 180, dt.AddMinutes(3)));
Altitudes altitudes = new Altitudes(alts);

Tuple<int, AltitudeAtTime> max = altitudes.FindMaximumAltitude();
max.Item2.Altitude.Should().BeApproximately(3, 0.001);
max.Item2.AtTime.Should().BeSameDateAs(dt.AddMinutes(2));
max.Item1.Should().Be(2);

alts.Clear();
alts.Add(new AltitudeAtTime(1, 180, dt));
alts.Add(new AltitudeAtTime(2, 180, dt.AddMinutes(1)));
alts.Add(new AltitudeAtTime(3, 180, dt.AddMinutes(2)));
alts.Add(new AltitudeAtTime(4, 180, dt.AddMinutes(3)));
altitudes = new Altitudes(alts);

max = altitudes.FindMaximumAltitude();
max.Item2.Altitude.Should().BeApproximately(4, 0.001);
max.Item2.AtTime.Should().BeSameDateAs(dt.AddMinutes(3));
max.Item1.Should().Be(3);

alts.Clear();
alts.Add(new AltitudeAtTime(4, 180, dt));
alts.Add(new AltitudeAtTime(3, 180, dt.AddMinutes(1)));
alts.Add(new AltitudeAtTime(2, 180, dt.AddMinutes(2)));
alts.Add(new AltitudeAtTime(1, 180, dt.AddMinutes(3)));
altitudes = new Altitudes(alts);

max = altitudes.FindMaximumAltitude();
max.Item2.Altitude.Should().BeApproximately(4, 0.001);
max.Item2.AtTime.Should().BeSameDateAs(dt.AddMinutes(1));
max.Item1.Should().Be(0);
}

[Test]
public void TestFindMin() {
List<AltitudeAtTime> alts = new List<AltitudeAtTime>();
DateTime dt = DateTime.Now;
alts.Add(new AltitudeAtTime(4, 180, dt));
alts.Add(new AltitudeAtTime(3, 180, dt.AddMinutes(1)));
alts.Add(new AltitudeAtTime(2, 180, dt.AddMinutes(2)));
alts.Add(new AltitudeAtTime(3, 180, dt.AddMinutes(3)));
Altitudes altitudes = new Altitudes(alts);

Tuple<int, AltitudeAtTime> min = altitudes.FindMinimumAltitude();
min.Item2.Altitude.Should().BeApproximately(2, 0.001);
min.Item2.AtTime.Should().BeSameDateAs(dt.AddMinutes(2));
min.Item1.Should().Be(2);

alts.Clear();
alts.Add(new AltitudeAtTime(1, 180, dt));
alts.Add(new AltitudeAtTime(2, 180, dt.AddMinutes(1)));
alts.Add(new AltitudeAtTime(3, 180, dt.AddMinutes(2)));
alts.Add(new AltitudeAtTime(4, 180, dt.AddMinutes(3)));
altitudes = new Altitudes(alts);

min = altitudes.FindMinimumAltitude();
min.Item2.Altitude.Should().BeApproximately(1, 0.001);
min.Item2.AtTime.Should().BeSameDateAs(dt);
min.Item1.Should().Be(0);

alts.Clear();
alts.Add(new AltitudeAtTime(4, 180, dt));
alts.Add(new AltitudeAtTime(3, 180, dt.AddMinutes(1)));
alts.Add(new AltitudeAtTime(2, 180, dt.AddMinutes(2)));
alts.Add(new AltitudeAtTime(1, 180, dt.AddMinutes(3)));
altitudes = new Altitudes(alts);

min = altitudes.FindMinimumAltitude();
min.Item2.Altitude.Should().BeApproximately(1, 0.001);
min.Item2.AtTime.Should().BeSameDateAs(dt.AddMinutes(3));
min.Item1.Should().Be(3);
}

[Test]
public void TestBad() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
using FluentAssertions;
using NINA.Astrometry;
using NINA.Core.Utility;
using NINA.Plugin.TargetPlanning.Test.Astrometry;
using NUnit.Framework;
using System;
using System.Threading;
using TargetPlanning.NINAPlugin.Astrometry;

namespace TargetPlanning.NINAPlugin.Test.Astrometry {

public class AstrometryUtilsTest {

[Test]
public void TestAirmass() {
for (int i = 0; i <= 90; i += 5) {
double airmass = AstroUtil.Airmass(i);
// TODO: ...
//TestContext.WriteLine(String.Format("{0,2:F0} {1,9:F2}", i, airmass));
}
}

[Test]
[TestCase("5:55:11", "7:24:30", 2022, 10, 27, 22, 25, 0, 0.0792, 80.9998)] // Betelgeuse rise
[TestCase("5:55:11", "7:24:30", 2022, 10, 28, 4, 46, 20, 62.4049, 181.0032)] // Betelgeuse transit
Expand Down Expand Up @@ -108,6 +101,15 @@ public void TestRisesAtLocationNorthHemisphere(double ra, double dec, bool expec
AstrometryUtils.RisesAtLocation(TestUtil.TEST_LOCATION_1, coordinates).Should().Be(expected);
}

[Test]
[TestCase(0, -40, true)]
[TestCase(0, -46, false)]
[TestCase(0, 70, true)]
public void TestRisesAtLocationNorthHemisphereMinAlt(double ra, double dec, bool expected) {
Coordinates coordinates = new Coordinates(ra, dec, Epoch.J2000, Coordinates.RAType.Degrees);
AstrometryUtils.RisesAtLocationWithMinimumAltitude(TestUtil.TEST_LOCATION_1, coordinates, 10).Should().Be(expected);
}

[Test]
[TestCase(0, -50, true)]
[TestCase(0, 56, false)]
Expand All @@ -117,6 +119,15 @@ public void TestRisesAtLocationSouthHemisphere(double ra, double dec, bool expec
AstrometryUtils.RisesAtLocation(TestUtil.TEST_LOCATION_2, coordinates).Should().Be(expected);
}

[Test]
[TestCase(0, -40, true)]
[TestCase(0, 46, false)]
[TestCase(0, -70, true)]
public void TestRisesAtLocationSouthHemisphereMinAlt(double ra, double dec, bool expected) {
Coordinates coordinates = new Coordinates(ra, dec, Epoch.J2000, Coordinates.RAType.Degrees);
AstrometryUtils.RisesAtLocationWithMinimumAltitude(TestUtil.TEST_LOCATION_2, coordinates, 10).Should().Be(expected);
}

[Test]
[TestCase(0, 56, true)]
[TestCase(0, 54, false)]
Expand Down Expand Up @@ -155,6 +166,27 @@ public void TestIsAbovePolarCircle() {
AstrometryUtils.IsAbovePolarCircle(TestUtil.TEST_LOCATION_3).Should().BeTrue();
}

[Test]
[TestCase(2022, 88.7958, 12, 24)] // Betelgeuse
[TestCase(2024, 88.7958, 12, 24)] // Betelgeuse, leap year
[TestCase(2022, 201.608, 5, 3)] // Spica
[TestCase(2024, 201.608, 5, 2)] // Spica, leap year
public void TestGetMidnightTransitDate(int year, double ra, int month, int day) {
CancellationTokenSource tokenSource = new CancellationTokenSource();
Logger.SetLogLevel(NINA.Core.Enum.LogLevelEnum.TRACE);

try {
Coordinates c = new Coordinates(ra, 0, Epoch.J2000, Coordinates.RAType.Degrees);
DateTime dt = AstrometryUtils.GetMidnightTransitDate(TestUtil.TEST_LOCATION_1, c, year, tokenSource.Token);
dt.Year.Should().Be(year);
dt.Month.Should().Be(month);
dt.Day.Should().Be(day);
}
finally {
tokenSource.Dispose();
}
}

[Test]
public void TestBad() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
using FluentAssertions;
using NINA.Astrometry;
using NINA.Core.Utility;
using NUnit.Framework;
using System;
using System.Threading;
using TargetPlanning.NINAPlugin.Astrometry;

namespace NINA.Plugin.TargetPlanning.Test.Astrometry {

public class HeliacalSolverTest {

private CancellationTokenSource tokenSource;

[SetUp]
public void SetUp() {
Logger.SetLogLevel(Core.Enum.LogLevelEnum.TRACE);
tokenSource = new CancellationTokenSource();
}

[TearDown]
public void TearDown() {
Logger.SetLogLevel(Core.Enum.LogLevelEnum.INFO);
tokenSource.Dispose();
}

[Test]
public void testGetHeliacalRisingDate() {

ObserverInfo location = TestUtil.TEST_LOCATION_1;
Coordinates target = TestUtil.SPICA;
DateTime transitMidnight = AstrometryUtils.GetMidnightTransitDate(location, target, 2022, tokenSource.Token);
HeliacalSolver solver = new HeliacalSolver(location, target, transitMidnight);

DateTime hr = solver.GetHeliacalRisingDate(tokenSource.Token);
hr.Month.Should().Be(11);
hr.Day.Should().Be(7);

DateTime hs = solver.GetHeliacalSettingDate(tokenSource.Token);
hs.Month.Should().Be(9);
hs.Day.Should().Be(5);

target = TestUtil.BETELGEUSE;
transitMidnight = AstrometryUtils.GetMidnightTransitDate(location, target, 2022, tokenSource.Token);
solver = new HeliacalSolver(location, target, transitMidnight);

hr = solver.GetHeliacalRisingDate(tokenSource.Token);
hr.Month.Should().Be(7);
hr.Day.Should().Be(24);

hs = solver.GetHeliacalSettingDate(tokenSource.Token);
hs.Month.Should().Be(5);
hs.Day.Should().Be(16);

target = TestUtil.M42;
transitMidnight = AstrometryUtils.GetMidnightTransitDate(location, target, 2022, tokenSource.Token);
solver = new HeliacalSolver(location, target, transitMidnight);

hr = solver.GetHeliacalRisingDate(tokenSource.Token);
hr.Month.Should().Be(7);
hr.Day.Should().Be(28);

hs = solver.GetHeliacalSettingDate(tokenSource.Token);
hs.Month.Should().Be(5);
hs.Day.Should().Be(5);
}

[Test]
[TestCase(80, 80, 90)]
[TestCase(-80, -80, -90)]
[TestCase(35, 15, 50)]
[TestCase(35, 19, 50)]
[TestCase(35, 21, 60)]
[TestCase(0, 4, 0)]
[TestCase(0, -4, 0)]
[TestCase(-35, -15, -50)]
[TestCase(-35, -19, -50)]
[TestCase(-35, -21, -60)]
public void testGetMappedConstant(double latitude, double dec, int expected) {
ObserverInfo location = new ObserverInfo();
location.Latitude = latitude;
location.Longitude = -80;
Coordinates target = new Coordinates(0, dec, Epoch.J2000, Coordinates.RAType.Degrees);

DateTime transitMidnight = AstrometryUtils.GetMidnightTransitDate(location, target, 2022, tokenSource.Token);
HeliacalSolver solver = new HeliacalSolver(location, target, transitMidnight);
solver.GetMappedConstant().Should().Be(expected);
}

/*
//[Test]
public void testGenConstantSheets() {
ObserverInfo location = new ObserverInfo();
location.Latitude = -35;
location.Longitude = -80;
location.Elevation = 0;
for (int constant = 90; constant >= -90; constant -= 10) {
TestContext.WriteLine($"\n--- CONSTANT {constant} ------------------------------------------\n");
StringBuilder sb = new StringBuilder();
sb.Append("CONST,DEC,LAT,HR,HS,HR Off,HS Off\n");
for (int dec = 90; dec >= -90; dec -= 5) {
double lat = constant - dec;
Coordinates coords = new Coordinates(AstroUtil.HMSToDegrees("0:0:0"),
AstroUtil.DMSToDegrees(string.Format("{0}:0:0", dec)),
Epoch.J2000, Coordinates.RAType.Degrees);
//TestContext.WriteLine($"{dec} {lat}");
location.Latitude = lat;
if (lat > 66 || lat < -66) {
TestContext.WriteLine($"dec={dec} lat={lat} skipping: APC");
continue;
}
if (!AstrometryUtils.RisesAtLocation(location, coords)) {
TestContext.WriteLine($"dec={dec} lat={lat} skipping: NV");
continue;
}
if (AstrometryUtils.CircumpolarAtLocation(location, coords)) {
TestContext.WriteLine($"at dec={dec} lat={lat} skipping: CP");
continue;
}
try {
DateTime tt = AstrometryUtils.GetMidnightTransitDate(location, coords, 2022, tokenSource.Token);
HeliacalSolver solver = new HeliacalSolver(location, coords);
DateTime guessHR = tt.AddMonths(-6);
DateTime hr = solver.GetHeliacalRisingDate(guessHR);
DateTime guessHS = tt.AddMonths(6);
DateTime hs = solver.GetHeliacalSettingDate(guessHS);
TestContext.WriteLine($"{dec},{lat},{tt:MM/dd/yyyy},{hr:MM/dd/yyyy},{hs:MM/dd/yyyy},{(hr - tt).Days},{(hs - tt).Days}");
sb.Append($"{constant},{dec},{lat},{hr:MM/dd/yyyy},{hs:MM/dd/yyyy},{(hr - tt).Days},{(hs - tt).Days}\n");
}
catch (Exception e) {
TestContext.WriteLine(e.Message);
}
}
File.WriteAllText($"G:\\Photography\\Astrophotography\\Notes\\C{constant}.csv", sb.ToString());
}
throw new Exception("oops");
}*/

/*
//[Test]
public void testGenConstantRange() {
ObserverInfo location = new ObserverInfo();
location.Latitude = -35;
location.Longitude = -80;
location.Elevation = 0;
TestContext.Write($",");
for (int dec = 90; dec >= -90; dec--) {
TestContext.Write($"{dec},");
}
TestContext.WriteLine("");
for (int lat = 90; lat >= -90; lat--) {
TestContext.Write($"{lat},");
for (int dec = 90; dec >= -90; dec--) {
double constant = dec + lat;
location.Latitude = lat;
Coordinates coords = new Coordinates(AstroUtil.HMSToDegrees("0:0:0"),
AstroUtil.DMSToDegrees(String.Format("{0}:0:0", dec)),
Epoch.J2000, Coordinates.RAType.Degrees);
String display = constant.ToString();
if (AstrometryUtils.IsAbovePolarCircle(location)) {
display = "APC";
}
else if (!AstrometryUtils.RisesAtLocation(location, coords)) {
display = "NV";
}
else if (AstrometryUtils.CircumpolarAtLocation(location, coords)) {
display = "CP";
}
TestContext.Write($"{display},");
}
TestContext.WriteLine("");
}
throw new Exception("oops");
}*/
}

}
Loading

0 comments on commit fd9d9d5

Please sign in to comment.