Beispiel #1
0
        private void FillPhotometrySummary(TargetData tstar)
        {
            SourceMagBox.Text = tstar.SourceUncorrectedMagnitude.ToString("0.00");
            TargetToSourcePositionErrorBox.Text = Utility.NAGenerator((int)tstar.TargetToSourcePositionError, 1000);

            //APASS

            TargetToAPASSPositionErrorBox.Text = Utility.NAGenerator((int)tstar.TargetToAPASSCatalogPositionError, 1000);
            APASSNameBox.Text = tstar.APASSCatalogName;
            APASSRABox.Text   = Utility.SexidecimalRADec(tstar.APASSCatalogRA, true);
            APASSDecBox.Text  = Utility.SexidecimalRADec(tstar.APASSCatalogDec, false);

            APASSCorrectedMagBox.Text   = tstar.APASSSourceCorrectedMagnitude.ToString("0.000");
            CorrelatedStarCountBox.Text = tstar.APASSStarCount.ToString();
            APASSRSquaredBox.Text       = tstar.APASSMagnitudeRSquared.ToString("0.000");
            APASSAccuracyBox.Text       = tstar.APASSMagPopulationStandardError.ToString("0.000");
            APASSSlopeBox.Text          = tstar.APASSMagnitudeGradient.ToString("0.000");
            APASSInterceptBox.Text      = tstar.APASSMagnitudeIntercept.ToString("0.000");

            //GAIA
            TargetToGAIAPositionErrorBox.Text = Utility.NAGenerator((int)tstar.TargetToGAIACatalogPositionError, 1000);
            GAIANameBox.Text = tstar.GAIACatalogName;
            GAIARABox.Text   = Utility.SexidecimalRADec(tstar.GAIACatalogRA, true);
            GAIADecBox.Text  = Utility.SexidecimalRADec(tstar.GAIACatalogDec, false);

            GAIACorrectedMagBox.Text = tstar.GAIASourceCorrectedMagnitude.ToString("0.000");
            GAIARSquaredBox.Text     = (tstar.GAIAMagnitudeRSquared).ToString("0.000");
            GAIAAccuracyBox.Text     = (tstar.GAIASourceCorrectedMagnitude * (1 - tstar.GAIAMagnitudeRSquared)).ToString("0.000");
            GAIASlopeBox.Text        = tstar.GAIAMagnitudeGradient.ToString("0.000");
            GAIAInterceptBox.Text    = tstar.GAIAMagnitudeIntercept.ToString("0.000");
            return;
        }
Beispiel #2
0
        private TargetData SearchForLightSourceInventory(ccdsoftImage tsximg, TargetData lightSource)
        {
            sky6Utils tsxu   = new sky6Utils();
            double    ra     = lightSource.TargetRA;
            double    dec    = lightSource.TargetDec;
            double    rDelta = 1000;
            double    rmsDelta;
            int       sIndex = -1;

            for (int iSource = 0; iSource < XPosArr.Length; iSource++)
            {
                tsximg.XYToRADec((double)XPosArr[iSource], (double)YPosArr[iSource]);
                double raSrc  = tsximg.XYToRADecResultRA();
                double decSrc = tsximg.XYToRADecResultDec();;
                tsxu.ComputeAngularSeparation(ra, dec, raSrc, decSrc);
                rmsDelta = tsxu.dOut0;
                if (rmsDelta <= rDelta)
                {
                    rDelta = rmsDelta;
                    sIndex = iSource;
                    lightSource.InventoryArrayIndex         = sIndex;
                    lightSource.TargetToSourcePositionError = rDelta * 3600.0;
                    lightSource.SourceRA  = raSrc;
                    lightSource.SourceDec = decSrc;
                    lightSource.SourceUncorrectedMagnitude = (double)MagArr[sIndex];
                    lightSource.SourceX = (double)XPosArr[sIndex];
                    lightSource.SourceY = (double)YPosArr[sIndex];
                }
            }
            return(lightSource);
        }
Beispiel #3
0
        public void StorePhotometry(TargetData pData)
        {
            //Create an XElement with the data
            //
            XElement newStarXdata  = CreateXrecord(pData);
            XElement archivedStarX = XElement.Load(StarchiveFullFilePath);
            //ignore duplications
            bool duplicateFlag = false;
            IEnumerable <XElement> targetXList = archivedStarX.Elements(PhotometryRecordX);

            foreach (XElement targetX in targetXList)
            {
                if ((targetX.Element(TargetNameX).Value == pData.TargetName) &&
                    (targetX.Element(ImageDateX).Value == pData.ImageDate.ToString()) &&
                    (targetX.Element(ImageFilterX).Value == pData.ImageFilter.ToString()) &&
                    (targetX.Element(SourceMagnitudeX).Value == pData.SourceUncorrectedMagnitude.ToString()))
                {
                    duplicateFlag = true;
                    break;
                }
            }
            if (!duplicateFlag)
            {
                archivedStarX.Add(newStarXdata);
                archivedStarX.Save(StarchiveFullFilePath);
            }
            return;
        }
Beispiel #4
0
        private void ArchiveStar(TargetData varTarget)
        {
            //Method to store star mag for future reference
            Starchive photoSave = new Starchive();

            photoSave.StorePhotometry(varTarget);
            return;
        }
