Exemplo n.º 1
0
        //=================== GET Info PW3 =========================//
        //private void GetPlanwaveInfo()
        //{
        //    double lst, altRadians, azRadians;
        //    String uRLString = "http://localhost:8220/status";
        //    XmlTextReader reader = new XmlTextReader(uRLString);
        //    textBox9.BeginInvoke((Action)(() =>
        //    {
        //        label20.ForeColor = System.Drawing.Color.Green;
        //        label20.Text = "Connected";
        //        String elementName = "";
        //        textBox9.Text = "";
        //        while (reader.Read())
        //        {
        //            switch (reader.NodeType)
        //            {
        //                case XmlNodeType.Element:
        //                    elementName = reader.Name;

        //                    if (elementName == "utc" ||
        //                        elementName == "jd" ||
        //                        elementName == "lst" ||
        //                        elementName == "azm_radian" ||
        //                        elementName == "alt_radian")
        //                    {
        //                        textBox9.Text += " " + reader.Name + " : ";
        //                    }
        //                    break;
        //                case XmlNodeType.Text:

        //                    if (elementName == "utc" ||
        //                        elementName == "jd" ||
        //                        elementName == "lst" ||
        //                        elementName == "azm_radian" ||
        //                        elementName == "alt_radian")
        //                    {
        //                        switch (elementName)
        //                        {
        //                            case "lst": string[] lst_split = reader.Value.Split(' '); lst = Convert.ToDouble(lst_split[0]); textBox9.Text += reader.Value; break;
        //                            case "azm_radian": textBox9.Text += Convert.ToString((Convert.ToDouble(reader.Value) * 57.2957795131)); string[] altSplit = reader.Value.Split(' '); altRadians = Convert.ToDouble(altSplit[0]) * 57.2957795131; break;
        //                            case "alt_radian": textBox9.Text += Convert.ToString((Convert.ToDouble(reader.Value) * 57.2957795131)); string[] azmSplit = reader.Value.Split(' '); azRadians = Convert.ToDouble(azmSplit[0]) * 57.2957795131; break;
        //                            default: textBox9.Text += reader.Value; break;
        //                        }
        //                        textBox9.Text += System.Environment.NewLine;
        //                    }
        //                    elementName = "";
        //                    break;
        //            }
        //        }
        //    }));
        //}

        //=============================================//

        //=============  Calculate Sun Position ==============//mmmmmm
        public void sunPosition(out double sunAlt, out double sunAzm)
        {
            try
            {
                RaDec    raDec             = Sun.GetRaDec(AstroTime.JulianDayUTC(DateTime.Now));
                AltAz    sunAltAzm         = AstroLib.RADecToAltAz(DateTime.Now, raDec);
                String   altSunBeforeSprit = Convert.ToString(sunAltAzm.Alt);
                String[] sunAltSprit       = altSunBeforeSprit.Split(' ');
                Double   sunAltSprited     = Convert.ToDouble(sunAltSprit[0]);
                String   azmSunBeforeSprit = Convert.ToString(sunAltAzm.Az);
                String[] sunAzmSprit       = azmSunBeforeSprit.Split(' ');
                Double   sunAzmSprited     = Convert.ToDouble(sunAzmSprit[0]);
                sunAlt = sunAltSprited;
                sunAzm = sunAzmSprited;
                double revertSunAzm = sunAzm - 180;
                if (revertSunAzm < 0)
                {
                    revertSunAzm = revertSunAzm + 360;
                }
                textBox10.Invoke((Action)(() =>
                {
                    textBox10.Text = "Local Date Time: " + DateTime.Now + Environment.NewLine +
                                     "Latitude Ref : " + LATITUDE + Environment.NewLine +
                                     "Longitude Ref : " + LONGITUDE + Environment.NewLine +
                                     "Sun Alt : " + Math.Round(Convert.ToDecimal(sunAltSprited), 5) + Environment.NewLine +
                                     "Sun Azm : " + Math.Round(Convert.ToDecimal(sunAzmSprited), 5) + Environment.NewLine +
                                     "Revert Azm : " + Math.Round(Convert.ToDecimal(revertSunAzm), 5);
                    textBox14.Text = Convert.ToString(Math.Round(Convert.ToDecimal(aDU), 2));
                    textBox13.Text = exposureTime;

                    textBox20.Text = Convert.ToString(Convert.ToDecimal(variableAdu)); //TEST
                }));
            }
            catch { sunAlt = 0; sunAzm = 0; }
        }
