23 from astropy
import units
24 from astropy.units
import cds
30 __all__ = [
"refraction",
"differentialRefraction"]
34 deltaRefractScale = 1.0E8
37 def refraction(wavelength, elevation, observatory, weather=None):
38 """Calculate overall refraction under atmospheric and observing conditions. 40 The calculation is taken from Stone 1996 41 "An Accurate Method for Computing Atmospheric Refraction" 45 wavelength is in nm (valid for 230.2 < wavelength < 2058.6) 46 elevation : `lsst.afw.geom.Angle` 47 Elevation of the observation, as an Angle. 48 observatory : `lsst.afw.coord.Observatory` 49 Class containing the longitude, latitude, 50 and altitude of the observatory. 51 weather : `lsst.afw.coord.Weather`, optional 52 Class containing the measured temperature, pressure, and humidity 53 at the observatory during an observation 54 If omitted, typical conditions for the observatory's elevation will be calculated. 59 The angular refraction for light of the given wavelength, 60 under the given observing conditions. 62 if wavelength < 230.2:
63 raise ValueError(
"Refraction calculation is valid for wavelengths between 230.2 and 2058.6 nm.")
64 if wavelength > 2058.6:
65 raise ValueError(
"Refraction calculation is valid for wavelengths between 230.2 and 2058.6 nm.")
66 latitude = observatory.getLatitude()
67 altitude = observatory.getElevation()
70 reducedN =
deltaN(wavelength, weather)/deltaRefractScale
72 atmosScaleheightRatio = 4.5908E-6*temperature.to_value(units.Kelvin)
76 relativeGravity = (1. + 0.005302*np.sin(latitude.asRadians())**2. -
77 0.00000583*np.sin(2.*latitude.asRadians())**2. - 0.000000315*altitude)
80 tanZ = np.tan(np.pi/2. - elevation.asRadians())
81 atmosTerm1 = reducedN*relativeGravity*(1. - atmosScaleheightRatio)
82 atmosTerm2 = reducedN*relativeGravity*(atmosScaleheightRatio - reducedN/2.)
83 result =
Angle(atmosTerm1*tanZ + atmosTerm2*tanZ**3.)
88 """Calculate the differential refraction between two wavelengths. 93 wavelength is in nm (valid for 230.2 < wavelength < 2058.6) 94 wavelengthRef : `float` 95 Reference wavelength, typically the effective wavelength of a filter. 96 elevation : `lsst.afw.geom.Angle` 97 Elevation of the observation, as an Angle. 98 observatory : `lsst.afw.coord.Observatory` 99 Class containing the longitude, latitude, 100 and altitude of the observatory. 101 weather : `lsst.afw.coord.Weather`, optional 102 Class containing the measured temperature, pressure, and humidity 103 at the observatory during an observation 104 If omitted, typical conditions for the observatory's elevation will be calculated. 108 `lsst.afw.geom.Angle` 109 The refraction at `wavelength` - the refraction at `wavelengthRef`. 111 refractionStart =
refraction(wavelength, elevation, observatory, weather=weather)
112 refractionEnd =
refraction(wavelengthRef, elevation, observatory, weather=weather)
113 return refractionStart - refractionEnd
117 """Calculate the differential refractive index of air. 119 The differential refractive index is the difference of 120 the refractive index from 1., multiplied by 1E8 to simplify 121 the notation and equations. Calculated as (n_air - 1)*10^8 123 This replicates equation 14 of Stone 1996 128 wavelength is in nanometers 129 weather : `lsst.afw.coord.Weather` 130 Class containing the measured temperature, pressure, and humidity 131 at the observatory during an observation 136 The difference of the refractive index of air from 1., 137 calculated as (n_air - 1)*10^8 139 waveNum = 1E3/wavelength
140 dryAirTerm = 2371.34 + (683939.7/(130. - waveNum**2.)) + (4547.3/(38.9 - waveNum**2.))
141 wetAirTerm = 6487.31 + 58.058*waveNum**2. - 0.71150*waveNum**4. + 0.08851*waveNum**6.
147 """Calculate dry air pressure term to refractive index calculation. 149 This replicates equation 15 of Stone 1996 153 weather : `lsst.afw.coord.Weather` 154 Class containing the measured temperature, pressure, and humidity 155 at the observatory during an observation 160 Returns the relative density of dry air 161 at the given pressure and temperature. 165 airPressure = weather.getAirPressure()*units.pascal
166 dryPressure = airPressure - waterVaporPressure
167 eqn = dryPressure.to_value(cds.mbar)*(57.90E-8 - 9.3250E-4/temperature.to_value(units.Kelvin) +
168 0.25844/temperature.to_value(units.Kelvin)**2.)
169 densityFactor = (1. + eqn)*dryPressure.to_value(cds.mbar)/temperature.to_value(units.Kelvin)
174 """Calculate water vapor pressure term to refractive index calculation. 176 This replicates equation 16 of Stone 1996 180 weather : `lsst.afw.coord.Weather` 181 Class containing the measured temperature, pressure, and humidity 182 at the observatory during an observation 187 Returns the relative density of water vapor 188 at the given pressure and temperature. 192 densityEqn1 = (-2.37321E-3 + 2.23366/temperature.to_value(units.Kelvin) -
193 710.792/temperature.to_value(units.Kelvin)**2. +
194 7.75141E-4/temperature.to_value(units.Kelvin)**3.)
195 densityEqn2 = waterVaporPressure.to_value(cds.mbar)*(1. + 3.7E-4*waterVaporPressure.to_value(cds.mbar))
196 relativeDensity = waterVaporPressure.to_value(cds.mbar)/temperature.to_value(units.Kelvin)
197 densityFactor = (1 + densityEqn2*densityEqn1)*relativeDensity
203 """Convert humidity and temperature to water vapor pressure. 205 This replicates equations 18 & 20 of Stone 1996 209 weather : `lsst.afw.coord.Weather` 210 Class containing the measured temperature, pressure, and humidity 211 at the observatory during an observation 215 `astropy.units.Quantity` 216 The water vapor pressure in Pascals 217 calculated from the given humidity and temperature. 219 humidity = weather.getHumidity()
220 x = np.log(humidity/100.0)
222 temperatureEqn1 = (temperature + 238.3*units.Celsius)*x + 17.2694*temperature
223 temperatureEqn2 = (temperature + 238.3*units.Celsius)*(17.2694 - x) - 17.2694*temperature
224 dewPoint = 238.3*temperatureEqn1/temperatureEqn2
225 waterVaporPressure = (4.50874 + 0.341724*dewPoint + 0.0106778*dewPoint**2 + 0.184889E-3*dewPoint**3 +
226 0.238294E-5*dewPoint**4 + 0.203447E-7*dewPoint**5)*133.32239*units.pascal
228 return waterVaporPressure
232 """Thin wrapper to return the measured temperature from an observation. 236 weather : `lsst.afw.coord.Weather` 237 Class containing the measured temperature, pressure, and humidity 238 at the observatory during an observation 239 useKelvin : bool, optional 240 Set to True to return the temperature in Kelvin instead of Celsius 241 This is needed because Astropy can't easily convert 242 between Kelvin and Celsius. 246 `astropy.units.Quantity` 247 The temperature in Celsius, unless `useKelvin` is set. 249 temperature = weather.getAirTemperature()*units.Celsius
251 temperature = temperature.to(units.Kelvin, equivalencies=units.temperature())
256 """Set default local weather conditions if they are missing. 260 weather : `lsst.afw.coord.Weather` 261 Class containing the measured temperature, pressure, and humidity 262 at the observatory during an observation 263 altitude : `astropy.units.Quantity` 264 The altitude of the observatory, in meters. 268 `lsst.afw.coord.Weather` 269 Updated Weather class with any `nan` values replaced by defaults. 271 if isinstance(altitude, units.quantity.Quantity):
274 altitude2 = altitude*units.meter
275 p0 = 101325.*units.pascal
276 g = 9.80665*units.meter/units.second**2
277 R0 = 8.31447*units.Joule/(units.mol*units.Kelvin)
278 T0 = 19.*units.Celsius
279 lapseRate = -6.5*units.Celsius/units.km
280 M = 0.0289644*units.kg/units.mol
282 temperature = T0 + lapseRate*altitude2
283 temperatureK = temperature.to(units.Kelvin, equivalencies=units.temperature())
284 pressure = p0*np.exp(-(g*M*altitude2)/(R0*temperatureK))
286 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)