Ejemplo n.º 1
0
        private int pixeldepth = 16;  //Fixed pixel depth -- May be changed latger

        public ImageArray(string filepath)
        //Open a new integer array representing the contents of a TSX image
        //  get and store the width and height in pixels for changes
        //  close the TSX window
        {
            ccdsoftImage tsx_im = new ccdsoftImage();

            imageFilePath = filepath;
            tsx_im.Path   = imageFilePath;
            tsx_im.Open();
            //tsx_im.AttachToActive();
            var img = tsx_im.DataArray;
            var pix = new int[img.Length];

            for (int i = 0; i < img.Length; i++)
            {
                pix[i] = Convert.ToInt32(img[i]);
            }
            imagePixels          = pix;
            pixelSizeX           = tsx_im.WidthInPixels;
            pixelSizeY           = tsx_im.HeightInPixels;
            tsx_im.DetachOnClose = 0;
            tsx_im.Close();
            tsx_im = null;
            pix    = null;
            GC.Collect();
            return;
        }
Ejemplo n.º 2
0
        public static bool DialogOpenImageFile(ccdsoftImage tsximg, string agnName)
        {
            using (OpenFileDialog imageFileDialog = new OpenFileDialog())
            {
                imageFileDialog.Filter = "*.fit|*.fit";
                Configuration cfg = new Configuration();
                string        imageFileDirectory = cfg.ImageBankFolder + "\\" + agnName;
                if (Directory.Exists(imageFileDirectory))
                {
                    imageFileDialog.InitialDirectory = imageFileDirectory;
                    if (imageFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        tsximg.Path = imageFileDialog.FileName;
                        try { tsximg.Open(); }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            return(false);
                        }

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(false);
            }
        }
Ejemplo n.º 3
0
            public XYToRADec(string wcsfilepath, double Xpos, double Ypos)
            {
                //Open reference image in TSX.  Plate solve.
                ccdsoftImage tsx_img = new ccdsoftImage();

                tsx_img.Path = wcsfilepath;
                tsx_img.Open();
                tsx_img.DetachOnClose = 0;
                try
                {
                    tsx_img.InsertWCS(true);
                }
                catch
                {
                    tsx_img.Close();
                    plateSolve = false;
                    return;
                }
                tsx_img.XYToRADec(Xpos, Ypos);
                targetRA    = tsx_img.XYToRADecResultRA();
                targetDec   = tsx_img.XYToRADecResultDec();
                northangle  = tsx_img.NorthAngle;
                imagescale  = tsx_img.ScaleInArcsecondsPerPixel;
                imagewidth  = tsx_img.WidthInPixels;
                imageheight = tsx_img.HeightInPixels;
                plateSolve  = true;
                tsx_img.Close();
                return;
            }
Ejemplo n.º 4
0
 public static bool DirectOpenFitsFile(ccdsoftImage tsximg, string filePath)
 {
     tsximg.Path = filePath;
     try { tsximg.Open(); }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 5
0
 public static bool DialogOpenFitsFile(ccdsoftImage tsximg)
 {
     using (OpenFileDialog fitsDialog = new OpenFileDialog())
     {
         fitsDialog.Filter = "*.fit|*.fit";
         if (fitsDialog.ShowDialog() == DialogResult.OK)
         {
             tsximg.Path = fitsDialog.FileName;
             try { tsximg.Open(); }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
                 return(false);
             }
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 6
0
            public RADecToXY(string wcsfilepath, double tRA, double tDec)
            {
                //Open reference image in TSX.  Plate solve.
                ccdsoftImage tsx_img = new ccdsoftImage();

                tsx_img.Path = wcsfilepath;
                tsx_img.Open();
                tsx_img.DetachOnClose = 0;
                try
                {
                    tsx_img.InsertWCS(true);
                }
                catch
                {
                    tsx_img.Close();
                    plateSolveResult = false;
                    return;
                }
                tsx_img.RADecToXY(tRA, tDec);
                targetX     = Convert.ToInt32(tsx_img.RADecToXYResultX());
                targetY     = Convert.ToInt32(tsx_img.RADecToXYResultY());
                northangle  = tsx_img.NorthAngle;
                imagescale  = tsx_img.ScaleInArcsecondsPerPixel;
                imagewidth  = tsx_img.WidthInPixels;
                imageheight = tsx_img.HeightInPixels;
                //Check for some catastrophic problem with the image link result
                if ((targetX < 0) || (targetX > imagewidth) || (targetY < 0) || (targetY > imageheight))
                {
                    plateSolveResult = false;
                }
                else
                {
                    plateSolveResult = true;
                };

                tsx_img.Close();
                return;
            }
Ejemplo n.º 7
0
        public string Display(string galaxyName, double suspectRAhrs, double suspectDecdeg)
        {
            const int sampleSize = 20;

            //Test code for PlateSolve2 Wrapper
            //CancellationToken cToken;
            TargetName   = galaxyName;
            TargetRAhrs  = suspectRAhrs;
            TargetDecdeg = suspectDecdeg;
            string followUpfileName = FollowUpPath + "\\" + TargetName + ".fit";

            TargetImageDir = ImageBankPath + "\\" + TargetName;
            //Show suspect in astroimage form, if PlateSolve2 is installed
            // if not, then an exception will be thrown

            //
            //test code
            //fileName = "C:\\Users\\Rick McAlister\\Documents\\SuperScan\\Image Bank\\NGC 1023\\NGC 1023_2019-10-31-2138.fit";
            //fileName = "C:\\Users\\Rick McAlister\\Documents\\SuperScan\\Image Bank\\NGC 1023\\CurrentImage.fit";
            //

            TargetFits = new FitsFile(followUpfileName, true);
            double pixSize = 1;

            if (TargetFits.FocalLength != 0)
            {
                pixSize = (206.265 / TargetFits.FocalLength) * TargetFits.XpixSz;
            }
            //
            ccdsoftImage tsxim = new ccdsoftImage();

            tsxim.Path = FollowUpPath + "\\" + galaxyName + ".fit";
            tsxim.Open();
            //Try to image link.  If not successful, probably too few stars
            //  if so, just return out of this;
            ImageLink tsxil = new ImageLink();

            tsxil.pathToFITS = tsxim.Path;
            try { tsxil.execute(); }
            catch (Exception ex)
            {
                return("Image Link Error: " + ex.Message);
            }
            //Show pic on scrren
            tsxim.Visible = 0;

            ImageLinkResults tsxilr = new ImageLinkResults();
            int    rlt     = tsxilr.succeeded;
            string rltText = tsxilr.errorText;

            try
            {
                //tsxim.InsertWCS(true);
                tsxim.ShowInventory();
            }
            catch (Exception ex)
            {
                string evx = ex.Message;
                return(evx);
            }

            //Look for a light source within 10 pixels of the target RA/Dec
            //The developer is picking an arbitrary 10 pixel square box as "near"
            int iLS = FindClosestLightSource(tsxim, TargetRAhrs, TargetDecdeg, 10);

            if (iLS == -1)
            {
                return("No light source found at suspect location\r\n  **Aborting check**");
            }

            //Success -- light source at target location.  Get magnitude and X,Y coordinates for all light sources
            var rMagArr = tsxim.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryMagnitude);
            var rXArr   = tsxim.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryX);
            var rYArr   = tsxim.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryY);

            double rMag;
            string cName;
            int    starIndex    = 0;
            int    starCount    = 0;
            int    minStarCount = sampleSize;
            double tMag         = rMagArr[iLS];

            //Collect a set of catalog stars that have positions that match up
            //  with reference light sources of similar intensity to the target
            //  light source.
            //
            //  first, create data arrays for reference magnitudes and catalog magnitudes
            double[] refMag = new double[sampleSize];
            double[] catMag = new double[sampleSize];
            double[] difMag = new double[sampleSize];
            //double[] meanDev = new double[sampleSize];
            //  second, create TSX objects for the star chart and object information
            sky6StarChart         tsxsc = new sky6StarChart();
            sky6ObjectInformation tsxoi = new sky6ObjectInformation();

            //loop over all the stars in the light source magnitude array,
            // or until a sufficient number of stars are found that match  up
            do
            {
                //Compare the reference light source magnitude to the target light source magnitude
                //  if within 1 magnitude of each other then look up the associated star, if any
                rMag = (double)rMagArr[starIndex];
                if (Math.Abs(tMag - rMag) <= 1.0)
                {
                    //Get the RA/Dec location of the reference light source
                    tsxim.XYToRADec(rXArr[starIndex], rYArr[starIndex]);
                    double rRA  = tsxim.XYToRADecResultRA();
                    double rDec = tsxim.XYToRADecResultDec();
                    //Center the star chart on the RA/Dec coordinates
                    tsxsc.RightAscension = rRA;
                    tsxsc.Declination    = rDec;
                    int Xcen = tsxsc.WidthInPixels / 2;
                    int Ycen = tsxsc.HeightInPixels / 2;
                    //find the star at the center of the chart
                    tsxsc.ClickFind(Xcen, Ycen);
                    //get the name of the star, if any
                    tsxoi.Property(Sk6ObjectInformationProperty.sk6ObjInfoProp_SOURCE_CATALOG);
                    string cSrc = tsxoi.ObjInfoPropOut;
                    //if there is a name, then get its properties
                    if (cSrc != "")
                    {
                        //Get the name of the star
                        tsxoi.Property(Sk6ObjectInformationProperty.sk6ObjInfoProp_NAME1);
                        cName = tsxoi.ObjInfoPropOut;
                        //Get the catalog magnitude of the star
                        tsxoi.Property(Sk6ObjectInformationProperty.sk6ObjInfoProp_MAG);
                        catMag[starCount] = tsxoi.ObjInfoPropOut;
                        refMag[starCount] = rMag;
                        starCount++;
                    }
                }
                starIndex++;
            } while ((starCount < minStarCount) && (starIndex < rMagArr.Length));

            //Compute the difference bewtween reference magnitude and catalog magnitude
            for (int i = 0; i < starCount; i++)
            {
                difMag[i] = refMag[i] - catMag[i];
            }
            //Compute the average difference
            double avgMagDif = 0;

            for (int i = 0; i < starCount; i++)
            {
                avgMagDif += difMag[i];
            }
            avgMagDif = avgMagDif / starCount;
            //Compute the mean square of the deviation
            double avgMagDev = 0;

            for (int i = 0; i < starCount; i++)
            {
                avgMagDev += Math.Pow((difMag[i] - avgMagDif), 2);
            }
            avgMagDev = Math.Sqrt(avgMagDev / starCount);

            //Compute the adjusted magnitude for target
            double avgTgtAdjMag = tMag - avgMagDif;
            //Compute the adjusted magnitude error
            double meanDevTgtAdjMag = avgMagDev;

            //Return center of starchart to target location
            //Set the center of view to the suspect//s RA/Dec and light up the target icon
            //
            //Recenter the star chart on the RA/Dec coordinates
            tsxsc.RightAscension = TargetRAhrs;
            tsxsc.Declination    = TargetDecdeg;
            int Xtcen = tsxsc.WidthInPixels / 2;
            int Ytcen = tsxsc.HeightInPixels / 2;

            //find the star at the center of the chart
            tsxsc.ClickFind(Xtcen, Ytcen);
            tsxoi.Property(Sk6ObjectInformationProperty.sk6ObjInfoProp_NAME1);
            string starName = tsxoi.ObjInfoPropOut;

            //Open astrodisplay form of follow up image

            tsxim = null;
            tsxoi = null;
            tsxsc = null;
            //Report on computed apparant magnitude
            return("Nearest star: " + starName + "\r\n" +
                   "Adjusted apparent magnitude = " +
                   avgTgtAdjMag.ToString() + "  +/- " +
                   meanDevTgtAdjMag.ToString());
        }
Ejemplo n.º 8
0
        public bool NewStar(string gname, string dfilepath, string rfilepath)
        {
            //Look for star-like reminant in difference image using the TSX "ShowInventory" (Sextractor) function
            //   return true if star-like object found, false if not.
            //

            //Open a new TSX Image object, then load and open difference image
            ccdsoftImage tsx_dif = new ccdsoftImage();

            tsx_dif.Path = dfilepath;
            tsx_dif.Open();
            //Prepare TSX to close the image window when closing the image
            tsx_dif.DetachOnClose = 0;
            //Look for stars using Sextractor
            //  If fails, close the object and image
            try
            {
                int tdstat = tsx_dif.ShowInventory();
            }
            catch
            {
                tsx_dif.Close();
                LogEntry("No suspects:  Sextractor failed on Difference Image.");
                return(false);
            }
            // Sextractor didnt// run into any problems, but may have found nothing
            //   Check how many objects found, if none then close up and return false
            //   If something is found, then leave the window open and return "true"
            var dMagArr = tsx_dif.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryMagnitude);
            //double[] FWHMArr = Convert.ToDouble(tDiff.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryFWHM));
            var dXPosArr = tsx_dif.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryX);
            var dYPosArr = tsx_dif.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryY);
            //double[] ElpArr = Convert.ToDouble(tDiff.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryEllipticity));
            var dClsArr = tsx_dif.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryClass);

            if (dMagArr.Length == 0)
            {
                tsx_dif.Close();
                LogEntry("No suspects:  No light sources found on Difference Image.");
                return(false);
            }
            else
            {
                //We have at least one hit in the box.  Now look to see if any don//t match up with
                //  light sources found in the reduced reference image.
                //Open a new TSX Image object, then load and open difference image
                ccdsoftImage tsx_ref = new ccdsoftImage();
                tsx_ref.Path = rfilepath;
                tsx_ref.Open();
                //Prepare TSX to close the image window when closing the image
                tsx_ref.DetachOnClose = 0;
                //Look for stars using Sextractor
                //  If fails, close the object and image
                try
                {
                    int cdstat = tsx_ref.ShowInventory();
                }
                catch
                {
                    tsx_ref.Close();
                    tsx_dif.Close();
                    LogEntry("No suspects:  Sextractor failed on Reference Image.");
                    return(false);
                }
                // Sextractor didnt// run into any problems, but may have found nothing
                //   Check how many objects found, if none then close up and return false
                //   If something is found, then leave the window open and return "true"
                var rMagArr = tsx_ref.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryMagnitude);
                //double[] FWHMArr = Convert.ToDouble(tDiff.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryFWHM));
                var rXPosArr = tsx_ref.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryX);
                var rYPosArr = tsx_ref.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryY);
                //double[] ElpArr = Convert.ToDouble(tDiff.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryEllipticity));
                var rClsArr = tsx_ref.InventoryArray((int)ccdsoftInventoryIndex.cdInventoryClass);
                //So let//s make being within 20 pixels (40 arcsec) of each other sufficient for calling two light sources the same.
                //Proceed through the light source array looking for matches, there shouldn//t be many
                int     proximity = 20;
                Boolean nomatch;
                for (int di = 0; di < dXPosArr.Length; di++)
                {
                    double dXpos = Convert.ToDouble(dXPosArr[di]);
                    double dYpos = Convert.ToDouble(dYPosArr[di]);
                    double dCls  = Convert.ToDouble(dClsArr[di]);
                    nomatch = true;
                    if (dCls >= 0.8)
                    {
                        for (int ri = 0; ri < rXPosArr.Length; ri++)
                        {
                            double rXpos = Convert.ToDouble(rXPosArr[ri]);
                            double rYpos = Convert.ToDouble(rYPosArr[ri]);

                            if ((Math.Abs(dXpos - rXpos) <= proximity) && (Math.Abs(dYpos - rYpos) <= proximity))
                            {
                                nomatch = false;
                                break;
                            }
                        }
                        if (nomatch)
                        {
                            // A suspect has been found. Log it//s x,y location on the Difference image, then
                            //  Get its location (RA,Dec) by using XYToRADec method that runs yet another Image Link
                            //  on the current image file (not the cropped one), extrapolating the cropped difference image x,y
                            //  to the uncropped current image, then using TSX to convert the extrapolated X,Y to an RA,Dec.
                            //
                            //  Add to Suspect List then, log, close, collect and return

                            //  We may do more later...
                            LogEntry("Suspect without alibi in " + dfilepath + " at X= " + Convert.ToInt32(dXpos) + "   Y= " + Convert.ToInt32(dYpos));

                            double    xCurPos = ((dXpos - (tsx_dif.WidthInPixels) / 2)) + (grandeWidth / 2);
                            double    yCurPos = ((dYpos - (tsx_dif.HeightInPixels) / 2)) + (grandeHeight / 2);
                            XYToRADec ss_perp = new XYToRADec(curImagePath, xCurPos, yCurPos);
                            double    pRA     = ss_perp.RA;
                            double    pDec    = ss_perp.Dec;
                            LogEntry("Suspect//s coordinates (RA,Dec) = " + pRA.ToString() + " Hrs, " + pDec.ToString() + " Deg");

                            //Now create a new entry and save the suspect in the suspect file
                            Suspect ss_sus = new Suspect();
                            ss_sus.GalaxyName = gname;
                            ss_sus.Event      = DateTime.Now;
                            ss_sus.SuspectRA  = pRA;
                            ss_sus.SuspectDec = pDec;
                            ss_sus.SuspectCurrentLocationX = dXpos;
                            ss_sus.SuspectCurrentLocationY = dYpos;
                            ss_sus.Store();

                            tsx_dif.Close();
                            tsx_dif = null;
                            tsx_ref.Close();
                            tsx_ref = null;
                            ss_perp = null;
                            ss_sus  = null;
                            GC.Collect();
                            return(true);
                        }
                    }
                }
                //If no suspects found, log, close, collect and return;
                LogEntry("All suspects have alibis from Reference image.");
                tsx_dif.Close();
                tsx_dif = null;
                tsx_ref.Close();
                tsx_ref = null;
                return(false);
            }
        }