Exemplo n.º 2
0
            public static AzAlt GetPosition(DateTime dt, double lat, double lng)
            {
                double lw  = rad * -lng;
                double phi = rad * lat;
                double d   = JulianDays(dt);
                RaDec  c   = SunCoords(d);
                double H   = SiderealTime(d, lw) - c.ra;

                return(new AzAlt {
                    azimuth = Azimuth(H, phi, c.dec), altitude = Altitude(H, phi, c.dec)
                });
            }
Exemplo n.º 3
0
        public JsonResult <PositionResult> GetPosition()
        {
            RaDec          astro  = celestialConversion.CalcualteRaDec(Program.mControl.elPos, Program.mControl.azPos, Program.mControl.settings.latitude, Program.mControl.settings.longitude);
            PositionResult result = new PositionResult()
            {
                Azimuth        = Program.mControl.azPos,
                Elevation      = Program.mControl.elPos,
                RightAscension = astro.RA,
                Declination    = astro.Dec
            };

            return(Json(result));
        }
Exemplo n.º 4
0
            public static MoonFracPhaseAngle GetMoonIllumination(DateTime dt)
            {
                double        d     = JulianDays(dt);
                RaDec         s     = SunCoords(d);
                MoonRaDecDist m     = MoonCoords(d);
                double        sdist = 149598000; // distance from Earth to Sun in km
                double        phi   = Math.Acos(Math.Sin(s.dec) * Math.Sin(m.dec) + Math.Cos(s.dec) * Math.Cos(m.dec) * Math.Cos(s.ra - m.ra));
                double        inc   = Math.Atan2(sdist * Math.Sin(phi), m.dist - sdist * Math.Cos(phi));
                double        angle = Math.Atan2(Math.Cos(s.dec) * Math.Sin(s.ra - m.ra), Math.Sin(s.dec) * Math.Cos(m.dec) -
                                                 Math.Cos(s.dec) * Math.Sin(m.dec) * Math.Cos(s.ra - m.ra));

                return(new MoonFracPhaseAngle {
                    fraction = (1 + Math.Cos(inc)) / 2, phase = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / PI, angle = angle
                });
            }
