Skip to content
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

Bring current with 7 dec 15 vallado CPP version #35

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 15 additions & 16 deletions sgp4/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
* typerun - type of run verification 'v', catalog 'c',
* manual 'm'
* typeinput - type of manual input mfe 'm', epoch 'e', dayofyr 'd'
* afspc_mode - True for afspc calculations, False for 'improved' mode
* opsmode - mode of operation afspc or improved 'a', 'i'
* whichconst - which set of constants to use 72, 84
*
* outputs :
Expand All @@ -99,7 +99,7 @@
--------------------------------------------------------------------------- */
"""

def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False):
def twoline2rv(longstr1, longstr2, whichconst, opsmode='i'):
"""Return a Satellite imported from two lines of TLE data.

Provide the two TLE lines as strings `longstr1` and `longstr2`,
Expand All @@ -112,7 +112,7 @@ def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False):

Normally, computations are made using various recent improvements
to the algorithm. If you want to turn some of these off and go
back into "afspc" mode, then set `afspc_mode` to `True`.
back into "opsmode" mode, then set `opsmode` to `a`.

"""

Expand All @@ -139,17 +139,18 @@ def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False):
line[63] == ' '):

_saved_satnum = satrec.satnum = int(line[2:7])
# classification = line[7] or 'U'
# intldesg = line[9:17]
satrec.line1 = line
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this debugging code, or an idea for a new feature? Vallado's routines don't save the lines, and here in Python there may be a danger: will users do things like take a satellite, adjust a parameter, and expect .line1 to now reflect the new parameter? It might be safer to not cache this data since the source library does not.

satrec.classification = line[7] or 'U'
satrec.intldesg = line[9:17]
two_digit_year = int(line[18:20])
satrec.epochdays = float(line[20:32])
satrec.ndot = float(line[33:43])
satrec.nddot = float(line[44] + '.' + line[45:50])
nexp = int(line[50:52])
satrec.bstar = float(line[53] + '.' + line[54:59])
ibexp = int(line[59:61])
# numb = int(line[62])
# elnum = int(line[64:68])
satrec.ephtype = line[62]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading Vallado's code correctly, it takes satrec.ephtype and satrec.elnum from line2 instead of line1. Can we switch to do the same, for compatibility in case the lines disagree?

satrec.elnum = int(line[64:68])
else:
raise ValueError(error_message.format(1, LINE1, line))

Expand All @@ -171,24 +172,24 @@ def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False):
if _saved_satnum != satrec.satnum:
raise ValueError('Object numbers in lines 1 and 2 do not match')

satrec.line2 = line
satrec.inclo = float(line[8:16])
satrec.nodeo = float(line[17:25])
satrec.ecco = float('0.' + line[26:33].replace(' ', '0'))
satrec.argpo = float(line[34:42])
satrec.mo = float(line[43:51])
satrec.no = float(line[52:63])
#revnum = line[63:68]
satrec.no_kozai = float(line[52:63])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, drat. This creates an incompatible change that will crash Python programs that looked at the .no attribute previously. After merging this, I might add a .no property that returns this value, to prevent breakage. But I agree that we should follow Vallado, as a higher priority.

satrec.revnum = line[63:68]
#except (AssertionError, IndexError, ValueError):
else:
raise ValueError(error_message.format(2, LINE2, line))

# ---- find no, ndot, nddot ----
satrec.no = satrec.no / xpdotp; # rad/min
satrec.no_kozai = satrec.no_kozai / xpdotp; # rad/min
satrec.nddot= satrec.nddot * pow(10.0, nexp);
satrec.bstar= satrec.bstar * pow(10.0, ibexp);

# ---- convert to sgp4 units ----
satrec.a = pow( satrec.no*tumin , (-2.0/3.0) );
satrec.ndot = satrec.ndot / (xpdotp*1440.0); # ? * minperday
satrec.nddot= satrec.nddot / (xpdotp*1440.0*1440);

Expand All @@ -198,8 +199,6 @@ def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False):
satrec.argpo = satrec.argpo * deg2rad;
satrec.mo = satrec.mo * deg2rad;

satrec.alta = satrec.a*(1.0 + satrec.ecco) - 1.0;
satrec.altp = satrec.a*(1.0 - satrec.ecco) - 1.0;

"""
// ----------------------------------------------------------------
Expand All @@ -225,9 +224,9 @@ def twoline2rv(longstr1, longstr2, whichconst, afspc_mode=False):
int(sec_fraction * 1000000.0 // 1.0))

# ---------------- initialize the orbit at sgp4epoch -------------------
sgp4init(whichconst, afspc_mode, satrec.satnum, satrec.jdsatepoch-2433281.5, satrec.bstar,
satrec.ecco, satrec.argpo, satrec.inclo, satrec.mo, satrec.no,
satrec.nodeo, satrec)
sgp4init(whichconst, opsmode, satrec.satnum, satrec.jdsatepoch-2433281.5, satrec.bstar,
satrec.ndot, satrec.nddot, satrec.ecco, satrec.argpo, satrec.inclo, satrec.mo,
satrec.no_kozai, satrec.nodeo, satrec)

return satrec

Expand Down