Environment Class#
- class rocketpy.Environment[source]#
Keeps all environment information stored, such as wind and temperature conditions, as well as gravity.
- Variables:
Environment.earth_radius (
float) – Value of Earth’s Radius as 6.3781e6 m.Environment.air_gas_constant (
float) – Value of Air’s Gas Constant as 287.05287 J/K/KgEnvironment.gravity (
Function) – Gravitational acceleration. Positive values point the acceleration down. SeeEnvironment.set_gravity_model()for more information.Environment.latitude (
float) – Launch site latitude.Environment.longitude (
float) – Launch site longitude.Environment.datum (
string) – The desired reference ellipsoid model, the following options are available:SAD69,WGS84,NAD83, andSIRGAS2000.Environment.initial_east (
float) – Launch site East UTM coordinateEnvironment.initial_north (
float) – Launch site North UTM coordinateEnvironment.initial_utm_zone (
int) – Launch site UTM zone numberEnvironment.initial_utm_letter (
string) – Launch site UTM letter, to keep the latitude band and describe the UTM ZoneEnvironment.initial_hemisphere (
string) – Launch site South/North hemisphereEnvironment.initial_ew (
string) – Launch site East/West hemisphereEnvironment.elevation (
float) – Launch site elevation.Environment.datetime_date (
datetime) – Date time of launch in UTC time zone using thedatetimeobject.Environment.local_date (
datetime) – Date time of launch in the local time zone, defined by theEnvironment.timezoneparameter.Environment.timezone (
string) –Local time zone specification. See pytz. for time zone information.
Environment.elev_lon_array (
array) – Unidimensional array containing the longitude coordinates.Environment.elev_lat_array (
array) – Unidimensional array containing the latitude coordinates.Environment.elev_array (
array) – Two-dimensional Array containing the elevation information.Environment.topographic_profile_activated (
bool) – True if the user already set a topographic profile. False otherwise.Environment.max_expected_height (
float) – Maximum altitude in meters to keep weather data. The altitude must be Above Sea Level (ASL). Especially useful for controlling plots. Can be altered as desired by runningmax_expected_height = number.Environment.pressure_ISA (
Function) – Air pressure in Pa as a function of altitude as defined by the International Standard Atmosphere ISO 2533.Environment.temperature_ISA (
Function) – Air temperature in K as a function of altitude as defined by the International Standard Atmosphere ISO 2533Environment.pressure (
Function) – Air pressure in Pa as a function of altitude.Environment.barometric_height (
Function) – Geometric height above sea level in m as a function of pressure.Environment.temperature (
Function) – Air temperature in K as a function of altitude.Environment.speed_of_sound (
Function) – Speed of sound in air in m/s as a function of altitude.Environment.density (
Function) – Air density in kg/m³ as a function of altitude.Environment.dynamic_viscosity (
Function) – Air dynamic viscosity in Pa*s as a function of altitude.Environment.wind_speed (
Function) – Wind speed in m/s as a function of altitude.Environment.wind_direction (
Function) – Wind direction (from which the wind blows) in degrees relative to north (positive clockwise) as a function of altitude.Environment.wind_heading (
Function) – Wind heading (direction towards which the wind blows) in degrees relative to north (positive clockwise) as a function of altitude.Environment.wind_velocity_x (
Function) – Wind U, or X (east) component of wind velocity in m/s as a function of altitude.Environment.wind_velocity_y (
Function) – Wind V, or Y (north) component of wind velocity in m/s as a function of altitude.Environment.atmospheric_model_type (
string) – Describes the atmospheric model which is being used. Can only assume the following values:standard_atmosphere,custom_atmosphere,wyoming_sounding,windy,forecast,reanalysis,ensemble.Environment.atmospheric_model_file (
string) – Address of the file used for the atmospheric model being used. Only defined forwyoming_sounding,windy,forecast,reanalysis,ensembleEnvironment.atmospheric_model_dict (
dictionary) – Dictionary used to properly interpretnetCDFandOPeNDAPfiles. Only defined forforecast,reanalysis,ensemble.Environment.atmospheric_model_init_date (
datetime) – Datetime object instance of first available date innetCDFandOPeNDAPfiles when usingForecast,ReanalysisorEnsemble.Environment.atmospheric_model_end_date (
datetime) – Datetime object instance of last available date innetCDFandOPeNDAPfiles when usingForecast,ReanalysisorEnsemble.Environment.atmospheric_model_interval (
int) – Hour step between weather condition used innetCDFandOPeNDAPfiles when usingForecast,ReanalysisorEnsemble.Environment.atmospheric_model_init_lat (
float) – Latitude of vertex just before the launch site innetCDFandOPeNDAPfiles when usingForecast,ReanalysisorEnsemble.Environment.atmospheric_model_end_lat (
float) – Latitude of vertex just after the launch site innetCDFandOPeNDAPfiles when usingForecast,ReanalysisorEnsemble.Environment.atmospheric_model_init_lon (
float) – Longitude of vertex just before the launch site innetCDFandOPeNDAPfiles when usingForecast,ReanalysisorEnsemble.Environment.atmospheric_model_end_lon (
float) – Longitude of vertex just after the launch site innetCDFandOPeNDAPfiles when usingForecast,ReanalysisorEnsemble.Environment.lat_array (
array) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. Two-element list[x1, x2]containing the latitude coordinates of the grid-cell vertices that bracket the launch site and are used in bilinear interpolation.Environment.lon_array (
array) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. Two-element list[y1, y2]containing the longitude coordinates of the grid-cell vertices that bracket the launch site and are used in bilinear interpolation.Environment.lon_index (
int) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. Index to a grid longitude which is just over the launch site longitude, whilelon_index- 1 points to a grid longitude which is just under the launch site longitude.Environment.lat_index (
int) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. Index to a grid latitude which is just over the launch site latitude, whilelat_index- 1 points to a grid latitude which is just under the launch site latitude.Environment.geopotentials (
array) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. 2x2 matrix for each pressure level of geopotential heights corresponding to the vertices of the grid cell which surrounds the launch site.Environment.wind_us (
array) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. 2x2 matrix for each pressure level of wind U (east) component corresponding to the vertices of the grid cell which surrounds the launch site.Environment.wind_vs (
array) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. 2x2 matrix for each pressure level of wind V (north) component corresponding to the vertices of the grid cell which surrounds the launch site.Environment.levels (
array) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. List of pressure levels available in the file.Environment.temperatures (
array) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. 2x2 matrix for each pressure level of temperatures corresponding to the vertices of the grid cell which surrounds the launch site.Environment.time_array (
array) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. Two-element list with the first and last values from the dataset time variable in the dataset native units.Environment.height (
array) – Defined ifnetCDForOPeNDAPfile is used, for Forecasts, Reanalysis and Ensembles. List of geometric height corresponding to launch site location.Environment.level_ensemble (
array) – Only defined when using Ensembles.Environment.height_ensemble (
array) – Only defined when using Ensembles.Environment.temperature_ensemble (
array) – Only defined when using Ensembles.Environment.wind_u_ensemble (
array) – Only defined when using Ensembles.Environment.wind_v_ensemble (
array) – Only defined when using Ensembles.Environment.wind_heading_ensemble (
array) – Only defined when using Ensembles.Environment.wind_direction_ensemble (
array) – Only defined when using Ensembles.Environment.wind_speed_ensemble (
array) – Only defined when using Ensembles.Environment.num_ensemble_members (
int) – Number of ensemble members. Only defined when using Ensembles.Environment.ensemble_member (
int) – Current selected ensemble member. Only defined when using Ensembles.Environment.earth_rotation_vector (
list[float]) – Earth’s angular velocity vector in the Flight Coordinate System.
Notes
All the attributes listed as Function objects can be accessed as regular arrays, or called as a Function. See
rocketpy.Functionfor more information.- __init__(gravity=None, date=None, latitude=0.0, longitude=0.0, elevation=0.0, datum='SIRGAS2000', timezone='UTC', max_expected_height=80000.0)[source]#
Initializes the Environment class, capturing essential parameters of the launch site, including the launch date, geographical coordinates, and elevation. This class is designed to calculate crucial variables for the Flight simulation, such as atmospheric air pressure, density, and gravitational acceleration.
Note that the default atmospheric model is the International Standard Atmosphere as defined by ISO 2533 unless specified otherwise in
Environment.set_atmospheric_model().- Parameters:
gravity (
int,float,callable,string,array, optional) – Surface gravitational acceleration. Positive values point the acceleration down. If None, the Somigliana formula is used. SeeEnvironment.set_gravity_model()for more information.date (
listortuple, optional) –List or tuple of length 4, stating (year, month, day, hour) in the time zone of the parameter
timezone. Alternatively, can be adatetimeobject specifying launch date and time. The dates are stored as follows:Environment.local_date: Local time of launch in the time zone specified by the parametertimezone.Environment.datetime_date: UTC time of launch.
Must be given if a
windy,forecast,reanalysisorensembleatmospheric model will be used. Default is None. SeeEnvironment.set_date()for more information.latitude (
float, optional) – Latitude in degrees (ranging from -90 to 90) of rocket launch location. Must be given if awindy,forecast,reanalysisorensembleatmospheric model will be used or if Open-Elevation will be used to compute elevation. Positive values correspond to the North. Default value is 0, which corresponds to the equator.longitude (
float, optional) – Longitude in degrees (ranging from -180 to 180) of rocket launch location. Must be given if awindy,forecast,reanalysisorensembleatmospheric model will be used or if Open-Elevation will be used to compute elevation. Positive values correspond to the East. Default value is 0, which corresponds to the Greenwich Meridian.elevation (
float, optional) – Elevation of launch site measured as height above sea level in meters. Alternatively, can be set asOpen-Elevationwhich uses the Open-Elevation API to find elevation data. For this option, latitude and longitude must also be specified. Default value is 0.datum (
string, optional) – The desired reference ellipsoidal model, the following options are available: “SAD69”, “WGS84”, “NAD83”, and “SIRGAS2000”. The default is “SIRGAS2000”.timezone (
string, optional) – Name of the time zone. To see all time zones, import pytz and runprint(pytz.all_timezones). Default time zone is “UTC”.max_expected_height (
float, optional) – Maximum altitude in meters to keep weather data. The altitude must be above sea level (ASL). Especially useful for visualization. Can be altered as desired by runningmax_expected_height = number. Depending on the atmospheric model, this value may be automatically modified.
- Return type:
None
- set_date(date, timezone='UTC')[source]#
Set date and time of launch and update weather conditions if date dependent atmospheric model is used.
- Parameters:
date (
list,tuple,datetime) – List or tuple of length 4, stating (year, month, day, hour) in the time zone of the parametertimezone. See Notes for more information. Alternatively, can be adatetimeobject specifying launch date and time.timezone (
string, optional) – Name of the time zone. To see all time zones, import pytz and runprint(pytz.all_timezones). Default time zone is “UTC”.
- Return type:
None
Notes
If the
dateis given as a list or tuple, it should be in the same time zone as specified by thetimezoneparameter. This local time will be available in the attributeEnvironment.local_datewhile the UTC time will be available in the attributeEnvironment.datetime_date.If the
dateis given as adatetimeobject without a time zone, it will be assumed to be in the same time zone as specified by thetimezoneparameter. However, if thedatetimeobject has a time zone specified in itstzinfoattribute, thetimezoneparameter will be ignored.
Examples
Let’s set the launch date as an list:
>>> date = [2000, 1, 1, 13] # January 1st, 2000 at 13:00 UTC+1 >>> env = Environment() >>> env.set_date(date, timezone="Europe/Rome") >>> print(env.datetime_date) # Get UTC time 2000-01-01 12:00:00+00:00 >>> print(env.local_date) 2000-01-01 13:00:00+01:00
Now let’s set the launch date as a
datetimeobject:>>> from datetime import datetime >>> date = datetime(2000, 1, 1, 13, 0, 0) >>> env = Environment() >>> env.set_date(date, timezone="Europe/Rome") >>> print(env.datetime_date) # Get UTC time 2000-01-01 12:00:00+00:00 >>> print(env.local_date) 2000-01-01 13:00:00+01:00
- set_location(latitude, longitude)[source]#
Set latitude and longitude of launch and update atmospheric conditions if location dependent model is being used.
- Parameters:
latitude (
float) – Latitude of launch site. May range from -90 to 90 degrees.longitude (
float) – Longitude of launch site. Either from 0 to 360 degrees or from -180 to 180 degrees.
- Return type:
None
- set_gravity_model(gravity=None)[source]#
Defines the gravity model based on the given user input to the gravity parameter. The gravity model is responsible for computing the gravity acceleration at a given height above sea level in meters.
- Parameters:
gravity (
int,float,callable,string,list, optional) –The gravitational acceleration in m/s² to be used in the simulation, this value is positive when pointing downwards. The input type can be one of the following:
intorfloat: The gravity acceleration is set as a constant function with respect to height;callable: This callable should receive the height above sea level in meters and return the gravity acceleration;list: The datapoints should be structured as[(h_i,g_i), ...]whereh_iis the height above sea level in meters andg_iis the gravity acceleration in m/s²;string: The string should correspond to a path to a CSV file containing the gravity acceleration data;None: The Somigliana formula is used to compute the gravity acceleration.
This parameter is used as a
Functionobject source, check out the available input types for a more detailed explanation.- Returns:
Function object representing the gravity model.
- Return type:
Notes
This method does not set the gravity acceleration, it only returns a
Functionobject representing the gravity model.Examples
Let’s prepare a Environment object with a constant gravity acceleration:
>>> g_0 = 9.80665 >>> env_cte_g = Environment(gravity=g_0) >>> env_cte_g.gravity([0, 100, 1000]) [np.float64(9.80665), np.float64(9.80665), np.float64(9.80665)]
It’s also possible to variate the gravity acceleration by defining its function of height:
>>> R_t = 6371000 >>> g_func = lambda h : g_0 * (R_t / (R_t + h))**2 >>> env_var_g = Environment(gravity=g_func) >>> g = env_var_g.gravity(1000) >>> print(f"{g:.6f}") 9.803572
- somigliana_gravity#
Computes the gravity acceleration with the Somigliana formula [1]. An height correction is applied to the normal gravity that is accurate for heights used in aviation. The formula is based on the WGS84 ellipsoid, but is accurate for other reference ellipsoids.
- Parameters:
height (
float) – Height above the reference ellipsoid in meters.- Returns:
Function object representing the gravity model.
- Return type:
References
- set_elevation(elevation='Open-Elevation')[source]#
Set elevation of launch site given user input or using the Open-Elevation API.
- Parameters:
elevation (
float,string, optional) –Elevation of launch site measured as height above sea level in meters. Alternatively, can be set as
Open-Elevationwhich uses the Open-Elevation API to find elevation data. For this option, latitude and longitude must have already been specified.See also
- Return type:
None
- set_topographic_profile(type, file, dictionary='netCDF4', crs=None)[source]#
[UNDER CONSTRUCTION] Defines the Topographic profile, importing data from previous downloaded files. Mainly data from the Shuttle Radar Topography Mission (SRTM) and NASA Digital Elevation Model will be used but other models and methods can be implemented in the future. So far, this function can only handle data from NASADEM, available at: https://cmr.earthdata.nasa.gov/search/concepts/C1546314436-LPDAAC_ECS.html
- Parameters:
type (
string) – Defines the topographic model to be used, usually ‘NASADEM Merged DEM Global 1 arc second nc’ can be used. To download this kind of data, access ‘https://search.earthdata.nasa.gov/search’. NASADEM data products were derived from original telemetry data from the Shuttle Radar Topography Mission (SRTM).file (
string) – The path/name of the topographic file. Usually .nc provided bydictionary (
string, optional) – Dictionary which helps to read the specified file. By default ‘netCDF4’ which works well with .nc files will be used.crs (
string, optional) – Coordinate reference system, by default None, which will use the crs provided by the file.
- get_elevation_from_topographic_profile(lat, lon)[source]#
Function which receives as inputs the coordinates of a point and finds its elevation in the provided Topographic Profile.
- Parameters:
lat (
float) – latitude of the point.lon (
float) – longitude of the point.
- Returns:
elevation – Elevation provided by the topographic data, in meters.
- Return type:
float | int
- set_atmospheric_model(type, file=None, dictionary=None, pressure=None, temperature=None, wind_u=0, wind_v=0)[source]#
Define the atmospheric model for this Environment.
- Parameters:
type (
string) – Atmospheric model selector (case-insensitive). Accepted values are"standard_atmosphere","wyoming_sounding","windy","forecast","reanalysis","ensemble"and"custom_atmosphere".file (
string | netCDF4.Dataset, optional) –Data source or model shortcut. Meaning depends on
type:"standard_atmosphere"and"custom_atmosphere": ignored."wyoming_sounding": URL of the sounding text page."windy": one of"ECMWF","GFS","ICON"or"ICONEU"."forecast": local path, OPeNDAP URL, opennetCDF4.Dataset, or one of"GFS","NAM"or"RAP"for the latest available forecast."reanalysis": local path, OPeNDAP URL, or opennetCDF4.Dataset."ensemble": local path, OPeNDAP URL, opennetCDF4.Dataset, or"GEFS"for the latest available forecast.
dictionary (
dict | str, optional) –Variable-name mapping for
"forecast","reanalysis"and"ensemble". It may be a custom dictionary or a built-in mapping name (for example:"ECMWF","ECMWF_v0","NOAA","GFS","NAM","RAP","HIRESW","GEFS","MERRA2"or"CMC").If
dictionaryis omitted andfileis one of RocketPy’s latest-model shortcuts, the matching built-in mapping is selected automatically. For ensemble datasets, the mapping must include the ensemble dimension key (typically"ensemble").pressure (
float,string,array,callable, optional) – This defines the atmospheric pressure profile. Should be given if the type parameter iscustom_atmosphere. If not, than the theStandard Atmospherepressure will be used. If a float is given, it will define a constant pressure profile. The float should be in units of Pa. If a string is given, it should point to a .CSV file containing at most one header line and two columns of data. The first column must be the geometric height above sea level in meters while the second column must be the pressure in Pa. If an array is given, it is expected to be a list or array of coordinates (height in meters, pressure in Pa). Finally, a callable or function is also accepted. The function should take one argument, the height above sea level in meters and return a corresponding pressure in Pa.temperature (
float,string,array,callable, optional) – This defines the atmospheric temperature profile. Should be given if the type parameter iscustom_atmosphere. If not, than the theStandard Atmospheretemperature will be used. If a float is given, it will define a constant temperature profile. The float should be in units of K. If a string is given, it should point to a .CSV file containing at most one header line and two columns of data. The first column must be the geometric height above sea level in meters while the second column must be the temperature in K. If an array is given, it is expected to be a list or array of coordinates (height in meters, temperature in K). Finally, a callable or function is also accepted. The function should take one argument, the height above sea level in meters and return a corresponding temperature in K.wind_u (
float,string,array,callable, optional) – This defines the atmospheric wind-u profile, corresponding the magnitude of the wind speed heading East. Should be given if the type parameter iscustom_atmosphere. If not, it will be assumed to be constant and equal to 0. If a float is given, it will define a constant wind-u profile. The float should be in units of m/s. If a string is given, it should point to a .CSV file containing at most one header line and two columns of data. The first column must be the geometric height above sea level in meters while the second column must be the wind-u in m/s. If an array is given, it is expected to be an array of coordinates (height in meters, wind-u in m/s). Finally, a callable or function is also accepted. The function should take one argument, the height above sea level in meters and return a corresponding wind-u in m/s.wind_v (
float,string,array,callable, optional) – This defines the atmospheric wind-v profile, corresponding the magnitude of the wind speed heading North. Should be given if the type parameter iscustom_atmosphere. If not, it will be assumed to be constant and equal to 0. If a float is given, it will define a constant wind-v profile. The float should be in units of m/s. If a string is given, it should point to a .CSV file containing at most one header line and two columns of data. The first column must be the geometric height above sea level in meters while the second column must be the wind-v in m/s. If an array is given, it is expected to be an array of coordinates (height in meters, wind-v in m/s). Finally, a callable or function is also accepted. The function should take one argument, the height above sea level in meters and return a corresponding wind-v in m/s.
- Return type:
None- Raises:
ValueError – If
typeis unknown, if required launch date/time information is missing for date-dependent models, if Windy model names are invalid, or if required atmospheric variables cannot be read from the input dataset.TypeError – If
dictionaryis invalid for"forecast","reanalysis"or"ensemble".KeyError – If a built-in mapping name passed in
dictionaryis unknown.
See also
- Atmospheric Models
Overview of all atmospheric-model workflows in the user guide.
- Forecasts
Forecast and Windy usage details, including latest-model shortcuts.
- Reanalysis
Reanalysis and MERRA-2 examples.
- Soundings
Wyoming sounding workflow and RUC migration notes.
- Custom Atmosphere
Defining pressure, temperature and wind profiles directly.
- Ensemble
Ensemble forecasts and member-selection workflow.
- Connecting to other APIs
Building custom mapping dictionaries for NetCDF/OPeNDAP APIs.
- process_standard_atmosphere()[source]#
Sets pressure and temperature profiles corresponding to the International Standard Atmosphere defined by ISO 2533 and ranging from -2 km to 80 km of altitude above sea level. Note that the wind profiles are set to zero.
- Return type:
None
- process_custom_atmosphere(pressure=None, temperature=None, wind_u=0, wind_v=0)[source]#
Import pressure, temperature and wind profile given by user.
- Parameters:
pressure (
float,string,array,callable, optional) – This defines the atmospheric pressure profile. Should be given if the type parameter iscustom_atmosphere. If not, than the the Standard Atmosphere pressure will be used. If a float is given, it will define a constant pressure profile. The float should be in units of Pa. If a string is given, it should point to a .CSV file containing at most one header line and two columns of data. The first column must be the geometric height above sea level in meters while the second column must be the pressure in Pa. If an array is given, it is expected to be a list or array of coordinates (height in meters, pressure in Pa). Finally, a callable or function is also accepted. The function should take one argument, the height above sea level in meters and return a corresponding pressure in Pa.temperature (
float,string,array,callable, optional) – This defines the atmospheric temperature profile. Should be given if the type parameter iscustom_atmosphere. If not, than the the Standard Atmosphere temperature will be used. If a float is given, it will define a constant temperature profile. The float should be in units of K. If a string is given, it should point to a .CSV file containing at most one header line and two columns of data. The first column must be the geometric height above sea level in meters while the second column must be the temperature in K. If an array is given, it is expected to be a list or array of coordinates (height in meters, temperature in K). Finally, a callable or function is also accepted. The function should take one argument, the height above sea level in meters and return a corresponding temperature in K.wind_u (
float,string,array,callable, optional) – This defines the atmospheric wind-u profile, corresponding the the magnitude of the wind speed heading East. Should be given if the type parameter iscustom_atmosphere. If not, it will be assumed constant and 0. If a float is given, it will define a constant wind-u profile. The float should be in units of m/s. If a string is given, it should point to a .CSV file containing at most one header line and two columns of data. The first column must be the geometric height above sea level in meters while the second column must be the wind-u in m/s. If an array is given, it is expected to be an array of coordinates (height in meters, wind-u in m/s). Finally, a callable or function is also accepted. The function should take one argument, the height above sea level in meters and return a corresponding wind-u in m/s.wind_v (
float,string,array,callable, optional) – This defines the atmospheric wind-v profile, corresponding the the magnitude of the wind speed heading North. Should be given if the type parameter iscustom_atmosphere. If not, it will be assumed constant and 0. If a float is given, it will define a constant wind-v profile. The float should be in units of m/s. If a string is given, it should point to a .CSV file containing at most one header line and two columns of data. The first column must be the geometric height above sea level in meters while the second column must be the wind-v in m/s. If an array is given, it is expected to be an array of coordinates (height in meters, wind-v in m/s). Finally, a callable or function is also accepted. The function should take one argument, the height above sea level in meters and return a corresponding wind-v in m/s.
- Return type:
None
- process_windy_atmosphere(model='ECMWF')[source]#
Process data from Windy.com to retrieve atmospheric forecast data.
- Parameters:
model (
string, optional) – The atmospheric model to use. Default isECMWF. Options are:ECMWFfor the ECMWF-HRES model,GFSfor the GFS model,ICONfor the ICON-Global model orICONEUfor the ICON-EU model.- Raises:
ValueError – If
modelis not one ofECMWF,GFS,ICONorICONEU.
- process_wyoming_sounding(file)[source]#
Import and process the upper air sounding data from Wyoming Upper Air Soundings database given by the url in file. Sets pressure, temperature, wind-u, wind-v profiles and surface elevation.
- Parameters:
file (
string) –URL of an upper air sounding data output from Wyoming Upper Air Soundings database.
Example:
Notes
More can be found at: http://weather.uwyo.edu/upperair/sounding.html.
- Return type:
None
- process_forecast_reanalysis(file, dictionary)[source]#
Import and process atmospheric data from weather forecasts and reanalysis given as
netCDForOPeNDAPfiles. Sets pressure, temperature, wind-u and wind-v profiles and surface elevation obtained from a weather file innetCDFformat or from anOPeNDAPURL, both given through the file parameter. The date and location of the launch should already have been set through the date and location parameters when initializing the Environment. ThenetCDFandOPeNDAPdatasets must contain at least geopotential height or geopotential, temperature, wind-u and wind-v profiles as a function of pressure levels. If surface geopotential or geopotential height is given, elevation is also set. Otherwise, elevation is not changed. Profiles are interpolated bi-linearly using supplied latitude and longitude. The date used is the nearest one to the date supplied. Furthermore, a dictionary must be supplied through the dictionary parameter in order for the dataset to be accurately read. Lastly, the dataset must use a rectangular grid sorted in either ascending or descending order of latitude and longitude.- Parameters:
file (
string) – String containing path to localnetCDFfile or URL of anOPeNDAPfile, such as NOAA’s NOMAD or UCAR TRHEDDS server.dictionary (
dictionary) –Specifies the dictionary to be used when reading
netCDFandOPeNDAPfiles, allowing for the correct retrieval of data. The dictionary structure should specify the short names used for time, latitude, longitude, pressure levels, temperature profile, geopotential or geopotential height profile, wind-u and wind-v profiles in the dataset given in the file parameter. An example is the following dictionary, generally used to readOPeNDAPfiles from NOAA’s NOMAD server:dictionary = { "time": "time", "latitude": "lat", "longitude": "lon", "level": "lev", "temperature": "tmpprs", "surface_geopotential_height": "hgtsfc", "geopotential_height": "hgtprs", "geopotential": None, "u_wind": "ugrdprs", "v_wind": "vgrdprs", }
- Return type:
None- Raises:
ValueError – If launch date/time was not set before loading date-dependent data, or if required geopotential/geopotential-height, temperature, wind-u, or wind-v variables cannot be read from the dataset.
- process_ensemble(file, dictionary)[source]#
Import and process atmospheric data from weather ensembles given as
netCDForOPeNDAPfiles. Sets pressure, temperature, wind-u and wind-v profiles and surface elevation obtained from a weather ensemble file innetCDFformat or from anOPeNDAPURL, both given through the file parameter. The date and location of the launch should already have been set through the date and location parameters when initializing the Environment. ThenetCDFandOPeNDAPdatasets must contain at least geopotential height or geopotential, temperature, wind-u and wind-v profiles as a function of pressure levels. If surface geopotential or geopotential height is given, elevation is also set. Otherwise, elevation is not changed. Profiles are interpolated bi-linearly using supplied latitude and longitude. The date used is the nearest one to the date supplied. Furthermore, a dictionary must be supplied through the dictionary parameter in order for the dataset to be accurately read. Lastly, the dataset must use a rectangular grid sorted in either ascending or descending order of latitude and longitude. By default the first ensemble forecast is activated. To activate other ensemble forecasts seeEnvironment.select_ensemble_member().- Parameters:
file (
string) – String containing path to local.ncfile or URL of anOPeNDAPfile, such as NOAA’s NOMAD or UCAR TRHEDDS server.dictionary (
dictionary) –Specifies the dictionary to be used when reading
netCDFandOPeNDAPfiles, allowing for the correct retrieval of data. The dictionary structure should specify the short names used for time, latitude, longitude, pressure levels, temperature profile, geopotential or geopotential height profile, wind-u and wind-v profiles in the dataset given in the file parameter. An example is the following dictionary, generally used to readOPeNDAPfiles from NOAA’s NOMAD server:dictionary = { "time": "time", "latitude": "lat", "longitude": "lon", "level": "lev", "ensemble": "ens", "surface_geopotential_height": "hgtsfc", "geopotential_height": "hgtprs", "geopotential": None, "u_wind": "ugrdprs", "v_wind": "vgrdprs", }
See also
See,class- Raises:
ValueError – If launch date/time was not set before loading date-dependent data, or if required geopotential/geopotential-height, temperature, wind-u, or wind-v variables cannot be read from the dataset.
- select_ensemble_member(member=0)[source]#
Activates the specified ensemble member, ensuring all atmospheric variables read from the Environment instance correspond to the selected ensemble member.
- Parameters:
member (
int, optional) – The ensemble member to activate. Index starts from 0. Default is 0.- Raises:
ValueError – If the specified ensemble member index is out of range.
Notes
The first ensemble member (index 0) is activated by default when loading an ensemble model. This member typically represents a control member that is generated without perturbations. Other ensemble members are generated by perturbing the control member.
- pressure_ISA#
Pressure, in Pa, as a function of height above sea level as defined by the International Standard Atmosphere ISO 2533.
- barometric_height_ISA#
Returns the inverse function of the
pressure_ISAfunction.
- temperature_ISA#
Air temperature, in K, as a function of altitude as defined by the International Standard Atmosphere ISO 2533.
- calculate_density_profile()[source]#
Compute the density of the atmosphere as a function of height. This function is automatically called whenever a new atmospheric model is set.
Notes
- The density is calculated as:
- \[\rho = \frac{P}{RT}\]
Examples
Creating an Environment object and calculating the density at Sea Level:
>>> env = Environment() >>> env.calculate_density_profile() >>> float(env.density(0)) 1.225000018124288
Creating an Environment object and calculating the density at 1000m above Sea Level:
>>> env = Environment() >>> env.calculate_density_profile() >>> float(env.density(1000)) 1.1115112430077818
- calculate_speed_of_sound_profile()[source]#
Compute the speed of sound in the atmosphere as a function of height. This function is automatically called whenever a new atmospheric model is set.
Notes
- The speed of sound is calculated as:
- \[a = \sqrt{\gamma \cdot R \cdot T}\]
- calculate_dynamic_viscosity()[source]#
Compute the dynamic viscosity of the atmosphere as a function of height by using the formula given in ISO 2533. This function is automatically called whenever a new atmospheric model is set.
Notes
- The dynamic viscosity is calculated as:
- \[\mu = \frac{B \cdot T^{1.5}}{(T + S)}\]
where B and S are constants, and T is the temperature.
This equation is invalid for very high or very low temperatures.
Also invalid under conditions occurring at altitudes above 90 km.
- add_wind_gust(wind_gust_x, wind_gust_y)[source]#
Adds a function to the current stored wind profile, in order to simulate a wind gust.
- Parameters:
wind_gust_x (
float,callable) – Callable, function of altitude, which will be added to the x velocity of the current stored wind profile. If float is given, it will be considered as a constant function in altitude.wind_gust_y (
float,callable) – Callable, function of altitude, which will be added to the y velocity of the current stored wind profile. If float is given, it will be considered as a constant function in altitude.
- export_environment(filename='environment')[source]#
Export important attributes of Environment class to a
.jsonfile, saving the information needed to recreate the same environment using thecustom_atmospheremodel.- Parameters:
filename (
string) – The name of the file to be saved, without the extension.
- set_earth_geometry(datum)[source]#
Sets the Earth geometry for the
Environmentclass based on the provided datum.- Parameters:
datum (
str) – The datum to be used for the Earth geometry. The following options are supported: ‘SIRGAS2000’, ‘SAD69’, ‘NAD83’, ‘WGS84’.- Returns:
earth_geometry – The namedtuple containing the Earth geometry.
- Return type:
namedtuple
- static calculate_earth_radius(lat, semi_major_axis=6378137.0, flattening=0.0033528106647474805)[source]#
Function to calculate the Earth’s radius at a specific latitude based on ellipsoidal reference model. The Earth radius here is assumed as the distance between the ellipsoid’s center of gravity and a point on ellipsoid surface at the desired latitude.
- Parameters:
lat (
float) – latitude at which the Earth radius will be calculatedsemi_major_axis (
float) – The semi-major axis of the ellipsoid used to represent the Earth, must be given in meters (default is 6,378,137.0 m, which corresponds to the WGS84 ellipsoid)flattening (
float) – The flattening of the ellipsoid used to represent the Earth, usually between 1/250 and 1/150 (default is 1/298.257223563, which corresponds to the WGS84 ellipsoid)
- Returns:
radius – Earth radius at the desired latitude, in meters
- Return type:
float
Notes
The ellipsoid is an approximation for the Earth model and will result in an estimate of the perfect distance between Earth’s relief and its center of gravity.
- static decimal_degrees_to_arc_seconds(angle)[source]#
Function to convert an angle in decimal degrees to degrees, arc minutes and arc seconds.
- Parameters:
angle (
float) – The angle that you need convert. Must be given in decimal degrees.- Returns:
degrees (
int) – The degrees.arc_minutes (
int) – The arc minutes. 1 arc-minute = (1/60)*degreearc_seconds (
float) – The arc Seconds. 1 arc-second = (1/3600)*degree
Examples
Convert 45.5 degrees to degrees, arc minutes and arc seconds:
>>> from rocketpy import Environment >>> Environment.decimal_degrees_to_arc_seconds(45.5) (45, 30, 0.0)