-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttphandle_solve.go
89 lines (79 loc) · 2.67 KB
/
httphandle_solve.go
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
package main
import (
"encoding/json"
"fmt"
"github.com/kairos10/weqalign/api/am"
"math"
"net/http"
"strconv"
)
const alignPointsDistance = 2 // distance in degrees for the DEC displacement
func GetHttpPlateSolver() func(http.ResponseWriter, *http.Request) {
type solverStatus struct {
FileId uint64
SolverStatus string
//NCP, ...
RA0DEC90_X float64
RA0DEC90_Y float64
RA0DEC95_X float64
RA0DEC95_Y float64
RA90DEC95_X float64
RA90DEC95_Y float64
PixScale float64
NegParity bool
NorthernHemisphere bool
Stars []am.XYStarPos
}
plateSolver := am.GetPlateSolver()
return func(w http.ResponseWriter, r *http.Request) {
sImgId := r.FormValue("imgid")
imgId, err := strconv.ParseUint(sImgId, 10, 64)
if err != nil { imgId = 0 }
imgRes, ok := resources.getResource(imgId)
if !ok {
http.Error(w, "not found", http.StatusNotFound)
return
}
if imgRes.solverResponse != nil {
ss := imgRes.solverResponse.(*solverStatus)
json, _ := json.MarshalIndent(*ss, "", " ")
w.Write(json)
} else {
w.Header().Set("Retry-After", "10")
http.Error(w, "", http.StatusServiceUnavailable)
fmt.Printf("not ready: %d\n", imgId)
}
if imgRes.solverResponse == nil {
plate := am.ImagePlate{FilePath: imgRes.path}
_ = plateSolver(&plate)
stat := plate.GetStatus()
if stat == am.ImagePlateStatusSOLVED || stat == am.ImagePlateStatusFAILED {
ss := solverStatus{FileId: imgId, SolverStatus: stat.String()}
imgRes.solverResponse = &ss
if stat == am.ImagePlateStatusSOLVED {
am.PlateGetWcsInfo(&plate)
ra0dec90x, ra0dec90y := am.PlateRD2XY(&plate, 0, 90) // XY for NCP
ra0dec270x, ra0dec270y := am.PlateRD2XY(&plate, 0, 270) // XY for SCP
if ra0dec270x != 0 && ra0dec270y != 0 &&
(ra0dec90x == 0 || math.Abs(ra0dec270x) < math.Abs(ra0dec90x)) &&
(ra0dec90y == 0 || math.Abs(ra0dec270y) < math.Abs(ra0dec90y)) {
// SCP closer
ss.RA0DEC90_X, ss.RA0DEC90_Y = ra0dec270x, ra0dec270y
ss.RA0DEC95_X, ss.RA0DEC95_Y = am.PlateRD2XY(&plate, 0, 270+alignPointsDistance)
ss.RA90DEC95_X, ss.RA90DEC95_Y = am.PlateRD2XY(&plate, 90, 270+alignPointsDistance)
ss.NorthernHemisphere = true
} else {
// use NCP
ss.RA0DEC90_X, ss.RA0DEC90_Y = ra0dec90x, ra0dec90y
ss.RA0DEC95_X, ss.RA0DEC95_Y = am.PlateRD2XY(&plate, 0, 90+alignPointsDistance)
ss.RA90DEC95_X, ss.RA90DEC95_Y = am.PlateRD2XY(&plate, 90, 90+alignPointsDistance)
ss.NorthernHemisphere = false
}
ss.PixScale = plate.PixScale
ss.NegParity = plate.NegParity
ss.Stars = am.PlateGetStars(&plate)
}
}
}
}
}