Pyorbital

repository·main·Indexed 42 days ago

https://github.com/pytroll/pyorbital

A Python library for scheduling satellite passes, computing orbital parameters from Two-Line Element (TLE) files, and performing astronomical calculations. It provides tools for calculating satellite position, velocity, and geolocation, as well as computing solar angles and observer ECI positions.

Tokens
12.6K
Snippets
52
Records
61
Agent score
54%

What's inside Pyorbital

  1. Configure geolocation conventions

    main

    Geolocation in Pyorbital is affected by two main settings: Nadir Convention and Rotation Order. You can set these per function call or globally.

    Available Options

    Nadir Convention (defines 'down'):

    • "legacy" (Default): The direction used in previous Pyorbital versions. Not re-orthogonalised against velocity.
    • "geocentric": Straight at the center of the Earth. More accurate for most orbits.
    • "geodetic": Along the ellipsoid normal.

    Rotation Order (defines roll/pitch application):

    • "legacy" (Default): Roll first, then pitch. The along-track component is compressed by cos(scan_angle).
    • "pitch_first": Pitch first, then roll. The along-track component is independent of the scan angle.

    Setting Conventions

    1. Per function call (highest precedence):

    from pyorbital.geoloc import geolocate
    lons, lats, alts = geolocate(orbital, scan_geometry, times, 
                                nadir_convention="geocentric", 
                                rotation_order="pitch_first")

    2. Process-wide via context manager:

    import pyorbital
    with pyorbital.config.set(nadir_convention="geocentric", rotation_order="pitch_first"):
        # All calls within this block use the new settings
        reprocess()

    3. Via Environment Variables: Set PYORBITAL_NADIR_CONVENTION and PYORBITAL_ROTATION_ORDER in your shell.

    IMPORTANT

    To reproduce existing Pyorbital products exactly (e.g., for archive reprocessing), you must pin both to "legacy". Mixing "legacy" nadir with "pitch_first" rotation will not reproduce legacy output.

    from pyorbital.geoloc import geolocate
    lons, lats, alts = geolocate(orbital, scan_geometry, times,   # doctest: +SKIP
                                  nadir_convention="geocentric",
                                  rotation_order="pitch_first")
  2. Install Pyorbital from source

    main

    You can install the latest in-development version from GitHub using pip:

    pip install git+https://github.com/pytroll/pyorbital.git

    If you are developing Pyorbital and want changes to reflect immediately, clone the repository and install it in "editable" mode:

    git clone git://github.com/pytroll/pyorbital.git
    cd pyorbital
    pip install -e .
  3. Add missing satellite platforms

    main

    Pyorbital uses a platforms.txt file to map satellite names to NORAD identifiers. If your satellite is not supported, you can add it by:

    1. Copying the existing platforms.txt file.
    2. Adding your satellite name and its NORAD identifier (the first number in a TLE file).
    3. Placing the modified file in a directory specified by the PYORBITAL_CONFIG_PATH environment variable.

    You can use the check_platform.py script to verify if a satellite is already supported:

    python -m pyorbital.check_platform -s SATELLITE_NAME
    python -m pyorbital.check_platform -s NOAA-21
  4. Parse TLE files with tlefile

    main

    The pyorbital.tlefile module allows you to parse NORAD Two-Line Element (TLE) files.

    If no path is provided to the read function, Pyorbital attempts to find local TLE files using the glob pattern defined in the TLES environment variable. If TLES is not set, it attempts to download TLEs from Celestrak.

    To use a specific local TLE file:

    from pyorbital import tlefile
    tle = tlefile.read('satellite_name', '/path/to/my/tle_file.txt')
    print(tle.inclination)
    from pyorbital import tlefile
    tle = tlefile.read('noaa 18', '/path/to/my/tle_file.txt')
    print(tle.inclination)
  5. Compute astronomical parameters

    main

    The pyorbital.astronomy module provides functions for satellite remote sensing parameters, such as the Sun-zenith angle.

    from pyorbital import astronomy
    import datetime as dt
    
    # Parameters
    utc_time = dt.datetime(2012, 5, 15, 15, 45)
    lon, lat = 12, 56
    
    # Compute Sun-zenith angle
    angle = astronomy.sun_zenith_angle(utc_time, lon, lat)
    from pyorbital import astronomy
    import datetime as dt
    
    utc_time = dt.datetime(2012, 5, 15, 15, 45)
    lon, lat = 12, 56
    print(astronomy.sun_zenith_angle(utc_time, lon, lat))
  6. Compute satellite position and velocity with Orbital

    main

    The pyorbital.orbital.Orbital class is used to compute a satellite's position, velocity, and geolocation at a specific time.

    Using current TLEs (Internet-based)

    By default, initializing Orbital with just a name will attempt to use the most recent TLEs from the internet.

    from pyorbital.orbital import Orbital
    import datetime as dt
    
    # Initialize with satellite name
    orb = Orbital("Suomi NPP")
    now = dt.datetime.now(dt.timezone.utc)
    
    # Get normalized position and velocity
    pos, vel = orb.get_position(now)
    
    # Get longitude, latitude, and altitude
    lon, lat, alt = orb.get_lonlatalt(now)

    Using specific TLE files for accuracy

    For historical data or higher accuracy, provide a specific TLE file path to the Orbital constructor:

    from pyorbital.orbital import Orbital
    import datetime as dt
    
    dtobj = dt.datetime(2015, 2, 7, 3, 0)
    snpp = Orbital('Suomi NPP', tle_file='/path/to/tle/files/tle-20150207.txt')
    lon, lat, alt = snpp.get_lonlatalt(dtobj)
    from pyorbital.orbital import Orbital
    import datetime as dt
    
    # Use current TLEs from the internet:
    orb = Orbital("Suomi NPP")
    now = dt.datetime.now(dt.timezone.utc)
    
    # Get normalized position and velocity of the satellite:
    pos, vel = orb.get_position(now)
    
    # Get longitude, latitude and altitude of the satellite:
    lon, lat, alt = orb.get_lonlatalt(now)
  7. Configure the Pyorbital configuration path

    main

    Pyorbital looks for configuration files (like platforms.txt) in a specific directory. You can control this directory using environment variables:

    • PYORBITAL_CONFIG_PATH: Use this to specify a custom directory for configuration files. This is the preferred method.
    • PPP_CONFIG_DIR: This is deprecated and no longer supported. Use PYORBITAL_CONFIG_PATH instead.

    The platforms.txt file within this directory should contain satellite names and their NORAD numbers, one per line, ignoring lines starting with #.