Beispiel #5
0
        private XElement CreateXrecord(TargetData pData)
        {
            XElement newStarXdata = new XElement(PhotometryRecordX,
                                                 new XElement(TargetNameX, pData.TargetName),
                                                 new XElement(IsImageLinkedX, pData.IsImageLinked.ToString()),
                                                 new XElement(TargetRAX, pData.TargetRA.ToString()),
                                                 new XElement(TargetDecX, pData.TargetDec.ToString()),
                                                 new XElement(SourceRAX, pData.SourceRA.ToString()),
                                                 new XElement(SourceDecX, pData.SourceDec.ToString()),
                                                 new XElement(SourceMagnitudeX, pData.SourceUncorrectedMagnitude.ToString()),
                                                 new XElement(TargetToSourcePositionErrorX, pData.TargetToSourcePositionError.ToString()),
                                                 new XElement(SourceEllipticityX, pData.SourceEllipticity.ToString()),
                                                 new XElement(SourceFWHMX, pData.SourceFWHM.ToString()),
                                                 new XElement(SourceADUX, pData.SourceADU.ToString()),

                                                 new XElement(APASSCatalogNameX, pData.APASSCatalogName),
                                                 new XElement(APASSCatalogRAX, pData.APASSCatalogRA.ToString()),
                                                 new XElement(APASSCatalogDecX, pData.APASSCatalogDec.ToString()),
                                                 new XElement(APASSCatalogMagnitudeX, pData.APASSCatalogMagnitude.ToString()),
                                                 new XElement(APASSCatalogMagnitudeBX, pData.APASSCatalogMagnitudeB.ToString()),
                                                 new XElement(APASSCatalogMagnitudeVX, pData.APASSCatalogMagnitudeV.ToString()),
                                                 new XElement(APASSCatalogMagnitudeRX, pData.APASSCatalogMagnitudeR.ToString()),
                                                 new XElement(APASSCatalogMagnitudeGX, pData.APASSCatalogMagnitudeG.ToString()),
                                                 new XElement(APASSStarCountX, pData.APASSStarCount.ToString()),
                                                 new XElement(APASSMagnitudeGradientX, pData.APASSMagnitudeGradient.ToString()),
                                                 new XElement(APASSMagnitudeInterceptX, pData.APASSMagnitudeIntercept.ToString()),
                                                 new XElement(APASSMagnitudeRSquaredX, pData.APASSMagnitudeRSquared.ToString()),
                                                 new XElement(APASSSourceCorrectedMagnitudeX, pData.APASSSourceCorrectedMagnitude.ToString()),
                                                 new XElement(APASSMagnitudeCorrectionAccuracyX, pData.APASSMagPopulationStandardError.ToString()),

                                                 new XElement(TargetToAPASSCatalogPositionErrorX, pData.TargetToAPASSCatalogPositionError.ToString()),
                                                 new XElement(SourceToAPASSCatalogPositionErrorX, pData.SourceToAPASSCatalogPositionError.ToString()),

                                                 new XElement(GAIACatalogNameX, pData.GAIACatalogName),
                                                 new XElement(GAIACatalogRAX, pData.GAIACatalogRA.ToString()),
                                                 new XElement(GAIACatalogDecX, pData.GAIACatalogDec.ToString()),
                                                 new XElement(GAIACatalogMagnitudeX, pData.GAIACatalogMagnitude.ToString()),
                                                 new XElement(GAIACatalogMagnitudeBX, pData.GAIACatalogMagnitudeB.ToString()),
                                                 new XElement(GAIACatalogMagnitudeGX, pData.GAIACatalogMagnitudeG.ToString()),
                                                 new XElement(GAIACatalogMagnitudeRX, pData.GAIACatalogMagnitudeR.ToString()),
                                                 new XElement(GAIAStarCountX, pData.GAIAStarCount.ToString()),
                                                 new XElement(GAIAMagnitudeGradientX, pData.GAIAMagnitudeGradient.ToString()),
                                                 new XElement(GAIAMagnitudeInterceptX, pData.GAIAMagnitudeIntercept.ToString()),
                                                 new XElement(GAIAMagnitudeRSquaredX, pData.GAIAMagnitudeRSquared.ToString()),
                                                 new XElement(GAIASourceCorrectedMagnitudeX, pData.GAIASourceCorrectedMagnitude.ToString()),
                                                 new XElement(GAIAMagnitudeCorrectionAccuracyX, pData.GAIAMagPopulationStandardError.ToString()),

                                                 new XElement(TargetToGAIACatalogPositionErrorX, pData.TargetToGAIACatalogPositionError.ToString()),
                                                 new XElement(SourceToGAIACatalogPositionErrorX, pData.SourceToGAIACatalogPositionError.ToString()),

                                                 new XElement(ImageDateX, pData.ImageDate.ToString()),
                                                 new XElement(ImageFilterX, pData.ImageFilter.ToString()),
                                                 new XElement(ComputedSeeingX, pData.ComputedSeeing),
                                                 new XElement(AirMassX, pData.AirMass));

            return(newStarXdata);
        }
Beispiel #6
0
        private void SelectTargetListBox_Click(object sender, EventArgs e)
        {
            currentTargetIndex = SelectTargetListBox.SelectedIndex;
            if (!CurveOnlyBox.Checked)
            {
                //close the current tsx image if one is open
                if (TSX_Image != null)
                {
                    VariScanFileManager.CloseImageFile(TSX_Image);
                }
                //Get the directory name that was chosen
                string targetChoice = SelectTargetListBox.SelectedItem.ToString();
                //Load the variable list entry info for that choice of targets, if none -- return
                TargetList varList = new TargetList();
                IEnumerable <TargetList.TargetXDescriptor> tgtList = varList.GetTargetList();
                TargetList.TargetXDescriptor tgtDef = tgtList.FirstOrDefault(name => name.Name == targetChoice);
                if (tgtDef == null)
                {
                    return;
                }

                FitsIsOpen           = VariScanFileManager.DialogOpenImageFile(TSX_Image, tgtDef.Name);
                OpenFileNameBox.Text = TSX_Image.Path;
                if (FitsIsOpen)
                {
                    TargetedNameBox.Text   = tgtDef.Name;
                    TargetedRABox.Text     = Utility.SexidecimalRADec(tgtDef.RA, true);
                    TargetedDecBox.Text    = Utility.SexidecimalRADec(tgtDef.Dec, false);
                    TargetedFilterBox.Text = tgtList.ElementAt(SelectTargetListBox.SelectedIndex).Filter.ToString();
                    TargetData tstar = Analyze(tgtDef.Name, tgtDef.RA, tgtDef.Dec);
                    if (tstar.IsImageLinked)
                    {
                        ManageTSXProcess.MinimizeTSX();
                        SourceRATextBox.Text  = Utility.SexidecimalRADec(tstar.SourceRA, true);
                        SourceDecTextBox.Text = Utility.SexidecimalRADec(tstar.SourceDec, false);
                        tstar = GraphMagnitudes(tstar);
                        tstar = GraphSource(tstar);
                        FillPhotometrySummary(tstar);
                        PlotPhotometryHistory(tgtDef.Name);
                        ManageTSXProcess.NormalizeTSX();
                    }
                    Show();
                    System.Windows.Forms.Application.DoEvents();
                }
            }
            else
            {
                string targetChoice = SelectTargetListBox.SelectedItem.ToString();
                PlotPhotometryHistory(targetChoice);
                Show();
                System.Windows.Forms.Application.DoEvents();
            }
        }
Beispiel #7
0
        public List <TargetData> RetrieveAllPhotometry()
        {
            List <TargetData> starList = new List <TargetData>();

            if (!File.Exists(StarchiveFullFilePath))
            {
                return(starList);
            }
            XElement starAllXdata            = XElement.Load(StarchiveFullFilePath);
            IEnumerable <XElement> starXlist = starAllXdata.Elements(PhotometryRecordX);

            foreach (XElement star in starXlist)
            {
                TargetData pd = CreateTarget(star);
                starList.Add(pd);
            }
            return(starList);
        }
