ast2000tools.space_mission.SpaceMission¶
-
class
ast2000tools.space_mission.
SpaceMission
(seed, data_path=None, has_moons=True, verbose=True)¶ Bases:
object
Represents a mission to launch a rocket from your home planet and land it safely on another planet.
This class is used to keep track of your mission’s progress and verify your results.
- Parameters
seed (int) – The seed to use when generating random solar system and mission properties.
data_path (str, optional) – Specifies the path to the directory where output XML files should be stored (e.g. the MCAst data folder). By default, a folder called “XMLs” is created in the working directory.
has_moons (bool, optional) – Whether the generated planets should be visualized with moons. Setting to False increases performance. Default is True.
verbose (bool, optional) – Whether to print non-essential status messages. Default is True.
Methods
Initiates an interplanetary travel process allowing you to guide your spacecraft to a different planet.
Initiates a landing sequence process allowing you to land on a planet.
generate_orbit_video
(times, planet_positions)Calls
generate_orbit_video()
for theast2000tools.solar_system.SolarSystem
instance associated with the mission.get_sky_image_pixel
(polar_angle, azimuth_angle)Finds the index of the pixel in the full-sky image correspnding to the given spherical coordinates.
launch_rocket
([time_step])Simulates a rocket launch based on the previously specified launch parameters.
load
(filename[, verbose])Loads an instance of
SpaceMission
from the specified binary file.Returns the distances to the bodies of the solar system as measured by your spacecraft directly after launch.
Returns the Doppler shifts of the two reference stars as measured by your spacecraft directly after launch.
save
(filename, mission[, verbose])Saves the given instance of
SpaceMission
as a binary file.set_launch_parameters
(thrust, …)Used to specify various parameters required to perform a launch.
take_picture
([filename, full_sky_image_path])Generates a picture of the sky in the direction that the spacecraft is pointing directly after launch.
verify_launch_result
(position_after_launch)Verifies that your computation of the final spacecraft position after launch gives a resonable result.
Verifies that your manually inferred values of the position, velocity and pointing angle of the spacecraft directly after launch are reasonable.
verify_planet_positions
(simulation_duration, …)Calls
verify_planet_positions()
for theast2000tools.solar_system.SolarSystem
instance associated with the mission.Attributes
The path to the directory where output XML files will be stored.
The index of the planet to land on after the interplanetary travel.
Whether the destination state after the interplanetary travel has been recorded.
The estimated duration of the launch (the time required to reach escape velocity) in seconds.
The initial mass of fuel contained in the rocket in kilograms.
Array of shape (2,) containing the initial x and y-position for the landing sequence, in astronomical units relative to the star.
The initial time for the landing sequence, in years.
Array of shape (2,) containing the initial x and y-velocity for the landing sequence, in astronomical units per year relative to the star.
The cross-sectional area of the lander in square meters.
The mass of the lander in kilograms.
Whether the landing sequence has been successfully completed.
The azimuthal angle of the landing site in degrees.
The polar angle of the landing site in degrees.
Whether the launch parameters have been specified.
Array of shape (2,) containing the x and y-position of the launch site, in astronomical units relative to the star.
Whether the launch result has been successfully verified.
Whether the manually inferred orientation data has been successfully verified.
The object representing the ongoing interplanetary travel.
The object representing the ongoing landing sequence.
The central wavelength of the spectral line (H-alpha) used to measure Doppler shifts, in nanometers.
Whether the rocket has been successfully launched.
The mass loss rate of the rocket engine in kilograms per second.
The thrust of the rocket engine in Newtons.
The seed used to generate random solar system and mission properties.
The cross-sectional area of the spacecraft in square meters.
The mass of the spacecraft in kilograms.
Tuple (\(\phi_0\), \(\phi_1\)) containing the azimuthal angles of the reference stars relative to the solar system x-axis, in degrees.
Tuple (\(\Delta\lambda_0\), \(\Delta\lambda_1\)) containing the Doppler shifts of the stars relative to your sun, in nanometers.
The randomized solar system where the space mission takes place.
The time of the end of the launch in years.
The time of the start of the launch in years.
Whether non-essential status messages will be printed.
-
property
system
¶ The randomized solar system where the space mission takes place.
-
property
rocket_thrust
¶ The thrust of the rocket engine in Newtons. Only available after calling
set_launch_parameters()
.- Type
-
property
rocket_mass_loss_rate
¶ The mass loss rate of the rocket engine in kilograms per second. Only available after calling
set_launch_parameters()
.- Type
-
property
initial_fuel_mass
¶ The initial mass of fuel contained in the rocket in kilograms. Only available after calling
set_launch_parameters()
.- Type
-
property
estimated_launch_duration
¶ The estimated duration of the launch (the time required to reach escape velocity) in seconds. Only available after calling
set_launch_parameters()
.- Type
-
property
launch_position
¶ Array of shape (2,) containing the x and y-position of the launch site, in astronomical units relative to the star. Only available after calling
set_launch_parameters()
.- Type
1-D
numpy.ndarray
-
property
time_of_launch
¶ The time of the start of the launch in years. Only available after calling
set_launch_parameters()
.- Type
-
property
time_after_launch
¶ The time of the end of the launch in years. Only available after calling
launch_rocket()
.- Type
-
property
reference_wavelength
¶ The central wavelength of the spectral line (H-alpha) used to measure Doppler shifts, in nanometers.
- Type
-
property
star_direction_angles
¶ Tuple (\(\phi_0\), \(\phi_1\)) containing the azimuthal angles of the reference stars relative to the solar system x-axis, in degrees.
- Type
-
property
star_doppler_shifts_at_sun
¶ Tuple (\(\Delta\lambda_0\), \(\Delta\lambda_1\)) containing the Doppler shifts of the stars relative to your sun, in nanometers.
- Type
-
property
ongoing_interplanetary_travel
¶ The object representing the ongoing interplanetary travel. Only available after calling
begin_interplanetary_travel()
.- Type
-
property
ongoing_landing_sequence
¶ The object representing the ongoing landing sequence. Only available after calling
begin_landing_sequence()
.- Type
-
property
destination_planet_idx
¶ The index of the planet to land on after the interplanetary travel. Only available after calling
record_destination()
.- Type
-
property
initial_landing_time
¶ The initial time for the landing sequence, in years. Only available after calling
record_destination()
.- Type
-
property
initial_landing_position
¶ Array of shape (2,) containing the initial x and y-position for the landing sequence, in astronomical units relative to the star. Only available after calling
record_destination()
.- Type
1-D
numpy.ndarray
-
property
initial_landing_velocity
¶ Array of shape (2,) containing the initial x and y-velocity for the landing sequence, in astronomical units per year relative to the star. Only available after calling
record_destination()
.- Type
1-D
numpy.ndarray
-
property
landing_site_polar_angle
¶ The polar angle of the landing site in degrees. Only available after completing a successful landing with
LandingSequence
.- Type
-
property
landing_site_azimuth_angle
¶ The azimuthal angle of the landing site in degrees. Only available after completing a successful landing with
LandingSequence
.- Type
-
property
launch_result_verified
¶ Whether the launch result has been successfully verified.
- Type
-
property
manual_orientation_verified
¶ Whether the manually inferred orientation data has been successfully verified.
- Type
-
property
destination_recorded
¶ Whether the destination state after the interplanetary travel has been recorded.
- Type
-
static
save
(filename, mission, verbose=True)¶ Saves the given instance of
SpaceMission
as a binary file.- Parameters
filename (str) – The name/path to use for the written binary file. Warning: If there exists a file with the same name it will be overwritten.
mission (
SpaceMission
) – The instance ofSpaceMission
to save.verbose (bool, optional) – Set to False to mute the message saying that the file was successfully saved.
-
static
load
(filename, verbose=True)¶ Loads an instance of
SpaceMission
from the specified binary file.- Parameters
- Returns
The loaded
SpaceMission
instance.- Return type
- Raises
ValueError – When filename does not point to a valid file.
-
set_launch_parameters
(thrust, mass_loss_rate, initial_fuel_mass, estimated_launch_duration, launch_position, time_of_launch)¶ Used to specify various parameters required to perform a launch.
Note
Any existing launch results will be cleared.
- Parameters
thrust (float) – The total thrust of the rocket engine in Newtons.
mass_loss_rate (float) – The total rate of mass loss of the rocket engine in kilograms per second.
initial_fuel_mass (float) – The total mass of rocket fuel contained in the rocket before launch, in kilograms.
estimated_launch_duration (float) – The estimated duration of the launch, i.e. the time required to reach escape velocity, in seconds.
launch_position (1-D array_like) – Array of shape (2,) containing the x and y-position of the launch site, in astronomical units relative to the star. Must be close to the surface of your home planet (maximum 1% deviation).
time_of_launch (float) – The time of the start of the launch in years.
-
launch_rocket
(time_step=0.01)¶ Simulates a rocket launch based on the previously specified launch parameters.
Note
Any existing launch result verification will be cleared.
- Parameters
time_step (float, optional) – The time step duration to use for the simulation, in seconds. Not allowed to exceed the default of 0.01. Decrease if you suspect that higher accuracy is needed.
- Raises
RuntimeError – When called before
set_launch_parameters()
.RuntimeError – When the rocket runs out of fuel.
RuntimeError – When the rocket is unable to overcome gravity.
RuntimeError – When the rocket reaches escape velocity too quickly.
RuntimeError – When the rocket hasn’t reached escape velocity at the time the simulation is completed.
-
verify_launch_result
(position_after_launch)¶ Verifies that your computation of the final spacecraft position after launch gives a resonable result.
- Parameters
position_after_launch (1-D array_like) – Array of shape (2,) containing your values for the x and y-position of the spacecraft after launch, in astronomical units relative to the star.
- Raises
RuntimeError – When called before
launch_rocket()
.RuntimeError – When the input position is too far from the correct position.
-
verify_planet_positions
(simulation_duration, planet_positions, filename='planet_trajectories.npz')¶ Calls
verify_planet_positions()
for theast2000tools.solar_system.SolarSystem
instance associated with the mission.Note
The exact trajectories will be needed in later stages of the mission. By default, this wrapper causes the trajectories to be stored in the file “planet_trajectories.npz” in the working directory. The syntax for loading the data is:
with np.load('planet_trajectories.npz') as f: times = f['times'] exact_planet_positions = f['planet_positions']
-
generate_orbit_video
(times, planet_positions, number_of_frames=None, reduce_other_periods=True, filename='orbit_video.xml')¶ Calls
generate_orbit_video()
for theast2000tools.solar_system.SolarSystem
instance associated with the mission.
-
static
get_sky_image_pixel
(polar_angle, azimuth_angle)¶ Finds the index of the pixel in the full-sky image correspnding to the given spherical coordinates.
-
take_picture
(filename='sky_picture.png', full_sky_image_path='himmelkule.npy')¶ Generates a picture of the sky in the direction that the spacecraft is pointing directly after launch.
Note
You can safely assume that the spacecraft is looking along the solar system plane.
- Parameters
filename (str, optional) – The name/path to use for the generated image. By default the image is stored as “sky_picture.png” in the working directory.
full_sky_image_path (str, optional) – The name/path to use when looking for the sky data file. This file must be downloaded from the course website. By default the file is assumed to be named “himmelkule.npy” and reside in the working directory.
- Raises
RuntimeError – When called before
verify_launch_result()
.ValueError – When full_sky_image_path does not point to a valid file.
-
measure_star_doppler_shifts
()¶ Returns the Doppler shifts of the two reference stars as measured by your spacecraft directly after launch.
Note
The Doppler shifts are computed for the H-alpha spectral line, which has a central wavelength of 656.3 nm.
- Returns
Tuple (\(\Delta\lambda_0\), \(\Delta\lambda_1\)) containing the Doppler shifts of the stars relative to your spacecraft, in nanometers.
- Return type
- Raises
RuntimeError – When called before
verify_launch_result()
.
-
measure_distances
()¶ Returns the distances to the bodies of the solar system as measured by your spacecraft directly after launch.
- Returns
Array of shape (number_of_planets+1,) containing the distances to the planets and sun (last entry) in your system, in astronomical units.
- Return type
1-D
numpy.ndarray
- Raises
RuntimeError – When called before
verify_launch_result()
.
-
verify_manual_orientation
(position_after_launch, velocity_after_launch, angle_after_launch)¶ Verifies that your manually inferred values of the position, velocity and pointing angle of the spacecraft directly after launch are reasonable.
- Parameters
position_after_launch (1-D array_like) – Array of shape (2,) containing your inferred values for the x and y-position of the spacecraft, in astronomical units relative to the star.
velocity_after_launch (1-D array_like) – Array of shape (2,) containing your inferred values for the x and y-velocity of the spacecraft, in astronomical units per year relative to the star.
angle_after_launch (float) – Your inferred value for the azimuthal angle of the spacecraft’s pointing, in degrees.
- Raises
RuntimeError – When called before
verify_launch_result()
.RuntimeError – When any of the inputted values are too far from the correct values.
-
begin_interplanetary_travel
()¶ Initiates an interplanetary travel process allowing you to guide your spacecraft to a different planet.
Note
Any ongoing interplanetary travel or landing sequence will be terminated. Any recorded destination state will be cleared.
- Returns
A new instance of
InterplanetaryTravel
associated with your system.- Return type
-
begin_landing_sequence
(assume_uniform_gravity_atmosphere=True)¶ Initiates a landing sequence process allowing you to land on a planet.
Note
Any ongoing interplanetary travel or landing sequence will be terminated. Any recorded landing site coordinates will be cleared.
- Parameters
assume_uniform_gravity_atmosphere (bool, optional) – Whether to neglect the change of gravitational force with height when modelling the atmosphere. Default is True.
- Returns
A new instance of
LandingSequence
associated with your system.- Return type