Exemplo n.º 5
0
        //=================== Ecposure ===================//
        public void exposeCamera(int hBin, int vBin, int tdi, double exposureTime)
        {
            Image <Gray, float> image;
            Image <Rgb, byte>   imageRGB;
            int ulX, ulY, lrX, lrY;

            fliCCD.GetVisibleArea(out ulX, out ulY, out lrX, out lrY);
            int width  = lrX - ulX;
            int height = lrY - ulY;

            ushort[][] data = new ushort[height][];
            fliCCD.SetImageArea(ulX, ulY, lrX, lrY);
            exposureTime = exposureTime * 1000;
            fliCCD.SetExposureTime(Convert.ToInt32(exposureTime));
            fliCCD.SetHBin(hBin);
            fliCCD.SetVBin(vBin);
            fliCCD.SetTDI(tdi);
            sunPosition(out double sunAltStart, out double sunAzmStart);
            fliCCD.Expose();

            while (!fliCCD.IsDownloadReady())
            {
                Thread.Sleep(100);
            }
            for (int y = 0; y < height; y++)
            {
                data[y] = new ushort[width];
                fliCCD.GrabRow(data[y]);
            }
            sunPosition(out double sunAltEnd, out double sunAzmEnd);
            Matrix <float> matrix = new Matrix <float>(height, width);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    matrix.Data[y, x] = data[y][x];
                }
            }

            image = matrix.Mat.ToImage <Gray, float>();
            //imageBox1.Image = image2;

            string ADU = Convert.ToString(image.GetAverage());

            string[] words = ADU.Split('[', ']');
            aDU = Convert.ToDouble(words[1]);
            string localDate    = DateTime.Now.ToString("dd/MM/yyyy_THH':'mm':'ss");
            string fileFitsName = "ImageFits/Sun_alt_ " + sunAltStart + "_ADU_" + aDU + ".fits";

            addRecord(localDate, Convert.ToString(sunAltStart), Convert.ToString(sunAltEnd), Convert.ToString(sunAzmStart), Convert.ToString(sunAzmEnd), Convert.ToString((exposureTime / 1000)), filterSelect, Convert.ToString(ADU), "dataRecord/info_expose.txt");

            //========== write .fits =========//
            SRSLib.ImageLib.ImageType imageFit = new SRSLib.ImageLib.ImageType();
            imageFit.N1            = height;
            imageFit.N2            = width;
            imageFit.N3            = 1;
            imageFit.Simple        = true;
            imageFit.HaveHistogram = true;
            imageFit.HaveDateTime  = true;
            imageFit.HaveLevels    = true;
            imageFit.XBinning      = hBin;
            imageFit.YBinning      = vBin;
            imageFit.NAxis         = 2;
            imageFit.BScale        = 1;
            imageFit.DateObsStr    = Convert.ToString(DateTime.UtcNow);
            imageFit.HaveDateTime  = true;
            String[] header_fit = new String[50];
            imageFit.Header     = header_fit;
            imageFit.BScale     = 1;
            imageFit.Filter     = filterSelect;
            imageFit.DateObsStr = localDate;
            imageFit.Exposure   = (exposureTime / 1000);
            imageFit.JD         = AstroCalculation.AstroLib.GetLocalJD();
            RaDec raDec = Sun.GetRaDec(AstroTime.JulianDayUTC(DateTime.Now));

            imageFit.DecRad      = Convert.ToDouble(raDec.Dec.Rads);
            imageFit.RARad       = Convert.ToDouble(raDec.Ra.Rads);
            imageFit.ImageType   = "Flat Field";
            imageFit.Data        = matrix.Data;
            imageFit.Temperature = fliCCD.GetTemperature();

            SRSLib.ImageLib.WriteFITS(ref imageFit, fileFitsName, false);

            //===================================================//

            //====================== Convert .Fits To .JPG ===========================//

            String stretchType = comboBox2.Text;

            strecthImage.GetStrecthType(stretchType, out double lowerPercen, out double upperPercen);
            Matrix <UInt16> NewImg   = strecthImage.ConvertStretchImageU16BitToJPG(matrix.Convert <UInt16>(), lowerPercen, upperPercen);
            string          imageJpg = "imageJPG/Sun_alt_ " + sunAltStart + "_ADU_" + aDU + " .jpg";

            NewImg.Save(imageJpg);

            pictureBox1.Image = Image.FromFile(imageJpg);
            //=======================================================================//
            //=========================Plot Graph AllSky=========================//
            AllskyPlotGraph(out string fileNameAllsky);

            //===================================================================//

            //======================Insert Mongo DB ====================//
            CCD_Mongo cCDMongo = new CCD_Mongo(sunAltStart, sunAltEnd, sunAzmStart, sunAzmEnd, filterSelect, (exposureTime / 1000), aDU, fileFitsName, imageJpg, fileNameAllsky, DateTime.Now);

            collection.InsertOne(cCDMongo);
            //==========================================================//

            NewImg = null;
            data   = null;
            matrix = null;
            image  = null;

            textBox14.Text    = Convert.ToString(Math.Round(Convert.ToDecimal(aDU), 2));
            this.exposureTime = Convert.ToString((exposureTime / 1000));
            textBox13.Text    = this.exposureTime;
        }
Exemplo n.º 6
0
        private static double HourAngle(double st, RaDec raDec)
        {
            var H = st - raDec.Ra;

            return(H * rads);
        }