diff --git a/src/ootk-core.ts b/src/ootk-core.ts index a029e74..d4d7b4f 100644 --- a/src/ootk-core.ts +++ b/src/ootk-core.ts @@ -46,4 +46,3 @@ export * from './transforms'; export * from './types/types'; export * from './utils/constants'; export * from './utils/functions'; -export { Utils } from './utils/utils'; diff --git a/src/utils/functions.ts b/src/utils/functions.ts index d0dc6b8..1dc7116 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -625,7 +625,7 @@ export function sign(value: number) { return value >= 0 ? 1 : -1; } -const spaceObjTypeStrMap = { +const spaceObjTypeStrMap_ = { [SpaceObjectType.UNKNOWN]: 'Unknown', [SpaceObjectType.PAYLOAD]: 'Payload', [SpaceObjectType.ROCKET_BODY]: 'Rocket Body', @@ -657,9 +657,24 @@ const spaceObjTypeStrMap = { [SpaceObjectType.FRAGMENT]: 'Fragment', }; +/** + * Converts a SpaceObjectType to a string representation. + * @param spaceObjType - The SpaceObjectType to convert. + * @returns The string representation of the SpaceObjectType. + */ export const spaceObjType2Str = (spaceObjType: SpaceObjectType): string => - spaceObjTypeStrMap[spaceObjType] || 'Unknown'; + spaceObjTypeStrMap_[spaceObjType] || 'Unknown'; +/** + * Calculates the Doppler factor for a given location, position, and velocity. + * The Doppler factor is a measure of the change in frequency or wavelength of a wave + * as observed by an observer moving relative to the source of the wave. + * + * @param location - The location vector of the observer. + * @param position - The position vector of the source. + * @param velocity - The velocity vector of the source. + * @returns The calculated Doppler factor. + */ export const dopplerFactor = (location: EciVec3, position: EciVec3, velocity: EciVec3): number => { const mfactor = 7.292115e-5; const c = 299792.458; // Speed of light in km/s @@ -690,3 +705,21 @@ export const dopplerFactor = (location: EciVec3, position: EciVec3, velocity: Ec return dopplerFactor; }; + +/** + * Creates an array of numbers from start to stop (inclusive) with the specified step. + * + * @param start The starting number. + * @param stop The ending number. + * @param step The step value. + * @returns An array of numbers. + */ +export function createVec(start: number, stop: number, step: number): number[] { + const array = []; + + for (let i = start; i <= stop; i += step) { + array.push(i); + } + + return array; +} diff --git a/src/utils/utils.ts b/src/utils/utils.ts deleted file mode 100644 index 0a3ce30..0000000 --- a/src/utils/utils.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as Types from '../types/types'; - -class Utils { - static Types = Types; - - static createVec(start: number, stop: number, step: number): number[] { - const array = []; - - for (let i = start; i <= stop; i += step) { - array.push(i); - } - - return array; - } -} - -export { Utils }; diff --git a/test/tle/tle.json b/test/tle/tle.json deleted file mode 100644 index 3ee8367..0000000 --- a/test/tle/tle.json +++ /dev/null @@ -1,132 +0,0 @@ -[ - { - "line1": "1 25544U 98067A 22203.46960946 .00003068 00000+0 61583-4 0 9996", - "line2": "2 25544 51.6415 161.8339 0005168 35.9781 54.7009 15.50067047350657", - "linenum1": 1, - "linenum2": 2, - "satNum": 25544, - "satNumRaw": "25544", - "classification": "U", - "intlDes": "98067A", - "intlDesYear": 98, - "intlDesLaunchNum": 67, - "intlDesLaunchPiece": "A", - "epochYear": 22, - "epochYearFull": 2022, - "epochDay": 203.46960946, - "meanMoDev1": 0.00003068, - "meanMoDev2": 0, - "bstar": 0.000061583, - "ephemerisType": 0, - "elsetNum": 999, - "checksum1": 6, - "satNum2": 25544, - "satNumRaw2": "25544", - "inclination": 51.6415, - "raan": 161.8339, - "eccentricity": 0.0005168, - "argOfPerigee": 35.9781, - "meanAnomaly": 54.7009, - "meanMotion": 15.50067047, - "revNum": 35065, - "checksum2": 7 - }, - { - "line1": "1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 1 2927", - "line2": "2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537", - "linenum1": 1, - "linenum2": 2, - "satNum": 25544, - "satNumRaw": "25544", - "classification": "U", - "intlDes": "98067A", - "intlDesYear": 98, - "intlDesLaunchNum": 67, - "intlDesLaunchPiece": "A", - "epochYear": 8, - "epochYearFull": 2008, - "epochDay": 264.51782528, - "meanMoDev1": -0.00002182, - "meanMoDev2": 0, - "bstar": -0.000011606, - "ephemerisType": 1, - "elsetNum": 292, - "checksum1": 7, - "satNum2": 25544, - "satNumRaw2": "25544", - "inclination": 51.6416, - "raan": 247.4627, - "eccentricity": 0.0006703, - "argOfPerigee": 130.536, - "meanAnomaly": 325.0288, - "meanMotion": 15.72125391, - "revNum": 56353, - "checksum2": 7 - }, - { - "NOTE": "This is not really confidential information!", - "line1": "1 00900C 64063C 22206.54439792 .00000383 00000+0 39865-3 0 9990", - "line2": "2 00900 90.1732 41.6064 0024845 267.8011 122.0949 13.73849289875890", - "linenum1": 1, - "linenum2": 2, - "satNum": 900, - "satNumRaw": "00900", - "classification": "C", - "intlDes": "64063C", - "intlDesYear": 64, - "intlDesLaunchNum": 63, - "intlDesLaunchPiece": "C", - "epochYear": 22, - "epochYearFull": 2022, - "epochDay": 206.54439792, - "meanMoDev1": 0.00000383, - "meanMoDev2": 0, - "bstar": 0.00039865, - "ephemerisType": 0, - "elsetNum": 999, - "checksum1": 0, - "satNum2": 900, - "satNumRaw2": "00900", - "inclination": 90.1732, - "raan": 41.6064, - "eccentricity": 0.0024845, - "argOfPerigee": 267.8011, - "meanAnomaly": 122.0949, - "meanMotion": 13.73849289, - "revNum": 87589, - "checksum2": 0 - }, - { - "NOTE": "This is not really secret information!", - "line1": "1 A3712S 95060A 22206.53025105 -.00000022 00000+0 00000+0 0 9991", - "line2": "2 A3712 13.5389 14.0082 0001997 133.0685 227.0577 1.00275623 18615", - "linenum1": 1, - "linenum2": 2, - "satNum": 103712, - "satNumRaw": "A3712", - "classification": "S", - "intlDes": "95060A", - "intlDesYear": 95, - "intlDesLaunchNum": 60, - "intlDesLaunchPiece": "A", - "epochYear": 22, - "epochYearFull": 2022, - "epochDay": 206.53025105, - "meanMoDev1": -0.00000022, - "meanMoDev2": 0, - "bstar": 0, - "ephemerisType": 0, - "elsetNum": 999, - "checksum1": 1, - "satNum2": 103712, - "satNumRaw2": "A3712", - "inclination": 13.5389, - "raan": 14.0082, - "eccentricity": 0.0001997, - "argOfPerigee": 133.0685, - "meanAnomaly": 227.0577, - "meanMotion": 1.00275623, - "revNum": 1861, - "checksum2": 5 - } -] diff --git a/test/tle/tle.test.js b/test/tle/tle.test.ts similarity index 68% rename from test/tle/tle.test.js rename to test/tle/tle.test.ts index e921a83..ce1560b 100644 --- a/test/tle/tle.test.js +++ b/test/tle/tle.test.ts @@ -6,65 +6,65 @@ */ import { Tle } from '../../lib/ootk-core'; -import tleData from './tle.json'; +import { tleData } from './tleData'; describe('Valid TLEs', () => { tleData.forEach((testCase) => { describe(`TLE ${testCase.satNum}: Line 1 Parsing`, () => { it('should parse the line number', () => { - expect(Tle.getLineNumber(testCase.line1)).toBe(testCase.linenum1); - expect(Tle.getLineNumber(testCase.line2)).toBe(testCase.linenum2); + expect(Tle.lineNumber(testCase.line1)).toBe(testCase.linenum1); + expect(Tle.lineNumber(testCase.line2)).toBe(testCase.linenum2); }); it('should parse satellite number', () => { - expect(Tle.getSatNum(testCase.line1)).toBe(testCase.satNum); - expect(Tle.getSatNum(testCase.line2)).toBe(testCase.satNum2); + expect(Tle.satNum(testCase.line1)).toBe(testCase.satNum); + expect(Tle.satNum(testCase.line2)).toBe(testCase.satNum2); }); it('should parse satellite number as a raw string', () => { - expect(Tle.getRawSatNum(testCase.line1)).toBe(testCase.satNumRaw); - expect(Tle.getRawSatNum(testCase.line2)).toBe(testCase.satNumRaw2); + expect(Tle.rawSatNum(testCase.line1)).toBe(testCase.satNumRaw); + expect(Tle.rawSatNum(testCase.line2)).toBe(testCase.satNumRaw2); }); it('should parse satellite classification', () => { - expect(Tle.getClassification(testCase.line1)).toBe(testCase.classification); + expect(Tle.classification(testCase.line1)).toBe(testCase.classification); }); it('should parse International Designator', () => { - expect(Tle.getIntlDesYear(testCase.line1)).toBe(testCase.intlDesYear); - expect(Tle.getIntlDesLaunchNum(testCase.line1)).toBe(testCase.intlDesLaunchNum); - expect(Tle.getIntlDesLaunchPiece(testCase.line1)).toBe(testCase.intlDesLaunchPiece); - expect(Tle.getIntlDes(testCase.line1)).toBe(testCase.intlDes); + expect(Tle.intlDesYear(testCase.line1)).toBe(testCase.intlDesYear); + expect(Tle.intlDesLaunchNum(testCase.line1)).toBe(testCase.intlDesLaunchNum); + expect(Tle.intlDesLaunchPiece(testCase.line1)).toBe(testCase.intlDesLaunchPiece); + expect(Tle.intlDes(testCase.line1)).toBe(testCase.intlDes); }); it('should parse epoch', () => { - expect(Tle.getEpochYear(testCase.line1)).toBe(testCase.epochYear); - expect(Tle.getEpochYearFull(testCase.line1)).toBe(testCase.epochYearFull); - expect(Tle.getEpochDay(testCase.line1)).toBe(testCase.epochDay); + expect(Tle.epochYear(testCase.line1)).toBe(testCase.epochYear); + expect(Tle.epochYearFull(testCase.line1)).toBe(testCase.epochYearFull); + expect(Tle.epochDay(testCase.line1)).toBe(testCase.epochDay); }); it('should parse first derivative', () => { - expect(Tle.getMeanMoDev1(testCase.line1)).toBe(testCase.meanMoDev1); + expect(Tle.meanMoDev1(testCase.line1)).toBe(testCase.meanMoDev1); }); it('should parse second derivative', () => { - expect(Tle.getMeanMoDev2(testCase.line1)).toBe(testCase.meanMoDev2); + expect(Tle.meanMoDev2(testCase.line1)).toBe(testCase.meanMoDev2); }); it('should parse bstar', () => { - expect(Tle.getBstar(testCase.line1)).toBe(testCase.bstar); + expect(Tle.bstar(testCase.line1)).toBe(testCase.bstar); }); it('should parse ephemerisType', () => { - expect(Tle.getEphemerisType(testCase.line1)).toBe(testCase.ephemerisType); + expect(Tle.ephemerisType(testCase.line1)).toBe(testCase.ephemerisType); }); it('should parse element number', () => { - expect(Tle.getElsetNum(testCase.line1)).toBe(testCase.elsetNum); + expect(Tle.elsetNum(testCase.line1)).toBe(testCase.elsetNum); }); it('should parse checksum', () => { - expect(Tle.getChecksum(testCase.line1)).toBe(testCase.checksum1); + expect(Tle.checksum(testCase.line1)).toBe(testCase.checksum1); }); it('should parse all of line 1', () => { @@ -92,35 +92,35 @@ describe('Valid TLEs', () => { describe(`TLE ${testCase.satNum}: Line 2 Parsing`, () => { it('should parse satellite inclination', () => { - expect(Tle.getInclination(testCase.line2)).toBe(testCase.inclination); + expect(Tle.inclination(testCase.line2)).toBe(testCase.inclination); }); it('should parse right ascension of ascending node', () => { - expect(Tle.getRaan(testCase.line2)).toBe(testCase.raan); + expect(Tle.rightAscension(testCase.line2)).toBe(testCase.raan); }); it('should parse eccentricity', () => { - expect(Tle.getEccentricity(testCase.line2)).toBe(testCase.eccentricity); + expect(Tle.eccentricity(testCase.line2)).toBe(testCase.eccentricity); }); it('should parse argument of perigee', () => { - expect(Tle.getArgOfPerigee(testCase.line2)).toBe(testCase.argOfPerigee); + expect(Tle.argOfPerigee(testCase.line2)).toBe(testCase.argOfPerigee); }); it('should parse mean anomaly', () => { - expect(Tle.getMeanAnomaly(testCase.line2)).toBe(testCase.meanAnomaly); + expect(Tle.meanAnomaly(testCase.line2)).toBe(testCase.meanAnomaly); }); it('should parse mean motion', () => { - expect(Tle.getMeanMotion(testCase.line2)).toBe(testCase.meanMotion); + expect(Tle.meanMotion(testCase.line2)).toBe(testCase.meanMotion); }); it('should parse revolution number', () => { - expect(Tle.getRevNum(testCase.line2)).toBe(testCase.revNum); + expect(Tle.revNum(testCase.line2)).toBe(testCase.revNum); }); it('should parse checksum', () => { - expect(Tle.getChecksum(testCase.line2)).toBe(testCase.checksum2); + expect(Tle.checksum(testCase.line2)).toBe(testCase.checksum2); }); it('should parse all of line 2', () => { @@ -136,11 +136,12 @@ describe('Valid TLEs', () => { meanMotion: testCase.meanMotion, revNum: testCase.revNum, checksum2: testCase.checksum2, + period: testCase.period, }); }); describe('TLE Parsing', () => { it('should parse a TLE for main orbital data', () => { - const tle = Tle.parseTle(testCase.line1, testCase.line2); + const tle = Tle.parse(testCase.line1, testCase.line2); expect(tle).toEqual({ satNum: testCase.satNum, @@ -156,11 +157,12 @@ describe('Valid TLEs', () => { argOfPerigee: testCase.argOfPerigee, meanAnomaly: testCase.meanAnomaly, meanMotion: testCase.meanMotion, + period: testCase.period, }); }); it('should parse a TLE for all data', () => { - const tle = Tle.parseTleFull(testCase.line1, testCase.line2); + const tle = Tle.parseAll(testCase.line1, testCase.line2); expect(tle).toEqual({ lineNumber1: testCase.linenum1, @@ -189,6 +191,7 @@ describe('Valid TLEs', () => { revNum: testCase.revNum, checksum1: testCase.checksum1, checksum2: testCase.checksum2, + period: testCase.period, }); }); }); diff --git a/test/tle/tleData.ts b/test/tle/tleData.ts new file mode 100644 index 0000000..e4e75f6 --- /dev/null +++ b/test/tle/tleData.ts @@ -0,0 +1,138 @@ +import { TleLine1, TleLine2 } from 'lib/ootk-core'; + +export const tleData = [ + { + line1: '1 25544U 98067A 22203.46960946 .00003068 00000+0 61583-4 0 9996' as TleLine1, + line2: '2 25544 51.6415 161.8339 0005168 35.9781 54.7009 15.50067047350657' as TleLine2, + linenum1: 1, + linenum2: 2, + satNum: 25544, + satNumRaw: '25544', + classification: 'U', + intlDes: '98067A', + intlDesYear: 98, + intlDesLaunchNum: 67, + intlDesLaunchPiece: 'A', + epochYear: 22, + epochYearFull: 2022, + epochDay: 203.46960946, + meanMoDev1: 0.00003068, + meanMoDev2: 0, + bstar: 0.000061583, + ephemerisType: 0, + elsetNum: 999, + checksum1: 6, + satNum2: 25544, + satNumRaw2: '25544', + inclination: 51.6415, + raan: 161.8339, + eccentricity: 0.0005168, + argOfPerigee: 35.9781, + meanAnomaly: 54.7009, + meanMotion: 15.50067047, + revNum: 35065, + checksum2: 7, + period: 92.89920734635164, + }, + { + line1: '1 25544U 98067A 08264.51782528 -.00002182 00000-0 -11606-4 0 2927' as TleLine1, + line2: '2 25544 51.6416 247.4627 0006703 130.5360 325.0288 15.72125391563537' as TleLine2, + linenum1: 1, + linenum2: 2, + satNum: 25544, + satNumRaw: '25544', + classification: 'U', + intlDes: '98067A', + intlDesYear: 98, + intlDesLaunchNum: 67, + intlDesLaunchPiece: 'A', + epochYear: 8, + epochYearFull: 2008, + epochDay: 264.51782528, + meanMoDev1: -0.00002182, + meanMoDev2: 0, + bstar: -0.000011606, + ephemerisType: 0, + elsetNum: 292, + checksum1: 7, + satNum2: 25544, + satNumRaw2: '25544', + inclination: 51.6416, + raan: 247.4627, + eccentricity: 0.0006703, + argOfPerigee: 130.536, + meanAnomaly: 325.0288, + meanMotion: 15.72125391, + revNum: 56353, + checksum2: 7, + period: 91.5957472758609, + }, + { + NOTE: 'This is not really confidential information!', + line1: '1 00900C 64063C 22206.54439792 .00000383 00000+0 39865-3 0 9990' as TleLine1, + line2: '2 00900 90.1732 41.6064 0024845 267.8011 122.0949 13.73849289875890' as TleLine2, + linenum1: 1, + linenum2: 2, + satNum: 900, + satNumRaw: '00900', + classification: 'C', + intlDes: '64063C', + intlDesYear: 64, + intlDesLaunchNum: 63, + intlDesLaunchPiece: 'C', + epochYear: 22, + epochYearFull: 2022, + epochDay: 206.54439792, + meanMoDev1: 0.00000383, + meanMoDev2: 0, + bstar: 0.00039865, + ephemerisType: 0, + elsetNum: 999, + checksum1: 0, + satNum2: 900, + satNumRaw2: '00900', + inclination: 90.1732, + raan: 41.6064, + eccentricity: 0.0024845, + argOfPerigee: 267.8011, + meanAnomaly: 122.0949, + meanMotion: 13.73849289, + revNum: 87589, + checksum2: 0, + period: 104.81499037264487, + }, + { + NOTE: 'This is not really secret information!', + line1: '1 A3712S 95060A 22206.53025105 -.00000022 00000+0 00000+0 0 9991' as TleLine1, + line2: '2 A3712 13.5389 14.0082 0001997 133.0685 227.0577 1.00275623 18615' as TleLine2, + linenum1: 1, + linenum2: 2, + satNum: 103712, + satNumRaw: 'A3712', + classification: 'S', + intlDes: '95060A', + intlDesYear: 95, + intlDesLaunchNum: 60, + intlDesLaunchPiece: 'A', + epochYear: 22, + epochYearFull: 2022, + epochDay: 206.53025105, + meanMoDev1: -0.00000022, + meanMoDev2: 0, + bstar: 0, + ephemerisType: 0, + elsetNum: 999, + checksum1: 1, + satNum2: 103712, + satNumRaw2: 'A3712', + inclination: 13.5389, + raan: 14.0082, + eccentricity: 0.0001997, + argOfPerigee: 133.0685, + meanAnomaly: 227.0577, + meanMotion: 1.00275623, + revNum: 1861, + checksum2: 5, + period: 1436.0419381288712, + }, +]; diff --git a/test/utils/utils.test.ts b/test/utils/utils.test.ts index e0dacb7..a2e7c5d 100644 --- a/test/utils/utils.test.ts +++ b/test/utils/utils.test.ts @@ -3,7 +3,7 @@ * @since 1.0.0-alpha3 */ -import { EciVec3, Kilometers, linearDistance, Utils, Vec3 } from '../../lib/ootk-core'; // eslint-disable-line +import { EciVec3, Kilometers, linearDistance, Vec3 } from '../../lib/ootk-core'; // eslint-disable-line import { dopplerFactor, getDayOfYear } from '../../lib/utils/functions'; const numDigits = 8; @@ -116,12 +116,6 @@ describe('Distance function', () => { }); }); -describe('Create Vector Function', () => { - test('if vector creation is correct', () => { - expect(Utils.createVec(1, 10, 2)).toEqual([1, 3, 5, 7, 9]); - }); -}); - describe('doy Functions', () => { test('if doy is correct', () => { expect(getDayOfYear(new Date(2022, 0, 1))).toEqual(1);