Kstars

guidestars.h
1 /*
2  SPDX-FileCopyrightText: 2020 Hy Murveit <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QObject>
10 #include <QList>
11 #include <QVector3D>
12 
13 #include "fitsviewer/fitsdata.h"
14 #include "fitsviewer/fitssepdetector.h"
15 #include "starcorrespondence.h"
16 #include "vect.h"
17 #include "../guideview.h"
18 #include "calibration.h"
19 
20 namespace SSolver
21 {
22 class Parameters;
23 }
24 
25 /*
26  * This class manages selecting a guide star, finding that star in a new image
27  * and calculating the drift of the new star image.
28  * The major methods are:
29  *
30  * GuideStars guideStars();
31  * guideStars.selectGuideStar(QSharedPointer<FITSdata>);
32  * Selects a guide star, given the input image. This can be done at the start of
33  * calibration, when guiding starts, or when the guide star is lost.
34  *
35  * Vector xy = guideStars.findGuideStar(QSharedPointer<FITSdata>, QRect trackingBox)
36  * Finds the guide star that was previously selected. xy will contain the pixel coordinates
37  * {x,y,0}. The tracking box is not enforced if the multi-star star-finding algorithm
38  * is used, however, if that fails, it backs off to the star with the best score
39  * (basically the brightest star) in the tracking box.
40  *
41  * bool success = guideStars.getDrift(guideStarDrift, reticle_x, reticle_y, RADrift, DECDrift)
42  * Returns the star movement in RA and DEC. The reticle can be input indicating
43  * that the desired position for the original guide star and reference stars has
44  * shifted (e.g. dithering).
45  */
46 
47 class GuideStars
48 {
49  public:
50  GuideStars();
51  ~GuideStars() {}
52 
53  // Select a guide star, given the image.
54  // Performs a SEP processing to detect stars, then finds the
55  // most desirable guide star.
56  QVector3D selectGuideStar(const QSharedPointer<FITSData> &imageData);
57 
58  // Finds the guide star previously selected with selectGuideStar()
59  // in a new image. This sets up internal structures for getDrift().
60  GuiderUtils::Vector findGuideStar(const QSharedPointer<FITSData> &imageData, const QRect &trackingBox,
61  QSharedPointer<GuideView> &guideView, bool firstFrame);
62 
63  // Finds the drift of the star positions in arc-seconds for RA and DEC.
64  // Must be called after findGuideStar().
65  // Returns false if this can't be calculated.
66  // setCalibration must have been called once before this (so that pixel
67  // positions can be converted to RA and DEC).
68  bool getDrift(double oneStarDrift, double reticle_x, double reticle_y,
69  double *RADrift, double *DECDrift);
70 
71  // Use this calibration object for conversions to arcseconds and RA/DEC.
72  void setCalibration(const Calibration &calibration);
73 
74  // Returns the sky background object that was obtained from SEP analysis.
75  const SkyBackground &skybackground() const
76  {
77  return skyBackground;
78  }
79  double getGuideStarMass() const
80  {
81  return guideStarMass;
82  }
83  double getGuideStarSNR() const
84  {
85  return guideStarSNR;
86  }
87 
88  void reset()
89  {
90  starCorrespondence.reset();
91  }
92 
93  private:
94  // Used to initialize the StarCorrespondence object, which ultimately finds
95  // the guidestar using the geometry between it and the other stars detected.
96  void setupStarCorrespondence(const QList<Edge> &neighbors, int guideIndex);
97 
98  // Evaluates which stars are desirable as guide stars and reference stars.
99  void evaluateSEPStars(const QList<Edge *> &starCenters, QVector<double> *scores,
100  const QRect *roi, const double maxHFR) const;
101 
102  // Prepares parameters for evaluateSEPStars().
103  SSolver::Parameters getStarExtractionParameters(int num);
104 
105  // Returns the top num stars according to the evaluateSEPStars criteria.
106  void findTopStars(const QSharedPointer<FITSData> &imageData, int num, QList<Edge> *stars,
107  const double maxHFR,
108  const QRect *roi = nullptr,
109  QList<double> *outputScores = nullptr,
110  QList<double> *minDistances = nullptr);
111  // The interface to the SEP star detection algoritms.
112  int findAllSEPStars(const QSharedPointer<FITSData> &imageData, QList<Edge*> *sepStars, int num);
113 
114  // Convert from input image coordinates to output RA and DEC coordinates.
115  GuiderUtils::Vector point2arcsec(const GuiderUtils::Vector &p) const;
116 
117  // Returns the RA and DEC distance between the star and the reference star.
118  void computeStarDrift(const Edge &star, const Edge &reference,
119  double *driftRA, double *driftDEC) const;
120  // Selects the guide star given the star detections and score generated
121  // by evaluateSEPStars().
122  QVector3D selectGuideStar(const QList<Edge> &detectedStars,
123  const QList<double> &sepScores,
124  int maxX, int maxY,
125  const QList<double> &minDistances);
126 
127  // Computes the distance from stars[i] to its closest neighbor.
128  double findMinDistance(int index, const QList<Edge*> &stars);
129 
130  // Plot the positions of the neighbor stars on the guideView display.
131  void plotStars(QSharedPointer<GuideView> &guideView, const QRect &trackingBox);
132 
133  // These three methods are useful for testing.
134  void setDetectedStars(const QList<Edge> &stars)
135  {
136  detectedStars = stars;
137  }
138  void setSkyBackground(const SkyBackground &background)
139  {
140  skyBackground = background;
141  }
142  void setStarMap(const QVector<int> &map)
143  {
144  starMap = map;
145  }
146  int getStarMap(int index);
147 
148  // Sky background value generated by the SEP processing.
149  // Used to calculate star SNR values.
150  SkyBackground skyBackground;
151 
152  // Used to find the guide star in a new set of image detections.
153  StarCorrespondence starCorrespondence;
154 
155  // These are set when the guide star is detected, and can be queried, e.g.
156  // for logging.
157  double guideStarMass = 0;
158  double guideStarSNR = 0;
159 
160  // The newly detected stars.
161  QVector<int> starMap;
162  // This maps between the newly detected stars and the reference stars.
163  QList<Edge> detectedStars;
164 
165  Calibration calibration;
166  bool calibrationInitialized {false};
167 
168  // Find guide star will allow robust star correspondence.
169  bool allowMissingGuideStar { true };
170 
171  int unreliableDectionCounter { 0 };
172 
173  friend class TestGuideStars;
174 };
KGuiItem reset()
QFuture< void > map(Sequence &sequence, MapFunctor function)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Aug 14 2022 04:13:56 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.