From 502183889bb2307947798d062e761e1b44ea428c Mon Sep 17 00:00:00 2001 From: yosata Date: Mon, 3 Aug 2020 11:07:42 +0200 Subject: [PATCH] Refactored some variable names and updated descriptions --- AstroAtmosphere/dispersionModels.py | 88 +++++++++++++++------------- AstroAtmosphere/examples.py | 18 +++--- AstroAtmosphere/refractionModels.py | 90 +++++++++++++++-------------- setup.py | 4 +- 4 files changed, 107 insertions(+), 93 deletions(-) diff --git a/AstroAtmosphere/dispersionModels.py b/AstroAtmosphere/dispersionModels.py index 7976329..d61665a 100644 --- a/AstroAtmosphere/dispersionModels.py +++ b/AstroAtmosphere/dispersionModels.py @@ -39,39 +39,45 @@ class dispersion(Observatory): Methods ------- - setReducedHeight(p, rho) - Sets the reduced atmospheric height. - planeParallel(n1, n2, zenith) - Returns the atmospheric dispersion assuming a plane parallel - atmosphere cassini(n1, n2, zenith, reduced_height=None) - Returns the atmospheric dispersion asusming Cassini's homegeneous - atmosphere model - tan5(n1, n2, zenith, reduced_height=None) - Returns the atmospheric dispersion following Oriani's theorem, - including a fifth order term in the expansion. - oriani(n1, n2, zenith, reduced_height=None) - Returns the atmospheric dispersion following the classic version - of Oriani's theorem. - corbard(n1, n2, zenith, reduced_height=None) - Returns the atmospheric dispersion following the method described - in Corbard et al., 2019. - refractionIntegral(n1, n2, z0, R0=None, useStandardAtmosphere=True, heightData=None, rhoData=None) - Returns the atmospheric dispersion following the refraction integral. - psi(x) - Submethod for corbard() - set_rc() - Sets the local radius of curvature of the Earth at the observer. - set_H(p, rho) - Sets the reduced height for the conditions at the observer, assuming - an adiabatic atmosphere. - H_isotherm(T) - Sets the reduced height for the conditions at the observer, assuming - an isothermal atmosphere. + Returns the atmospheric dispersion assuming Cassini's homegeneous + atmosphere model. cassiniError(z, l1, l2, T, p, RH, xc, dl1=0, dl2=0, dT=0.2, dP=20, dRH=0.02, dCO2=20, dz=0, lat=None, h=None) Returns the uncertainty in the atmospheric dispersion, assuming - Cassini's homegeneous atmosphere model and the given parameters. + Cassini's homegeneous atmosphere model and the given parameters. + corbard(n1, n2, zenith, reduced_height=None) + Returns the atmospheric dispersion following the method described + in Corbard et al., 2019. + gammaCoefficients(n1, reduced_height=None) + Helper function for matharExponential(), that calculates the gamma + coefficients. + H_isotherm(T) + Sets the reduced height for the conditions at the observer, assuming + an isothermal atmosphere. + matharExponential(n1, n2, zenith, reduced_height=None) + Returns the atmospheric dispersion assuming Mathar's barometric + exponential model. + oriani(n1, n2, zenith, reduced_height=None) + Returns the atmospheric dispersion following the classic version + of Oriani's theorem. + planeParallel(n1, n2, zenith) + Returns the atmospheric dispersion assuming a plane parallel + atmosphere. + psi(x) + Submethod for corbard(). + refractionIntegral(n1, n2, zenith, R0=None, useStandardAtmosphere=True, heightData=None, rhoData=None) + Returns the atmospheric dispersion following the refraction integral. + setReducedHeight(p, rho) + Sets the reduced atmospheric height. + set_H(p, rho) + Sets the reduced height for the conditions at the observer, assuming + an adiabatic atmosphere. + set_rc() + Sets the local radius of curvature of the Earth at the observer. + tan5(n1, n2, zenith, reduced_height=None) + Returns the atmospheric dispersion following Oriani's theorem, + including a fifth order term in the expansion. Other Observatory() methods ''' def __init__(self, lat, h): @@ -113,7 +119,7 @@ class dispersion(Observatory): return np.degrees(_R1) - np.degrees(_R2) - def cassiniError(self, z, l1, l2, T, p, RH, xc, dl1=0, dl2=0, dT=0.2, dP=20, + def cassiniError(self, zenith, l1, l2, T, p, RH, xc, dl1=0, dl2=0, dT=0.2, dP=20, dRH=0.02, dCO2=20, dz=0, lat=None, h=None): ''' Calculates the uncertainty in the atmospheric dispersion, @@ -128,7 +134,7 @@ class dispersion(Observatory): Parameters ---------- - z : float + zenith : float Angle of observation in degrees. zenith = 0 means the observation is directly overhead. l1 : float @@ -222,7 +228,7 @@ class dispersion(Observatory): _rho_obs = self.rho(p, T, RH, xc) self.rc = self.set_rc() * 1000 self.H = self.set_H(p, _rho_obs) - _alpha = self.rc * np.sin(np.deg2rad(z)) / (self.rc + self.H) + _alpha = self.rc * np.sin(np.deg2rad(zenith)) / (self.rc + self.H) _p_a = p - RH*self.svp(T) _p_w = RH*self.svp(T) _x_w_a = self.xw(_p_a, T, _RH_a) @@ -369,7 +375,7 @@ class dispersion(Observatory): # Partial derivatives for derivation to z - _zenith = np.deg2rad(z) + _zenith = np.deg2rad(zenith) _dz = np.deg2rad(dz) _R = self.rc _H = self.H @@ -420,14 +426,14 @@ class dispersion(Observatory): return _rList[0] - _rList[1] - def gammaCoefficients(self, n0, reduced_height=None): + def gammaCoefficients(self, n1, reduced_height=None): ''' Submethod for matharExponential(). Calculates the gamma coefficients. Parameters ---------- - n0 : float + n1 : float Refractive index at the wavelength of interest at the observer reduced_height : float (optional) Reduced height of the atmosphere. Default value is calculated @@ -444,7 +450,7 @@ class dispersion(Observatory): else: H = self.H - _chi0 = n0**2 - 1 + _chi0 = n1**2 - 1 _Khat = H / self.rc _g1 = (1 - 5/24 * _Khat * _chi0**2 - 3/4 * _chi0 - 3/8 * _Khat**2 * _chi0 \ @@ -483,7 +489,7 @@ class dispersion(Observatory): * _chi0**2 - 180 * _Khat**3 * _chi0 - 9/5 * _Khat * _chi0**4) * 35/128 g = np.array([_g1, _g3, _g5, _g7, _g9]) - g*= n0*_chi0/2 + g*= n1*_chi0/2 return g @@ -659,7 +665,7 @@ class dispersion(Observatory): return np.exp(x**2) * _int[0] - def refractionIntegral(self, n1, n2, z0, R0=None, useStandardAtmosphere=True, + def refractionIntegral(self, n1, n2, zenith, R0=None, useStandardAtmosphere=True, heightData=None, rhoData=None): ''' Using data that gives temperature, pressure and density as a @@ -678,7 +684,7 @@ class dispersion(Observatory): Refractive index at the shortest wavelength of interest n2 : float Refractive index at the longest wavelength of interest - z0 : float + zenith : float Angle of observation in degrees. zenith = 0 means the observation is directly overhead. R0 : float (optional) @@ -711,7 +717,7 @@ class dispersion(Observatory): _rList = [] - z0 = np.deg2rad(z0) + zenith = np.deg2rad(zenith) # Integration of the refraction integral over the atmosphere layers. for _n in [n1, n2]: @@ -723,7 +729,7 @@ class dispersion(Observatory): _n_h = 1 + (_n - 1) / _Dens[0] * _Dens # Calculation of the zenith angle for given height and refractive index, from the refractive invariant - _z = np.arcsin( (_n * R0) / (_n_h * _R) * np.sin(z0) ) + _z = np.arcsin( (_n * R0) / (_n_h * _R) * np.sin(zenith) ) # Calculation of log space derivative of n and r _lnn = np.log(_n_h) diff --git a/AstroAtmosphere/examples.py b/AstroAtmosphere/examples.py index 0b488d4..d13257a 100644 --- a/AstroAtmosphere/examples.py +++ b/AstroAtmosphere/examples.py @@ -68,7 +68,7 @@ def quick_refractive_index(l, conditions='STANDARD', T=288.15, p=101325, return n -def quick_refraction(l, z, conditions='STANDARD', T=288.15, p=101325, +def quick_refraction(l, zenith, conditions='STANDARD', T=288.15, p=101325, H=0.0, xc=450, lat=0, h=0): ''' Function to quickly calculate the refraction @@ -79,8 +79,9 @@ def quick_refraction(l, z, conditions='STANDARD', T=288.15, p=101325, ---------- l : float Wavelength in microns - z : float - Zenith angle of the observation + zenith : float + Angle of observation in degrees. + zenith = 0 means the observation is directly overhead. conditions : string 'STANDARD' or 'CERRO_ARMAZONES', refers to the standard atmospheric conditions. @@ -132,10 +133,10 @@ def quick_refraction(l, z, conditions='STANDARD', T=288.15, p=101325, # Initializing refraction model and setting the reduced height ref = refraction(lat, h) ref.setReducedHeight(p, rho) - return ref.cassini(n, z) + return ref.cassini(n, zenith) -def quick_dispersion(l1, l2, z, conditions='STANDARD', T=288.15, +def quick_dispersion(l1, l2, zenith, conditions='STANDARD', T=288.15, p=101325, H=0.0, xc=450, lat=0, h=0): ''' Function to quickly calculate the dispersion @@ -148,8 +149,9 @@ def quick_dispersion(l1, l2, z, conditions='STANDARD', T=288.15, Shortest wavelength of interest in micron. l2 : float Longest wavelength of interest in micron. - z : float - Zenith angle of the observation + zenith : float + Angle of observation in degrees. + zenith = 0 means the observation is directly overhead. conditions : string 'STANDARD' or 'CERRO_ARMAZONES', refers to the standard atmospheric conditions. @@ -202,4 +204,4 @@ def quick_dispersion(l1, l2, z, conditions='STANDARD', T=288.15, # Initializing refraction model and setting the reduced height disp = dispersion(lat, h) disp.setReducedHeight(p, rho) - return disp.cassini(n1, n2, z) \ No newline at end of file + return disp.cassini(n1, n2, zenith) \ No newline at end of file diff --git a/AstroAtmosphere/refractionModels.py b/AstroAtmosphere/refractionModels.py index 61a72a1..d07a7b5 100644 --- a/AstroAtmosphere/refractionModels.py +++ b/AstroAtmosphere/refractionModels.py @@ -38,39 +38,45 @@ class refraction(Observatory): Methods ------- - setReducedHeight(p, rho) - Sets the reduced atmospheric height. - planeParallel(n1, n2, zenith) - Returns the atmospheric refraction assuming a plane parallel - atmosphere cassini(n1, n2, zenith, reduced_height=None) - Returns the atmospheric refraction asusming Cassini's homegeneous - atmosphere model - tan5(n1, n2, zenith, reduced_height=None) - Returns the atmospheric refraction following Oriani's theorem, - including a fifth order term in the expansion. - oriani(n1, n2, zenith, reduced_height=None) - Returns the atmospheric refraction following the classic version - of Oriani's theorem. - corbard(n1, n2, zenith, reduced_height=None) - Returns the atmospheric refraction following the method described - in Corbard et al., 2019. - refractionIntegral(n1, n2, z0, R0=None, useStandardAtmosphere=True, heightData=None, rhoData=None) - Returns the atmospheric refraction following the refraction integral. - psi(x) - Submethod for corbard() - set_rc() - Sets the local radius of curvature of the Earth at the observer. - set_H(p, rho) - Sets the reduced height for the conditions at the observer, assuming - an adiabatic atmosphere. - H_isotherm(T) - Sets the reduced height for the conditions at the observer, assuming - an isothermal atmosphere. + Returns the atmospheric refraction assuming Cassini's homegeneous + atmosphere model. cassiniError(z, l1, l2, T, p, RH, xc, dl1=0, dl2=0, dT=0.2, dP=20, dRH=0.02, dCO2=20, dz=0, lat=None, h=None) Returns the uncertainty in the atmospheric refraction, assuming - Cassini's homegeneous atmosphere model and the given parameters. + Cassini's homegeneous atmosphere model and the given parameters. + corbard(n1, n2, zenith, reduced_height=None) + Returns the atmospheric refraction following the method described + in Corbard et al., 2019. + gammaCoefficients(n1, reduced_height=None) + Helper function for matharExponential(), that calculates the gamma + coefficients. + H_isotherm(T) + Sets the reduced height for the conditions at the observer, assuming + an isothermal atmosphere. + matharExponential(n1, zenith, reduced_height=None) + Returns the atmospheric refraction assuming Mathar's barometric + exponential model. + oriani(n1, n2, zenith, reduced_height=None) + Returns the atmospheric refraction following the classic version + of Oriani's theorem. + planeParallel(n1, n2, zenith) + Returns the atmospheric refraction assuming a plane parallel + atmosphere. + psi(x) + Submethod for corbard(). + refractionIntegral(n1, n2, zenith, R0=None, useStandardAtmosphere=True, heightData=None, rhoData=None) + Returns the atmospheric refraction following the refraction integral. + setReducedHeight(p, rho) + Sets the reduced atmospheric height. + set_H(p, rho) + Sets the reduced height for the conditions at the observer, assuming + an adiabatic atmosphere. + set_rc() + Sets the local radius of curvature of the Earth at the observer. + tan5(n1, n2, zenith, reduced_height=None) + Returns the atmospheric refraction following Oriani's theorem, + including a fifth order term in the expansion. Other Observatory() methods ''' def __init__(self, lat, h): @@ -141,13 +147,13 @@ class refraction(Observatory): else: _H = self.H _zenith = np.deg2rad(zenith) - _dz = np.deg2rad(dz) - _R = self.rc - _dRdn = (_R * np.sin(_zenith)) / ((_R + _H) * np.sqrt(1 - ((n**2 * _R**2 * np.sin(_zenith)**2)/(_R + _H)**2))) + _dz = np.deg2rad(dz) + _R = self.rc + _dRdn = (_R * np.sin(_zenith)) / ((_R + _H) * np.sqrt(1 - ((n**2 * _R**2 * np.sin(_zenith)**2)/(_R + _H)**2))) - _dRdz = (_R * np.cos(_zenith)) / (_R + _H) * ( n / np.sqrt(1-(n**2 * _R**2 * np.sin(_zenith)**2)/(_R + _H)**2) - 1 / np.sqrt(1-(_R**2 * np.sin(_zenith)**2)/(_R + _H)**2) ) + _dRdz = (_R * np.cos(_zenith)) / (_R + _H) * ( n / np.sqrt(1-(n**2 * _R**2 * np.sin(_zenith)**2)/(_R + _H)**2) - 1 / np.sqrt(1-(_R**2 * np.sin(_zenith)**2)/(_R + _H)**2) ) - _dR = np.sqrt( (_dRdn * dn)**2 + (_dRdz * _dz)**2) + _dR = np.sqrt( (_dRdn * dn)**2 + (_dRdz * _dz)**2) return np.degrees(_dR) @@ -185,14 +191,14 @@ class refraction(Observatory): return np.degrees(_R) - def gammaCoefficients(self, n0, reduced_height=None): + def gammaCoefficients(self, n1, reduced_height=None): ''' Submethod for matharExponential(). Calculates the gamma coefficients. Parameters ---------- - n0 : float + n1 : float Refractive index at the wavelength of interest at the observer reduced_height : float (optional) Reduced height of the atmosphere. Default value is calculated @@ -210,7 +216,7 @@ class refraction(Observatory): else: H = self.H - _chi0 = n0**2 - 1 + _chi0 = n1**2 - 1 _Khat = H / self.rc _g1 = (1 - 5/24 * _Khat * _chi0**2 - 3/4 * _chi0 - 3/8 * _Khat**2 * _chi0 \ @@ -249,7 +255,7 @@ class refraction(Observatory): * _chi0**2 - 180 * _Khat**3 * _chi0 - 9/5 * _Khat * _chi0**4) * 35/128 g = np.array([_g1, _g3, _g5, _g7, _g9]) - g*= n0*_chi0/2 + g*= n1*_chi0/2 return g @@ -408,7 +414,7 @@ class refraction(Observatory): return np.exp(x**2) * _int[0] - def refractionIntegral(self, n1, z0, R0=None, useStandardAtmosphere=True, + def refractionIntegral(self, n1, zenith, R0=None, useStandardAtmosphere=True, heightData=None, rhoData=None): ''' Using data that gives temperature, pressure and density as a @@ -425,7 +431,7 @@ class refraction(Observatory): ---------- n1 : float Refractive index at the wavelength of interest - z0 : float + zenith : float Angle of observation in degrees. zenith = 0 means the observation is directly overhead. R0 : float (optional) @@ -457,7 +463,7 @@ class refraction(Observatory): _Dens = rhoData _h = heightData - z0 = np.deg2rad(z0) + zenith = np.deg2rad(zenith) _Dens = np.asarray(_Dens) _h = np.asarray(_h) _R = R0 + _h * 1000 @@ -466,7 +472,7 @@ class refraction(Observatory): _n_h = 1 + (n0 - 1) / _Dens[0] * _Dens # Calculation of the zenith angle for given height and refractive index, from the refractive invariant - _z = np.arcsin( (n0 * R0) / (_n_h * _R) * np.sin(z0) ) + _z = np.arcsin( (n0 * R0) / (_n_h * _R) * np.sin(zenith) ) # Calculation of log space derivative of n and r _lnn = np.log(_n_h) diff --git a/setup.py b/setup.py index b614c1c..ad68afe 100644 --- a/setup.py +++ b/setup.py @@ -21,14 +21,14 @@ def setup_package(): # write_version_py() setup(name='AstroAtmosphere', - version='1.0', + version='1.1', description='Collection of equations for refractive index, refraction and dispersion calculations of atmospheric air.', long_description=__readme__, long_description_content_type='text/markdown', author='Joost van den Born', author_email='born@astron.nl', url='https://gitlab.astro-wise.org/micado/atmosphericmodel', - download_url='https://gitlab.astro-wise.org/micado/atmosphericmodel/-/archive/v1/atmosphericmodel-v1.tar.gz', + download_url='https://gitlab.astro-wise.org/micado/atmosphericmodel/-/archive/v11/atmosphericmodel-v1.1.tar.gz', license='GNU General Public License v3', data_files = [('',['LICENSE.txt'])], package_dir={'AstroAtmosphere': 'AstroAtmosphere'},