Beispiel #8
0
        private void SingleButton_Click(object sender, EventArgs e)
        {
            //DialogResult odr = OrphanFileDialog.ShowDialog();

            //close the current tsx image if one is open
            if (TSX_Image != null)
            {
                VariScanFileManager.CloseImageFile(TSX_Image);
            }

            TargetList.TargetXDescriptor tgtDef = new TargetList.TargetXDescriptor("Orphan", 0, 0, 0);

            FitsIsOpen           = VariScanFileManager.DialogOrphanImageFile(TSX_Image, tgtDef.Name);
            OpenFileNameBox.Text = TSX_Image.Path;
            if (FitsIsOpen)
            {
                Fits fits = new Fits(TSX_Image);
                tgtDef.Name            = fits.FitsTarget;
                tgtDef.RA              = (double)(fits.FitsRA ?? 0);
                tgtDef.Dec             = (double)(fits.FitsDec ?? 0);
                tgtDef.Filter          = 3;
                tgtDef.LastImagingDate = fits.FitsUTCDateTime;

                TargetedNameBox.Text   = tgtDef.Name;
                TargetedRABox.Text     = Utility.SexidecimalRADec(tgtDef.RA, true);
                TargetedDecBox.Text    = Utility.SexidecimalRADec(tgtDef.Dec, false);
                TargetedFilterBox.Text = fits.Filter;
                TargetData tstar = Analyze(tgtDef.Name, tgtDef.RA, tgtDef.Dec);
                if (tstar.IsImageLinked)
                {
                    ManageTSXProcess.MinimizeTSX();
                    SourceRATextBox.Text  = Utility.SexidecimalRADec(tstar.SourceRA, true);
                    SourceDecTextBox.Text = Utility.SexidecimalRADec(tstar.SourceDec, false);
                    tstar = GraphMagnitudes(tstar);
                    tstar = GraphSource(tstar);
                    FillPhotometrySummary(tstar);
                    PlotPhotometryHistory(tgtDef.Name);
                    ManageTSXProcess.NormalizeTSX();
                }
            }
            Show();
            System.Windows.Forms.Application.DoEvents();
            return;
        }
Beispiel #9
0
        public List <TargetData> RetrievePhotometry(string tgtName, string imageFilter)
        {
            //Open file, convert xml entries to list, if any
            List <TargetData> starList = new List <TargetData>();

            if (!File.Exists(StarchiveFullFilePath))
            {
                return(starList);
            }
            XElement starAllXdata            = XElement.Load(StarchiveFullFilePath);
            IEnumerable <XElement> starXlist = starAllXdata.Elements(PhotometryRecordX);

            foreach (XElement star in starXlist)
            {
                if ((star.Element(TargetNameX).Value == tgtName) && (star.Element(ImageFilterX).Value == imageFilter))
                {
                    TargetData pd = CreateTarget(star);
                    starList.Add(pd);
                }
            }
            return(starList);
        }
Beispiel #10
0
        public List <TargetData> RetrieveAllPhotometrySummarized()
        {
            List <TargetData> starchiveList     = new List <TargetData>();
            List <TargetData> starTgtList       = new List <TargetData>();
            List <TargetData> starCondensedList = new List <TargetData>();

            //If no starchive, then return a null list
            if (!File.Exists(StarchiveFullFilePath))
            {
                return(starTgtList);
            }
            //Load starchive
            XElement starchiveAllXdata            = XElement.Load(StarchiveFullFilePath);
            IEnumerable <XElement> starchiveXlist = starchiveAllXdata.Elements(PhotometryRecordX);

            //Translate each entry to a target structure
            //Create list of all targets
            foreach (XElement srec in starchiveXlist)
            {
                TargetData pd = CreateTarget(srec);
                starTgtList.Add(pd);
            }
            var starGroups = starTgtList.GroupBy(s => s.TargetName);

            foreach (var st in starGroups)
            {
                var dateGroups = st.GroupBy(s => s.ImageDate.Date);
                foreach (var dt in dateGroups)
                {
                    Tuple <double, double> catalogMeans = TargetEnsembleMean(dt.ToList());
                    dt.ToList()[0].APASSSourceCorrectedMagnitude = catalogMeans.Item1;
                    dt.ToList()[0].GAIASourceCorrectedMagnitude  = catalogMeans.Item2;
                    starCondensedList.Add(dt.ToList()[0]);
                }
            }
            return(starCondensedList);
        }
Beispiel #11
0
        private TargetData CreateTarget(XElement xData)
        {
            XElement   nF    = new XElement("Null", "0.0");
            TargetData tData = new TargetData
            {
                TargetName    = FetchX(xData, TargetNameX, "None"),
                IsImageLinked = Convert.ToBoolean(FetchX(xData, IsImageLinkedX, "False")),
                TargetRA      = Convert.ToDouble(FetchX(xData, TargetRAX, "0.0")),
                TargetDec     = Convert.ToDouble(FetchX(xData, TargetDecX, "0.0")),
                SourceRA      = Convert.ToDouble(FetchX(xData, SourceRAX, "0.0")),
                SourceDec     = Convert.ToDouble(FetchX(xData, SourceDecX, "0.0")),
                SourceUncorrectedMagnitude  = Convert.ToDouble(FetchX(xData, SourceMagnitudeX, "0.0")),
                TargetToSourcePositionError = Convert.ToDouble(FetchX(xData, TargetToSourcePositionErrorX, "0.0")),
                SourceEllipticity           = Convert.ToDouble(FetchX(xData, SourceEllipticityX, "0.0")),
                SourceFWHM = Convert.ToDouble(FetchX(xData, SourceFWHMX, "0.0")),
                SourceADU  = Convert.ToDouble(FetchX(xData, SourceADUX, "0.0")),

                APASSCatalogName                = FetchX(xData, APASSCatalogNameX, "None"),
                APASSCatalogRA                  = Convert.ToDouble(FetchX(xData, APASSCatalogRAX, "0.0")),
                APASSCatalogDec                 = Convert.ToDouble(FetchX(xData, APASSCatalogDecX, "0.0")),
                APASSCatalogMagnitude           = Convert.ToDouble(FetchX(xData, APASSCatalogMagnitudeX, "0.0")),
                APASSCatalogMagnitudeB          = Convert.ToDouble(FetchX(xData, APASSCatalogMagnitudeBX, "0.0")),
                APASSCatalogMagnitudeV          = Convert.ToDouble(FetchX(xData, APASSCatalogMagnitudeVX, "0.0")),
                APASSCatalogMagnitudeR          = Convert.ToDouble(FetchX(xData, APASSCatalogMagnitudeRX, "0.0")),
                APASSCatalogMagnitudeG          = Convert.ToDouble(FetchX(xData, APASSCatalogMagnitudeGX, "0.0")),
                APASSStarCount                  = Convert.ToInt32(FetchX(xData, APASSStarCountX, "0")),
                APASSMagnitudeGradient          = Convert.ToDouble(FetchX(xData, APASSMagnitudeGradientX, "0.0")),
                APASSMagnitudeIntercept         = Convert.ToDouble(FetchX(xData, APASSMagnitudeInterceptX, "0.0")),
                APASSMagnitudeRSquared          = Convert.ToDouble(FetchX(xData, APASSMagnitudeRSquaredX, "0.0")),
                APASSSourceCorrectedMagnitude   = Convert.ToDouble(FetchX(xData, APASSSourceCorrectedMagnitudeX, "0.0")),
                APASSMagPopulationStandardError = Convert.ToDouble(FetchX(xData, APASSMagnitudeCorrectionAccuracyX, "0.0")),

                TargetToAPASSCatalogPositionError = Convert.ToDouble(FetchX(xData, TargetToAPASSCatalogPositionErrorX, "0.0")),
                SourceToAPASSCatalogPositionError = Convert.ToDouble(FetchX(xData, SourceToAPASSCatalogPositionErrorX, "0.0")),

                GAIACatalogName                = FetchX(xData, GAIACatalogNameX, "None"),
                GAIACatalogRA                  = Convert.ToDouble(FetchX(xData, GAIACatalogRAX, "0.0")),
                GAIACatalogDec                 = Convert.ToDouble(FetchX(xData, GAIACatalogDecX, "0.0")),
                GAIACatalogMagnitude           = Convert.ToDouble(FetchX(xData, GAIACatalogMagnitudeX, "0.0")),
                GAIACatalogMagnitudeB          = Convert.ToDouble(FetchX(xData, GAIACatalogMagnitudeBX, "0.0")),
                GAIACatalogMagnitudeG          = Convert.ToDouble(FetchX(xData, GAIACatalogMagnitudeGX, "0.0")),
                GAIACatalogMagnitudeR          = Convert.ToDouble(FetchX(xData, GAIACatalogMagnitudeRX, "0.0")),
                GAIAStarCount                  = Convert.ToInt32(FetchX(xData, GAIAStarCountX, "0")),
                GAIAMagnitudeGradient          = Convert.ToDouble(FetchX(xData, GAIAMagnitudeGradientX, "0.0")),
                GAIAMagnitudeIntercept         = Convert.ToDouble(FetchX(xData, GAIAMagnitudeInterceptX, "0.0")),
                GAIAMagnitudeRSquared          = Convert.ToDouble(FetchX(xData, GAIAMagnitudeRSquaredX, "0.0")),
                GAIASourceCorrectedMagnitude   = Convert.ToDouble(FetchX(xData, GAIASourceCorrectedMagnitudeX, "0.0")),
                GAIAMagPopulationStandardError = Convert.ToDouble(FetchX(xData, GAIAMagnitudeCorrectionAccuracyX, "0.0")),

                TargetToGAIACatalogPositionError = Convert.ToDouble(FetchX(xData, TargetToGAIACatalogPositionErrorX, "0.0")),
                SourceToGAIACatalogPositionError = Convert.ToDouble(FetchX(xData, SourceToGAIACatalogPositionErrorX, "0.0")),

                ImageDate      = Convert.ToDateTime(FetchX(xData, ImageDateX, DateTime.MinValue.ToString())),
                ImageFilter    = FetchX(xData, ImageFilterX, "NA"),
                ComputedSeeing = FetchX(xData, ComputedSeeingX, "NA"),

                AirMass = Convert.ToDouble(FetchX(xData, AirMassX, "0.0"))
            };

            return(tData);
        }
