///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //----------------------------------------- COORDINATE_TRANSFORMATION --------------------------------------------- /* * This script does the following: * - Transform from horizontal to celestial coordinates * * * */ // returns the sidereal time at the designated longitude public static float LocalSiderealTime(float lng) { // get the current time DateTime now = DateTime.Now; //create time custom time object AASDate dateSunCalc = new AASDate(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, true); //get greenwich time double greenwich_sidereal_time = AASSidereal.MeanGreenwichSiderealTime(dateSunCalc.Julian); //adjust for longitude double adj_st = greenwich_sidereal_time + (lng * (24.0 / 360.0)); if (adj_st >= 24.0) { adj_st -= 24.0; } if (adj_st < 0) { adj_st += 24.0; } return((float)adj_st); }
public static AAS2DCoordinate SunPosition(DateTime dateTime) { var bHighPrecision = false; dateTime = dateTime.ToUniversalTime(); // NOTE: time must be converted to Universal Time //Calculate the topocentric horizontal position of the Sun AASDate dateSunCalc = new AASDate(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, true); double JDSun = dateSunCalc.Julian + AASDynamicalTime.DeltaT(dateSunCalc.Julian) / 86400.0; double SunLong = AASSun.ApparentEclipticLongitude(JDSun, bHighPrecision); double SunLat = AASSun.ApparentEclipticLatitude(JDSun, bHighPrecision); AAS2DCoordinate Equatorial = AASCoordinateTransformation.Ecliptic2Equatorial(SunLong, SunLat, AASNutation.TrueObliquityOfEcliptic(JDSun)); double SunRad = AASEarth.RadiusVector(JDSun, bHighPrecision); AAS2DCoordinate SunTopo = AASParallax.Equatorial2Topocentric(Equatorial.X, Equatorial.Y, SunRad, RT_LONG, RT_LAT, RT_HEIGHT, JDSun); double AST = AASSidereal.ApparentGreenwichSiderealTime(dateSunCalc.Julian); double LongtitudeAsHourAngle = AASCoordinateTransformation.DegreesToHours(RT_LONG); double LocalHourAngle = AST - LongtitudeAsHourAngle - SunTopo.X; AAS2DCoordinate SunHorizontal = AASCoordinateTransformation.Equatorial2Horizontal(LocalHourAngle, SunTopo.Y, RT_LAT); SunHorizontal.Y += AASRefraction.RefractionFromTrue(SunHorizontal.Y, 1013, 10); //The result above should be that we have a setting Sun at Y degrees above the horizon at azimuth X degrees south of the westerly horizon //NOTE: for azimuth west is considered positive, to get east as positive subtract the result from 360 return(SunHorizontal); }
public static AAS2DCoordinate MoonPosition(DateTime dateTime) { dateTime = dateTime.ToUniversalTime(); // NOTE: time must be converted to Universal Time //Calculate the topocentric horizontal position of the Moon AASDate dateMoonCalc = new AASDate(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, true); double JDMoon = dateMoonCalc.Julian + AASDynamicalTime.DeltaT(dateMoonCalc.Julian) / 86400.0; double MoonLong = AASMoon.EclipticLongitude(JDMoon); double MoonLat = AASMoon.EclipticLatitude(JDMoon); AAS2DCoordinate Equatorial = AASCoordinateTransformation.Ecliptic2Equatorial(MoonLong, MoonLat, AASNutation.TrueObliquityOfEcliptic(JDMoon)); double MoonRad = AASMoon.RadiusVector(JDMoon); MoonRad /= 149597870.691; //Convert KM to AU AAS2DCoordinate MoonTopo = AASParallax.Equatorial2Topocentric(Equatorial.X, Equatorial.Y, MoonRad, RT_LONG, RT_LAT, RT_HEIGHT, JDMoon); double AST = AASSidereal.ApparentGreenwichSiderealTime(dateMoonCalc.Julian); double LongtitudeAsHourAngle = AASCoordinateTransformation.DegreesToHours(RT_LONG); double LocalHourAngle = AST - LongtitudeAsHourAngle - MoonTopo.X; AAS2DCoordinate MoonHorizontal = AASCoordinateTransformation.Equatorial2Horizontal(LocalHourAngle, MoonTopo.Y, RT_LAT); MoonHorizontal.Y += AASRefraction.RefractionFromTrue(MoonHorizontal.Y, 1013, 10); //The result above should be that we have a rising Moon at Y degrees above the horizon at azimuth X degrees east of the southern horizon //NOTE: for azimuth west is considered positive, to get east as positive subtract the result from 360 return(MoonHorizontal); }
public void NutationInObliquityTest() { var date = new AASDate(1987, 4, 10, 0, 0, 0, true); double nutationInEcliptic = AASNutation.NutationInObliquity(date.Julian); Assert.Equal(9.4425206987573933, nutationInEcliptic); }
public void MeanObliquityOfEclipticTest() { var date = new AASDate(1987, 4, 10, 0, 0, 0, true); double obliquity = AASNutation.MeanObliquityOfEcliptic(date.Julian); Assert.Equal(23.440946290957317, obliquity); }
public Coordinate OrientationToCoordinate(Orientation currHorizontal, DateTime datetime) { // We don't want to modify the current orientation, so we must create a new instance Orientation horizontal = (Orientation)currHorizontal.Clone(); if (horizontal == null) { throw new ArgumentException("Orientation cannot be null"); } // Since AASharp considers south zero, flip the orientation 180 degrees horizontal.Azimuth += 180; if (horizontal.Azimuth > 360) { horizontal.Azimuth -= 360; } AAS2DCoordinate equatorial = AASCoordinateTransformation.Horizontal2Equatorial(horizontal.Azimuth, horizontal.Elevation, Location.Latitude); AASDate date = new AASDate(datetime.Year, datetime.Month, datetime.Day, datetime.Hour, datetime.Minute, datetime.Second, true); double ApparentGreenwichSiderealTime = AASSidereal.ApparentGreenwichSiderealTime(date.Julian); double LongtitudeAsHourAngle = AASCoordinateTransformation.DegreesToHours(Location.Longitude); double RightAscension = ApparentGreenwichSiderealTime - LongtitudeAsHourAngle - equatorial.X; if (RightAscension < 0) { RightAscension += 24; } return(new Coordinate(RightAscension, equatorial.Y)); }
public void NutationInLongitudeTest() { var date = new AASDate(1987, 4, 10, 0, 0, 0, true); double nutationInLongitude = AASNutation.NutationInLongitude(date.Julian); Assert.Equal(-3.7879310766037446, nutationInLongitude); }
public void JulianDate(int year, int month, int day, int expectedJulianDay) { bool bGregorian = AASDate.AfterPapalReform(year, month, day); var date = new AASDate(year, month, day, 12, 0, 0, bGregorian); Assert.Equal(expectedJulianDay, date.Julian); }
public void DeltaTTest2(long year, long month, double day, double hour, double minute, double second, bool isGregorianCalendar, double expectedDeltaT) { var date = new AASDate(year, month, day, hour, minute, second, isGregorianCalendar); double deltaT = AASDynamicalTime.DeltaT(date.Julian); Assert.Equal(expectedDeltaT, deltaT); }
public void UpdateJd(int year, int month, int day, int hour, int minute, double second) { //if we are using local time, let us convert the input to UTC if (!useUTC) { int secondInt = (int)Math.Truncate(second); int milisecond = (int)((second - secondInt) * 1000); try{ DateTime utc = new DateTime(year, month, day, hour, minute, secondInt, milisecond); utc.ToUniversalTime(); year = utc.Year; month = utc.Month; day = utc.Day; hour = utc.Hour; minute = utc.Minute; second = utc.Second + utc.Millisecond / 1000.0d; localDatetime = utc.ToLocalTime(); }catch (ArgumentOutOfRangeException a) { } } double dayDec = day + hour / HOURS_PER_DAY + minute / MINUTES_PER_DAY + second / SECONDS_PER_DAY; jd = Convert.ToDecimal(AASDate.DateToJD(year, month, dayDec, gregorianCalendar)); }
public void GregorianToJulianTest(long year, long month, long day, long expectedYear, long expectedMonth, long expectedDay) { AASCalendarDate gregorianDate = AASDate.GregorianToJulian(year, month, day); Assert.Equal(expectedYear, gregorianDate.Year); Assert.Equal(expectedMonth, gregorianDate.Month); Assert.Equal(expectedDay, gregorianDate.Day); }
public void DateInitialisation(int year, int month, int day) { bool bGregorian = AASDate.AfterPapalReform(year, month, day); var date = new AASDate(year, month, day, 12, 0, 0, bGregorian); Assert.Equal(year, date.Year); Assert.Equal(month, date.Month); Assert.Equal(day, date.Day); }
public void DayOfYearToDayAndMonthTest(long dayOfYear, bool isLeap, long expectedDayOfMonth, long expectedMonth) { long dayOfMonth = 0; long month = 0; AASDate.DayOfYearToDayAndMonth(dayOfYear, isLeap, ref dayOfMonth, ref month); Assert.Equal(expectedDayOfMonth, dayOfMonth); Assert.Equal(expectedMonth, month); }
public void MeanGreenwichSiderealTimeTest(int year, int month, int day, int hours, int minutes, int seconds, bool isGregorian, double expectedSideralTime) { var date = new AASDate(); date.Set(year, month, day, hours, minutes, seconds, isGregorian); double meanGreenwichSiderealTime = AASSidereal.MeanGreenwichSiderealTime(date.Julian); Assert.Equal(expectedSideralTime, meanGreenwichSiderealTime); }
public void IsLeapTest(int year, bool isLeap) { //Test of the instance property var date = new AASDate(year, 1, 1, year >= 1582); Assert.Equal(isLeap, date.Leap); //Test of the static method Assert.Equal(isLeap, AASDate.IsLeap(year, year >= 1582)); }
public void DaysInMonthTest(int month, bool isLeap, int expectedNumberOfDay) { //Test of the instance method var date = new AASDate(isLeap ? 2016 : 2017, month, 1, true); Assert.Equal(expectedNumberOfDay, date.DaysInMonth()); //Test of the static method Assert.Equal(expectedNumberOfDay, AASDate.DaysInMonth(month, isLeap)); }
[InlineData(2018, 3, 25, 12, 15, 29.999984800815632)]//TODO : Second should return 30. But AA+ also return 29.9999... To check with AA+ author public void YearMonthDayHourMinuteSecondTest(int year, int month, int day, double hour, double minute, double second) { var date = new AASDate(year, month, day, hour, minute, second, true); Assert.Equal(year, date.Year); Assert.Equal(month, date.Month); Assert.Equal(day, date.Day); Assert.Equal(hour, date.Hour); Assert.Equal(minute, date.Minute); Assert.Equal(second, date.Second); }
public static AASCalendarDate DateOfPesach(long Year, bool bGregorianCalendar = true) { //What will be the return value AASCalendarDate Pesach = new AASCalendarDate(); long C = AASDate.INT(Year / 100.0); long S = AASDate.INT((3 * C - 5) / 4.0); if (bGregorianCalendar == false) { S = 0; } long A = Year + 3760; long a = (12 * Year + 12) % 19; long b = Year % 4; double Q = -1.904412361576 + 1.554241796621 * a + 0.25 * b - 0.003177794022 * Year + S; long INTQ = AASDate.INT(Q); long j = (INTQ + 3 * Year + 5 * b + 2 - S) % 7; double r = Q - INTQ; if ((j == 2) || (j == 4) || (j == 6)) { Pesach.Day = INTQ + 23; } else if ((j == 1) && (a > 6) && (r >= 0.632870370)) { Pesach.Day = INTQ + 24; } else if ((j == 0) && (a > 11) && (r >= 0.897723765)) { Pesach.Day = INTQ + 23; } else { Pesach.Day = INTQ + 22; } if (Pesach.Day > 31) { Pesach.Month = 4; Pesach.Day -= 31; } else { Pesach.Month = 3; } Pesach.Year = A; return(Pesach); }
private DateTime GetAutumnalEquinox(int year) { long curYear = 0, month = 0, day = 0, hour = 0, minutes = 0; double seconds = 0; var date = new AASDate(); var spring = AASEquinoxesAndSolstices.SouthwardEquinox(year, true); date.Set(spring, true); date.Get(ref curYear, ref month, ref day, ref hour, ref minutes, ref seconds); var dt = new DateTime((int)curYear, (int)month, (int)day, (int)hour, (int)minutes, (int)seconds); var converDt = TimeZoneInfo.ConvertTimeFromUtc(dt, timeZone); return(converDt); }
public Coordinate GetSunCoordinate(DateTime datetime) { AASDate date = new AASDate(datetime.Year, datetime.Month, datetime.Day, datetime.Hour, datetime.Minute, datetime.Second, true); double JD = date.Julian + AASDynamicalTime.DeltaT(date.Julian) / 86400.0; double SunLong = AASSun.ApparentEclipticLongitude(JD, false); double SunLat = AASSun.ApparentEclipticLatitude(JD, false); AAS2DCoordinate equatorial = AASCoordinateTransformation.Ecliptic2Equatorial(SunLong, SunLat, AASNutation.TrueObliquityOfEcliptic(JD)); double SunRad = AASEarth.RadiusVector(JD, false); // This line gives us RA & Declination. AAS2DCoordinate SunTopo = AASParallax.Equatorial2Topocentric(equatorial.X, equatorial.Y, SunRad, Location.Longitude, Location.Latitude, Location.Altitude, JD); return(new Coordinate(SunTopo.X, SunTopo.Y)); }
public static long DaysInYear(long Year) { //Find the previous civil year corresponding to the specified jewish year long CivilYear = Year - 3761; //Find the date of the next Jewish Year in that civil year AASCalendarDate CurrentPesach = DateOfPesach(CivilYear); bool bGregorian = AASDate.AfterPapalReform(CivilYear, CurrentPesach.Month, CurrentPesach.Day); AASDate CurrentYear = new AASDate(CivilYear, CurrentPesach.Month, CurrentPesach.Day, bGregorian); AASCalendarDate NextPesach = DateOfPesach(CivilYear + 1); AASDate NextYear = new AASDate(CivilYear + 1, NextPesach.Month, NextPesach.Day, bGregorian); return((long)(NextYear.Julian - CurrentYear.Julian)); }
public Coordinate GetMoonCoordinate(DateTime datetime) { AASDate date = new AASDate(datetime.Year, datetime.Month, datetime.Day, datetime.Hour, datetime.Minute, datetime.Second, true); double JD = date.Julian + AASDynamicalTime.DeltaT(date.Julian) / 86400.0; double MoonLong = AASMoon.EclipticLongitude(JD); double MoonLat = AASMoon.EclipticLatitude(JD); AAS2DCoordinate Equatorial = AASCoordinateTransformation.Ecliptic2Equatorial(MoonLong, MoonLat, AASNutation.TrueObliquityOfEcliptic(JD)); double MoonRad = AASMoon.RadiusVector(JD); MoonRad /= 149597870.691; //Convert KM to AU AAS2DCoordinate MoonTopo = AASParallax.Equatorial2Topocentric(Equatorial.X, Equatorial.Y, MoonRad, Location.Longitude, Location.Latitude, Location.Altitude, JD); return(new Coordinate(MoonTopo.X, MoonTopo.Y)); }
public void Reset() { DateTime dt = DateTime.Now; localDatetime = dt; if (useUTC) { dt = TimeZoneInfo.ConvertTimeToUtc(dt); } double dayDec = dt.Day + dt.Hour / HOURS_PER_DAY + dt.Minute / MINUTES_PER_DAY + dt.Second / SECONDS_PER_DAY + dt.Millisecond / MILLISECONDS_PER_DAY; jd = Convert.ToDecimal(AASDate.DateToJD(dt.Year, dt.Month, dayDec, gregorianCalendar)); }
public static AASCalendarDate MoslemToJulian(long Year, long Month, long Day) { //What will be the return value AASCalendarDate julianDate = new AASCalendarDate(); long N = Day + AASDate.INT(29.5001 * (Month - 1) + 0.99); long Q = AASDate.INT(Year / 30.0); long R = Year % 30; long A = AASDate.INT((11 * R + 3) / 30.0); long W = 404 * Q + 354 * R + 208 + A; long Q1 = AASDate.INT(W / 1461.0); long Q2 = W % 1461; long G = 621 + 4 * AASDate.INT(7 * Q + Q1); long K = AASDate.INT(Q2 / 365.2422); long E = AASDate.INT(365.2422 * K); long J = Q2 - E + N - 1; long X = G + K; long XMod4 = X % 4; if ((J > 366) && (XMod4 == 0)) { J -= 366; X++; } if ((J > 365) && (XMod4 > 0)) { J -= 365; X++; } julianDate.Year = X; var julienDateDay = julianDate.Day; var julienDateMonth = julianDate.Month; AASDate.DayOfYearToDayAndMonth(J, AASDate.IsLeap(X, false), ref julienDateDay, ref julienDateMonth); julianDate.Day = julienDateDay; julianDate.Month = julienDateMonth; return(julianDate); }
public Orientation CoordinateToOrientation(Coordinate coordinate, DateTime datetime) { if (coordinate == null) { throw new ArgumentException("Coordinate cannot be null"); } AASDate date = new AASDate(datetime.Year, datetime.Month, datetime.Day, datetime.Hour, datetime.Minute, datetime.Second, true); double ApparentGreenwichSiderealTime = AASSidereal.ApparentGreenwichSiderealTime(date.Julian); double LongtitudeAsHourAngle = AASCoordinateTransformation.DegreesToHours(Location.Longitude); double LocalHourAngle = ApparentGreenwichSiderealTime - LongtitudeAsHourAngle - coordinate.RightAscension; AAS2DCoordinate Horizontal = AASCoordinateTransformation.Equatorial2Horizontal(LocalHourAngle, coordinate.Declination, Location.Latitude); // Since AASharp considers south zero, flip the orientation 180 degrees Horizontal.X += 180; if (Horizontal.X > 360) { Horizontal.X -= 360; } return(new Orientation(Horizontal.X, Horizontal.Y)); }
/// <summary> /// /// </summary> /// <param name="ra">RA in hours</param> /// <param name="dec">declination in degrees</param> /// <param name="epoch">epoch in years AD</param> /// <returns>constellation abbreviation (3 letters), or '' on error</returns> public static Constellation GetConstellation(double ra, double dec, int epoch) { AASDate j1875 = new AASDate(1875, 1, 1, 12, 0, 0, true); AASDate jEpoch = new AASDate(epoch, 1, 1, 12, 0, 0, true); var coordinates = AASPrecession.PrecessEquatorial(ra, dec, jEpoch.Julian, j1875.Julian); ra = coordinates.X; dec = coordinates.Y; var foundConstellationBoundary = Constellations.Boundaries.FirstOrDefault(boundary => !(dec < boundary.LowerDeclination || ra < boundary.LowerRightAscension || ra >= boundary.UpperRightAscension)); if (foundConstellationBoundary != null) { return(Constellations.ConstellationsData.Single(c => c.Abbreviation == foundConstellationBoundary.ConstellationAbbreviation)); } throw new NotFoundException($"Constellation not found for coordinates RA : {ra}, Dec : {dec}"); }
public void DateToJDTest(long year, long month, double day, bool isGregorianCalendar, double expectedJD) { double JD = AASDate.DateToJD(year, month, day, isGregorianCalendar); Assert.Equal(expectedJD, JD); }
public void DayOfWeekTest(long year, long month, double day, bool isGregorianCalendar, DAY_OF_WEEK expectedDayOfWeek) { var date = new AASDate(year, month, day, isGregorianCalendar); Assert.Equal(expectedDayOfWeek, date.DayOfWeek); }
public void JulianTest(int year, int month, int day, bool isGregorianCalendar, double expectedJulianDay) { var date = new AASDate(year, month, day, isGregorianCalendar); Assert.Equal(expectedJulianDay, date.Julian); }
public void DaysInYearTest(int year, int expectedNumberOfDay) { var date = new AASDate(year, 1, 1, true); Assert.Equal(expectedNumberOfDay, date.DaysInYear()); }