Skip to content

Commit

Permalink
fix codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
whitetuft committed Jul 12, 2024
1 parent a73f3b6 commit 2a5918c
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions pyrtlib/weighting_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class WeightingFunctions(object):
"""
This class is used to compute the weighting functions
.. note::
The weighting functions are computed always using last absorption model available.
"""
Expand Down Expand Up @@ -138,25 +138,25 @@ def _perform_calculation(self) -> Dict[str, np.ndarray]:
_, other = rte.execute(False)

return other

def _mean_channel(self, a: np.ndarray, bandpass: np.ndarray) -> np.ndarray:
"""
Compute the mean of the input array based on bandpass.
Args:
a (np.ndarray): The input array.
bandpass (np.ndarray): The bandpass array.
Returns:
np.ndarray: The mean of the input array based on bandpass.
"""

channel_mean = np.zeros((len(bandpass), a.shape[1]))
cnt = 0
for i in range(len(bandpass)):
channel_mean[i, :] = np.mean(a[cnt:bandpass[i]+cnt, :], axis=0)
cnt += bandpass[i]

return channel_mean

def generate_wf(self) -> np.ndarray:
Expand Down Expand Up @@ -228,10 +228,11 @@ def plot_wf(self, wgt: np.ndarray, title: Optional[str] = '', ylim: Optional[Tup
# plt.rc('font', family=['cmr10'])
# plt.rc('mathtext', fontset='cm')
# plt.rc('axes.formatter', use_mathtext=False)

if self.bandpass is not None:
wgt = self._mean_channel(wgt, self.bandpass)
self.frequencies = np.array([np.mean(self.frequencies[i:i+j]) for i,j in enumerate(self.bandpass)])
self.frequencies = np.array(
[np.mean(self.frequencies[i:i+j]) for i, j in enumerate(self.bandpass)])

if yaxis == 'p':
y = self.pinterp[:-1]
Expand All @@ -245,7 +246,8 @@ def plot_wf(self, wgt: np.ndarray, title: Optional[str] = '', ylim: Optional[Tup
normalize = np.max(
wgt, axis=1) if normalized else np.ones(wgt.shape[1])

plt.figure(figsize=kwargs.get('figsize', (5, 10)), dpi=kwargs.get('dpi', 150))
plt.figure(figsize=kwargs.get('figsize', (5, 10)),
dpi=kwargs.get('dpi', 150))
for i in range(len(self.frequencies)):
if self.satellite:
line_s = 'dashed' if y[np.argmax(wgt[i, 1:])] == 0. else None
Expand All @@ -269,7 +271,7 @@ def plot_wf(self, wgt: np.ndarray, title: Optional[str] = '', ylim: Optional[Tup
plt.ylim(ylim[0], ylim[1])
if xlim:
plt.xlim(xlim[0], xlim[1])

if title:
plt.title(title)
plt.grid(color='#d6d6d6', linestyle='dashed')
Expand All @@ -279,7 +281,7 @@ def plot_wf(self, wgt: np.ndarray, title: Optional[str] = '', ylim: Optional[Tup
self.pinterp[np.where(self.zinterp == np.max(self.zinterp))]))
if ylim:
ax_twinx.set_ylim((self.pinterp[np.where(self.zinterp == ylim[0])],
self.pinterp[np.where(self.zinterp == ylim[1])]))
self.pinterp[np.where(self.zinterp == ylim[1])]))
ax_twinx.set_yscale('log')
ax_twinx.set_ylabel('Pressure [$hPa$]')
ax_twinx.tick_params(axis='both', which='both', direction='in')
Expand Down Expand Up @@ -321,8 +323,9 @@ def plot_wf_grouped(self, wgt: np.ndarray, title: Optional[str] = '',

y = self.zinterp[:-1]
y_label = 'Height [$km$]'

plt.figure(figsize=kwargs.get('figsize', (10, 4)), dpi=kwargs.get('dpi', 150))

plt.figure(figsize=kwargs.get('figsize', (10, 4)),
dpi=kwargs.get('dpi', 150))
cnt = 0
max_increment = np.array([])
for i in grouped_frequencies:
Expand Down Expand Up @@ -364,7 +367,7 @@ def plot_wf_grouped(self, wgt: np.ndarray, title: Optional[str] = '',
self.pinterp[np.where(self.zinterp == np.max(self.zinterp))]))
if ylim:
ax_twinx.set_ylim((self.pinterp[np.where(self.zinterp == ylim[0])],
self.pinterp[np.where(self.zinterp == ylim[1])]))
self.pinterp[np.where(self.zinterp == ylim[1])]))
ax_twinx.set_yscale('log')
ax_twinx.set_ylabel('Pressure [$hPa$]')
ax_twinx.tick_params(axis='both', which='both', direction='in')
Expand Down

0 comments on commit 2a5918c

Please sign in to comment.