Skip to content

Conversation

@plentydone
Copy link

Failure looks like this:

ERROR: test_export_tle_sgp4init (sgp4.tests.TestFunctions.test_export_tle_sgp4init)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/andrew/python-sgp4/.tox/py312/lib/python3.12/site-packages/sgp4/tests.py", line 252, in test_export_tle_sgp4init
    outline1, outline2 = export_tle(sat)
                         ^^^^^^^^^^^^^^^
  File "/home/andrew/python-sgp4/.tox/py312/lib/python3.12/site-packages/sgp4/exporter.py", line 89, in export_tle
    append(str(satrec.revnum).rjust(5))
               ^^^^^^^^^^^^^
AttributeError: 'Satrec' object has no attribute 'revnum'. Did you mean: 'elnum'?

Let me know if any adjustments are needed.

Copy link
Owner

@brandon-rhodes brandon-rhodes left a comment

Choose a reason for hiding this comment

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

Thanks for putting together this fix, complete with a test! It looks like a couple of tests are failing in CI, but I'll be happy to merge this once you get them fixed. Thanks!

sgp4/model.py Outdated

self.jdsatepoch = whole_jd
self.jdsatepochF = fraction
self.revnum = 0
Copy link
Owner

Choose a reason for hiding this comment

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

Could you move this down to just beneath self.classification? That's what it sits next to over in the C++ code, and would make it a bit easier for my eyes to find it later than up here with the dates.

Copy link
Author

Choose a reason for hiding this comment

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

I think setting this to 0 here was a flawed approach, which I didn't see until I saw the failing CI tests. To make the patch less invasive, I adjusted my approach just to fix the error when exporting a TLE from a pure python Satrec initialized with sgp4init, as I'm not aware of anything else that needs it.

sgp4/tests.py Outdated
outline1, outline2 = export_tle(sat)
parsed_sat = Satrec.twoline2rv(outline1, outline2, WGS84)
for attr in VANGUARD_ATTRS.keys():
assertEqual(getattr(parsed_sat, attr), getattr(sat, attr))
Copy link
Owner

Choose a reason for hiding this comment

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

I like how you didn't just make sure that export_tle() worked, but that the same satellite came back when re-parsed.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! Updated to use assert_satellites_match which I hadn't noticed before.

@plentydone plentydone force-pushed the revnum branch 2 times, most recently from 436de5e to 8ee25ed Compare March 16, 2025 15:59
@plentydone
Copy link
Author

Sorry for the spam with the broken tests. I couldn't replicate locally for some reason, will figure out in the next day or two.

@plentydone
Copy link
Author

Finally came back to this, saw what I did wrong in the tests, and fixed and expanded them. Hopefully it's all good this time!

brandon-rhodes added a commit that referenced this pull request Jul 29, 2025
This missing attribute was preventing such satellites from exporting.
(This supersedes pull request #134, which tried instead to harden the
export routine against the possibly-missing attribute.)
@brandon-rhodes
Copy link
Owner

I have finally had time to circle back to this, and in case anyone else's code ever looks for .revnum, I think it makes the most sense for the module to simply guarantee that the attribute is always there:

6d89ae1

Also, I have written a test.sh test script that tests locally whether both the compiled and the pure-Python versions of SGP4 work. That way, we avoid needing to have tests with branches inside that do different things depending on whether the C++ successfully compiled.

@plentydone
Copy link
Author

Looks great, thanks Brandon!

@brandon-rhodes
Copy link
Owner

I'm hoping to find time next week for a release, to get this feature out. Thanks again for pointing out the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants