-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from SatCloP/wgt
[feature] add computation of weighting functions
- Loading branch information
Showing
9 changed files
with
590 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
Computation of Weighting Functions | ||
================================== | ||
""" | ||
|
||
# %% | ||
# This example shows how to use the :py:class:`pyrtlib.weighting_functions.WeightingFunctions` method | ||
# to compute the weighting functions for the MWS channels for the U.S. standard atmospheric profile. | ||
|
||
import numpy as np | ||
import warnings | ||
warnings.filterwarnings("ignore", category=UserWarning) | ||
from pyrtlib.weighting_functions import WeightingFunctions | ||
from pyrtlib.climatology import AtmosphericProfiles as atmp | ||
from pyrtlib.utils import ppmv2gkg, mr2rh, get_frequencies_sat | ||
|
||
z, p, _, t, md = atmp.gl_atm(atmp.US_STANDARD) | ||
gkg = ppmv2gkg(md[:, atmp.H2O], atmp.H2O) | ||
rh = mr2rh(p, t, gkg)[0] / 100 | ||
|
||
wf = WeightingFunctions(z, p, t, rh) | ||
wf.frequencies = np.array([50.5, 53.2, 54.35, 54.9, 59.4, 58.825, 58.4]) | ||
wgt = wf.generate_wf() | ||
|
||
wf.plot_wf(wgt, 'Downlooking', ylim=[0, 60], legend=True, figsize=(8, 6), dpi=100) | ||
|
||
#%% | ||
# As above but with the weighting functions computed in uplooking mode. | ||
|
||
wf.satellite = False | ||
wgt = wf.generate_wf() | ||
|
||
wf.plot_wf(wgt, 'Uplooking', ylim=[0, 10], figsize=(8, 6), dpi=100) | ||
|
||
#%% | ||
# The weighting functions can also be computed for a different set of channels. | ||
# The bandpass values are used to compute the weighting functions for the ATMS channels. | ||
# The following code compute the weighting functions for the ATMS channels 5-15. | ||
|
||
cf53 = 53.596 | ||
cf57 = 57.290344 | ||
frq = np.array([52.8, cf53-0.115, cf53+0.115, 54.4, 54.94, 55.5, cf57, | ||
cf57-0.217, cf57+0.217, | ||
cf57-0.3222-0.048, cf57-0.3222+0.048, cf57+0.3222-0.048, cf57+0.3222+0.048, | ||
cf57-0.3222-0.022, cf57-0.3222+0.022, cf57+0.3222-0.022, cf57+0.3222+0.022, | ||
cf57-0.3222-0.010, cf57-0.3222+0.010, cf57+0.3222-0.010, cf57+0.3222+0.010, | ||
cf57-0.3222-0.0045, cf57-0.3222+0.0045, cf57+0.3222-0.0045, cf57+0.3222+0.0045]) | ||
|
||
wf.satellite = True | ||
wf.frequencies = frq | ||
wf.bandpass = np.array([1, 2, 1, 1, 1, 1, 2, 4, 4, 4, 4]) | ||
wf.legend_labels = [f'Channel {i+5}' for i in range(len(wf.bandpass))] | ||
wgt = wf.generate_wf() | ||
|
||
wf.plot_wf(wgt, 'ATMS Channels 5-15', ylim=[0, 70], xlim=[0, 0.11], legend=True, figsize=(8, 6), dpi=100) | ||
|
||
#%% | ||
# The weighting functions can also be computed for a different set of frequencies. | ||
# The following code compute the weighting functions for the MWS channels for a standard tropical atmosphere. | ||
# for grouped frequencies. | ||
|
||
wf.satellite = True | ||
wf.frequencies = get_frequencies_sat('MWS') | ||
wgt = wf.generate_wf() | ||
wf.plot_wf_grouped(wgt, 'MWS Channels (grouped)', ylim=[0, 60], | ||
grouped_frequencies=[4, 9, 19, 1, 13], | ||
grouped_labels=['23-52', '53-55', '57', '89', '164-229'], dpi=350) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from unittest import TestCase | ||
|
||
import numpy as np | ||
from pyrtlib.weighting_functions import WeightingFunctions | ||
from pyrtlib.climatology import AtmosphericProfiles as atmp | ||
from pyrtlib.utils import ppmv2gkg, mr2rh | ||
import numpy as np | ||
import matplotlib | ||
matplotlib.use('Template') | ||
|
||
class Test(TestCase): | ||
def wf_computation(self, frq: np.ndarray): | ||
z, p, d, t, md = atmp.gl_atm(atmp.TROPICAL) | ||
gkg = ppmv2gkg(md[:, atmp.H2O], atmp.H2O) | ||
rh = mr2rh(p, t, gkg)[0] / 100 | ||
|
||
wf = WeightingFunctions(z, p, t, rh) | ||
wf.frequencies = frq | ||
|
||
return wf.generate_wf(), z, wf | ||
|
||
def test_f_89(self): | ||
wgt, z, _ = self.wf_computation(np.array([89.0])) | ||
np.testing.assert_almost_equal(z[np.argmax(wgt)], 0., decimal=15) | ||
|
||
def test_f_57(self): | ||
wgt, z, _ = self.wf_computation(np.array([57.290344])) | ||
np.testing.assert_almost_equal(z[np.argmax(wgt)], 18., decimal=15) | ||
|
||
def test_f_57_6(self): | ||
wgt, z, _ = self.wf_computation(np.array([57.660544])) | ||
np.testing.assert_almost_equal(z[np.argmax(wgt)], 27.5, decimal=15) | ||
|
||
def test_plot_wf(self): | ||
wgt, z, wf = self.wf_computation(np.array([57.660544])) | ||
wf.plot_wf(wgt, 'Test', legend=True, ylim=(0, 60), xlim=(0, .1), figsize=(8, 6), dpi=100) | ||
|
||
def test_plot_wf_grouped(self): | ||
wgt, z, wf = self.wf_computation(np.array([57.660544])) | ||
wf.plot_wf_grouped(wgt, 'Test', grouped_frequencies=[ | ||
1], grouped_labels=['Test'], dpi=100) | ||
|
||
def test_plot_wf_multiple(self): | ||
freqs = np.array([57.290344, 57.660544, 89.0]) | ||
wgt, z, wf = self.wf_computation(freqs) | ||
wf.satellite = False | ||
wf.plot_wf(wgt, 'Multiple Frequencies', | ||
legend=True, figsize=(8, 6), dpi=100) | ||
|
||
def test_plot_wf_bandpass(self): | ||
cf53 = 53.596 | ||
cf57 = 57.290344 | ||
freqs = np.array([52.8, cf53-0.115, cf53+0.115, 54.4, 54.94, 55.5, cf57, cf57-0.217, cf57+0.217, cf57-0.3222-0.048, cf57-0.3222+0.048, cf57+0.3222-0.048, cf57+0.3222+0.048]) | ||
wgt, z, wf = self.wf_computation(freqs) | ||
wf.bandpass = np.array([1, 2, 1, 1, 1, 1, 2, 4]) | ||
wf.plot_wf(wgt, 'Bandpass', | ||
legend=True, figsize=(8, 6), dpi=100) |
Oops, something went wrong.