Beispiel #1
0
        //When a suspect is chosen from the textbox list, parse the line for galaxy name and date
        //  then have TSX open the difference image, the reference image and the current image
        //  then have TSX set the FOV to the size of the galaxy, set the center of the chart to the
        //  coordinates of the suspect and place the target circle over the coordinates.
        //
        //Then...
        //
        private void SuspectListbox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ///If nothing selected then exit
            ///
            ///Parse the selected line for the galaxy name and image time.
            ///Load up the suspect data
            ///Lay in the clearer follow up image and prep to blink the two latest images
            ///

            //Set the cursor to wait
            UseWaitCursor = true;
            Show();
            FormCrunchingNotice cForm = new FormCrunchingNotice();

            cForm.Show();
            BlinkButton.BackColor = Color.LightSalmon;
            //pull the selected suspect entry from the suspect list box
            string susitem;

            try { susitem = SuspectListbox.Items[SuspectListbox.SelectedIndex].ToString(); }
            catch (Exception ex) { return; }
            //Clear the blink list
            BlinkList = null;
            //Parse the selected entry for relavent info and create a suspect object to work with
            int    galLen  = susitem.IndexOf("\t");
            string galname = susitem.Substring(0, galLen - 1);

            galname = galname.TrimEnd();
            int      dateLen  = susitem.IndexOf(":") - galLen + 2;
            string   galevent = susitem.Substring(galLen + 1, dateLen);
            DateTime galdate  = Convert.ToDateTime(galevent);

            CurrentSuspect = new Suspect();
            //Check to see if the stored suspect info loads ok, if so then
            //  have TSX upload the image files and target the RA/Dec
            bool susLoad = CurrentSuspect.Load(galname, galdate);

            if (susLoad)
            {
                CurrentDrillDown = new DrillDown(CurrentSuspect.Event);

                CurrentDrillDown.Display(galname, CurrentSuspect.SuspectRA, CurrentSuspect.SuspectDec);

                sky6StarChart         tsx_sc = new sky6StarChart();
                sky6ObjectInformation tsx_oi = new sky6ObjectInformation();
                //Get the galaxy major axis
                tsx_sc.Find(galname);
                tsx_oi.Index = 0;
                tsx_oi.Property(Sk6ObjectInformationProperty.sk6ObjInfoProp_MAJ_AXIS_MINS);
                double galaxis = tsx_oi.ObjInfoPropOut;
                //Set the FOV size to  the galaxy size
                tsx_sc.FieldOfView = galaxis / 60;
                //Set the center of view to the suspect//s RA/Dec and light up the target icon
                //tsx_sc.Find(suspect.SuspectRA.ToString() + ", " + suspect.SuspectDec.ToString());
                tsx_sc.RightAscension = CurrentSuspect.SuspectRA;
                tsx_sc.Declination    = CurrentSuspect.SuspectDec;
                //Check TNS for supernova reports for 60 arc seconds around this location for the last 10 days
                TNSReader     tnsReport = new TNSReader();
                List <string> snList    = tnsReport.RunLocaleQuery(CurrentSuspect.SuspectRA, CurrentSuspect.SuspectDec, 60, 10);
                if (snList != null)
                {
                    NotesTextBox.AppendText("Supernova reported for " + snList[0] + " at this location\r\n");
                }
                else
                {
                    NotesTextBox.AppendText("No supernova report for this location\r\n");
                }
                //Give the user an opportunity to clear the suspect by updating its status to cleared -- or not.
                Clipboard.Clear();
                try { Clipboard.SetText(CurrentSuspect.SuspectRA.ToString() + ", " + CurrentSuspect.SuspectDec.ToString()); }
                catch (Exception ex)
                {
                    NotesTextBox.AppendText(ex.Message);
                    return;
                }
                //Display the suspect position information
                NotesTextBox.AppendText("Suspect RA and Dec written to clipboard\r\n");
                LocationTextBox.Text = CurrentSuspect.SuspectRA.ToString() + ", " + CurrentSuspect.SuspectDec.ToString();
                Show();
                System.Windows.Forms.Application.DoEvents();
                //Show followup Image in picture box
                CurrentFollowUpImage     = CurrentDrillDown.GetFollowUpImage(ImageZoom);
                ImagePictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
                ImagePictureBox.Image    = CurrentFollowUpImage;
                BlinkButton.BackColor    = Color.LightGreen;
                ClearButton.BackColor    = Color.LightGreen;
                UseWaitCursor            = false;
            }
            cForm.Close();
            Show();
            return;
        }
