@saber-usa/node-common 1.7.40 → 1.7.41-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/udl.js +160 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saber-usa/node-common",
3
- "version": "1.7.40",
3
+ "version": "1.7.41-alpha.1",
4
4
  "description": "Common node functions for Saber",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/udl.js CHANGED
@@ -11,12 +11,162 @@ import {
11
11
  azElToRaDec,
12
12
  raDecToGeodetic,
13
13
  estimateSlantRange,
14
+ getResiduals,
14
15
  } from "./astro.js";
15
16
  import {REGIMES, MU} from "./constants.js";
16
17
  import {lowerCaseObjectKeys, jsonArrayOrNull} from "./transform.js";
17
18
  import {isDefined} from "./utils.js";
18
19
  import _ from "lodash";
19
20
 
21
+ /**
22
+ * Resolves the sensor id for a UDL observation, preferring idSensor and
23
+ * falling back to origSensorId.
24
+ * @param {Object} ob UDL observation row
25
+ * @return {String|null} resolved sensor id
26
+ */
27
+ const getSensorId = (ob) => ob.idSensor ?? ob.origSensorId ?? null;
28
+
29
+ const getObsSatno = (udlRow) => udlRow.idOnOrbit ?? udlRow.origObjectId ?? null;
30
+
31
+ /**
32
+ * Converts a UDL EOObservation row to NPS EoObs (PascalCase keys).
33
+ * Callers that insert via ingest should wrap with lowerCaseObjectKeys.
34
+ * @param {Object} udlRow
35
+ * @param {Object} tles - satNo → TLE map (empty skips residuals)
36
+ * @param {Object} log - logger with .error
37
+ * @return {Object}
38
+ */
39
+ const udlToNpsObs = (udlRow, tles = {}, log = console) => {
40
+ const satno = getObsSatno(udlRow);
41
+ const sensorId = getSensorId(udlRow);
42
+ let result = {
43
+ IdUdl: get(udlRow, "id", null),
44
+ ObTime: get(udlRow, "obTime", null),
45
+ IdSensor: sensorId,
46
+ SatNo: satno,
47
+ TrackId: get(udlRow, "trackId", null),
48
+ Uct: get(udlRow, "uct", null),
49
+ Azimuth: get(udlRow, "azimuth", null),
50
+ AzimuthRate: get(udlRow, "azimuthRate", null),
51
+ AzimuthUnc: get(udlRow, "azimuthUnc", null),
52
+ Elevation: get(udlRow, "elevation", null),
53
+ ElevationRate: get(udlRow, "elevationRate", null),
54
+ ElevationUnc: get(udlRow, "elevationUnc", null),
55
+ Range: get(udlRow, "range", null),
56
+ Ra: get(udlRow, "ra", null),
57
+ Dec: get(udlRow, "declination", null),
58
+ SenLat: get(udlRow, "senlat", null),
59
+ SenLon: get(udlRow, "senlon", null),
60
+ SenAlt: get(udlRow, "senalt", null),
61
+ SenX: get(udlRow, "senx", null),
62
+ SenY: get(udlRow, "seny", null),
63
+ SenZ: get(udlRow, "senz", null),
64
+ Mag: get(udlRow, "mag", null),
65
+ MagUnc: get(udlRow, "magUnc", null),
66
+ LosUnc: get(udlRow, "losUnc", null),
67
+ GeoLat: get(udlRow, "geolat", null),
68
+ GeoLon: get(udlRow, "geolon", null),
69
+ GeoAlt: get(udlRow, "geoalt", null),
70
+ GeoRange: get(udlRow, "georange", null),
71
+ SolarPhaseAngle: get(udlRow, "solarPhaseAngle", null),
72
+ SolarEqPhaseAngle: get(udlRow, "solarEqPhaseAngle", null),
73
+ SolarDecAngle: get(udlRow, "solarDecAngle", null),
74
+ ExpDuration: get(udlRow, "expDuration", null),
75
+ ShutterDelay: get(udlRow, "shutterDelay", null),
76
+ Source: get(udlRow, "source", null),
77
+ DataMode: get(udlRow, "dataMode", null),
78
+ Type: get(udlRow, "type", null),
79
+ AzimuthBias: get(udlRow, "azimuthBias", null),
80
+ ElevationBias: get(udlRow, "elevationBias", null),
81
+ RangeUnc: get(udlRow, "rangeUnc", null),
82
+ RangeBias: get(udlRow, "rangeBias", null),
83
+ RangeRate: get(udlRow, "rangeRate", null),
84
+ RangeRateUnc: get(udlRow, "rangeRateUnc", null),
85
+ RaUnc: get(udlRow, "raUnc", null),
86
+ RaBias: get(udlRow, "raBias", null),
87
+ RaRate: get(udlRow, "raRate", null),
88
+ DeclinationUnc: get(udlRow, "declinationUnc", null),
89
+ DeclinationBias: get(udlRow, "declinationBias", null),
90
+ DeclinationRate: get(udlRow, "declinationRate", null),
91
+ TimingBias: get(udlRow, "timingBias", null),
92
+ ReferenceFrame: get(udlRow, "referenceFrame", null),
93
+ SenReferenceFrame: get(udlRow, "senReferenceFrame", null),
94
+ CreatedAt: fixDate(get(udlRow, "createdAt", null)),
95
+ };
96
+
97
+ try {
98
+ result = enrichUdlFields({...result});
99
+ const tle = tles[satno];
100
+ const residuals = tle ? getResiduals([{...result}], tle) : null;
101
+ const first = residuals?.[0];
102
+ result.ElevationResidual = first?.ElErr ?? null;
103
+ result.AzimuthResidual = first?.AzErr ?? null;
104
+ } catch (e) {
105
+ log.error("Error enriching UDL fields: ", e);
106
+ }
107
+
108
+ return result;
109
+ };
110
+
111
+ /**
112
+ * Converts a UDL RadarObservation row to NPS RadarObs (PascalCase keys).
113
+ * Sen* come from the sensors map only (not the UDL row).
114
+ * Callers that insert via ingest should wrap with lowerCaseObjectKeys.
115
+ * @param {Object} udlRow
116
+ * @param {Object} tles
117
+ * @param {Object} sensors - idSensor → {latitude, longitude, altitude}
118
+ * @param {Object} log
119
+ * @return {Object}
120
+ */
121
+ const udlToRadarObs = (udlRow, tles = {}, sensors = {}, log = console) => {
122
+ const satno = getObsSatno(udlRow);
123
+ const sensorId = getSensorId(udlRow);
124
+ const sensor = sensors[sensorId];
125
+
126
+ let result = {
127
+ IdUdl: get(udlRow, "id", null),
128
+ ObTime: get(udlRow, "obTime", null),
129
+ IdSensor: sensorId,
130
+ SatNo: satno,
131
+ TrackId: get(udlRow, "trackId", null),
132
+ Uct: get(udlRow, "uct", null),
133
+ Azimuth: get(udlRow, "azimuth", null),
134
+ AzimuthUnc: get(udlRow, "azimuthUnc", null),
135
+ Elevation: get(udlRow, "elevation", null),
136
+ ElevationUnc: get(udlRow, "elevationUnc", null),
137
+ Ra: get(udlRow, "ra", null),
138
+ Dec: get(udlRow, "declination", null),
139
+ Range: get(udlRow, "range", null),
140
+ RangeUnc: get(udlRow, "rangeUnc", null),
141
+ RangeRate: get(udlRow, "rangeRate", null),
142
+ RangeRateUnc: get(udlRow, "rangeRateUnc", null),
143
+ Doppler: get(udlRow, "doppler", null),
144
+ DopplerUnc: get(udlRow, "dopplerUnc", null),
145
+ Rcs: get(udlRow, "rcs", null),
146
+ Snr: get(udlRow, "snr", null),
147
+ Beam: get(udlRow, "beam", null),
148
+ SenLat: sensor ? sensor.latitude : null,
149
+ SenLon: sensor ? sensor.longitude : null,
150
+ SenAlt: sensor ? sensor.altitude : null,
151
+ Source: get(udlRow, "source", null),
152
+ DataMode: get(udlRow, "dataMode", null),
153
+ Type: get(udlRow, "type", null),
154
+ CreatedAt: fixDate(get(udlRow, "createdAt", null)),
155
+ };
156
+
157
+ try {
158
+ result = enrichUdlFields({...result});
159
+ const tle = tles[satno];
160
+ const residuals = tle && sensor ? getResiduals([{...result}], tle) : null;
161
+ const first = residuals?.[0];
162
+ result.ElevationResidual = first?.ElErr ?? null;
163
+ result.AzimuthResidual = first?.AzErr ?? null;
164
+ } catch (e) {
165
+ log.error("Error enriching UDL fields: ", e);
166
+ }
167
+ return result;
168
+ };
169
+
20
170
  const udlToNpsElset = (udlRow) => {
21
171
  let derivedElset;
22
172
  try {
@@ -420,4 +570,13 @@ const udlToNpsState = (udlRow) => {
420
570
  return npsState;
421
571
  };
422
572
 
423
- export {udlToNpsElset, udlToNpsGroundSite, udlToNpsConjunction, udlToNpsState, enrichUdlFields};
573
+ export {
574
+ udlToNpsElset,
575
+ udlToNpsGroundSite,
576
+ udlToNpsConjunction,
577
+ udlToNpsState,
578
+ enrichUdlFields,
579
+ getSensorId,
580
+ udlToNpsObs,
581
+ udlToRadarObs,
582
+ };