Skip to content

Conversation

@chrisfinlay
Copy link
Owner

No description provided.

chrisfinlay and others added 9 commits January 20, 2026 00:51
Space-Track.org deprecated the tle, tle_latest, and tle_publish API
endpoints on January 12, 2025, replacing them with gp and gp_history.
This update ensures continued functionality with the new API.

Changes:
- Updated fetch_tle_data() to use st_client.gp_history()
- Updated get_tles_by_name() to use st.gp_history()
- Changed JSON parsing from ast.literal_eval() to json.loads()
  (new endpoint returns proper JSON format)
- Enhanced spacetrack_time_to_isot() to handle both old and new
  epoch formats (YYYY-MM-DD HH:MM:SS and ISO 8601)
- Updated type_cast_tles() to only cast columns that exist in
  the response (column set differs slightly with new endpoint)

Testing:
- Added comprehensive test suite (test_tle_api.py) with 18 tests
- Tests cover fetch_tle_data, get_tles_by_id, get_tles_by_name,
  get_visible_satellite_tles, and all helper functions
- All tests pass with real API calls

The new gp_history endpoint supports:
- Historical TLE data with same parameters as old endpoint
- 9-digit catalog numbers (future-proof)
- Multiple data formats (TLE, JSON, CSV, XML, KVN, HTML)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updated test credential handling to work seamlessly in both CI/CD
and local development environments:

Test fixture changes (test_tle_api.py):
- Support SPACETRACK_LOGIN environment variable (GitHub Actions)
- Default to ~/.credentials/spacetrack_login.yaml for local dev
- Fallback to examples/test/ and tests/ directories
- Clear error message when credentials not found

Workflow changes (test.yml):
- Pass SPACETRACK_LOGIN env var to pytest command
- Ensures tests can use credentials from GitHub Secrets

Testing verified:
- ✓ Works without env var (uses ~/.credentials/spacetrack_login.yaml)
- ✓ Works with env var (uses SPACETRACK_LOGIN from environment)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
SpaceTrack API returns error responses with columns ['error', 'Fetch_Timestamp']
when satellite names are not found. Updated get_tles_by_name() to:
- Detect error responses by checking for missing NORAD_CAT_ID column
- Handle empty DataFrames before concatenation
- Validate cached files have valid TLE data
- Return empty DataFrame with Fetch_Timestamp when no TLEs found

Fixes 4 failing tests in GitHub Actions:
- test_get_tles_by_name_with_caching
- test_get_tles_by_name_multiple
- test_get_tles_by_name_nonexistent
- test_get_visible_satellite_tles_by_name

All tests now pass locally with Python 3.11 after clearing cache.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
SpaceTrack credentials are now completely optional, allowing users to work
with cached or manually imported TLE data without API access.

New console scripts:
- tabsim-setup-spacetrack: Interactive setup for SpaceTrack credentials
  - Prompts for username/password with hidden input
  - Saves to tabsim/data/rfi/tles/spacetrack_login.yaml
  - Sets secure permissions (600)

- tabsim-import-tles: Import TLE text files and convert to JSON
  - Supports standard 3-line TLE format
  - Can process individual files or entire directories
  - Extracts NORAD ID, epoch, and satellite name
  - Outputs JSON compatible with existing TLE cache system

Changes to tabsim/tle.py:
- Added load_spacetrack_credentials() function
- Searches for credentials in priority order:
  1. TLE data directory (tabsim/data/rfi/tles/)
  2. Home directory (~/.credentials/)
  3. Current working directory
- Returns (None, None) when credentials not found

Changes to tests/test_tle_api.py:
- Updated fixture to use load_spacetrack_credentials()
- Tests skip gracefully with helpful message when no credentials
- Maintains backward compatibility with SPACETRACK_LOGIN env var

Changes to pyproject.toml:
- Added pyyaml dependency
- Registered new console scripts
- Removed deprecated spacetrack warning filter from pytest.ini

All scripts tested and verified working with sample TLE data.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Modified add_tle_satellite_sources() in config.py to:
- Use load_spacetrack_credentials() when spacetrack_path not provided
  or when the specified file doesn't exist
- Falls back gracefully with warning message when no credentials found
- Maintains backward compatibility with explicit spacetrack_path

This allows sim_vis to work without requiring spacetrack_login.yaml in
examples/test directory. Credentials are now automatically loaded from:
1. Specified path (if exists)
2. tabsim/data/rfi/tles/spacetrack_login.yaml
3. ~/.credentials/spacetrack_login.yaml

All test_sim-vis.py tests now pass.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Combined optimizations to reduce API load on GitHub Actions:

Option 1 - Removed redundant tests (3 API calls saved):
- Removed test_get_tles_by_id_mixed_cache_remote (2 calls)
  Already tested cache behavior in test_get_tles_by_id_basic_and_caching
- Removed test_fetch_tle_data_invalid_norad_id (1 call)
  Error handling tested in other tests

Option 2 - Reduced Python version matrix:
- Test only 3.9, 3.11, 3.13 (oldest, middle, newest)
- Down from 5 versions to 3 (40% reduction)

Fixed cache reuse in test_get_tles_by_name_basic_caching_multiple:
- Changed tle_dir=None to tle_dir=temp_tle_dir for multiple satellite test
- ISS now loaded from cache, only HUBBLE requires API call
- Reduces from 3 to 2 API calls for this test

FINAL RESULTS:
- Tests: 18 → 9 (50% reduction)
- API calls per run: 16 → 9 (44% reduction)
- Python versions: 5 → 3
- Total concurrent calls: 80 → 27
- SpaceTrack rate limit: 30/minute
- Status: ✓ UNDER LIMIT by 3 calls (90% of limit)

All 9 tests pass locally. This ensures GitHub Actions won't hit
SpaceTrack's rate limit while maintaining comprehensive test coverage.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add id-token: write permission for trusted publishing
- Reference pypi environment for deployment
- Remove password/token (not needed with trusted publishing)

This requires:
1. PyPI environment configured in GitHub Settings
2. PyPI trusted publishing configured for this repo

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@chrisfinlay chrisfinlay merged commit 6e69386 into main Jan 21, 2026
1 check passed
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.

1 participant