-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinpoint.pas
377 lines (295 loc) · 9.83 KB
/
pinpoint.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
unit Pinpoint;
{$mode objfpc}{$H+}
interface
uses Classes, ComObj, Variants, SysUtils, COMCtrls, Dialogs, dateutils;
procedure Pinpoint_Open;
procedure PinPoint_Init;
procedure PinPoint_Close;
function PinPoint_Reset:boolean;
function PinPoint_OpenImage:boolean;
function PinPoint_CloseImage:boolean;
function PinPoint_PlateSolve:boolean;
var
PinPointObject: Variant;
imageLoaded: boolean;
PinpointAssigned: boolean;
implementation
uses Main, global;
procedure ImageTime; forward;
//******************************************************************************
// Open
//******************************************************************************
procedure Pinpoint_Open;
begin
// not using PP
if not(Main_Form.UsePinPoint_CheckBox.checked) then exit;
if PinpointAssigned then exit;
// init
imageLoaded := false;
// create OLE object
try
PinPointObject := CreateOleObject('PinPoint.Plate');
PinpointAssigned := true;
except
ShowMessage('Connection to Pinpoint failed');
exit;
end;
end;
//******************************************************************************
// Init
//******************************************************************************
procedure PinPoint_Init;
begin
end;
procedure PinPoint_Close;
begin
end;
//******************************************************************************
// Open Image
//******************************************************************************
function PinPoint_OpenImage:boolean;
begin
// not using PP
if not(Main_Form.UsePinPoint_CheckBox.checked) then
begin
result := true;
exit;
end;
// init
PinPoint_Open;
result := false;
// remove old one
if imageLoaded then
begin
PinPointObject.DetachFITS;
imageLoaded := false;
end;
// attach the image
if not PinPointObject.AttachFITS(wideString(newImage.fileName)) then
begin
PlateSolveError := 'attach error';
exit;
end;
imageLoaded := true;
// reset image parameters
if not PinPoint_Reset then exit;
// I guess it worked
newImage.UTCDateTime := 0.0;
newImage.RAhours := 0.0;
newImage.DECdegrees := 0.0;
newImage.airmass := 0.0;
newImage.ExposureInterval := 0.0;
newImage.MatchFitOrder := 0;
newImage.FullWidthHalfMax := 0.0;
newImage.ImageBackgroundMean := 0.0;
newImage.ImageBackgroundSigma := 0.0;
newImage.MatchAvgResidual := 0.0;
newImage.MatchRMSResidual := 0.0;
// done
result := true;
end;
//******************************************************************************
// Plate Solve
//******************************************************************************
function PinPoint_PlateSolve:boolean;
var
r: double;
ra,mydec: double;
begin
// init
result := false;
newImage.solved := false;
PlateSolveError := '';
// load the FITS image into PinPoint
if not PinPoint_OpenImage then
begin
PlateSolveError := 'open image failed';
exit;
end;
// image Time
ImageTime;
// solve starting point
ra := PinPointObject.TargetRightAscension;
mydec := PinPointObject.TargetDeclination;
PinPointObject.RightAscension := ra;
PinPointObject.Declination := mydec;
// solve
// Convolve Gaussian',);
r := StrToFloat(Main_Form.FilterFWHM_MaskEdit.editText);
if Main_Form.ConvolveGaussian_CheckBox.checked then
begin
if not PinPointObject.ConvolveGaussian(r) then
PlateSolveError := 'ConvolveGaussian failed';
PinPointObject.imageModified := false;
end;
// Convolve Log',Main_Form.ConvolveLog_CheckBox.checked);
if Main_Form.ConvolveLog_CheckBox.checked then
begin
PinPointObject.ConvolveLog(r);
if not PinPointObject.ConvolveLog(r) then
PlateSolveError := 'ConvolveLog failed';
PinPointObject.imageModified := false;
end;
// Remove Hot Pixels',Main_Form.RemoveHotPixels_CheckBox.checked);
r := StrToFloat(Main_Form.HotPixelsThreshold_MaskEdit.editText);
if Main_Form.RemoveHotPixels_CheckBox.Checked then
PinPointObject.RemoveHotPixels(r);
// errors so far
if not (PlateSolveError = '') then
begin
result := false;
PinPoint_CloseImage;
exit;
end;
// plate solve
try
PinPointObject.Solve;
except
PlateSolveError := 'unable to plate solve image';
result := false;
end;
if PinPointObject.solved then
begin
result := true;
newImage.solved := true;
if not PinPointObject.CatalogStarsReady then
begin
PinPointObject.FindCatalogStars;
PinPointObject.FindImageStars;
end;
// update new image data
newImage.RAhours := PinPointObject.RightAscension;
newImage.DECdegrees := PinPointObject.Declination;
newImage.TelRA := PinPointObject.TargetRightAscension;
newImage.TelDEC := PinPointObject.TargetDeclination;
newImage.nCatalogStars := PinPointObject.CatalogStars.count;
newImage.nImageStars := PinPointObject.ImageStars.count;
try
newImage.airmass := PinPointObject.airmass;
except
newImage.airmass := 0.0;
end;
newImage.ExposureInterval := PinPointObject.ExposureInterval;
newImage.MatchFitOrder := PinPointObject.MatchFitOrder;
newImage.FullWidthHalfMax := PinPointObject.FullWidthHalfMax;
newImage.ImageBackgroundMean := PinPointObject.ImageBackgroundMean;
newImage.ImageBackgroundSigma := PinPointObject.ImageBackgroundSigma;
newImage.MatchAvgResidual := PinPointObject.MatchAvgResidual;
newImage.MatchRMSResidual := PinPointObject.MatchRMSResidual;
end;
// close the image
PinPoint_CloseImage;
end;
//******************************************************************************
// Close Image
//******************************************************************************
function PinPoint_CloseImage:boolean;
begin
// not using PP
if not(Main_Form.UsePinPoint_CheckBox.checked) then
begin
result := true;
exit;
end;
// remove old one
PinPointObject.DetachFITS;
imageLoaded := false;
// I guess it worked
result := true;
end;
//******************************************************************************
// Image Time (UTC observation time)
// "2018-10-05T07:01:54"
// 12345678901234567890
// 11111111112
//******************************************************************************
procedure ImageTime;
var
s: string;
year, month, day: word;
hour, min, sec: word;
td: TDateTime;
begin
s := PinPointObject.ReadFitsValue('DATE-OBS');
// UTC date
newImage.dateS := copy(s,2,10);
year := StrToIntDef(copy(s,2,4),0);
month := StrToIntDef(copy(s,7,2),0);
day := StrToIntDef(copy(s,10,2),0);
// UTC time
newImage.timeS := copy(s,13,8);
hour := StrToIntDef(copy(s,13,2),0);
min := StrToIntDef(copy(s,16,2),0);
sec := StrToIntDef(copy(s,19,2),0);
// encode into UTC DateTime
td := EncodeDate(year,month,day);
td := td + EncodeTime(hour,min,sec,0);
newImage.UTCDateTime := td;
// julian date
newImage.jd := td + 2415018.5;
end;
//******************************************************************************
// Reset
//******************************************************************************
function PinPoint_Reset: boolean;
var
n: integer;
begin
// init
result := false;
// Use Faint Stars
PinPointObject.UseFaintStars := Main_Form.UseFaintStars_CheckBox.checked;
// Use SExtractor
PinPointObject.UseSExtractor := Main_Form.UseSExtractor_CheckBox.checked;
// Max Solve Time
PinPointObject.MaxSolveTime := StrToFloat(Main_Form.maxSolveTime_MaskEdit.editText);
// Max Solve Stars
PinPointObject.MaxSolveStars := StrToInt(Main_Form.maxSolveStars_MaskEdit.editText);
// Min Star Size
PinPointObject.MinimumStarSize := StrToInt(Main_Form.MinStarSize_MaskEdit.editText);
// Min Match Stars
PinPointObject.MinMatchStars := StrToInt(Main_Form.MinMatchStars_MaskEdit.editText);
// Sigma Above Mean
PinPointObject.SigmaAboveMean := StrToFloat(Main_Form.SigmaAboveMean_MaskEdit.editText);
// Catalog
case Main_Form.catalog_combobox.ItemIndex of
0: PinPointObject.Catalog := 3; // GSC v1.1
1: PinPointObject.Catalog := 4; // ESA
2: PinPointObject.Catalog := 5; // USNO A2
3: PinPointObject.Catalog := 7; // USNO B1
4: PinPointObject.Catalog := 10; // USNO UCAC3
5: PinPointObject.Catalog := 11; // USNO UCAC4
else
PlateSolveError := 'invalid catalog';
exit;
end;
// Cat Path
PinPointObject.CatalogPath := wideString(Main_Form.catPath_DirectoryEdit.directory + '\');
// Cat Max Mag
PinPointObject.CatalogMaximumMagnitude := StrToFloat(Main_Form.maxMag_MaskEdit.editText);
// Cat Min Mag
PinPointObject.CatalogMinimumMagnitude := StrToFloat(Main_Form.CatMinMag_MaskEdit.editText);
// Cat Expansion
PinPointObject.CatalogExpansion := StrToFloat(Main_Form.CatExpansion_MaskEdit.editText);
// H Plate Scale
PinPointObject.ArcsecPerPixelHoriz := StrToFloat(Main_Form.hPlateScale_MaskEdit.editText);
// V Plate Scale
PinPointObject.ArcsecPerPixelVert := StrToFloat(Main_Form.vPlateScale_MaskEdit.editText);
// Inner Aperture
PinPointObject.InnerAperture := StrToFloat(Main_Form.InnerAperture_MaskEdit.editText);
// Outer Aperture
PinPointObject.OuterAperture := StrToFloat(Main_Form.OuterAperture_MaskEdit.editText);
// Exclusion Border
PinPointObject.ExclusionBorder := StrToInt(Main_Form.ExclusionBorder_MaskEdit.editText);
// Background Tile Size
n := StrToInt(Main_Form.BackgroundTileSize_MaskEdit.editText);
if n > 0 then
PinPointObject.BackgroundTileSize := n;
// Centroid Algorithm
PinPointObject.CentroidAlgorithm := Main_Form.CentroidAlgorithm_combobox.ItemIndex;
// Projection Type
PinPointObject.ProjectionType := Main_Form.ProjectionType_ComboBox.itemIndex;
// done
result := true;
end;
end.