Beispiel #12
0
        public static TargetData SetMagnitudeForFilter(TargetData lightSource, string filter)
        {
            switch (filter)
            {
            case "C":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeV;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeG;
                break;
            }

            case "B":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeB;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeB;
                break;
            }

            case "V":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeV;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeG;
                break;
            }

            case "G":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeG;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeG;
                break;
            }

            case "R":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeR;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeR;
                break;
            }

            case "Clear":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeV;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeG;
                break;
            }

            case "Red":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeR;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeR;
                break;
            }

            case "Blue":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeB;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeB;
                break;
            }

            case "Green":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeG;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeG;
                break;
            }

            case "Default":
            {
                lightSource.APASSCatalogMagnitude = lightSource.APASSCatalogMagnitudeV;
                lightSource.GAIACatalogMagnitude  = lightSource.GAIACatalogMagnitudeG;
                break;
            }
            }
            return(lightSource);
        }
Beispiel #13
0
        private TargetData GraphSource(TargetData sourceStar)
        {
            //This routine produces a 3D graph of a star//s astrometric information, from the center out to twice the FWHM radius.
            // using the Source Inventory as at the inventory Index

            //Check to see if the star was in the inventory array
            // if not, then just return
            int inventoryIndex = sourceStar.InventoryArrayIndex;

            if (inventoryIndex < 0)
            {
                return(sourceStar);
            }

            //Get the star center (x,y) and 2xFWHM (in pixels), as well as the maximum X and Y values
            double XMax     = TSX_Image.WidthInPixels - 1;
            double YMax     = TSX_Image.HeightInPixels - 1;
            double XCen     = (double)XPosArr[inventoryIndex];
            double YCen     = (double)YPosArr[inventoryIndex];
            int    fwhmSpan = (int)((double)FWHMArr[inventoryIndex] * 2);

            if (fwhmSpan < 0)
            {
                fwhmSpan = 0;
            }
            //Calculate the lowest and highest X positions for twice the FWHM
            int Pix0 = (int)(XCen - (fwhmSpan / 2));

            if (Pix0 < 0)
            {
                Pix0 = 0;
            }
            double PixN = XCen + (fwhmSpan / 2);

            if (PixN > XMax)
            {
                PixN = XMax;
            }

            Series[] Ypix = new Series[fwhmSpan];
            object[] Yline;

            StarADUChart.Series.Clear();

            SourceFWHMBox.Text        = ((double)FWHMArr[inventoryIndex]).ToString("0.00");
            SourceEllipticityBox.Text = ((double)EllipticityArr[inventoryIndex]).ToString("0.00");

            sourceStar.SourceEllipticity = (double)EllipticityArr[inventoryIndex];
            sourceStar.SourceFWHM        = (double)FWHMArr[inventoryIndex];

            //Convert X,Y coordinates to RA,Dec coordinates
            double cerr = TSX_Image.XYToRADec((double)XPosArr[inventoryIndex], (double)YPosArr[inventoryIndex]);

            sourceStar.SourceRA  = TSX_Image.XYToRADecResultRA();
            sourceStar.SourceDec = TSX_Image.XYToRADecResultDec();

            //Cataloged star should have already been found during Analysis
            StarADUChart.Titles[0].Text = sourceStar.APASSCatalogName;
            //PhotometryCatMagBox.Text = sourceStar.CatMagnitude.ToString("0.00");
            //PhotometrySourceMagBox.Text = ((double)MagArr[inventoryIndex]).ToString("0.00");
            //PhotometryAllCatalogCorrectedMagBox.Text = ((double)MagArr[inventoryIndex] + MeanMagDelta).ToString("0.00");

            //Create the graph series for the 2XFWHM X range around X center, for the 2XFWHM Y range around the Y center
            //  making sure to cut off any excursion either below 0 or about the X or Y ranges
            //
            //So... for a 2XFWHM number of data series,
            int maxStarADU = 0;

            for (int i = 0; i < fwhmSpan; i++)
            {
                //Create a series object for the scanned line and attach it to the graph
                Ypix[i] = new Series(i.ToString());
                StarADUChart.Series.Add(Ypix[i]);
                //Scan in the } data series from the image, if it runs over the range, presumably it will truncate normally
                int lineIndex = (int)(i + YCen - (fwhmSpan / 2));
                if (lineIndex >= 0 && lineIndex < YMax)
                {
                    Yline = TSX_Image.scanLine(lineIndex);
                    //Write the pixel values to the series while checking for saturation (indicate in the label).
                    //  and for the maximum ADU value

                    for (int j = Pix0; j <= PixN; j++)
                    {
                        if (j < Yline.Length)
                        {
                            int adu = (int)Yline[j];
                            if (adu > maxStarADU)
                            {
                                maxStarADU = adu;
                            }
                            Ypix[i].Points.Add(adu * PixelScale_arcsec);
                        }
                    }
                }

                //Set the chart configuration and display
                Ypix[i].XValueType  = ChartValueType.Auto;
                Ypix[i].ChartType   = SeriesChartType.SplineArea;
                Ypix[i].MarkerStyle = MarkerStyle.Circle;
            }
            //set the maximum ADU as the value at the center
            if (maxStarADU > SaturationADU)
            {
                MaxADULabel.ForeColor = Color.Black;
                MaxADULabel.BackColor = Color.Pink;
            }
            else
            {
                MaxADULabel.ForeColor = Color.White;
                MaxADULabel.BackColor = Color.Empty;
            }
            SourcePeakADUBox.Text = maxStarADU.ToString("0");
            sourceStar.SourceADU  = maxStarADU;
            //All done
            return(sourceStar);
        }
