-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added function json2satrec
in io.js
#122
Open
spacenewb
wants to merge
8
commits into
shashwatak:develop
Choose a base branch
from
spacenewb:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
232be66
Added function `json2satrec` in `io.js`
spacenewb 5840431
Implemented changes and corrections to code comments
spacenewb d6c82fe
fix: :bug: add missing import/export statements
thkruz ae74f65
feat: :zap: added updates to json2satrec
thkruz 4d914c4
test: :white_check_mark: add testing for json2satrec
thkruz db41147
fix: :pencil2: fix path for io import statements
thkruz 0ebec62
Merge pull request #1 from thkruz/jest-test-for-json2satrec
spacenewb 748a53e
Added function `sunPos` in `sun.js`
spacenewb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { deg2rad, twoPi } from './constants'; | ||
|
||
//////////////////////////////////////////////////////////////////////////////////// | ||
/* Line by Line MATLAB-to-Javascript conversion of "sun.mat" from Vallado package */ | ||
//////////////////////////////////////////////////////////////////////////////////// | ||
/* ----------------------------------------------------------------------------- | ||
* | ||
* function sunPos | ||
* | ||
* this function calculates the geocentric equatorial position vector | ||
* the sun given the julian date. this is the low precision formula and | ||
* is valid for years from 1950 to 2050. accuaracy of apparent coordinates | ||
* is 0.01 degrees. notice many of the calculations are performed in | ||
* degrees, and are not changed until later. this is due to the fact that | ||
* the almanac uses degrees exclusively in their formulations. | ||
* | ||
* author : david vallado 719-573-2600 1 mar 2001 | ||
* | ||
* inputs description range / units | ||
* jd - julian date days from 4713 bc | ||
* | ||
* outputs : | ||
* rsun - ijk position vector of the sun au | ||
* rtasc - right ascension rad | ||
* decl - declination rad | ||
* | ||
* coupling : | ||
* - | ||
* | ||
* references : | ||
* VALLADO, DAVID A. (2022) ‘Computer software in MATLAB’, in Fundamentals of astrodynamics and applications. 5th edn. | ||
* Computer software in MATLAB: http://celestrak.org/software/vallado-sw.php | ||
* --------------------------------------------------------------------------- */ | ||
|
||
export function sunPos(jd) { | ||
|
||
// ------------------------- implementation ----------------- | ||
// ------------------- initialize values -------------------- | ||
const tut1 = ( jd - 2451545.0 ) / 36525.0; | ||
|
||
const meanlong = (280.460 + 36000.77 * tut1) % 360.0; //deg | ||
|
||
const ttdb = tut1; // is this declaration required instead of replacing `ttdb` with `tut1` | ||
|
||
if (meananomaly < 0.0 ) { | ||
const meananomaly = twoPi + ((357.5277233 + 35999.05034 * ttdb) * deg2rad) % twoPi; //rad; | ||
} else { | ||
const meananomaly = ((357.5277233 + 35999.05034 * ttdb) * deg2rad) % twoPi; //rad; | ||
} | ||
|
||
const eclplong_raw = ((meanlong + 1.914666471 * Math.sin(meananomaly) + 0.019994643 * Math.sin(2.0 * meananomaly)) % 360.0) * deg2rad; //rad | ||
|
||
const obliquity = (23.439291 - 0.0130042 * ttdb) * deg2rad; //rad | ||
|
||
// --------- find magnitude of sun vector, and it's components ------ | ||
const magr = 1.000140612 - 0.016708617 * Math.cos( meananomaly ) - 0.000139589 * Math.cos( 2.0 * meananomaly ); // in au's | ||
|
||
const rsun = [ | ||
magr*Math.cos(eclplong_raw), | ||
magr*Math.cos(obliquity)*Math.sin(eclplong_raw), | ||
magr*Math.sin(obliquity)*Math.sin(eclplong_raw) | ||
]; | ||
|
||
const rtasc_raw = Math.atan( Math.cos(obliquity) * Math.tan(eclplong_raw) ); | ||
|
||
// --- check that rtasc is in the same quadrant as eclplong_raw ---- | ||
if ( eclplong_raw < 0.0 ) { | ||
const eclplong = eclplong_raw + twoPi; // make sure it's in 0 to 2pi range | ||
} else { | ||
const eclplong = eclplong_raw; | ||
} | ||
|
||
if ( Math.abs( eclplong_raw - rtasc_raw ) > pi*0.5 ) { | ||
const rtasc = rtasc_raw + 0.5 *pi*Math.round( (eclplong_raw - rtasc_raw)/(0.5 *pi)); | ||
} else { | ||
const rtasc = rtasc_raw; | ||
} | ||
|
||
const decl = Math.asin( Math.sin(obliquity) * Math.sin(eclplong_raw) ); | ||
|
||
return {rsun, rtasc, decl} | ||
} | ||
|
||
|
||
/* Original MATLAB code for Sun position from Vallado package (sun.mat) */ | ||
/* | ||
function [rsun,rtasc,decl] = sun ( jd ); | ||
|
||
twopi = 2.0*pi; | ||
deg2rad = pi/180.0; | ||
show = 'n'; | ||
|
||
% ------------------------- implementation ----------------- | ||
% ------------------- initialize values -------------------- | ||
tut1= ( jd - 2451545.0 )/ 36525.0; | ||
|
||
if show == 'y' | ||
fprintf(1,'tut1 %14.9f \n',tut1); | ||
end | ||
|
||
meanlong= 280.460 + 36000.77*tut1; | ||
meanlong= rem( meanlong,360.0 ); %deg | ||
|
||
ttdb= tut1; | ||
meananomaly= 357.5277233 + 35999.05034 *ttdb; | ||
meananomaly= rem( meananomaly*deg2rad,twopi ); %rad | ||
if ( meananomaly < 0.0 ) | ||
meananomaly= twopi + meananomaly; | ||
end | ||
|
||
eclplong_raw= meanlong + 1.914666471 *sin(meananomaly) ... | ||
+ 0.019994643 *sin(2.0 *meananomaly); %deg | ||
eclplong_raw= rem( eclplong_raw,360.0 ); %deg | ||
|
||
obliquity= 23.439291 - 0.0130042 *ttdb; %deg | ||
|
||
eclplong_raw = eclplong_raw *deg2rad; | ||
obliquity= obliquity *deg2rad; | ||
|
||
% --------- find magnitude of sun vector, ) components ------ | ||
magr= 1.000140612 - 0.016708617 *cos( meananomaly ) ... | ||
- 0.000139589 *cos( 2.0 *meananomaly ); % in au's | ||
|
||
rsun(1)= magr*cos( eclplong_raw ); | ||
rsun(2)= magr*cos(obliquity)*sin(eclplong_raw); | ||
rsun(3)= magr*sin(obliquity)*sin(eclplong_raw); | ||
|
||
if show == 'y' | ||
fprintf(1,'meanlon %11.6f meanan %11.6f eclplon %11.6f obli %11.6f \n', ... | ||
meanlong,meananomaly/deg2rad,eclplong_raw/deg2rad,obliquity/deg2rad); | ||
fprintf(1,'rs %11.9f %11.9f %11.9f \n',rsun); | ||
fprintf(1,'magr %14.7f \n',magr); | ||
end | ||
|
||
rtasc= atan( cos(obliquity)*tan(eclplong_raw) ); | ||
|
||
% --- check that rtasc is in the same quadrant as eclplong_raw ---- | ||
if ( eclplong_raw < 0.0 ) | ||
eclplong_raw= eclplong_raw + twopi; % make sure it's in 0 to 2pi range | ||
end | ||
if ( abs( eclplong_raw-rtasc ) > pi*0.5 ) | ||
rtasc= rtasc + 0.5 *pi*round( (eclplong_raw-rtasc)/(0.5 *pi)); | ||
end | ||
decl = asin( sin(obliquity)*sin(eclplong_raw) ); | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[ | ||
{ | ||
"tleLine1": "1 00001U 57001B 21005.53831292 -.00000083 00000-0 -11575-3 0 9996", | ||
"tleLine2": "2 00001 34.2508 325.6936 1846988 181.8107 177.4919 00.00000000227203", | ||
"description": "Mean motion is zero and that is not allowed.", | ||
"results": [{ | ||
"error": 2 | ||
}] | ||
}, | ||
{ | ||
"tleLine1": "1 00002U 57001B 21005.53831292 -.00000083 00000-0 -11575-3 0 9996", | ||
"tleLine2": "2 00002 34.2508 325.6936 1846988 181.8107 177.4919 00.00000001227203", | ||
"description": "Eccentricity is way too high because mean motion is nearly zero.", | ||
"results": [{ | ||
"error": 3 | ||
}] | ||
}, | ||
{ | ||
"tleLine1": "1 00004U 57001B 21005.53831292 -.00000083 00000-0 -11575-3 0 9996", | ||
"tleLine2": "2 00004 34.2508 325.6936 9999999 181.8107 177.4919 10.84863720227203", | ||
"description": "Eccentricity is way too high.", | ||
"results": [{ | ||
"error": 4 | ||
}] | ||
}, | ||
{ | ||
"tleLine1": "1 00006U 57001B 21005.53831292 -.00000083 00000-0 -11575-3 0 9996", | ||
"tleLine2": "2 00005 34.2508 325.6936 1846988 181.8107 177.4919 25.84863720227203", | ||
"description": "Satellite should be decayed already.", | ||
"results": [{ | ||
"error": 6 | ||
}] | ||
} | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why you are updating the name? Did you update the comments above too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because classically,
rv
stands for satellite state vector: [rx, ry, rz, vx, vy, vz]. This represents the position and velocity in the x,y and z directions. But this function actually returns asatrec
object.This is not the same as a satellite state vector. A
satrec
object is a dictionary containing all thesgp4
satellite information [sgp4io.cpp].I have not modified any other comments above. I figured that the old way on naming the function was not in-line with its modern interpretation of the term
rv
andsatrec
.