-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
94 lines (70 loc) · 2.8 KB
/
server.go
File metadata and controls
94 lines (70 loc) · 2.8 KB
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
/*****************************************************************************************************************/
// @author Michael Roberts <michael@observerly.com>
// @package @observerly/nova
// @license Copyright © 2021-2024 observerly
/*****************************************************************************************************************/
package solve
/*****************************************************************************************************************/
import (
"context"
"fmt"
pb "nova/internal/gen/solve/v1/solvev1connect"
firebase "firebase.google.com/go/v4"
"firebase.google.com/go/v4/storage"
"github.com/observerly/iris/pkg/fits"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"nova/internal/stores"
)
/*****************************************************************************************************************/
type server struct {
pb.UnimplementedSolveServiceHandler
App *firebase.App
Logger zerolog.Logger
Storage *storage.Client
Client *stores.FirebaseStore
}
/*****************************************************************************************************************/
func NewSolveServer(app *firebase.App, storage *storage.Client) *server {
// Create a new logger:
logger := log.With().Str("@observerly/solver", "rpc").Logger()
// Create a new Firebase Storage client:
client := stores.NewFirebaseStorageClient(storage)
return &server{
App: app,
Logger: logger,
Storage: storage,
Client: client,
}
}
/*****************************************************************************************************************/
func (s *server) RetrieveFITSFromStorage(
ctx context.Context,
bucketName string,
location string,
) (*fits.FITSImage, error) {
// Assume an image of 2x2 pixels with 16-bit depth, and no offset:
fit := fits.NewFITSImage(2, 0, 0, 65535)
// Get the buffer from the storage client:
buff, err := s.Client.RetriveBuffer(ctx, bucketName, location)
if err != nil {
s.Logger.Error().Err(err).Msg("Failed to get buffer")
return nil, err
}
// Read in our exposure data into the image:
err = fit.Read(buff)
if err != nil {
s.Logger.Error().Err(err).Msg("Failed to read exposure data")
return nil, fmt.Errorf("failed to read exposure data: %w", err)
}
// We know the image is 2D, so we can extract the width from the fits image:
width := fit.Header.Naxis1
// We know the image is 2D, so we can extract the height from the fits image:
height := fit.Header.Naxis2
if fit.Pixels != width*height {
s.Logger.Error().Msg("Failed to read exposure data")
return nil, fmt.Errorf("failed to read exposure data as the number of pixels does not match the width and height")
}
return fit, nil
}
/*****************************************************************************************************************/