Beispiel #14
0
        private void ScanImagesButton_Click(object sender, EventArgs e)
        {
            //Redden the command button
            Utility.ButtonRed(ScanImagesButton);
            Show();
            System.Windows.Forms.Application.DoEvents();

            //Get list of targets
            TargetList vList = new TargetList();
            List <TargetList.TargetXDescriptor> targetList = vList.GetTargetList();

            for (int iTgt = 0; iTgt < targetList.Count; iTgt++)
            {
                string targetDirectoryName = targetList[iTgt].Name;
                FitsNameBox.Text = targetDirectoryName;
                Show();
                System.Windows.Forms.Application.DoEvents();

                IEnumerable <string> targetImages = VariScanFileManager.TargetImageList(targetDirectoryName);
                if (targetImages != null)
                {
                    foreach (string iFile in targetImages)
                    {
                        //Use a direct fits reader to determine if the image has already been analyized, i.e. in Starchive (TSX is too slow)
                        Starchive recs  = new Starchive();
                        FitsFile  fitMe = new FitsFile(iFile);
                        FitsNameBox.Text   = targetDirectoryName;
                        FitsDateBox.Text   = fitMe.FitsUTCDateTime.ToShortDateString();
                        FitsTimeBox.Text   = fitMe.FitsUTCDateTime.ToShortTimeString();
                        FitsFilterBox.Text = fitMe.Filter.ToString();
                        Show();
                        System.Windows.Forms.Application.DoEvents();

                        if (!recs.HasMatchingPhotometryRecord(targetDirectoryName, fitMe.Filter, fitMe.FitsUTCDateTime))
                        {
                            if (TSX_Image != null)
                            {
                                VariScanFileManager.CloseImageFile(TSX_Image);
                            }
                            FitsIsOpen = VariScanFileManager.DirectOpenFitsFile(TSX_Image, iFile);
                            if (FitsIsOpen)
                            {
                                OpenFileNameBox.Text = iFile;
                                FITImage             = new Fits(TSX_Image);
                                //if (!recs.HasMatchingPhotometryRecord(targetDirectoryName, FITImage.Filter, FITImage.FitsUTCDateTime))
                                //{
                                ManageTSXProcess.MinimizeTSX();
                                TargetedNameBox.Text   = targetList[iTgt].Name;
                                TargetedRABox.Text     = Utility.SexidecimalRADec(targetList[iTgt].RA, true);
                                TargetedDecBox.Text    = Utility.SexidecimalRADec(targetList[iTgt].Dec, false);
                                TargetedFilterBox.Text = targetList[iTgt].Filter.ToString();
                                TargetData tstar = Analyze(targetList[iTgt].Name, targetList[iTgt].RA, targetList[iTgt].Dec);
                                if (tstar.IsImageLinked)
                                {
                                    SourceRATextBox.Text  = Utility.SexidecimalRADec(tstar.SourceRA, true);
                                    SourceDecTextBox.Text = Utility.SexidecimalRADec(tstar.SourceDec, false);
                                    tstar = GraphMagnitudes(tstar);
                                    tstar = GraphSource(tstar);
                                    FillPhotometrySummary(tstar);
                                    ArchiveStar(tstar);
                                    PlotPhotometryHistory(targetList[iTgt].Name);
                                    Show();
                                    System.Windows.Forms.Application.DoEvents();
                                }
                                else
                                {
                                    //Star did not image link -- archive it as is
                                    ArchiveStar(tstar);
                                }
                                ManageTSXProcess.NormalizeTSX();
                                //}
                                Show();
                                System.Windows.Forms.Application.DoEvents();
                            }
                        }
                    }
                }
            }
            breakLoop = false;
            Utility.ButtonGreen(BreakButton);
            //Green the command button
            Utility.ButtonGreen(ScanImagesButton);
            return;
        }
