Atmospheric properties (fluids.atmosphere)¶
This module contains models of earth’s atmosphere. Models are empirical and based on extensive research, primarily by NASA.
For reporting bugs, adding feature requests, or submitting pull requests, please use the GitHub issue tracker or contact the author at Caleb.Andrew.Bell@gmail.com.
Atmospheres¶
- class fluids.atmosphere.ATMOSPHERE_1976(Z, dT=0.0)[source]¶
US Standard Atmosphere 1976 class, which calculates T, P, rho, v_sonic, mu, k, and g as a function of altitude above sea level. Designed to provide reasonable results up to an elevation of 86,000 m (0.4 Pa). The model is also valid under sea level, to -610 meters.
- Parameters:
- Z
python:float
Elevation, [m]
- dT
python:float
,optional
Temperature difference from standard conditions used in determining the properties of the atmosphere, [K]
- Z
- Attributes:
- T
python:float
Temperature of atmosphere at specified conditions, [K]
- P
python:float
Pressure of atmosphere at specified conditions, [Pa]
- rho
python:float
Mass density of atmosphere at specified conditions [kg/m^3]
- H
python:float
Geopotential height, [m]
- g
python:float
Acceleration due to gravity, [m/s^2]
- mu
python:float
Viscosity of atmosphere at specified conditions, [Pa*s]
- k
python:float
Thermal conductivity of atmosphere at specified conditions, [W/m/K]
- v_sonic
python:float
Speed of sound of atmosphere at specified conditions, [m/s]
- T
Methods
density
(T, P)Method defined in the US Standard Atmosphere 1976 for calculating density of air as a function of T and P.
gravity
(Z)Method defined in the US Standard Atmosphere 1976 for calculating the gravitational acceleration above earth as a function of elevation only.
pressure_integral
(T1, P1, dH)Method to compute an integral of the pressure differential of an elevation difference with a base elevation defined by temperature T1 and pressure P1.
Method defined in the US Standard Atmosphere 1976 for calculating the speed of sound in air as a function of T only.
Method defined in the US Standard Atmosphere 1976 for calculating thermal conductivity of air as a function of T only.
viscosity
(T)Method defined in the US Standard Atmosphere 1976 for calculating viscosity of air as a function of T only.
Notes
Up to 32 km, the International Standard Atmosphere (ISA) and World Meteorological Organization (WMO) standard atmosphere are identical.
This is a revision of the US 1962 atmosphere.
References
[1]NOAA, NASA, and USAF. “U.S. Standard Atmosphere, 1976” October 15, 1976. http://ntrs.nasa.gov/search.jsp?R=19770009539.
[2]“ISO 2533:1975 - Standard Atmosphere.” ISO. http://www.iso.org/iso/catalogue_detail.htm?csnumber=7472.
[3]Yager, Robert J. “Calculating Atmospheric Conditions (Temperature, Pressure, Air Density, and Speed of Sound) Using C++,” June 2013. http://www.dtic.mil/cgi-bin/GetTRDoc?AD=ADA588839
Examples
>>> five_km = ATMOSPHERE_1976(5000) >>> five_km.P, five_km.rho, five_km.mu (54048.28614576141, 0.7364284207799743, 1.628248135362207e-05) >>> five_km.k, five_km.g, five_km.v_sonic (0.02273190295142526, 9.791241076982665, 320.5455196704035)
- static density(T, P)[source]¶
Method defined in the US Standard Atmosphere 1976 for calculating density of air as a function of T and P. MW is defined as 28.9644 g/mol, and R as 8314.32 J/kmol/K
\[\rho_g = \frac{P\cdot MW}{T\cdot R\cdot 1000}\]- Parameters:
- T
python:float
Temperature, [K]
- P
python:float
Pressure, [Pa]
- T
- Returns:
- rho
python:float
Mass density, [kg/m^3]
- rho
- static gravity(Z)[source]¶
Method defined in the US Standard Atmosphere 1976 for calculating the gravitational acceleration above earth as a function of elevation only.
\[g = g_0\left(\frac{r_0}{r_0+Z}\right)^2\]- Parameters:
- Z
python:float
Elevation above sea level, [m]
- Z
- Returns:
- g
python:float
Acceleration due to gravity, [m/s^2]
- g
- static pressure_integral(T1, P1, dH)[source]¶
Method to compute an integral of the pressure differential of an elevation difference with a base elevation defined by temperature T1 and pressure P1. This is similar to subtracting the pressures at two different elevations, except it allows for local conditions (temperature and pressure) to be taken into account. This is useful for e.x. evaluating the pressure difference between the top and bottom of a natural draft cooling tower.
- Parameters:
- T1
python:float
Temperature at the lower elevation condition, [K]
- P1
python:float
Pressure at the lower elevation condition, [Pa]
- dH
python:float
Elevation difference for which to evaluate the pressure difference, [m]
- T1
- Returns:
- delta_P
python:float
Pressure difference between the elevations, [Pa]
- delta_P
- static sonic_velocity(T)[source]¶
Method defined in the US Standard Atmosphere 1976 for calculating the speed of sound in air as a function of T only.
\[c = \left(\frac{\gamma R T}{MW}\right)^{0.5}\]- Parameters:
- T
python:float
Temperature, [K]
- T
- Returns:
- c
python:float
Speed of sound, [m/s]
- c
- static thermal_conductivity(T)[source]¶
Method defined in the US Standard Atmosphere 1976 for calculating thermal conductivity of air as a function of T only.
\[k_g = \frac{2.64638\times10^{-3}T^{1.5}} {T + 245.4\cdot 10^{-12./T}}\]- Parameters:
- T
python:float
Temperature, [K]
- T
- Returns:
- kg
python:float
Thermal conductivity, [W/m/K]
- kg
- class fluids.atmosphere.ATMOSPHERE_NRLMSISE00(Z, latitude=0.0, longitude=0.0, day=0, seconds=0.0, f107=150.0, f107_avg=150.0, geomagnetic_disturbance_indices=None)[source]¶
NRLMSISE 00 model for calculating temperature and density of gases in the atmosphere, from ground level to 1000 km, as a function of time of year, longitude and latitude, solar activity and earth’s geomagnetic disturbance.
NRLMSISE stands for the US Naval Research Laboratory Mass Spectrometer and Incoherent Scatter Radar Exosphere model, released in 2001; see [1] for details.
- Parameters:
- Z
python:float
Elevation, [m]
- latitude
python:float
,optional
Latitude, between -90 and 90 [degrees]
- longitude
python:float
,optional
Longitude, between -180 and 180 or 0 and 360, [degrees]
- day
python:float
,optional
Day of year, 0-366 [day]
- seconds
python:float
,optional
Seconds since start of day, in UT1 time; using UTC provides no loss in accuracy [s]
- f107
python:float
,optional
Daily average 10.7 cm solar flux measurement of the strength of solar emissions on the 100 MHz band centered on 2800 MHz, averaged hourly; in sfu units, which are multiples of 10^-22 W/m^2/Hz; use 150 as a default [10^-22 W/m^2/Hz]
- f107_avg
python:float
,optional
81-day sfu average; centered on specified day if possible, otherwise use the previous days [10^-22 W/m^2/Hz]
- geomagnetic_disturbance_indices
python:list
of
python:float
,optional
List of the 7 following Ap indexes also known as planetary magnetic indexes. Has a negligible effect on the calculation. 4 is the default value often used for each of these values, [-]
Average daily Ap.
3-hour average Ap centered on the current time.
3-hour average Ap before the current time.
6-hour average Ap before the current time.
9-hour average Ap before the current time.
Average Ap from 12 to 33 hours before the current time, based on eight 3-hour average Ap values.
Average Ap from 36 to 57 hours before the current time, based on eight 3-hour average Ap values.
- Z
- Attributes:
- rho
python:float
Mass density [kg/m^3]
- T
python:float
Temperature, [K]
- P
python:float
Pressure, calculated with ideal gas law [Pa]
- He_density
python:float
Density of helium atoms [count/m^3]
- O_density
python:float
Density of monatomic oxygen [count/m^3]
- N2_density
python:float
Density of nitrogen molecules [count/m^3]
- O2_density
python:float
Density of oxygen molecules [count/m^3]
- Ar_density
python:float
Density of Argon atoms [count/m^3]
- H_density
python:float
Density of hydrogen atoms [count/m^3]
- N_density
python:float
Density of monatomic nitrogen [count/m^3]
- O_anomalous_density
python:float
Density of anomalous oxygen; see [1] for details [count/m^3]
- particle_density
python:float
Total density of molecules [count/m^3]
- components
python:list
[python:str
] List of species making up the atmosphere [-]
- zs
python:list
[python:float
] Mole fractions of each molecule in the atmosphere, in order of components [-]
- rho
Notes
No full description has been published of this model; it has been defined by its implementation only. It was written in FORTRAN, and is accessible at ftp://hanna.ccmc.gsfc.nasa.gov/pub/modelweb/atmospheric/msis/nrlmsise00/
A C port of the model by Dominik Brodowskihas become popular, and is available on his website: http://www.brodo.de/space/nrlmsise/.
In 2013 Joshua Milas ported the C port to Python. This is an interface to his excellent port. It is a 1000-sloc model, and has been rigorously tested against the C version, and the online calculation tool available at [3] for parametric inputs of latitude, longitude, altitude, time of day and day of year.
This model is based on measurements other than gravity; it does not provide a calculation method for g. It does not provide transport properties.
This model takes on the order of ~2 ms.
References
[1] (1,2)Picone, J. M., A. E. Hedin, D. P. Drob, and A. C. Aikin. “NRLMSISE-00 Empirical Model of the Atmosphere: Statistical Comparisons and Scientific Issues.” Journal of Geophysical Research: Space Physics 107, no. A12 (December 1, 2002): 1468. doi:10.1029/2002JA009430.
[2]Tapping, K. F. “The 10.7 Cm Solar Radio Flux (F10.7).” Space Weather 11, no. 7 (July 1, 2013): 394-406. doi:10.1002/swe.20064.
[3]Natalia Papitashvili. “NRLMSISE-00 Atmosphere Model.” Accessed November 27, 2016. http://ccmc.gsfc.nasa.gov/modelweb/models/nrlmsise00.php.
Examples
>>> atmosphere = ATMOSPHERE_NRLMSISE00(1E3, 45, 45, 150) >>> atmosphere.T, atmosphere.rho (285.5440860623, 1.10190620264)
- fluids.atmosphere.airmass(func, angle, H_max=86400.0, R_planet=6371229.0, RI=1.000276)[source]¶
Calculates mass of air per square meter in the atmosphere using a provided atmospheric model. The lowest air mass is calculated straight up; as the angle is lowered to nearer and nearer the horizon, the air mass increases, and can approach 40x or more the minimum airmass.
\[m(\gamma) = \int_0^\infty \rho \left\{1 - \left[1 + 2(\text{RI}-1) (1-\rho/\rho_0)\right] \left[\frac{\cos \gamma}{(1+h/R)}\right]^2\right\}^{-1/2} dH\]- Parameters:
- func
python:float
Function which returns the density of the atmosphere as a function of elevation
- angle
python:float
Degrees above the horizon (90 = straight up), [degrees]
- H_max
python:float
,optional
Maximum height to compute the integration up to before the contribution of density becomes negligible, [m]
- R_planet
python:float
,optional
The radius of the planet for which the integration is being performed, [m]
- RI
python:float
,optional
The refractive index of the atmosphere (air on earth at 0.7 um as default) assumed a constant, [-]
- func
- Returns:
- m
python:float
Mass of air per square meter in the atmosphere, [kg/m^2]
- m
Notes
Numerical integration via SciPy’s quad is used to perform the calculation.
References
[1]Kasten, Fritz, and Andrew T. Young. “Revised Optical Air Mass Tables and Approximation Formula.” Applied Optics 28, no. 22 (November 15, 1989): 4735-38. https://doi.org/10.1364/AO.28.004735.
Examples
>>> airmass(lambda Z : ATMOSPHERE_1976(Z).rho, 90) 10356.12
Solar Radiation and Position¶
- fluids.atmosphere.solar_position(moment, latitude, longitude, Z=0.0, T=298.15, P=101325.0, atmos_refract=0.5667)[source]¶
Calculate the position of the sun in the sky. It is defined in terms of two angles - the zenith and the azimith. The azimuth tells where a sundial would see the sun as coming from; the zenith tells how high in the sky it is. The solar elevation angle is returned for convenience; it is the complimentary angle of the zenith.
The sun’s refraction changes how high it appears as though the sun is; so values are returned with an optional conversion to the apparent angle. This impacts only the zenith/elevation.
Uses the Reda and Andreas (2004) model described in [1], originally incorporated into the excellent pvlib library
- Parameters:
- moment
datetime
,optionally
with
pytz
info
Time and date for the calculation, in UTC time OR in the time zone of the latitude/longitude specified BUT WITH A TZINFO ATTACHED! Please be careful with this argument, time zones are confusing. [-]
- latitude
python:float
Latitude, between -90 and 90 [degrees]
- longitude
python:float
Longitude, between -180 and 180, [degrees]
- Z
python:float
,optional
Elevation above sea level for the solar position calculation, [m]
- T
python:float
,optional
Temperature of atmosphere at ground level, [K]
- P
python:float
,optional
Pressure of atmosphere at ground level, [Pa]
- atmos_refract
python:float
,optional
Atmospheric refractivity, [degrees]
- moment
- Returns:
- apparent_zenith
python:float
Zenith of the sun as observed from the ground based after accounting for atmospheric refraction, [degrees]
- zenith
python:float
Actual zenith of the sun (ignores atmospheric refraction), [degrees]
- apparent_altitude
python:float
Altitude of the sun as observed from the ground based after accounting for atmospheric refraction, [degrees]
- altitude
python:float
Actual altitude of the sun (ignores atmospheric refraction), [degrees]
- azimuth
python:float
The azimuth of the sun, [degrees]
- equation_of_time
python:float
Equation of time - the number of seconds to be added to the day’s mean solar time to obtain the apparent solar noon time, [seconds]
- apparent_zenith
Notes
If you were standing at the same longitude of the sun such that it was no further east or west than you were, the amount of angle it was south or north of you is the zenith. If it were directly overhead it would be 0°; a little north or south and it would be a little positive; near sunset or sunrise, near 90°; and at night, between 90° and 180°.
The solar altitude angle is defined as 90° -zenith. Note the elevation angle is just another name for the altitude angle.
The azimuth the angle in degrees that the sun is East of the North angle. It is positive North eastwards 0° to 360°. Other conventions may be used.
Note that due to differences in atmospheric refractivity, estimation of sunset and sunrise are accuract to no more than one minute. Refraction conditions truly vary across the atmosphere; so characterizing it by an average value is limiting as well.
References
[1]Reda, Ibrahim, and Afshin Andreas. “Solar Position Algorithm for Solar Radiation Applications.” Solar Energy 76, no. 5 (January 1, 2004): 577-89. https://doi.org/10.1016/j.solener.2003.12.003.
[2]“Navigation - What Azimuth Description Systems Are in Use? - Astronomy Stack Exchange.” https://astronomy.stackexchange.com/questions/237/what-azimuth-description-systems-are-in-use?rq=1.
Examples
>>> import pytz >>> from datetime import datetime, timedelta
Perth, Australia - sunrise
>>> solar_position(pytz.timezone('Australia/Perth').localize(datetime(2020, 6, 6, 7, 10, 57)), -31.95265, 115.85742) [90.89617025931, 90.89617025931, -0.896170259317, -0.896170259317, 63.6016017691, 79.0711232143]
Perth, Australia - Comparing against an online source https://www.suncalc.org/#/-31.9526,115.8574,9/2020.06.06/14:30/1/0
>>> solar_position(pytz.timezone('Australia/Perth').localize(datetime(2020, 6, 6, 14, 30, 0)), -31.95265, 115.85742) [63.4080568623, 63.4400018158, 26.59194313766, 26.55999818417, 325.121376246, 75.7467475485]
Perth, Australia - time input without timezone; must be converted by user to UTC!
>>> solar_position(datetime(2020, 6, 6, 14, 30, 0) - timedelta(hours=8), -31.95265, 115.85742) [63.4080568623, 63.4400018158, 26.59194313766, 26.55999818417, 325.121376246, 75.7467475485]
Sunrise occurs when the zenith is 90 degrees (Calgary, AB):
>>> local_time = datetime(2018, 4, 15, 6, 43, 5) >>> local_time = pytz.timezone('America/Edmonton').localize(local_time) >>> solar_position(local_time, 51.0486, -114.07)[0] 90.0005468548
Sunset occurs when the zenith is 90 degrees (13.5 hours later in this case):
>>> solar_position(pytz.timezone('America/Edmonton').localize(datetime(2018, 4, 15, 20, 30, 28)), 51.0486, -114.07) [89.999569566, 90.5410381216, 0.000430433876, -0.541038121618, 286.831378190, 6.63142952587]
- fluids.atmosphere.solar_irradiation(latitude, longitude, Z, moment, surface_tilt, surface_azimuth, T=None, P=None, solar_constant=1366.1, atmos_refract=0.5667, albedo=0.25, linke_turbidity=None, extraradiation_method='spencer', airmass_model='kastenyoung1989', cache=None)[source]¶
Calculates the amount of solar radiation and radiation reflected back the atmosphere which hits a surface at a specified tilt, and facing a specified azimuth.
This functions is a wrapper for the incredibly comprehensive pvlib library, and requires it to be installed.
- Parameters:
- latitude
python:float
Latitude, between -90 and 90 [degrees]
- longitude
python:float
Longitude, between -180 and 180, [degrees]
- Z
python:float
,optional
Elevation above sea level for the position, [m]
- moment
datetime
,optionally
with
pytz
info
Time and date for the calculation, in UTC time OR in the time zone of the latitude/longitude specified BUT WITH A TZINFO ATTACHED! Please be careful with this argument, time zones are confusing. [-]
- surface_tilt
python:float
The angle above the horizontal of the object being hit by radiation, [degrees]
- surface_azimuth
python:float
The angle the object is facing (positive, North eastwards 0° to 360°), [degrees]
- T
python:float
,optional
Temperature of atmosphere at ground level, [K]
- P
python:float
,optional
Pressure of atmosphere at ground level, [Pa]
- solar_constant
python:float
,optional
The amount of solar radiation which reaches earth’s disk (at a standardized distance of 1 AU); this constant is independent of activity or conditions on earth, but will vary throughout the sun’s lifetime and may increase or decrease slightly due to solar activity, [W/m^2]
- atmos_refract
python:float
,optional
Atmospheric refractivity at sunrise/sunset (0.5667 deg is an often used value; this varies substantially and has an impact of a few minutes on when sunrise and sunset is), [degrees]
- albedo
python:float
,optional
The average amount of reflection of the terrain surrounding the object at quite a distance; this impacts how much sunlight reflected off the ground, gets reflected back off clouds, [-]
- linke_turbidity
python:float
,optional
The amount of pollution/water in the sky versus a perfect clear sky; If not specified, this will be retrieved from a historical grid; typical values are 3 for cloudy, and 7 for severe pollution around a city, [-]
- extraradiation_method
python:str
,optional
The specified method to calculate the effect of earth’s position on the amount of radiation which reaches earth according to the methods available in the pvlib library, [-]
- airmass_model
python:str
,optional
The specified method to calculate the amount of air the sunlight needs to travel through to reach the earth according to the methods available in the pvlib library, [-]
- cache
python:dict
,optional
Dictionary to to check for values to use to skip some calculations; apparent_zenith, zenith, azimuth supported, [-]
- latitude
- Returns:
- poa_global
python:float
The total irradiance in the plane of the surface, [W/m^2]
- poa_direct
python:float
The total beam irradiance in the plane of the surface, [W/m^2]
- poa_diffuse
python:float
The total diffuse irradiance in the plane of the surface, [W/m^2]
- poa_sky_diffuse
python:float
The sky component of the diffuse irradiance, excluding the impact from the ground, [W/m^2]
- poa_ground_diffuse
python:float
The ground-sky diffuse irradiance component, [W/m^2]
- poa_global
Notes
The retrieval of linke_turbidity requires the pytables library (and Pandas); if it is not installed, specify a value of linke_turbidity to avoid the dependency.
There is some redundancy of the calculated results, according to the following relations. The total irradiance is normally that desired for engineering calculations.
poa_diffuse = poa_ground_diffuse + poa_sky_diffuse
poa_global = poa_direct + poa_diffuse
For a surface such as a pipe or vessel, an approach would be to split it into a number of rectangles and sum up the radiation absorbed by each.
This calculation is fairly slow.
References
[1]Will Holmgren, Calama-Consulting, Tony Lorenzo, Uwe Krien, bmu, DaCoEx, mayudong, et al. Pvlib/Pvlib-Python: 0.5.1. Zenodo, 2017. https://doi.org/10.5281/zenodo.1016425.
Examples
>>> import pytz >>> solar_irradiation(Z=1100.0, latitude=51.0486, longitude=-114.07, linke_turbidity=3, ... moment=pytz.timezone('America/Edmonton').localize(datetime(2018, 4, 15, 13, 43, 5)), surface_tilt=41.0, ... surface_azimuth=180.0) (1065.7621896280, 945.2656564506, 120.49653317744, 95.31535344213, 25.181179735317)
>>> cache = {'apparent_zenith': 41.099082295767545, 'zenith': 41.11285376417578, 'azimuth': 182.5631874250523} >>> solar_irradiation(Z=1100.0, latitude=51.0486, longitude=-114.07, ... moment=pytz.timezone('America/Edmonton').localize(datetime(2018, 4, 15, 13, 43, 5)), surface_tilt=41.0, ... linke_turbidity=3, T=300, P=1E5, ... surface_azimuth=180.0, cache=cache) (1042.567770367, 918.237754854, 124.3300155131, 99.622865737, 24.7071497753)
At night, there is no solar radiation and this function returns zeros:
>>> solar_irradiation(Z=1100.0, latitude=51.0486, longitude=-114.07, linke_turbidity=3, ... moment=pytz.timezone('America/Edmonton').localize(datetime(2018, 4, 15, 2, 43, 5)), surface_tilt=41.0, ... surface_azimuth=180.0) (0.0, -0.0, 0.0, 0.0, 0.0)
- fluids.atmosphere.sunrise_sunset(moment, latitude, longitude)[source]¶
Calculates the times at which the sun is at sunset; sunrise; and halfway between sunrise and sunset (transit).
Uses the Reda and Andreas (2004) model described in [1], originally incorporated into the excellent pvlib library
- Parameters:
- moment
datetime
Date for the calculation; needs to contain only the year, month, and day; if it is timezone-aware, the return values will be localized to this timezone [-]
- latitude
python:float
Latitude, between -90 and 90 [degrees]
- longitude
python:float
Longitude, between -180 and 180, [degrees]
- moment
- Returns:
- sunrise
datetime
The time at the specified day when the sun rises IN UTC IF MOMENT DOES NOT HAVE A TIMEZONE, OTHERWISE THE TIMEZONE GIVEN WITH IT, [-]
- sunset
datetime
The time at the specified day when the sun sets IN UTC IF MOMENT DOES NOT HAVE A TIMEZONE, OTHERWISE THE TIMEZONE GIVEN WITH IT, [-]
- transit
datetime
The time at the specified day when the sun is at solar noon - halfway between sunrise and sunset IN UTC IF MOMENT DOES NOT HAVE A TIMEZONE, OTHERWISE THE TIMEZONE GIVEN WITH IT, [-]
- sunrise
Notes
This functions takes on the order of 2 ms per calculation.
References
[1]Reda, Ibrahim, and Afshin Andreas. “Solar Position Algorithm for Solar Radiation Applications.” Solar Energy 76, no. 5 (January 1, 2004): 577-89. https://doi.org/10.1016/j.solener.2003.12.003.
Examples
>>> sunrise, sunset, transit = sunrise_sunset(datetime(2018, 4, 17), ... 51.0486, -114.07) >>> sunrise datetime.datetime(2018, 4, 17, 12, 36, 55, 782660) >>> sunset datetime.datetime(2018, 4, 18, 2, 34, 4, 249326) >>> transit datetime.datetime(2018, 4, 17, 19, 35, 46, 686265)
Example with time zone:
>>> import pytz >>> sunrise_sunset(pytz.timezone('America/Edmonton').localize(datetime(2018, 4, 17)), 51.0486, -114.07) (datetime.datetime(2018, 4, 16, 6, 39, 1, 570479, tzinfo=<DstTzInfo 'America/Edmonton' MDT-1 day, 18:00:00 DST>), datetime.datetime(2018, 4, 16, 20, 32, 25, 778162, tzinfo=<DstTzInfo 'America/Edmonton' MDT-1 day, 18:00:00 DST>), datetime.datetime(2018, 4, 16, 13, 36, 0, 386341, tzinfo=<DstTzInfo 'America/Edmonton' MDT-1 day, 18:00:00 DST>))
Note that the year/month/day as input with a timezone, is converted to UTC time as well.
- fluids.atmosphere.earthsun_distance(moment)[source]¶
Calculates the distance between the earth and the sun as a function of date and time. Uses the Reda and Andreas (2004) model described in [1], originally incorporated into the excellent pvlib library
- Parameters:
- moment
datetime
Time and date for the calculation, in UTC time (or GMT, which is almost the same thing); OR a timezone-aware datetime instance which will be internally converted to UTC, [-]
- moment
- Returns:
- distance
python:float
Distance between the center of the earth and the center of the sun, [m]
- distance
Notes
This function is quite accurate. The difference comes from the impact of the moon.
Note this function is not continuous; the sun-earth distance is not sufficiently accurately modeled for the change to be continuous throughout each day.
References
[1]Reda, Ibrahim, and Afshin Andreas. “Solar Position Algorithm for Solar Radiation Applications.” Solar Energy 76, no. 5 (January 1, 2004): 577-89. https://doi.org/10.1016/j.solener.2003.12.003.
Examples
>>> from datetime import datetime, timedelta >>> earthsun_distance(datetime(2003, 10, 17, 13, 30, 30)) 149090925951.18338
The distance at perihelion, which occurs at 4:21 according to this algorithm. The real value is 04:38 (January 2nd).
>>> earthsun_distance(datetime(2013, 1, 2, 4, 21, 50)) 147098089490.67123
The distance at aphelion, which occurs at 14:44 according to this algorithm. The real value is dead on - 14:44 (July 5).
>>> earthsun_distance(datetime(2013, 7, 5, 14, 44, 51, 0)) 152097354414.36044
Using a timezone-aware date:
>>> import pytz >>> earthsun_distance(pytz.timezone('America/Edmonton').localize(datetime(2020, 6, 6, 10, 0, 0, 0))) 151817805599.67142
This has a slightly different value than the value without a timezone; almost 5000 km further away!
>>> earthsun_distance(datetime(2020, 6, 6, 10, 0, 0, 0)) 151812898579.44104
Wind Models (requires Fortran compiler!)¶
- fluids.atmosphere.hwm93(Z, latitude=0, longitude=0, day=0, seconds=0, f107=150.0, f107_avg=150.0, geomagnetic_disturbance_index=4)[source]¶
Horizontal Wind Model 1993, for calculating wind velocity in the atmosphere as a function of time of year, longitude and latitude, solar activity and earth’s geomagnetic disturbance.
The model is described across the publications [1], [2], and [3].
- Parameters:
- Z
python:float
Elevation, [m]
- latitude
python:float
,optional
Latitude, between -90 and 90 [degrees]
- longitude
python:float
,optional
Longitude, between -180 and 180 or 0 and 360, [degrees]
- day
python:float
,optional
Day of year, 0-366 [day]
- seconds
python:float
,optional
Seconds since start of day, in UT1 time; using UTC provides no loss in accuracy [s]
- f107
python:float
,optional
Daily average 10.7 cm solar flux measurement of the strength of solar emissions on the 100 MHz band centered on 2800 MHz, averaged hourly; in sfu units, which are multiples of 10^-22 W/m^2/Hz; use 150 as a default [W/m^2/Hz]
- f107_avg
python:float
,optional
81-day sfu average; centered on specified day if possible, otherwise use the previous days [W/m^2/Hz]
- geomagnetic_disturbance_index
python:float
,optional
Average daily Ap or also known as planetary magnetic index.
- Z
- Returns:
- v_north
python:float
Wind velocity, meridional (Northward) [m/s]
- v_east
python:float
Wind velocity, zonal (Eastward) [m/s]
- v_north
Notes
No full description has been published of this model; it has been defined by its implementation only. It was written in FORTRAN, and is accessible at ftp://hanna.ccmc.gsfc.nasa.gov/pub/modelweb/atmospheric/hwm93/.
F2PY auto-compilation support is not yet currently supported. To compile this file, run the following command in a shell after navigating to $FLUIDSPATH/fluids/optional/. This should generate the file hwm93.so in that directory.
f2py -c hwm93.pyf hwm93.for --f77flags="-std=legacy"
If the module is not compiled, an import error will be raised.
References
[1]Hedin, A. E., N. W. Spencer, and T. L. Killeen. “Empirical Global Model of Upper Thermosphere Winds Based on Atmosphere and Dynamics Explorer Satellite Data.” Journal of Geophysical Research: Space Physics 93, no. A9 (September 1, 1988): 9959-78. doi:10.1029/JA093iA09p09959.
[2]Hedin, A. E., M. A. Biondi, R. G. Burnside, G. Hernandez, R. M. Johnson, T. L. Killeen, C. Mazaudier, et al. “Revised Global Model of Thermosphere Winds Using Satellite and Ground-Based Observations.” Journal of Geophysical Research: Space Physics 96, no. A5 (May 1, 1991): 7657-88. doi:10.1029/91JA00251.
[3]Hedin, A. E., E. L. Fleming, A. H. Manson, F. J. Schmidlin, S. K. Avery, R. R. Clark, S. J. Franke, et al. “Empirical Wind Model for the Upper, Middle and Lower Atmosphere.” Journal of Atmospheric and Terrestrial Physics 58, no. 13 (September 1996): 1421-47. doi:10.1016/0021-9169(95)00122-0.
Examples
>>> hwm93(5E5, 45, 50, 365) (-73.00312042236328, 0.1485661268234253)
- fluids.atmosphere.hwm14(Z, latitude=0, longitude=0, day=0, seconds=0, geomagnetic_disturbance_index=4)[source]¶
Horizontal Wind Model 2014, for calculating wind velocity in the atmosphere as a function of time of year, longitude and latitude, and earth’s geomagnetic disturbance. The model is described in [1].
The model no longer accounts for solar flux.
- Parameters:
- Z
python:float
Elevation, [m]
- latitude
python:float
,optional
Latitude, between -90 and 90 [degrees]
- longitude
python:float
,optional
Longitude, between -180 and 180 or 0 and 360, [degrees]
- day
python:float
,optional
Day of year, 0-366 [day]
- seconds
python:float
,optional
Seconds since start of day, in UT1 time; using UTC provides no loss in accuracy [s]
- geomagnetic_disturbance_index
python:float
,optional
Average daily Ap or also known as planetary magnetic index.
- Z
- Returns:
- v_north
python:float
Wind velocity, meridional (Northward) [m/s]
- v_east
python:float
Wind velocity, zonal (Eastward) [m/s]
- v_north
Notes
No full description has been published of this model; it has been defined by its implementation only. It was written in FORTRAN, and is accessible at http://onlinelibrary.wiley.com/store/10.1002/2014EA000089/asset/supinfo/ess224-sup-0002-supinfo.tgz?v=1&s=2a957ba70b7cf9dd0612d9430076297c3634ea75.
F2PY auto-compilation support is not yet currently supported. To compile this file, run the following commands in a shell after navigating to $FLUIDSPATH/fluids/optional/. This should generate the file hwm14.so in that directory.
Generate a .pyf signature file:
f2py -m hwm14 -h hwm14.pyf hwm14.f90
Compile the interface:
f2py -c hwm14.pyf hwm14.f90
If the module is not compiled, an import error will be raised.
No patches were necessary to either the generated pyf or hwm14.f90 file, as the authors of [1] have made it F2PY compatible.
Developed using 73 million data points taken by 44 instruments over 60 years.
References
[1] (1,2)Drob, Douglas P., John T. Emmert, John W. Meriwether, Jonathan J. Makela, Eelco Doornbos, Mark Conde, Gonzalo Hernandez, et al. “An Update to the Horizontal Wind Model (HWM): The Quiet Time Thermosphere.” Earth and Space Science 2, no. 7 (July 1, 2015): 2014EA000089. doi:10.1002/2014EA000089.
Examples
>>> hwm14(5E5, 45, 50, 365) (-38.64341354370117, 12.871272087097168)