/// <summary> /// Get the selected object in TheSkyX /// </summary> /// <returns></returns> public async Task <DeepSkyObject> GetTarget() { try { string response = await Query("GET_TARGET"); response = response.TrimEnd('\r', '\n'); /* * Split the coordinates and object name from the returned message. * GET_TARGET returns 4 fields, space-separated: * RA Dec Name Position_angle * * RA and Dec are in radians. Epoch is J2000. */ string[] info = response.Split(' '); if (!(info[0].Equals("?") || string.IsNullOrEmpty(info[2]))) { Coordinates newCoordinates = new Coordinates(Astrometry.RadianToHour(double.Parse(info[0].Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture)), Astrometry.ToDegree(double.Parse(info[1].Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture)), Epoch.J2000, Coordinates.RAType.Hours); DeepSkyObject dso = new DeepSkyObject(info[2], newCoordinates, string.Empty); return(dso); } else { throw new PlanetariumObjectNotSelectedException(); } } catch (Exception ex) { Logger.Error(ex); throw ex; } }
public void ToDegree_ValueTest() { var rad = Math.PI; var expectedDeg = 180; var deg = Astrometry.ToDegree(rad); Assert.AreEqual(expectedDeg, deg); }
public void CreateByRadiansTest(double inputRadians) { var angle = Angle.ByRadians(inputRadians); var expectedDegree = Astrometry.ToDegree(inputRadians); var expectedArcmin = Astrometry.DegreeToArcmin(expectedDegree); var expectedArcsec = Astrometry.DegreeToArcsec(expectedDegree); var expectedHours = Astrometry.DegreesToHours(expectedDegree); Assert.AreEqual(expectedHours, angle.Hours, TOLERANCE); Assert.AreEqual(inputRadians, angle.Radians, TOLERANCE); Assert.AreEqual(expectedDegree, angle.Degree, TOLERANCE); Assert.AreEqual(expectedArcmin, angle.ArcMinutes, TOLERANCE); Assert.AreEqual(expectedArcsec, angle.ArcSeconds, TOLERANCE); }
public void OperatorMultiplyDoubleTest(double firstDegree, double secondDegree) { var secondAngle = Angle.ByDegree(secondDegree); var angle = Astrometry.ToRadians(firstDegree) * secondAngle; var expectedRadian = Astrometry.ToRadians(firstDegree) * Astrometry.ToRadians(secondDegree); var expectedDegree = Astrometry.ToDegree(expectedRadian); var expectedArcmin = Astrometry.DegreeToArcmin(expectedDegree); var expectedArcsec = Astrometry.DegreeToArcsec(expectedDegree); var expectedHours = Astrometry.DegreesToHours(expectedDegree); Assert.AreEqual(expectedDegree, angle.Degree, TOLERANCE); Assert.AreEqual(expectedArcmin, angle.ArcMinutes, TOLERANCE); Assert.AreEqual(expectedArcsec, angle.ArcSeconds, TOLERANCE); Assert.AreEqual(expectedHours, angle.Hours, TOLERANCE); Assert.AreEqual(expectedRadian, angle.Radians, TOLERANCE); }
public void StaticAtan2Test(double xRadians, double yRadians) { var xAngle = Angle.ByRadians(xRadians); var yAngle = Angle.ByRadians(yRadians); var angle = Angle.Atan2(yAngle, xAngle); var rad = Math.Atan2(yRadians, xRadians); var expectedDegree = Astrometry.ToDegree(rad); var expectedArcmin = Astrometry.DegreeToArcmin(expectedDegree); var expectedArcsec = Astrometry.DegreeToArcsec(expectedDegree); var expectedHours = Astrometry.DegreesToHours(expectedDegree); Assert.AreEqual(expectedHours, angle.Hours, TOLERANCE); Assert.AreEqual(rad, angle.Radians, TOLERANCE); Assert.AreEqual(expectedDegree, angle.Degree, TOLERANCE); Assert.AreEqual(expectedArcmin, angle.ArcMinutes, TOLERANCE); Assert.AreEqual(expectedArcsec, angle.ArcSeconds, TOLERANCE); }
/// <summary> /// Return the configured user location from HNSKY /// </summary> /// <returns></returns> public async Task <Coords> GetSite() { try { var response = await Query("GET_LOCATION"); response = response.TrimEnd('\r', '\n'); /* * Split the latitude and longitude from the returned message. * GET_LOCATION returns 3 fields, space-separated: * Latitude Longitude Julian_Date * * Latitude and Logitude are in radians. */ var info = response.Split(' '); if (!(info[0].Equals("?") || string.IsNullOrEmpty(info[1]))) { /* * East is negative and West is positive in HNSKY. * We must flip longitude's sign here. */ var loc = new Coords { Latitude = Astrometry.ToDegree(double.Parse(info[1].Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture)), Longitude = Astrometry.ToDegree(double.Parse(info[0].Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture)) * -1, Elevation = 0 }; return(loc); } else { throw new PlanetariumFailedToGetCoordinates(); } } catch (Exception ex) { Logger.Error(ex); throw ex; } }
/// <summary> /// Extract result out of generated .axy file. File consists of three rows /// 1. row: RA,Dec,Code /// 2. row: Scale,Orientation,?,?,Stars /// </summary> /// <returns>PlateSolveResult</returns> protected override PlateSolveResult ReadResult( string outputFilePath, PlateSolveParameter parameter, PlateSolveImageProperties imageProperties) { PlateSolveResult result = new PlateSolveResult() { Success = false }; if (File.Exists(outputFilePath)) { using (var s = new StreamReader(outputFilePath)) { string line; int linenr = 0; while ((line = s.ReadLine()) != null) { string[] resultArr = line.Split(','); if (linenr == 0) { if (resultArr.Length > 2) { double ra, dec; int status; if (resultArr.Length == 5) { /* workaround for when decimal separator is comma instead of point. * won't work when result contains even numbers tho... */ status = int.Parse(resultArr[4]); if (status != 1) { /* error */ result.Success = false; break; } ra = double.Parse(resultArr[0] + "." + resultArr[1], CultureInfo.InvariantCulture); dec = double.Parse(resultArr[2] + "." + resultArr[3], CultureInfo.InvariantCulture); } else { status = int.Parse(resultArr[2]); if (status != 1) { /* error */ result.Success = false; break; } ra = double.Parse(resultArr[0], CultureInfo.InvariantCulture); dec = double.Parse(resultArr[1], CultureInfo.InvariantCulture); } /* success */ result.Success = true; result.Coordinates = new Coordinates(Astrometry.ToDegree(ra), Astrometry.ToDegree(dec), Epoch.J2000, Coordinates.RAType.Degrees); } } if (linenr == 1) { if (resultArr.Length > 2) { if (resultArr.Length > 5) { /* workaround for when decimal separator is comma instead of point. * won't work when result contains even numbers tho... */ result.Pixscale = double.Parse(resultArr[0] + "." + resultArr[1], CultureInfo.InvariantCulture); result.Orientation = double.Parse(resultArr[2] + "." + resultArr[3], CultureInfo.InvariantCulture); result.Flipped = !(double.Parse(resultArr[4] + "." + resultArr[5], CultureInfo.InvariantCulture) < 0); if (result.Flipped) { result.Orientation = result.Orientation - 180; } } else { result.Pixscale = double.Parse(resultArr[0], CultureInfo.InvariantCulture); result.Orientation = double.Parse(resultArr[1], CultureInfo.InvariantCulture); result.Flipped = !(double.Parse(resultArr[2], CultureInfo.InvariantCulture) < 0); if (result.Flipped) { result.Orientation = result.Orientation - 180; } } } } linenr++; } } } return(result); }