<jupyter_start><jupyter_text>EOSC 582 Assignment II (Petty, p128, 154, 168) - Due Feb 13<jupyter_code>__author__ = 'Yingkai (<NAME>'
__email__  = '<EMAIL>'<jupyter_output><empty_output><jupyter_text>Content1. [**Problem 6.9**](Problem-6.9)1. [**Problem 6.28**](Problem-6.28)1. [**Problem 7.4**](Problem-7.4)<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from __future__ import print_function
% matplotlib inline<jupyter_output><empty_output><jupyter_text>Problem 6.9 **Q1: Calculate $\mathrm{T_B}$**We can use inverse Planck function for $\mathrm{T_B}$:\begin{equation*}    T_B\left(\lambda, L_e\right) = \frac{2h/k_B}{\lambda \ln{\left( 2hc^2/\lambda^5 L_e+1 \right)}}\end{equation*}$h$: Planck constant; $k_B$: Boltzmann constant; $c$: Speed of light. Given conditions:<jupyter_code>wave_length = 12*1e-6 # m
radiance    = 6.2*1e6 # W/m^2/m/sr<jupyter_output><empty_output><jupyter_text>Constants:<jupyter_code>c=2.99792458e+08  # m/s, Speed of light
h=6.62606876e-34  # Js, Planck constant
kb=1.3806503e-23  # J/K, Boltzman constant<jupyter_output><empty_output><jupyter_text>Calculate $\mathrm{T_B}$<jupyter_code>TB = (h*c/kb)/(wave_length*np.log((2 * h * c**2)/(wave_length**5 * radiance) + 1))
print('Brightness Temperature: {}'.format(TB))<jupyter_output>Brightness Temperature: 275.039598465<jupyter_text>** Q2: Calculate real temperature by using emissivity** If the surface is in a thermal equilibrium state, we can use *Kirchhoff's law* and get the following relation:\begin{equation*}     L_e = \epsilon \cdot L_b\end{equation*}$\mathrm{L_e}$: "true" radiance; $\mathrm{L_b}$: "equvilant" black body radiance.Thus we get the right black body radiance for inverse Planck function.<jupyter_code>emiss = 0.9
radiance = radiance / emiss
T_true = (h*c/kb)/(wave_length*np.log((2 * h * c**2)/(wave_length**5 * radiance) + 1))
print('True Temperature: {}'.format(TB))<jupyter_output>True Temperature: 275.039598465<jupyter_text>** Q3: Ratio of brightness temperature and true temperature **<jupyter_code>TB/T_true<jupyter_output><empty_output><jupyter_text>The ratio is **not equal** to emissivity, and we can prove that by play with Planck function.  Problem 6.28<jupyter_code>Freq = np.array([    6.93    ,     10.65   ,    18.70    ,    23.80    ,    36.50    ,     89.00   ])
N_10 = np.array([8.095+2.371j, 7.431+2.708j, 6.164+2.980j, 5.566+2.958j, 4.575+2.721j, 3.115+1.842j])
N_20 = np.array([8.211+2.144j, 7.745+2.416j, 6.712+2.819j, 6.151+2.901j, 5.123+2.831j, 3.433+2.083j])<jupyter_output><empty_output><jupyter_text>** Q1: Calculate brightness temperature for all cases**Since the surface is smooth, we can use *Fresnel relations* for reflectivity:* For vertical polarization:\begin{equation*}    R_p = \left| \frac{cos \Phi_t - Ncos \Phi_i}{cos \Phi_t + Ncos \Phi_i} \right|^2\end{equation*}* For horizontal polarization:\begin{equation*}    R_s = \left| \frac{cos \Phi_i - Ncos \Phi_t}{cos \Phi_i + Ncos \Phi_t} \right|^2\end{equation*}Here $\mathrm \Phi_i = 55 ^ \circ $. According to *Snell's Law*:\begin{equation*}    \Phi_t = arcsin\left( \frac{sin\left( \Phi_i \right)}{N} \right)\end{equation*}Then we can calculate $\mathrm{T_B}$ as:* for horizontal channel:\begin{equation*}    T_{B} =  \epsilon_s T = \left( 1 - R_s \right) T\end{equation*}* for vertical channel:\begin{equation*}    T_{B} = \epsilon_p T = \left( 1 - R_p \right) T\end{equation*}<jupyter_code>def TBright_calc(theta_i, N, T):
    theta_t = np.arcsin( np.sin(theta_i)/N )
    Rp = np.abs((np.cos(theta_t) - N*np.cos(theta_i))/(np.cos(theta_t) + N*np.cos(theta_i)))**2
    Rs = np.abs((np.cos(theta_i) - N*np.cos(theta_t))/(np.cos(theta_i) + N*np.cos(theta_t)))**2
    TBH = T * (1-Rs)
    TBV = T * (1-Rp)
    return TBH, TBV