Beispiel #15
0
        private TargetData GraphMagnitudes(TargetData tData)
        {
            //Graphs the ccd magnitude against the catalog magnitude
            //  for all light sources for which cooresponding cataloged stars
            //   can be found.

            //List of star names found from catalog for stars
            List <string> catStarNames = new List <string>();
            //List of magnitudes as determined by TSX
            List <double> sexMagPlotPoints = new List <double>();
            //List of magnitudes as taken from catalog data
            List <double> catMagPlotPoints = new List <double>();
            //List of ADU's as determined from image data
            List <double> imgADUPlotPoints = new List <double>();
            //List of valid Target Data objects from APASS database
            List <TargetData> validCatalogedStars = new List <TargetData>();

            magArrPlotIndex = new List <int>();

            //Clear the Photometry Chart of plotted points
            PhotometryChart.Series[0].Points.Clear();

            //Display the total number of stars to analyze from the image light source arrays
            SourceCountBox.Text = "/" + MagArr.Length.ToString("0");
            Color savebackcolor = SourceCountBox.BackColor;

            for (int sIdx = 0; sIdx < WCSActiveArr.Length; sIdx++)
            {
                //Use a count down of the star count as a progress bar
                SourceCountBox.Text = (sIdx + 1).ToString("0") + "/" + WCSActiveArr.Length.ToString("0");
                //if the source is "active" (meaning used for imagelinking)
                //  get it's RA/Dec and pull up its Inventory data
                //  Search the catalogs and create a target data object,
                //  and, if found, add the source and catalog magnitudes
                //  and save to the culled list of targets (validStarPoints)
                if ((int)(double)WCSActiveArr[sIdx] == 1)
                {
                    //Gather Inventory at WCS target
                    double raStar  = (double)WCSRAArr[sIdx];
                    double decStar = (double)WCSDecArr[sIdx];
                    //Get the Inventory for the light source nearest this ra,dec location
                    var wcsInventory = TSX_Image.FindInventoryAtRADec(raStar, decStar);
                    //Load the information into a Target Data object
                    try
                    {
                        TargetData wcsStarData = new TargetData()
                        {
                            SourceRA  = raStar,
                            SourceDec = decStar,
                            SourceUncorrectedMagnitude = (double)wcsInventory[(int)TSXEnums.ccdsoftInventoryIndex.cdInventoryMagnitude]
                        };
                        //Add catalog data based on nearest APASS star
                        wcsStarData = NearestCatalogedStar.AcquireNearestQualifiedStar(wcsStarData);

                        //Get ADU at image X,Y position
                        //  Note: the Zero Y line is the top line of the image
                        int      xPos      = (int)wcsInventory[(int)TSXEnums.ccdsoftInventoryIndex.cdInventoryX];
                        int      yPos      = (int)wcsInventory[(int)TSXEnums.ccdsoftInventoryIndex.cdInventoryY];
                        object[] xDataLine = TSX_Image.scanLine(yPos);
                        int      xyADU     = (int)xDataLine[xPos];
                        wcsStarData.SourceADU = xyADU;
                        //Put the equivalent filter magnitude in the catalog magnitude field
                        wcsStarData = Filters.SetMagnitudeForFilter(wcsStarData, tData.ImageFilter);

                        if (wcsStarData.IsAPASSCataloged && wcsStarData.IsGAIACataloged &&
                            wcsStarData.APASSCatalogMagnitude < 30 && wcsStarData.GAIACatalogMagnitude < 30 &&
                            wcsStarData.SourceADU <= NonLinearADU &&
                            !wcsStarData.IsGCVSCataloged)
                        {
                            validCatalogedStars.Add(wcsStarData);
                        }
                    }
                    catch { };
                }
            }

            //Create arrays for source and catalog magnitudes
            double[] apassMagDeltaArray         = new double[validCatalogedStars.Count];
            double[] gaiaMagDeltaArray          = new double[validCatalogedStars.Count];
            double[] sourceMagDeltaArray        = new double[validCatalogedStars.Count];
            double[] apass_gaia_differenceArray = new double[validCatalogedStars.Count];
            for (int i = 0; i < validCatalogedStars.Count; i++)
            {
                apassMagDeltaArray[i]         = validCatalogedStars[i].APASSCatalogMagnitude;
                gaiaMagDeltaArray[i]          = validCatalogedStars[i].GAIACatalogMagnitude;
                sourceMagDeltaArray[i]        = validCatalogedStars[i].SourceUncorrectedMagnitude;
                apass_gaia_differenceArray[i] = validCatalogedStars[i].APASSCatalogMagnitudeG - validCatalogedStars[i].GAIACatalogMagnitudeG;
            }
            //Calculate APASS statistics
            try
            {
                //Regression of APASS star magnitudes to linear function mx+b
                Tuple <double, double> lineFitSourceToAPASS = MathNet.Numerics.Fit.Line(sourceMagDeltaArray, apassMagDeltaArray);
                double sourceCorrectedSourceToAPASS         = (tData.SourceUncorrectedMagnitude * lineFitSourceToAPASS.Item2) + lineFitSourceToAPASS.Item1;
                //Calculation of r2
                double rSquaredSourceToAPASS = MathNet.Numerics.GoodnessOfFit.RSquared(sourceMagDeltaArray.Select
                                                                                           (x => lineFitSourceToAPASS.Item1 + (lineFitSourceToAPASS.Item2 * x)), apassMagDeltaArray);
                //Calculation of APASS Population Standard Error
                double pseSourceToAPASS = MathNet.Numerics.GoodnessOfFit.PopulationStandardError(sourceMagDeltaArray.Select
                                                                                                     (x => lineFitSourceToAPASS.Item1 + (lineFitSourceToAPASS.Item2 * x)), apassMagDeltaArray);
                tData.APASSMagnitudeGradient          = lineFitSourceToAPASS.Item2;
                tData.APASSMagnitudeIntercept         = lineFitSourceToAPASS.Item1;
                tData.APASSSourceCorrectedMagnitude   = sourceCorrectedSourceToAPASS;
                tData.APASSMagnitudeRSquared          = rSquaredSourceToAPASS;
                tData.APASSMagPopulationStandardError = pseSourceToAPASS;
                //
            }
            catch { }
            //Calculate GAIA statistics
            try
            {
                //Regression of APASS star magnitudes to linear function mx+b
                Tuple <double, double> lineFitSourceToGAIA = MathNet.Numerics.Fit.Line(sourceMagDeltaArray, gaiaMagDeltaArray);
                double sourceCorrectedSourceToGAIA         = (tData.SourceUncorrectedMagnitude * lineFitSourceToGAIA.Item2) + lineFitSourceToGAIA.Item1;
                //Calculation of r2
                double rSquaredSourceToGAIA = MathNet.Numerics.GoodnessOfFit.RSquared(sourceMagDeltaArray.Select
                                                                                          (x => lineFitSourceToGAIA.Item1 + (lineFitSourceToGAIA.Item2 * x)), gaiaMagDeltaArray);
                //Calculation of APASS Population Standard Error
                double pseSourceToGAIA = MathNet.Numerics.GoodnessOfFit.PopulationStandardError(sourceMagDeltaArray.Select
                                                                                                    (x => lineFitSourceToGAIA.Item1 + (lineFitSourceToGAIA.Item2 * x)), gaiaMagDeltaArray);
                tData.GAIAMagnitudeGradient          = lineFitSourceToGAIA.Item2;
                tData.GAIAMagnitudeIntercept         = lineFitSourceToGAIA.Item1;
                tData.GAIASourceCorrectedMagnitude   = sourceCorrectedSourceToGAIA;
                tData.GAIAMagnitudeRSquared          = rSquaredSourceToGAIA;
                tData.GAIAMagPopulationStandardError = pseSourceToGAIA;
            }
            catch { }

            //Plot the APASS catalog vrs source mag
            for (int sIdx = 0; sIdx < validCatalogedStars.Count; sIdx++)
            {
                double catMag = validCatalogedStars[sIdx].APASSCatalogMagnitude;
                double sexMag = validCatalogedStars[sIdx].SourceUncorrectedMagnitude;

                if (Utility.IsBetween(maxMagVal, catMag, minMagVal))
                {
                    sexMagPlotPoints.Add(sexMag);
                    catMagPlotPoints.Add(catMag);
                    magArrPlotIndex.Add(sIdx);
                    //get index for next point in graphed series
                    int pLast = PhotometryChart.Series[0].Points.Count;
                    //Add the next point to the graph
                    PhotometryChart.Series[0].Points.AddXY(sexMag, catMag);
                }
            }
            //Calculate vectors for the ceiling and floor of photometry chart, if any
            if (sexMagPlotPoints.Count > 0)
            {
                double[] catVals = new double[sexMagPlotPoints.Count];
                double[] sexVals = new double[sexMagPlotPoints.Count];
                for (int i = 0; i < sexMagPlotPoints.Count; i++)
                {
                    catVals[i] = catMagPlotPoints[i];
                    sexVals[i] = sexMagPlotPoints[i];
                }

                tData.APASSStarCount = apassMagDeltaArray.Length;
                tData.GAIAStarCount  = gaiaMagDeltaArray.Length;

                PhotometryChart.ChartAreas[0].AxisX.Interval = 1;
                PhotometryChart.ChartAreas[0].AxisY.Interval = 1;

                PhotometryChart.ChartAreas[0].AxisX.Maximum = Math.Ceiling(sexVals.Max()) + 1;
                PhotometryChart.ChartAreas[0].AxisX.Minimum = Math.Floor(sexVals.Min()) - 1;
                PhotometryChart.ChartAreas[0].AxisY.Maximum = Math.Ceiling(catVals.Max()) + 1;
                PhotometryChart.ChartAreas[0].AxisY.Minimum = Math.Floor(catVals.Min()) - 1;
            }
            return(tData);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="lightSource"></param>
        /// <returns>TargetData[0] => APASS star
        /// TargetData[1] => GAIA star</returns>
        public static TargetData AcquireNearestQualifiedStar(TargetData lightSource)
        {
            //Find the nearest APASS star and the nearest GAIA star
            //
            const string GAIACatalogName   = "Gaia";
            const string APASSCatalogName  = "APASS";
            const string GCVSCatalogPrefix = "GCVS";

            InfoObj gaiaCatData  = new InfoObj();
            InfoObj apassCatData = new InfoObj();

            //Populate target data with catalog data, if found
            sky6StarChart tsxsc = new sky6StarChart();
            sky6Utils     tsxut = new sky6Utils();

            //Ultimately, we want to center the star chart on the FOV of the image,
            //  but not resize the chart
            tsxsc.EquatorialToStarChartXY(lightSource.SourceRA, lightSource.SourceDec);
            int xC = (int)tsxsc.dOut0;
            int yC = (int)tsxsc.dOut1;

            InfoObj[] catStarList = GetNearbyStars(tsxsc, xC, yC);
            //First, find the nearest star to the light source in the list from the catalog
            //Initialize a catalog info object with the first found star from a catalog
            gaiaCatData.CatalogSeparation  = 1000;
            apassCatData.CatalogSeparation = 1000;
            double separation;

            //Now find an APASS star that is closest, or default to the initial one
            // go through the catalog list of stars.
            foreach (InfoObj iob in catStarList)
            {
                //Disqualify any light source with a GCVS star nearby
                if (iob.CatalogedName.Contains(GCVSCatalogPrefix))
                {
                    lightSource.IsGCVSCataloged = true;
                }

                tsxut.ComputeAngularSeparation(lightSource.SourceRA, lightSource.SourceDec, iob.CatalogRA, iob.CatalogDec);
                separation = (double)tsxut.dOut0 * 3600.0;
                if (separation < apassCatData.CatalogSeparation & iob.CatalogedName.Contains(APASSCatalogName))
                {
                    apassCatData.CatalogedName     = iob.CatalogedName;
                    apassCatData.CatalogRA         = iob.CatalogRA;
                    apassCatData.CatalogDec        = iob.CatalogDec;
                    apassCatData.CatalogMag        = iob.CatalogMag;
                    apassCatData.CatalogMagB       = iob.CatalogMagB;
                    apassCatData.CatalogMagV       = iob.CatalogMagV;
                    apassCatData.CatalogMagR       = iob.CatalogMagR;
                    apassCatData.CatalogMagG       = iob.CatalogMagG;
                    apassCatData.CatalogSeparation = separation;
                }
                if (separation < gaiaCatData.CatalogSeparation & iob.CatalogedName.Contains(GAIACatalogName))
                {
                    gaiaCatData.CatalogedName     = iob.CatalogedName;
                    gaiaCatData.CatalogRA         = iob.CatalogRA;
                    gaiaCatData.CatalogDec        = iob.CatalogDec;
                    gaiaCatData.CatalogMag        = iob.CatalogMag;
                    gaiaCatData.CatalogMagB       = iob.CatalogMagB;
                    gaiaCatData.CatalogMagG       = iob.CatalogMagG;
                    gaiaCatData.CatalogMagR       = iob.CatalogMagR;
                    gaiaCatData.CatalogSeparation = separation;
                }
                //check for APASS entry and hold again if so and separation is smaller than thelast
            }
            lightSource.APASSCatalogName                  = apassCatData.CatalogedName;
            lightSource.APASSCatalogMagnitude             = apassCatData.CatalogMag;
            lightSource.APASSCatalogMagnitudeB            = apassCatData.CatalogMagB;
            lightSource.APASSCatalogMagnitudeV            = apassCatData.CatalogMagV;
            lightSource.APASSCatalogMagnitudeR            = apassCatData.CatalogMagR;
            lightSource.APASSCatalogMagnitudeG            = apassCatData.CatalogMagG;
            lightSource.APASSCatalogRA                    = apassCatData.CatalogRA;
            lightSource.APASSCatalogDec                   = apassCatData.CatalogDec;
            lightSource.SourceToAPASSCatalogPositionError = apassCatData.CatalogSeparation;
            tsxut.ComputeAngularSeparation(lightSource.TargetRA, lightSource.TargetDec, lightSource.APASSCatalogRA, lightSource.APASSCatalogDec);
            lightSource.TargetToAPASSCatalogPositionError = (double)tsxut.dOut0 * 3600.0;

            lightSource.GAIACatalogName                  = gaiaCatData.CatalogedName;
            lightSource.GAIACatalogMagnitude             = gaiaCatData.CatalogMag;
            lightSource.GAIACatalogMagnitudeB            = gaiaCatData.CatalogMagB;
            lightSource.GAIACatalogMagnitudeG            = gaiaCatData.CatalogMagG;
            lightSource.GAIACatalogMagnitudeR            = gaiaCatData.CatalogMagR;
            lightSource.GAIACatalogRA                    = gaiaCatData.CatalogRA;
            lightSource.GAIACatalogDec                   = gaiaCatData.CatalogDec;
            lightSource.SourceToGAIACatalogPositionError = gaiaCatData.CatalogSeparation;
            tsxut.ComputeAngularSeparation(lightSource.TargetRA, lightSource.TargetDec, lightSource.GAIACatalogRA, lightSource.GAIACatalogDec);
            lightSource.TargetToGAIACatalogPositionError = (double)tsxut.dOut0 * 3600.0;

            if (lightSource.APASSCatalogName != null)
            {
                string catPrefix = lightSource.APASSCatalogName.Split(' ')[0];
                lightSource.APASSCatalogName = Utility.CreateStarLabel("APASS ", lightSource.APASSCatalogRA, lightSource.APASSCatalogDec);
                lightSource.IsAPASSCataloged = true;
            }
            else
            {
                lightSource.IsAPASSCataloged = false;
            }

            if (lightSource.GAIACatalogName != null)
            {
                lightSource.GAIACatalogName = Utility.CreateStarLabel("Gaia ", lightSource.GAIACatalogRA, lightSource.GAIACatalogDec);
                lightSource.IsGAIACataloged = true;
            }
            else
            {
                lightSource.IsGAIACataloged = false;
            }

            return(lightSource);
        }
Beispiel #17
0
        private TargetData Analyze(string targetName, double targetRA, double targetDec)
        {
            //This is the primary routine.  The current image in TSX is activated and FITS information acquired.
            //  The image is { sent through image link to compute WCS information for each star.
            //  The results are sorted by magnitude, averaged, seeing estimated and results displayed.
            //
            Configuration cfg = new Configuration();

            TargetData targetData = new TargetData()
            {
                TargetName = targetName,
                TargetRA   = targetRA,
                TargetDec  = targetDec
            };

            //tsximg = new ccdsoftImage();
            TSXimglnk = new ImageLink();
            //Using FITS file information...
            FITImage = new Fits(TSX_Image);

            //Compute pixel scale = 206.256 * pixel size (in microns) / focal length
            //Set initial values in case the FITS words aren't there
            FITImage.PixSize = FITImage.PixSize ?? 9;
            //if (FITImage.FocalLength == null)
            //    MessageBox.Show("Focal Length was not set for this FITS image: defaulting to 2000 mm");
            FITImage.FocalLength = FITImage.FocalLength ?? 2563; //mm
            //if (FITImage.Aperture == null)
            //    MessageBox.Show("Aperture was not set for this FITS image: defaulting to 254 mm");
            FITImage.Aperture      = FITImage.Aperture ?? 356.0; //mm
            FocalRatio             = (double)FITImage.FocalLength / (double)FITImage.Aperture;
            targetData.ImageFilter = FITImage.Filter;
            targetData.ImageDate   = FITImage.FitsUTCDateTime;
            targetData.AirMass     = (double)(FITImage.FitsAirMass ?? 0);

            FITImage.Exposure = FITImage.Exposure ?? 0;
            //  focal length must be set to correct value in FITS header -- comes from camera set up in TSX
            PixelScale_arcsec = ConvertToArcSec((double)FITImage.PixSize, (double)FITImage.FocalLength);

            //Set the pixel scale for an InsertWCS image linking
            TSX_Image.ScaleInArcsecondsPerPixel = PixelScale_arcsec;

            //set saturation threshold
            SaturationADU = Math.Pow(2, (double)FITImage.PixBits) * 0.95;
            //set nonlinear threshold
            NonLinearADU = Convert.ToDouble(cfg.ADUMax);

            //ImageLink for light sources (Insert WCS)
            try { int ferr = TSX_Image.InsertWCS(true); }
            catch
            {
                targetData.IsImageLinked = false;
                return(targetData);
            }
            targetData.IsImageLinked = true;
            //Collect astrometric light source data from the image linking into single index arrays:
            //  magnitude, fmhm, ellipsicity, x and y position
            try { MagArr = (TSX_Image.InventoryArray((int)TSXEnums.ccdsoftInventoryIndex.cdInventoryMagnitude)); }
            catch
            {
                targetData.IsImageLinked = false;
                return(targetData);
            }

            FWHMArr        = TSX_Image.InventoryArray((int)TSXEnums.ccdsoftInventoryIndex.cdInventoryFWHM);        //FMHW, we think
            EllipticityArr = TSX_Image.InventoryArray((int)TSXEnums.ccdsoftInventoryIndex.cdInventoryEllipticity); //Ellipsity, we think
            XPosArr        = TSX_Image.InventoryArray((int)TSXEnums.ccdsoftInventoryIndex.cdInventoryX);           //X position, we think
            YPosArr        = TSX_Image.InventoryArray((int)TSXEnums.ccdsoftInventoryIndex.cdInventoryY);           //Y position, we think

            //Collect light sources used for image linking
            try { WCSActiveArr = TSX_Image.WCSArray((int)TSXEnums.ccdsoftWCSIndex.cdActive); }
            catch { return(targetData); }
            WCSRAArr            = TSX_Image.WCSArray((int)TSXEnums.ccdsoftWCSIndex.cdWCSRA);
            WCSDecArr           = TSX_Image.WCSArray((int)TSXEnums.ccdsoftWCSIndex.cdWCSDec);
            WCSXPosArr          = TSX_Image.WCSArray((int)TSXEnums.ccdsoftWCSIndex.cdWCSX);
            WCSYPosArr          = TSX_Image.WCSArray((int)TSXEnums.ccdsoftWCSIndex.cdWCSY);
            WCSResidualArr      = TSX_Image.WCSArray((int)TSXEnums.ccdsoftWCSIndex.cdWCSResidual);
            WCSCatalogIDArr     = TSX_Image.WCSArray((int)TSXEnums.ccdsoftWCSIndex.cdWCSCatalogID);
            WCSPositionErrorArr = TSX_Image.WCSArray((int)TSXEnums.ccdsoftWCSIndex.cdWCSPositionError);

            //Fill in Seeing Analysis information in the windows form:
            //Instrument info
            FocalLengthBox.Text         = ((double)FITImage.FocalLength).ToString("0");
            ApertureBox.Text            = ((double)FITImage.Aperture).ToString("0");
            FocalRatioBox.Text          = FocalRatio.ToString("0.0");
            PixSizeMicronBox.Text       = ((double)FITImage.PixSize).ToString("0.0");
            PixSizeArcSecBox.Text       = (ConvertToArcSec((double)FITImage.PixSize, (double)FITImage.FocalLength)).ToString("0.00");
            MaxResolutionArcSecBox.Text = ((ConvertToArcSec((double)FITImage.PixSize, (double)FITImage.FocalLength)) * 3.3).ToString("0.00");

            AirMassBox.Text = ((double)(FITImage.FitsAirMass ?? 0)).ToString("0.000");

            double FWHMAvg_pixels = MathNet.Numerics.Statistics.ArrayStatistics.Mean(Array.ConvertAll <object, double>(FWHMArr, x => (double)x));

            EllipticityAvg = MathNet.Numerics.Statistics.ArrayStatistics.Mean(Array.ConvertAll <object, double>(EllipticityArr, x => (double)x));
            //Star Size = (Seeing * Focal Length)/206.3 => Seeing = Star Size *206.3/focal length or Seeing = FWHM * focal length/ 206.3* microns;
            double FWHMAvg_arcsec = FWHMAvg_pixels * TSX_Image.ScaleInArcsecondsPerPixel;
            double FWHMAvg_micron = FWHMAvg_pixels * (double)FITImage.PixSize;

            SeeingMeanFWHMBox.Text = FWHMAvg_arcsec.ToString("0.00");
            FWHMSeeing_arcsec      = FWHMAvg_micron * 206.3 / ((double)FITImage.FocalLength);

            SeeingClassBox.Text       = GetSeeingClass(FWHMAvg_arcsec, (double)FITImage.Aperture);
            targetData.ComputedSeeing = GetSeeingClass(FWHMAvg_arcsec, (double)FITImage.Aperture);

            SeeingMeanEllipticityBox.Text = EllipticityAvg.ToString("0.00");
            //Create sorted index of stars, based on magnitude, high to low
            //Generate initial ordered array
            //Set the global sort array index to the first (greatest magnitude) entry {.
            //Create new target data for this variable target
            targetData = SearchForLightSourceInventory(TSX_Image, targetData);
            targetData = NearestCatalogedStar.AcquireNearestQualifiedStar(targetData);

            if (FitsIsOpen)
            {
                //Done
                //Display target, date and time for fits file
                FitsNameBox.Text = FITImage.FitsTarget;
                FitsDateBox.Text = FITImage.FitsUTCDate;
                FitsTimeBox.Text = FITImage.FitsUTCTime;
                //MeanLumBox.Text =  MeanAduToMag(24000).ToString("0.0");
                double backgroundADU = TSX_Image.Background;
                SourceBackgroundADUBox.Text = backgroundADU.ToString("0");
                FitsExposureBox.Text        = ((double)FITImage.Exposure).ToString("0.0");
                FitsFilterBox.Text          = FITImage.Filter;
                //Set the global value for the maximum pixel (used for determine staturation) at 95% of maximum ADU
            }
            return(targetData);
        }