def example(): """ wl = 500 alt = np.linspace(0,71000,20) P,T = ats.standard_atmosphere(alt) theta = np.linspace(0,np.pi, 50) out = rayleigh_angular_scattering_intensity(alt,P,T,wl,theta) plt.plot(theta,out) rod = rayleigh_optical_depth(alt,P,T,wl) print('rod: ', rod) rod_alt = integrate.simps(out * np.sin(theta) ,theta) * 2 * np.pi #this is exactly the AOD. the 2pi nesessary because we need to aditionally integrate over phi (from 0 to 2pi), since the function is independend from phi we simply need to multiply by 2pi print('rod, when integrating over all scattered light:', rod_alt)""" wl = 500 alt = np.linspace(0, 71000, 20) P, T = ats.standard_atmosphere(alt) theta = np.linspace(0, np.pi, 50) out = rayleigh_angular_scattering_intensity(alt, P, T, wl, theta) plt.plot(theta, out) rod = rayleigh_optical_depth(alt, P, T, wl) print('rod: ', rod) rod_alt = integrate.simps(out * np.sin(theta), theta) * 2 * np.pi # this is exactly the AOD. the 2pi nesessary because we need to aditionally integrate over phi (from 0 to 2pi), since the function is independend from phi we simply need to multiply by 2pi print('rod, when integrating over all scattered light:', rod_alt)
def example(): """ wl = 500 alt = np.linspace(0,71000,20) P,T = ats.standard_atmosphere(alt) theta = np.linspace(0,np.pi, 50) out = rayleigh_angular_scattering_intensity(alt,P,T,wl,theta) plt.plot(theta,out) rod = rayleigh_optical_depth(alt,P,T,wl) print('rod: ', rod) rod_alt = integrate.simps(out * np.sin(theta) ,theta) * 2 * np.pi #this is exactly the AOD. the 2pi nesessary because we need to aditionally integrate over phi (from 0 to 2pi), since the function is independend from phi we simply need to multiply by 2pi print('rod, when integrating over all scattered light:', rod_alt)""" wl = 500 alt = _np.linspace(0, 71000, 20) P, T = _ats.standard_atmosphere(alt) theta = _np.linspace(0, _np.pi, 50) out = rayleigh_angular_scattering_intensity(alt, P, T, wl, theta) _plt.plot(theta, out[0]) rod = rayleigh_optical_depth(alt, P, T, wl) print('rod: ', rod) rod_alt = _integrate.simps( out * _np.sin(theta), theta ) * 2 * _np.pi # this is exactly the AOD. the 2pi nesessary because we need to aditionally integrate over phi (from 0 to 2pi), since the function is independend from phi we simply need to multiply by 2pi print('rod, when integrating over all scattered light:', rod_alt)
def get_altitude(self, temperature=False): """Calculates the altitude from the measured barometric pressure Arguments --------- temperature: bool or array-like, optional False: temperature according to international standard is assumed. arraylike: actually measured temperature in Kelvin. Returns ------- returns altitude and adds it to this instance """ alt, tmp = atm_std.standard_atmosphere(self.data.Barometric_pressure, quantity='pressure') self.data['Altitude'] = alt return alt
def get_altitude(self, temperature=False): """Calculates the altitude from the measured barometric pressure Arguments --------- temperature: bool or array-like, optional False: temperature according to international standard is assumed. arraylike: actually measured temperature in Kelvin. Returns ------- returns altitude and adds it to this instance """ alt, tmp = atm_std.standard_atmosphere(self.data.loc[:,'Barometric_pressure'].copy(), quantity='pressure') self.data['Altitude'] = alt return alt
def simulate_from_rayleigh( time_series, layerbounderies, # altitude, # layerbounderies, pressure, temp, wl, no_angles, rotations, airmassfct, sun_azimuth): """ Fix this documentation! Simulates miniSASP signal from a size distribution layer series Arguments --------- layerbounderies: array-like altitude: float or array-like. Altitude for which the mSASP signal is simulated for in meters pressure: array, bool Atmospheric pressure in mbar. If False, value is taken from international standard atmosphere. temp: array, bool in K wl: wavelength in nm no_angles: int total number of angles considered. This included the number in multiple roations. most likely this is int(opt_prop.angular_scatt_func.shape[0] / 2) * rotations rotations: int. number of rotations the of the mSASP. Returns ------- pandas.DataFrame containing the sky brightness as a function of mSASPS azimuth angle""" layerbounderies = np.unique(layerbounderies.flatten()) altitude = (layerbounderies[1:] + layerbounderies[:-1]) / 2. time_series = solar.get_sun_position_TS(time_series) where = array_tools.find_closest(time_series.data.Altitude.values, altitude) solar_elev = time_series.data.Solar_position_elevation.values[where] solar_az = time_series.data.Solar_position_azimuth.values[where] alts = time_series.data.Altitude.values[ where] # thats over acurate, cal simply use the layerbounderies if (type(pressure).__name__ == 'bool') or (type(temp).__name__ == 'bool'): if pressure and temp: # temp = time_series.data.Temperature # pressure = time_series.data.Barometric_pressure_Pa lb = pd.DataFrame(index=layerbounderies) select_list = ["Temperature", "Altitude", "Pressure_Pa"] bla = [] for i in ["Temperature", "Altitude", "Pressure_Pa"]: if i not in time_series.data.columns: bla.append(i) if len(bla) != 0: txt = 'The underlying housekeeping data has to have the following attributes for this operation to work: %s' % ( ["Temperature", "Altitude", "Pressure_Pa"]) txt += '\nmissing:' for i in bla: txt += '\n \t' + i # print(txt) raise AttributeError(txt) hkt = time_series.data.loc[:, select_list] hkt.index = hkt.Altitude hkt = hkt.sort_index() hkt_lb = pd.concat([hkt, lb]).sort_index().interpolate() hkt_lb = hkt_lb.groupby(hkt_lb.index).mean().reindex(lb.index) temp = hkt_lb.Temperature.values + 273.15 pressure = hkt_lb.Pressure_Pa.values else: p, t = atmstd.standard_atmosphere(layerbounderies) if type(pressure).__name__ == 'bool': if pressure == False: pressure = p if type(temp).__name__ == 'bool': if temp == False: temp = t # print(pressure, temp) if (layerbounderies.shape != pressure.shape) or (layerbounderies.shape != temp.shape): raise ValueError('altitude, pressure and tmp have to have same shape') # time = time_series.data.index[where] what_mSASP_sees_rayleigh = pd.DataFrame() what_mSASP_sees_AOD_rayleigh = np.zeros(altitude.shape) for alt in range(altitude.shape[0]): # get the sun position at the time when the plane was at the particular altitude, sol_el = solar_elev[alt] sol_az = solar_az[alt] # print(alts[alt:]) # return ray_scatt_fct # angles between mSASP positions and sun. This is used to pick the angle in the phase functions if sun_azimuth: sun_azimuth = sol_az else: sun_azimuth = 0 mSASP2Sunangles = angle_MSASP_sun( sol_el, sun_azimuth=sun_azimuth, no_angles=no_angles, # pretty arbitrary number ... this is just to get a reasonal number of angles no_rotations=rotations) ray_scatt_fct = bray.rayleigh_angular_scattering_intensity( layerbounderies[alt:], pressure[alt:], temp[alt:], wl, mSASP2Sunangles.values.transpose()) ray_scatt_fct = pd.DataFrame(ray_scatt_fct, index=mSASP2Sunangles.index) # return layerbounderies[alt:], pressure[alt:],temp[alt:], wl, ray_scatt_fct if airmassfct: slant_adjust = 1. / np.sin(solar_elev[alt]) else: slant_adjust = 1. # closest_phase2sun_azi = array_tools.find_closest(ray_scatt_fct.index.values, # mSASP2Sunangles.mSASP_sun_angle.values) what_mSASP_sees_rayleigh[alts[alt]] = pd.Series( ray_scatt_fct.values.transpose()[0] * slant_adjust) # what_mSASP_sees_rayleigh.index = mSASP2Sunangles.index.values what_mSASP_sees_AOD_rayleigh[alt] = bray.rayleigh_optical_depth( layerbounderies[alt:], pressure[alt:], temp[alt:], wl) * slant_adjust # return layerbounderies[alt:],pressure[alt:],temp[alt:],wl, what_mSASP_sees_AOD_rayleigh[alt], slant_adjust what_mSASP_sees_rayleigh.index = mSASP2Sunangles.index what_mSASP_sees_AOD_rayleigh = pd.DataFrame(what_mSASP_sees_AOD_rayleigh, index=altitude, columns=['AOD_ray']) return what_mSASP_sees_rayleigh, what_mSASP_sees_AOD_rayleigh
def simulate_from_rayleigh(time_series, layerbounderies, # altitude, # layerbounderies, pressure, temp, wl, no_angles, rotations, airmassfct, sun_azimuth): """ Fix this documentation! Simulates miniSASP signal from a size distribution layer series Arguments --------- layerbounderies: array-like altitude: float or array-like. Altitude for which the mSASP signal is simulated for in meters pressure: array, bool Atmospheric pressure in mbar. If False, value is taken from international standard atmosphere. temp: array, bool in K wl: wavelength in nm no_angles: int total number of angles considered. This included the number in multiple roations. most likely this is int(opt_prop.angular_scatt_func.shape[0] / 2) * rotations rotations: int. number of rotations the of the mSASP. Returns ------- pandas.DataFrame containing the sky brightness as a function of mSASPS azimuth angle""" layerbounderies = np.unique(layerbounderies.flatten()) altitude = (layerbounderies[1:] + layerbounderies[:-1]) / 2. time_series = solar.get_sun_position_TS(time_series) where = array_tools.find_closest(time_series.data.Altitude.values, altitude) solar_elev = time_series.data.Solar_position_elevation.values[where] solar_az = time_series.data.Solar_position_azimuth.values[where] alts = time_series.data.Altitude.values[where] # thats over acurate, cal simply use the layerbounderies if (type(pressure).__name__ == 'bool') or (type(temp).__name__ == 'bool'): if pressure and temp: # temp = time_series.data.Temperature # pressure = time_series.data.Barometric_pressure_Pa lb = pd.DataFrame(index=layerbounderies) select_list = ["Temperature", "Altitude", "Pressure_Pa"] bla = [] for i in ["Temperature", "Altitude", "Pressure_Pa"]: if i not in time_series.data.columns: bla.append(i) if len(bla) != 0: txt='The underlying housekeeping data has to have the following attributes for this operation to work: %s'%(["Temperature", "Altitude", "Pressure_Pa"]) txt+='\nmissing:' for i in bla: txt += '\n \t' + i # print(txt) raise AttributeError(txt) hkt = time_series.data.loc[:, select_list] hkt.index = hkt.Altitude hkt = hkt.sort_index() hkt_lb = pd.concat([hkt, lb]).sort_index().interpolate() hkt_lb = hkt_lb.groupby(hkt_lb.index).mean().reindex(lb.index) temp = hkt_lb.Temperature.values + 273.15 pressure = hkt_lb.Pressure_Pa.values else: p, t = atmstd.standard_atmosphere(layerbounderies) if type(pressure).__name__ == 'bool': if pressure == False: pressure = p if type(temp).__name__ == 'bool': if temp == False: temp = t # print(pressure, temp) if (layerbounderies.shape != pressure.shape) or (layerbounderies.shape != temp.shape): raise ValueError('altitude, pressure and tmp have to have same shape') # time = time_series.data.index[where] what_mSASP_sees_rayleigh = pd.DataFrame() what_mSASP_sees_AOD_rayleigh = np.zeros(altitude.shape) for alt in range(altitude.shape[0]): # get the sun position at the time when the plane was at the particular altitude, sol_el = solar_elev[alt] sol_az = solar_az[alt] # print(alts[alt:]) # return ray_scatt_fct # angles between mSASP positions and sun. This is used to pick the angle in the phase functions if sun_azimuth: sun_azimuth = sol_az else: sun_azimuth = 0 mSASP2Sunangles = angle_MSASP_sun(sol_el, sun_azimuth=sun_azimuth, no_angles=no_angles, # pretty arbitrary number ... this is just to get a reasonal number of angles no_rotations=rotations) ray_scatt_fct = bray.rayleigh_angular_scattering_intensity(layerbounderies[alt:], pressure[alt:], temp[alt:], wl, mSASP2Sunangles.values.transpose()) ray_scatt_fct = pd.DataFrame(ray_scatt_fct, index=mSASP2Sunangles.index) # return layerbounderies[alt:], pressure[alt:],temp[alt:], wl, ray_scatt_fct if airmassfct: slant_adjust = 1. / np.sin(solar_elev[alt]) else: slant_adjust = 1. # closest_phase2sun_azi = array_tools.find_closest(ray_scatt_fct.index.values, # mSASP2Sunangles.mSASP_sun_angle.values) what_mSASP_sees_rayleigh[alts[alt]] = pd.Series(ray_scatt_fct.values.transpose()[0] * slant_adjust) # what_mSASP_sees_rayleigh.index = mSASP2Sunangles.index.values what_mSASP_sees_AOD_rayleigh[alt] = bray.rayleigh_optical_depth(layerbounderies[alt:], pressure[alt:], temp[alt:], wl) * slant_adjust # return layerbounderies[alt:],pressure[alt:],temp[alt:],wl, what_mSASP_sees_AOD_rayleigh[alt], slant_adjust what_mSASP_sees_rayleigh.index = mSASP2Sunangles.index what_mSASP_sees_AOD_rayleigh = pd.DataFrame(what_mSASP_sees_AOD_rayleigh, index=altitude, columns=['AOD_ray']) return what_mSASP_sees_rayleigh, what_mSASP_sees_AOD_rayleigh