theta_i = 55./360*2*np.pi<jupyter_output><empty_output><jupyter_text>calculate all the cases in a for-loop.<jupyter_code>TBH = np.empty([len(Freq), 2]) # horizontal channel for 10 and 20 degC cases
TBV = np.empty([len(Freq), 2])
for i in range(len(Freq)):
    TBH10, TBV10 = TBright_calc(theta_i, N_10[i], 10+273.15)
    TBH20, TBV20 = TBright_calc(theta_i, N_20[i], 20+273.15)
    TBH[i, :] = [TBH10, TBH20]
    TBV[i, :] = [TBV10, TBV20]<jupyter_output><empty_output><jupyter_text>Show the result.<jupyter_code>print('Brightness temperature: \n==============================\ni) Horizontal channels\n\t10degC\t\t20degC')
print(TBH)
print('ii) Vertical channels\n\t10degC\t\t20degC')
print(TBV)
print('==============================')<jupyter_output>Brightness temperature: 
==============================
i) Horizontal channels
	10degC		20degC
[[  65.29532065   67.7465206 ]
 [  67.77121174   69.62032484]
 [  73.8818992    74.1318003 ]
 [  77.90979187   77.25596997]
 [  87.5757405    85.1777878 ]
 [ 118.80285239  112.98584178]]
ii) Vertical channels
	10degC		20degC
[[ 155.74584188  161.52381861]
 [ 160.07532803  164.81423215]
 [ 170.31082826  172.47891809]
 [ 176.72608374  177.59438292]
 [ 191.0977424   189.89451221]
 [ 228.61742715  226.08061735]]
==============================<jupyter_text>** Sensitivity, find the best channel **Here I define the sensitivity as:\begin{equation*}    \frac{T_B(20^\circ C) - T_B(10^\circ C)}{10^\circ C}\end{equation*}And we believe sensible channel is good.<jupyter_code>Sen_TBH = (TBH[:, 1] - TBH[:, 0])/10
Sen_TBV = (TBV[:, 1] - TBV[:, 0])/10<jupyter_output><empty_output><jupyter_text>compare the results.<jupyter_code>print('Frequency: \n{}'.format(Freq))
print('Sensitivity for horizontal channel: \n{}'.format(Sen_TBH))
print('Sensitivity for vertical channel: \n{}'.format(Sen_TBV))<jupyter_output>Frequency: 
[  6.93  10.65  18.7   23.8   36.5   89.  ]
Sensitivity for horizontal channel: 
[ 0.24512     0.18491131  0.02499011 -0.06538219 -0.23979527 -0.58170106]
Sensitivity for vertical channel: 
[ 0.57779767  0.47389041  0.21680898  0.08682992 -0.12032302 -0.25368098]<jupyter_text>Channels with frequency higher than 23.8 GHz is not recomended, so we will use **6.93 GHz vertical** channel.  Problem 7.4 We can fill the blank with the following equations:\begin{equation*}    \beta_e = \rho k_e = \sigma_eN\end{equation*}\begin{equation*}    \widetilde{\omega} = \frac{\beta_s}{\beta_e}\end{equation*}\begin{equation*}    \sigma_e = k_em\end{equation*}\begin{equation*}    Qe = \frac{\sigma_e}{A}\end{equation*}And here I just type the results:<jupyter_code>a = np.array([3.89e2, 6.6e21, 2.8e-19 , 1e-4, 0  , 7.3e-26 , 4.8e-4 , 2.83e-23, 0.187  , 0      ]).T
b = np.array([1e3   , 1e10  , 7.07e-14, 0.2 , 0.1, 1.41e-17, 1.41e-7, 1.41e-14, 1.41e-4, 1.41e-5]).T
c = np.array([0.45  , 80    , 3.14e-6 , 0.6 , 0.4, 4.19e-6 , 3.35e-4, 1.89e-6 , 1.51e-4, 6.03e-5]).T
d = np.array([150   , 1e9   , 3.14e-10, 2   , 0.9, 4.19e-12, 4.19e-3, 6.28e-10, 0.628  , 0.565  ]).T
import csv
import pandas
from itertools import izip
with open('eosc582_a2_p74.csv', 'wb') as f:
    writer = csv.writer(f)
    writer.writerows(izip(a, b, c, d))
pd_table = pandas.read_csv('eosc582_a2_p74.csv', names=['(a)', '(b)', '(c)', '(d)'])
pd_table<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18756211841544795, 'fraction_numerical': 0.12153911685361352, 'mean_word_length': 4.563981042654029, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '490271', 'license': 'Unlicense', 'n_tokens_mistral': 3474, 'n_tokens_neox': 2885, 'n_words': 584, 'path': 'EOSC_582/EOSC_582_Assignment_II_Petty_p128_p154_p168.ipynb', 'repo_name': 'yingkaisha/Homework', 'size': '7057'}