-
Notifications
You must be signed in to change notification settings - Fork 31
Emilyyu/doppler shift calc changes #668
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
Open
emilyyu07
wants to merge
17
commits into
main
Choose a base branch
from
emilyyu/doppler-shift-calc-changes
base: main
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
17 commits
Select commit
Hold shift + click to select a range
d020291
Added doppler shift calculation code
FATCullen daed291
Fixed no-any-type error
FATCullen d079df6
Fixed no-any-return error
FATCullen f7b5140
Fixed no-any-return error
FATCullen 1ae5471
Fixed no-return-any error
FATCullen 898fb87
Line length limit fix
FATCullen 8edeb2a
Fixed some formatting issues
FATCullen 10c07c6
Fixed some formatting issues
FATCullen faacc8a
Formatting issues
FATCullen c863c62
Merge branch 'main' into finn/doppler-shift-calcs
FATCullen 6ff2249
Pull request corrections, removed tuples, added type hints
FATCullen 7b9f191
Formatting changes
FATCullen 4e11350
Final typing
FATCullen 06e3a40
Formatting fixes
FATCullen 4481c67
applied doppler calculation changes
emilyyu07 ce0673c
formatting changes
emilyyu07 1aa5597
adjusted doppler formula
emilyyu07 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 hidden or 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,107 @@ | ||
| from typing import Final | ||
|
|
||
| from skyfield.api import EarthSatellite, Time, Timescale, Topos | ||
|
|
||
| SPEED_OF_LIGHT_METERS_PER_SECOND: Final[int] = 299_792_458 | ||
| TRANSMISSION_FREQUENCY_HZ: Final[float] = 433_920_000 # Default frequency, UW-Orbital's 433.920 MHz band | ||
|
|
||
| """ | ||
| @brief Holds logic for calculating doppler shift from TLS and ground station coordinates | ||
| @details Since we're not actually getting TLE or interfacing with HackRF it's not hooked up to anything yet | ||
| """ | ||
|
|
||
|
|
||
| # Change: made function take in time as a parameter instead | ||
| def load_satellite(tle_line1: str, tle_line2: str, timescale: Timescale, name: str = "UW_SAT") -> EarthSatellite: | ||
| """ | ||
| @brief Loads satellite from TLE lines | ||
| @param tle_line1: First line of TLE | ||
| @param tle_line2: Second line of TLE | ||
| @param timescale: Time for which satellite position is being calculated | ||
| @param name: Optional satellite name | ||
| @returns EarthSatellite object | ||
| """ | ||
| return EarthSatellite(tle_line1, tle_line2, name, timescale) | ||
|
|
||
|
|
||
| # Change: made function take in time as a parameter | ||
| def calculate_relative_velocity( | ||
| satellite: EarthSatellite, | ||
| observer_latitude_deg: float, | ||
| observer_longitude_deg: float, | ||
| observer_altitude_m: float, | ||
| time_current: Time, | ||
| ) -> float: | ||
| """ | ||
| @brief Computes relative velocity between satellite and observer | ||
| @param satellite: EarthSatellite object | ||
| @param observer_latitude_deg: Latitude of observer in degrees | ||
| @param observer_longitude_deg: Longitude of observer in degrees | ||
| @param observer_altitude_m: Altitude of observer in meters | ||
| @param time_current: Time for which relative velocity is being calculated | ||
| @returns Relative radial velocity in m/s (positive is moving away) | ||
| """ | ||
|
|
||
| observer = Topos( | ||
| latitude_degrees=observer_latitude_deg, | ||
| longitude_degrees=observer_longitude_deg, | ||
| elevation_m=observer_altitude_m, | ||
| ) | ||
| difference = satellite - observer | ||
| topocentric = difference.at(time_current) | ||
|
|
||
| # Separate velocity and position vectors | ||
| vx, vy, vz = topocentric.velocity.km_per_s | ||
| vel: tuple[float, float, float] = (vx, vy, vz) | ||
|
|
||
| px, py, pz = topocentric.position.km | ||
| pos: tuple[float, float, float] = (px, py, pz) | ||
|
|
||
| # Normalize position | ||
| pos_mag = sum(p**2 for p in pos) ** 0.5 | ||
| los_unit = [p / pos_mag for p in pos] | ||
|
|
||
| # Radial velocity = dot product of velocity vector with line-of-sight unit vector | ||
| radial_velocity_km_s = sum(vel[i] * los_unit[i] for i in range(3)) | ||
|
|
||
| return float(radial_velocity_km_s * 1000.0) # km/s -> m/s | ||
|
|
||
|
|
||
| def compute_doppler_shift(frequency_hz: float, relative_velocity_m_s: float) -> float: | ||
| """ | ||
| @brief Computes the Doppler-shift frequency | ||
| @param frequency_hz: Transmission frequency in Hz | ||
| @param relative_velocity_m_s: Relative radial velocity in m/s | ||
| @returns Doppler-shift frequency in Hz | ||
| """ | ||
| return frequency_hz * ( | ||
| SPEED_OF_LIGHT_METERS_PER_SECOND / (SPEED_OF_LIGHT_METERS_PER_SECOND + relative_velocity_m_s) | ||
| ) | ||
|
|
||
|
|
||
| # Change: made trans freq a constant in the file that is passed instead of a parameter to the function | ||
| def calculate_doppler( | ||
| tle_line1: str, | ||
| tle_line2: str, | ||
| observer_latitude_deg: float, | ||
| observer_longitude_deg: float, | ||
| observer_altitude_m: float, | ||
| timescale: Timescale, | ||
| time_current: Time, | ||
| ) -> float: | ||
| """ | ||
| @brief High-level function to compute Doppler shift | ||
| @param tle_line1: First line of TLE data | ||
| @param tle_line2: Second line of TLE data | ||
| @param observer_latitude_deg: Latitude of observer in degrees | ||
| @param observer_longitude_deg: Longitude of observer in degrees | ||
| @param observer_altitude_m: Altitude of observer in meters | ||
| @param timescale: Time for which satellite position is being calculated | ||
| @param time_current: Time for which Doppler shift is being calculated | ||
| @returns Doppler-shifted frequency in Hz | ||
| """ | ||
| sat = load_satellite(tle_line1, tle_line2, timescale) | ||
| rv = calculate_relative_velocity( | ||
| sat, observer_latitude_deg, observer_longitude_deg, observer_altitude_m, time_current | ||
| ) | ||
| return compute_doppler_shift(TRANSMISSION_FREQUENCY_HZ, rv) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.