1 from __future__
import absolute_import, division, print_function
24 from astropy
import units
25 from astropy.units
import cds
31 __all__ = [
"refraction",
"differentialRefraction"]
35 deltaRefractScale = 1.0E8
38 def refraction(wavelength, elevation, observatory, weather=None):
39 """Calculate overall refraction under atmospheric and observing conditions. 41 The calculation is taken from Stone 1996 42 "An Accurate Method for Computing Atmospheric Refraction" 46 wavelength is in nm (valid for 230.2 < wavelength < 2058.6) 47 elevation : `lsst.afw.geom.Angle` 48 Elevation of the observation, as an Angle. 49 observatory : `lsst.afw.coord.Observatory` 50 Class containing the longitude, latitude, 51 and altitude of the observatory. 52 weather : `lsst.afw.coord.Weather`, optional 53 Class containing the measured temperature, pressure, and humidity 54 at the observatory during an observation 55 If omitted, typical conditions for the observatory's elevation will be calculated. 60 The angular refraction for light of the given wavelength, 61 under the given observing conditions. 63 if wavelength < 230.2:
64 raise ValueError(
"Refraction calculation is valid for wavelengths between 230.2 and 2058.6 nm.")
65 if wavelength > 2058.6:
66 raise ValueError(
"Refraction calculation is valid for wavelengths between 230.2 and 2058.6 nm.")
67 latitude = observatory.getLatitude()
68 altitude = observatory.getElevation()
71 reducedN =
deltaN(wavelength, weather)/deltaRefractScale
73 atmosScaleheightRatio = 4.5908E-6*temperature/units.Kelvin
77 relativeGravity = (1. + 0.005302*np.sin(latitude.asRadians())**2. -
78 0.00000583*np.sin(2.*latitude.asRadians())**2. - 0.000000315*altitude)
81 tanZ = np.tan(np.pi/2. - elevation.asRadians())
82 atmosTerm1 = reducedN*relativeGravity*(1. - atmosScaleheightRatio)
83 atmosTerm2 = reducedN*relativeGravity*(atmosScaleheightRatio - reducedN/2.)
84 result =
Angle(atmosTerm1*tanZ + atmosTerm2*tanZ**3.)
89 """Calculate the differential refraction between two wavelengths. 94 wavelength is in nm (valid for 230.2 < wavelength < 2058.6) 95 wavelengthRef : `float` 96 Reference wavelength, typically the effective wavelength of a filter. 97 elevation : `lsst.afw.geom.Angle` 98 Elevation of the observation, as an Angle. 99 observatory : `lsst.afw.coord.Observatory` 100 Class containing the longitude, latitude, 101 and altitude of the observatory. 102 weather : `lsst.afw.coord.Weather`, optional 103 Class containing the measured temperature, pressure, and humidity 104 at the observatory during an observation 105 If omitted, typical conditions for the observatory's elevation will be calculated. 109 `lsst.afw.geom.Angle` 110 The refraction at `wavelength` - the refraction at `wavelengthRef`. 112 refractionStart =
refraction(wavelength, elevation, observatory, weather=weather)
113 refractionEnd =
refraction(wavelengthRef, elevation, observatory, weather=weather)
114 return refractionStart - refractionEnd
118 """Calculate the differential refractive index of air. 120 The differential refractive index is the difference of 121 the refractive index from 1., multiplied by 1E8 to simplify 122 the notation and equations. Calculated as (n_air - 1)*10^8 124 This replicates equation 14 of Stone 1996 129 wavelength is in nanometers 130 weather : `lsst.afw.coord.Weather` 131 Class containing the measured temperature, pressure, and humidity 132 at the observatory during an observation 137 The difference of the refractive index of air from 1., 138 calculated as (n_air - 1)*10^8 140 waveNum = 1E3/wavelength
141 dryAirTerm = 2371.34 + (683939.7/(130. - waveNum**2.)) + (4547.3/(38.9 - waveNum**2.))
142 wetAirTerm = 6487.31 + 58.058*waveNum**2. - 0.71150*waveNum**4. + 0.08851*waveNum**6.
148 """Calculate dry air pressure term to refractive index calculation. 150 This replicates equation 15 of Stone 1996 154 weather : `lsst.afw.coord.Weather` 155 Class containing the measured temperature, pressure, and humidity 156 at the observatory during an observation 161 Returns the relative density of dry air 162 at the given pressure and temperature. 166 airPressure = weather.getAirPressure()*units.pascal
167 dryPressure = airPressure - waterVaporPressure
168 eqn = (dryPressure/cds.mbar)*(57.90E-8 - 9.3250E-4*units.Kelvin/temperature +
169 0.25844*units.Kelvin**2/temperature**2.)
170 densityFactor = (1. + eqn)*(dryPressure/cds.mbar)/(temperature/units.Kelvin)
175 """Calculate water vapor pressure term to refractive index calculation. 177 This replicates equation 16 of Stone 1996 181 weather : `lsst.afw.coord.Weather` 182 Class containing the measured temperature, pressure, and humidity 183 at the observatory during an observation 188 Returns the relative density of water vapor 189 at the given pressure and temperature. 193 densityEqn1 = (-2.37321E-3 + 2.23366*units.Kelvin/temperature -
194 710.792*units.Kelvin**2/temperature**2. +
195 7.75141E-4*units.Kelvin**3/temperature**3.)
196 densityEqn2 = (waterVaporPressure/cds.mbar)*(1. + 3.7E-4*waterVaporPressure/cds.mbar)
197 relativeDensity = waterVaporPressure*units.Kelvin/(temperature*cds.mbar)
198 densityFactor = (1 + densityEqn2*densityEqn1)*relativeDensity
204 """Convert humidity and temperature to water vapor pressure. 206 This replicates equations 18 & 20 of Stone 1996 210 weather : `lsst.afw.coord.Weather` 211 Class containing the measured temperature, pressure, and humidity 212 at the observatory during an observation 217 The water vapor pressure in millibar 218 calculated from the given humidity and temperature. 220 humidity = weather.getHumidity()
221 x = np.log(humidity/100.0)
223 temperatureEqn1 = (temperature + 238.3*units.Celsius)*x + 17.2694*temperature
224 temperatureEqn2 = (temperature + 238.3*units.Celsius)*(17.2694 - x) - 17.2694*temperature
225 dewPoint = 238.3*temperatureEqn1/temperatureEqn2
226 waterVaporPressure = (4.50874 + 0.341724*dewPoint + 0.0106778*dewPoint**2 + 0.184889E-3*dewPoint**3 +
227 0.238294E-5*dewPoint**4 + 0.203447E-7*dewPoint**5)*133.32239*units.pascal
229 return waterVaporPressure
233 """Thin wrapper to return the measured temperature from an observation. 237 weather : `lsst.afw.coord.Weather` 238 Class containing the measured temperature, pressure, and humidity 239 at the observatory during an observation 240 useKelvin : bool, optional 241 Set to True to return the temperature in Kelvin instead of Celsius 242 This is needed because Astropy can't easily convert 243 between Kelvin and Celsius. 247 `astropy.units.quantity.Quantity` 248 The temperature in Celsius, unless `useKelvin` is set. 250 temperature = weather.getAirTemperature()*units.Celsius
252 temperature = temperature.to(units.Kelvin, equivalencies=units.temperature())
257 """Set default local weather conditions if they are missing. 261 weather : `lsst.afw.coord.Weather` 262 Class containing the measured temperature, pressure, and humidity 263 at the observatory during an observation 264 altitude : `astropy.units.quantity.Quantity` 265 The altitude of the observatory, in meters. 269 `lsst.afw.coord.Weather` 270 Updated Weather class with any `nan` values replaced by defaults. 272 if isinstance(altitude, units.quantity.Quantity):
275 altitude2 = altitude*units.meter
276 p0 = 101325.*units.pascal
277 g = 9.80665*units.meter/units.second**2
278 R0 = 8.31447*units.Joule/(units.mol*units.Kelvin)
279 T0 = 19.*units.Celsius
280 lapseRate = -6.5*units.Celsius/units.km
281 M = 0.0289644*units.kg/units.mol
283 temperature = T0 + lapseRate*altitude2
284 temperatureK = temperature.to(units.Kelvin, equivalencies=units.temperature())
285 pressure = p0*np.exp(-(g*M*altitude2)/(R0*temperatureK))
287 weather =
Weather((temperature/units.Celsius).value, (pressure/units.pascal).value, humidity)
def densityFactorWater(weather)
def humidityToPressure(weather)
def defaultWeather(altitude)
def refraction(wavelength, elevation, observatory, weather=None)
def densityFactorDry(weather)
A class representing an angle.
Basic weather information sufficient for a simple model for air mass or refraction.
def differentialRefraction(wavelength, wavelengthRef, elevation, observatory, weather=None)
def deltaN(wavelength, weather)
def extractTemperature(weather, useKelvin=False)