Beispiel #2
0
        public bool Detect(string gname, double subFrameSizeInArcSec, double gRA, double gDec, string freshImagePath, string storedImagePath, string workingImageFolder)
        {
            //Store calling parameters
            galaxyName   = gname;
            curImagePath = freshImagePath;
            refImagePath = storedImagePath;
            galaxyRA     = gRA;
            galaxyDec    = gDec;

            //Create Image Array for reference image
            ImageArray refImage = new ImageArray(refImagePath);
            //Create Image Array for current image
            ImageArray curImage = new ImageArray(curImagePath);
            //Plate solve for x,y positions of galactic center
            RADecToXY refGal = new RADecToXY(refImagePath, gRA, gDec);

            if (!refGal.IsPlateSolved)
            {
                LogEntry("Reference image plate solve failure.");
                return(false);
            }
            else
            {
                LogEntry("Reference Image plate solve successful.");
            }
            RADecToXY curGal = new RADecToXY(curImagePath, gRA, gDec);

            if (!curGal.IsPlateSolved)
            {
                LogEntry("Current image plate solve failure.");
                return(false);
            }
            else
            {
                LogEntry("Current Image plate solve successful.");
            }
            //Save the image//s height and width for possible future use
            grandeHeight = curGal.Height;
            grandeWidth  = curGal.Width;

            //Set x,y boundaries for galaxy subframe
            //   using x,y coordinates of RA,Dec of galaxy in image
            //   offset by 2x the maximum axis size, in both x and y.
            int subframeSize = Convert.ToInt32(subFrameSizeInArcSec / refGal.Scale);

            //Compute rotation angle in radians
            double rotation = (curGal.PA - refGal.PA) * Math.PI / 180;

            //Open a new difference image in TSX of the galaxy subframe size
            ImageArray sdifImage = new ImageArray(subframeSize, subframeSize);

            //Open a new reference image in TSX of the galaxy subframe size
            ImageArray srefImage = new ImageArray(subframeSize, subframeSize);

            //Open a new current image in TSX of the galaxy subframe size
            ImageArray scurImage = new ImageArray(subframeSize, subframeSize);

            int    highpix = -32000;
            int    lowpix  = 32000;
            double curavg  = 0;
            double refavg  = 0;

            //First time through: create subframed and translated current and reference images registered to the galaxy center
            // get the average pixel value for the current and reference images and compute relative intensity
            //  between the two images.
            for (int iXp = 0; iXp < subframeSize; iXp++)
            {
                for (int iYp = 0; iYp < subframeSize; iYp++)
                {
                    int iXd = iXp - subframeSize / 2;
                    int iYd = iYp - subframeSize / 2;
                    int iXc = curGal.X + iXd;
                    int iYc = curGal.Y + iYd;
                    int iXr = refGal.X + TransformX(iXd, -iYd, rotation);
                    int iYr = refGal.Y - TransformY(iXd, -iYd, rotation);
                    //Subtract adjusted reference image pixel intensity from current image pixel intensity
                    //  and put it in the subframe array
                    int curPix = curImage.GetPixel(iXc, iYc);
                    scurImage.SetPixel(iXp, iYp, curPix);
                    int refPix = refImage.GetPixel(iXr, iYr);
                    srefImage.SetPixel(iXp, iYp, refPix);

                    int difPix = Math.Abs(curPix - refPix);

                    //Determine average pixel values for the current and reference images or at least, get the sum for now
                    curavg = curavg + curPix;
                    refavg = refavg + refPix;
                    //Keep track of high, low pixel values for the difference image
                    if (difPix > highpix)
                    {
                        highpix = difPix;
                    }
                    if (difPix < lowpix)
                    {
                        lowpix = difPix;
                    }
                }
            }

            curavg = curavg / (subframeSize * subframeSize);
            refavg = refavg / (subframeSize * subframeSize);
            double difintensity = curavg / refavg;

            //Second time through:  Create the difference image with difference between
            //  current image and reference images
            for (int iXp = 0; iXp < subframeSize; iXp++)
            {
                for (int iYp = 0; iYp < subframeSize; iYp++)
                {
                    //Subtract adjusted reference image pixel intensity from current image pixel intensity
                    int curPix = scurImage.GetPixel(iXp, iYp);
                    int refPix = srefImage.GetPixel(iXp, iYp);
                    int difPix = Convert.ToInt32(Math.Abs((curPix - (refPix * difintensity))));
                    //Pedistal out the current image average -- that is, all star candidates must be above the average pixel value
                    difPix = Convert.ToInt32((difPix - curavg) * Math.Sign(difPix - curavg));

                    // Normalize the pixel value between the high and low values
                    difPix = Convert.ToInt32((difPix - lowpix) * (highpix - lowpix) / (256 * 256));
                    //  OR
                    //difPix = Convert.ToInt32((difPix - lowpix) * (highpix - lowpix));

                    //Update the difference image with this pixel
                    sdifImage.SetPixel(iXp, iYp, difPix);
                }
            }
            //Normalize pixDiff to 256 bit intensity until TSX DataArray gets fixed
            //Normalize the array between the highs and lows, and flatten between 0 and 256

            //Save the difference image into the Galaxy Image Bank
            System.IO.FileInfo rfi       = new System.IO.FileInfo(workingImageFolder);
            string             rdir      = rfi.DirectoryName;
            string             dFilePath = rdir + "\\" + "DifferenceImage.fit";

            sdifImage.Store(dFilePath);
            string rFilePath = rdir + "\\" + "ReferenceImage.fit";

            srefImage.Store(rFilePath);
            string cFilePath = rdir + "\\" + "CurrentImage.fit";

            scurImage.Store(cFilePath);
            rfi       = null;
            sdifImage = null;
            srefImage = null;
            scurImage = null;
            GC.Collect();

            //Check for anomolies using TSX Sextractor (e.g. ShowInventory)
            if (NewStar(gname, dFilePath, rFilePath))
            {
                //If a suspect is found, take and store a five minute image for later analysis
                //  Can//t go longer than 5 minutes as Image Link seems to fail a lot with too many stars.
                //  This is going to take 10 minutes for the shot and dark, plus another dark
                //  will have to be taken for the regular scan upon resumption.
                LogEntry("Potential transient identified.  Taking follow up image.");
                DrillDown ss_dd = new DrillDown(DateTime.Now);
                ss_dd.Shoot(gname, DRILLDOWN_EXPOSURE);
                LogEntry("Follow up image acquired and stored.");
                return(true);
            }
            return(false);
        }