Updated documentation, descriptions for v1.0 release.

This commit is contained in:
yosata committed 2020-06-24 16:47:25 +02:00
1 parent 56051bb6a5
commit 8d50899db6
31 files changed
+17833 -192

No files matched your search

+299
View File
@@ -0,0 +1,299 @@
#!/usr/bin/env Python
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import host_subplot
from AstroAtmosphere import *
import pandas as pd
'''
@ Author: Joost van den Born
@ Contact: born@astron.nl
@ Description: Modeling the atmospheric refraction using multiple
models of the atmosphere and then comparing them.
Models included:
- Full integration method
- Plane-parallel atmosphere
- Cassini's model
- Tan5 model (A*tan(z) + B*tan^3(z) + C*tan^5(z))
- Oriani's theorem (A*tan(z) + B*tan^3(z))
- Erf model (from Corbard et al., 2019)
- SLALIB
One of the figures and all three tables are used in the paper.
'''
if __name__ == '__main__':
plt.rc('font', family='serif')
plt.rc('axes', labelsize='large')
# Conditions at Cerro Armazones
# T = 279.65 # k
# P = 71200 # Pa
# H = 0.22
# xc = 450 # ppm
# Conditions for the standard atmosphere
T = 288.15 # k
P = 101325 # Pa
H = 0.0
xc = 314 # ppm
lat = -24.5983 # degrees
h = 3064 # m
l1 = 1.49 # micron
l2 = 1.78 # micron
zenith = 30 # degrees
# Calculate the index of refraction
at = Observatory()
n1 = at.n_tph(l=l1, T=T, p=P, RH=H, xc=xc)
n2 = at.n_tph(l=l2, T=T, p=P, RH=H, xc=xc)
rho = at.rho(p=P, T=T, RH=H, xc=xc)
refractionAnalysis = True
dispersionAnalysis = True
tableCompare = True
errorTable = True
if dispersionAnalysis:
# Initiate the refraction class
ref = dispersion(lat, h)
ref.setReducedHeight(P, rho)
# Compare the refraction models to check if the output is okay
print ('Plane - parallel atmosphere dispersion: %s mas' %(ref.planeParallel(n1, n2, zenith) * 3.6e6))
print ('Cassini dispersion: %s mas' %(ref.cassini(n1, n2, zenith) * 3.6e6))
print ('Tan5 dispersion: %s mas' %(ref.tan5(n1, n2, zenith) * 3.6e6))
print ('Oriani dispersion: %s mas' %(ref.oriani(n1, n2, zenith) * 3.6e6))
print ('Corbard dispersion: %s mas' %(ref.corbard(n1, n2, zenith)*3.6e6))
print ('Full integration: %s mas' %(ref.refractionIntegral(n1, n2, zenith)*3.6e6))
print('-'*35)
# Now we calculate the dispersion over a wide range of zenith angles
# for ideal gas atmosphere
zenithRange = np.linspace(5, 85, 1000)
ppList = ref.planeParallel(n1, n2, zenithRange) * 3.6e6
cassiniList = ref.cassini(n1, n2, zenithRange) * 3.6e6
tan5List = ref.tan5(n1, n2, zenithRange) * 3.6e6
orianiList = ref.oriani(n1, n2, zenithRange) * 3.6e6
corbardList = [ref.corbard(n1, n2, z) * 3.6e6 for z in zenithRange]
fullIntegrationList = [ref.refractionIntegral(n1, n2, z) * 3.6e6 for z in zenithRange]
# for isothermal atmosphere
cassiniList_isotherm = ref.cassini(n1, n2, zenithRange, reduced_height=ref.H_isotherm(T)) * 3.6e6
tan5List_isotherm = ref.tan5(n1, n2, zenithRange, reduced_height=ref.H_isotherm(T)) * 3.6e6
orianiList_isotherm = ref.oriani(n1, n2, zenithRange, reduced_height=ref.H_isotherm(T)) * 3.6e6
corbardList_isotherm = [ref.corbard(n1, n2, z, reduced_height=ref.H_isotherm(T)) * 3.6e6 for z in zenithRange]
# check when the variation between the different models pass different values
dispersionWidth = []
widthList = []
for z in range(len(zenithRange)):
compList = [cassiniList[z], tan5List[z], orianiList[z], corbardList[z], cassiniList_isotherm[z], tan5List_isotherm[z], orianiList_isotherm[z], corbardList_isotherm[z], fullIntegrationList[z]]
width = np.max(compList) - np.min(compList)
widthList.append(width)
dispersionWidth.append((zenithRange[z], width))
masBorder = np.argmax(np.asarray(widthList)>1)
p1masBorder = np.argmax(np.asarray(widthList)>0.1)
p01masBorder = np.argmax(np.asarray(widthList)>0.01)
p001masBorder = np.argmax(np.asarray(widthList)>0.001)
plotAbsolute = 1
if plotAbsolute:
# Plotting it all, with vertical lines where the variation between the models exceed 1, 0.1, 0.01 and 0.001 mas.
fig = plt.figure(figsize=(9,5))
ax = fig.add_subplot(111)
ax.set_xlim([30,85])
ax.set_xlabel('Zenith (degrees)')
ax.set_ylabel('Dispersion (mas)')
ax.grid(True, alpha=0.3)
ax.axvline(dispersionWidth[masBorder][0], linestyle='--', color='k', linewidth=0.5)
ax.text(dispersionWidth[masBorder][0]-0.5, 402, '1 mas', ha='center', va='bottom', rotation='vertical')
ax.axvline(dispersionWidth[p1masBorder][0], linestyle='--', color='k', linewidth=0.5)
ax.text(dispersionWidth[p1masBorder][0]-0.5, 402, '0.1 mas', ha='center', va='bottom', rotation='vertical')
ax.axvline(dispersionWidth[p01masBorder][0], linestyle='--', color='k', linewidth=0.5)
ax.text(dispersionWidth[p01masBorder][0]-0.5, 402, '10 $\mu$as', ha='center', va='bottom', rotation='vertical')
ax.axvline(dispersionWidth[p001masBorder][0], linestyle='--', color='k', linewidth=0.5)
ax.text(dispersionWidth[p001masBorder][0]-0.5, 402, '1 $\mu$as', ha='center', va='bottom', rotation='vertical')
ax.plot(zenithRange, ppList, 'k-', label='Plane-parallel', alpha=0.2)
ax.plot(zenithRange, cassiniList, 'g-', label='Cassini')
ax.plot(zenithRange, tan5List, 'b-', label='$Atan(z) - Btan^3(z) + Ctan^5(z)$')
ax.plot(zenithRange, orianiList, 'y-', label='$Atan(z) - Btan^3(z)$')
ax.plot(zenithRange, corbardList, 'r-', label='Error function')
ax.plot(zenithRange, fullIntegrationList, 'c-', label='Full integration')
ax.plot(zenithRange, cassiniList_isotherm, 'g--', label='Cassini (isotherm)')
ax.plot(zenithRange, tan5List_isotherm, 'b--', label='$Atan(z) - Btan^3(z) + Ctan^5(z)$ (isotherm)')
ax.plot(zenithRange, orianiList_isotherm, 'y--', label='$Atan(z) - Btan^3(z)$ (isotherm)')
ax.plot(zenithRange, corbardList_isotherm, 'r--', label='Error function (isotherm)')
ax.tick_params(axis ='both', direction='in')
ax.legend()
plt.tight_layout()
# plt.show()
plotRelative = 1
if plotRelative:
# RELATIVE TO FULL INTEGRATION
fig = plt.figure(figsize=(9,6))
ax = fig.add_subplot(111)
ax.set_xlim([30,85])
ax.set_xlabel('Zenith (degrees)', fontsize=18)
ax.set_ylabel(r'$\log_{10}(|(\Delta R - \Delta R_{int})|$ mas$^{-1})$', fontsize=18)
ax.axhline(np.log10(0.4), linestyle='-', linewidth=1, color='red')
ax.text(30.5, np.log10(0.4)+0.05, 'Residual dispersion requirement', fontsize=12)
ax.grid(True, which='major', alpha=0.3)
ax.grid(True, which='minor', alpha=0.2)
ax.plot(zenithRange, np.log10(np.abs(ppList-fullIntegrationList)), color='k', linestyle='-', linewidth=2, label='Plane-parallel')
ax.plot(zenithRange, np.log10(np.abs(cassiniList-fullIntegrationList)), color='g', linestyle=(0, (1, 1)), linewidth=2, label='Cassini')
ax.plot(zenithRange, np.log10(np.abs(orianiList-fullIntegrationList)), color='y', linestyle='-.', linewidth=2, label='Oriani')
ax.plot(zenithRange, np.log10(np.abs(tan5List-fullIntegrationList)), color='b', linestyle=(0, (5, 1)), linewidth=2, label='Oriani incl. fifth order')
ax.plot(zenithRange, np.log10(np.abs(np.asarray(corbardList)-fullIntegrationList)), color='r', linestyle=(0, (3, 1, 1, 1, 1, 1)), linewidth=2, label='Error function')
ax.plot(zenithRange, np.log10(np.abs(cassiniList-fullIntegrationList)), color='g', linestyle=(0, (1, 1)), linewidth=2)
ax.set_ylim(top=2.6, bottom=-7.2)
ax.tick_params(axis ='both', direction='in', labelsize=16)
ax.legend(fontsize=14, labelspacing=0.3, columnspacing=0.5, handletextpad=0.3, ncol=1, loc='lower right')
plt.tight_layout()
# plt.savefig('./figures/dispersionModels_with_SLALIB_minimal2.pdf', transparent=True, bbox_inches='tight')
# plt.savefig('./figures/dispersionModels_with_SLALIB_minimal2.png', transparent=True, bbox_inches='tight')
if refractionAnalysis:
# Initiate the refraction class
ref = refraction(lat, h)
ref.setReducedHeight(P, rho)
# Compare the refraction models to check if the output is okay
print ('Plane - parallel atmosphere refraction: %s arcsec' %(ref.planeParallel(n1, zenith) * 3.6e3))
print ('Cassini refraction: %s arcsec' %(ref.cassini(n1, zenith) * 3.6e3))
print ('Tan5 refraction: %s arcsec' %(ref.tan5(n1, zenith) * 3.6e3))
print ('Oriani refraction: %s arcsec' %(ref.oriani(n1, zenith) * 3.6e3))
print ('Corbard refraction: %s arcsec' %(ref.corbard(n1, zenith)*3.6e3))
print ('Full integration: %s mas' %(ref.refractionIntegral(n1, zenith)*3.6e3))
print('-'*35)
# Now we calculate the dispersion over a wide range of zenith angles
# for ideal gas atmosphere
zenithRange = np.linspace(0, 88, 1000)
ppList = ref.planeParallel(n1, zenithRange) * 3.6e3
cassiniList = ref.cassini(n1, zenithRange) * 3.6e3
tan5List = ref.tan5(n1, zenithRange) * 3.6e3
orianiList = ref.oriani(n1, zenithRange) * 3.6e3
corbardList = [ref.corbard(n1, z) * 3.6e3 for z in zenithRange]
fullIntegrationList = [ref.refractionIntegral(n1, z) * 3.6e3 for z in zenithRange]
# for isothermal atmosphere
cassiniList_isotherm = ref.cassini(n1, zenithRange, reduced_height=ref.H_isotherm(T)) * 3.6e3
tan5List_isotherm = ref.tan5(n1, zenithRange, reduced_height=ref.H_isotherm(T)) * 3.6e3
orianiList_isotherm = ref.oriani(n1, zenithRange, reduced_height=ref.H_isotherm(T)) * 3.6e3
corbardList_isotherm = [ref.corbard(n1, z, reduced_height=ref.H_isotherm(T)) * 3.6e3 for z in zenithRange]
# Plotting it all, with vertical lines where the variation between the models exceed 1, 0.1, 0.01 and 0.001 arcsec.
fig = plt.figure(figsize=(9,5))
ax = fig.add_subplot(111)
ax.set_xlim([80,88])
ax.set_xlabel('Zenith (degrees)')
ax.set_ylabel('Refraction (arcsec)')
ax.grid(True, alpha=0.3)
ax.plot(zenithRange, ppList, 'k-', label='Plane-parallel', alpha=0.2)
ax.plot(zenithRange, cassiniList, 'g-', label='Cassini')
ax.plot(zenithRange, tan5List, 'b-', label='$Atan(z) - Btan^3(z) + Ctan^5(z)$')
ax.plot(zenithRange, orianiList, 'y-', label='$Atan(z) - Btan^3(z)$')
ax.plot(zenithRange, corbardList, 'r-', label='Error function')
ax.plot(zenithRange, fullIntegrationList, 'c-', label='Full integration')
ax.tick_params(axis ='both', direction='in')
ax.legend()
plt.tight_layout()
if tableCompare:
refTableData = []
dispTableData = []
ref = refraction(lat, h)
ref.setReducedHeight(P, rho)
disp = dispersion(lat, h)
disp.setReducedHeight(P, rho)
zenithRange = [10, 30, 50, 60, 70, 80, 85]
headerList = np.array(['z', 'Plane-parallel', 'Cassini', 'tan3', 'tan5', 'Error function', 'Full integration'])
refTableData.append(headerList)
dispTableData.append(headerList)
for z in zenithRange:
ppValue = round(ref.planeParallel(n1, z) * 3.6e3, 3)
cassiniValue = round(ref.cassini(n1, z) * 3.6e3, 3)
tan3Value = round(ref.oriani(n1, z) * 3.6e3, 3)
tan5Value = round(ref.tan5(n1, z) * 3.6e3, 3)
erfValue = round(ref.corbard(n1, z) * 3.6e3, 3)
fullIntValue = round(ref.refractionIntegral(n1, z) * 3.6e3, 3)
refTableData.append([z, ppValue, cassiniValue, tan3Value, tan5Value, erfValue, fullIntValue])
ppValue = round(disp.planeParallel(n1, n2, z) * 3.6e6, 3)
cassiniValue = round(disp.cassini(n1, n2, z) * 3.6e6, 3)
tan3Value = round(disp.oriani(n1, n2, z) * 3.6e6, 3)
tan5Value = round(disp.tan5(n1, n2, z) * 3.6e6, 3)
erfValue = round(disp.corbard(n1, n2, z) * 3.6e6, 3)
fullIntValue = round(disp.refractionIntegral(n1, n2, z) * 3.6e6, 3)
dispTableData.append([z, ppValue, cassiniValue, tan3Value, tan5Value, erfValue, fullIntValue])
dfr = pd.DataFrame(np.asarray(refTableData))
dfd = pd.DataFrame(np.asarray(dispTableData))
print('-'*35,'\nREFRACTION COMPARISON:\n')
print(dfr.to_string(index=False))
print('-'*35)
print('-'*35,'\nDISPERSION COMPARISON:\n')
print(dfd.to_string(index=False))
print('-'*35)
# print(dfr.to_latex(index=False))
# print(dfd.to_latex(index=False))
if errorTable:
ref = dispersion(lat, h)
ref.setReducedHeight(P, rho)
dispTableData = []
headerList = np.array(['s_P', 's_T', 's_H', 's_disp', 's_disp(dl=0)'])
dispTableData.append(headerList)
# dPlist = [2, 20, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 20, 200]
# dTlist = [0, 0, 0, 0.02, 0.2, 2, 0, 0, 0, 0, 0, 0, 0.02, 0.2, 2 ]
# dRHlist= [0, 0, 0, 0, 0, 0, 0.002, 0.02, 0.2, 0, 0, 0, 0.002, 0.02, 0.2]
# dCO2list=[0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 20, 200, 2, 20, 200]
dPlist = [0, 10, 10, 20, 100]
dTlist = [0, 0.1, 0.2, 0.2, 1.0]
dRHlist= [0, 0.01, 0.01, 0.02, 0.05]
dCO2list=[0, 20, 20, 20, 20]
for i in range(len(dPlist)):
# nerr = at.dn_tph(l1, T, P, H, xc, dl=0, dT=dTlist[i], dP=dPlist[i], dRH=dRHlist[i], dCO2=dCO2list[i])
disp_error = ref.cassiniError(zenith, l1, l2, T, P, H, xc, dl1=0.001, dl2=0.001, dT=dTlist[i], dP=dPlist[i], dRH=dRHlist[i],
dCO2=dCO2list[i], dz=0) * 3.6e9
disp_error_dl0 = ref.cassiniError(zenith, l1, l2, T, P, H, xc, dl1=0, dl2=0, dT=dTlist[i], dP=dPlist[i], dRH=dRHlist[i],
dCO2=dCO2list[i], dz=0) * 3.6e9
dispTableData.append([dPlist[i], dTlist[i], dRHlist[i], disp_error, disp_error_dl0])
dfd = pd.DataFrame(np.asarray(dispTableData))
print('-'*35,'\nUNCERTAINTY ANALYSIS:\n')
print(dfd.to_string(index=False))
print('-'*35)
plt.show()