Skip to content

Commit

Permalink
correct a few errors detected by Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainp committed Aug 16, 2023
1 parent 4c57705 commit 7f8041b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
10 changes: 5 additions & 5 deletions smrt/core/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def channel_map_for_radar(frequency=None, polarization='HV', order='fp'):
frequency_str = ['%02i' % np.round(f / 1e9) for f in frequency]

if order == 'fp':
def channel_name(freq, pola_inc, pola_ref):
return str(freq_str) + str(pola_inc) + str(pola_refl)
if order == 'pf':
def channel_name(freq, pola_inc, pola_ref):
return str(pola_inc) + str(pola_refl) + str(freq_str)
def channel_name(freq_str, pola_inc, pola_ref):
return str(freq_str) + str(pola_inc) + str(pola_ref)
elif order == 'pf':
def channel_name(freq_str, pola_inc, pola_ref):
return str(pola_inc) + str(pola_ref) + str(freq_str)
else:
raise SMRTError('order must be fp or pf')

Expand Down
1 change: 1 addition & 0 deletions smrt/emmodel/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np

from smrt.core.lib import abs2, smrt_matrix, len_atleast_1d
from srmrt.core.error import SMRTError

This comment has been minimized.

Copy link
@cryptomare

cryptomare Aug 23, 2023

It should be smrt instead of srmrt



def rayleigh_scattering_matrix_and_angle_tsang00(mu_s, mu_i, dphi, npol=2):
Expand Down
44 changes: 23 additions & 21 deletions smrt/rtsolver/dort_nonormalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from ..core.error import SMRTError
from ..core.result import Result
from ..core import lib
from ..core.lib import is_equal_zero


class DORT(object):
"""Discrete Ordinate and Eigenvalue Solver
Expand Down Expand Up @@ -275,7 +277,7 @@ def dort_modem_banded(self, m, n_stream, mu, weight, outmu, n_stream_substrate,
debug_compute_BC = special_return in ["BC", "testeq"] # compute the full matrix boundary condition

# Boundary condition matrix
bBC = np.zeros((2*nband+1, nboundary)) # we use banded Boundary condition matrix
bBC = np.zeros((2 * nband + 1, nboundary)) # we use banded Boundary condition matrix

# rhs vector size
assert(len(intensity_down_m.shape) == 2)
Expand All @@ -289,8 +291,8 @@ def dort_modem_banded(self, m, n_stream, mu, weight, outmu, n_stream_substrate,
nsl = n_stream[l] # number of streams in layer l
nslnpol = nsl * npol # number of streams * npol in layer l
nsl2npol = 2 * nslnpol # number of eigenvalues in layer l (should be 2*npol*n_stream)
nslm1npol = (n_stream[l-1] * npol) if l > 0 else (n_stream0 * npol) # number of streams * npol in the layer l-1 (lm1)
nslp1npol = (n_stream[l+1] * npol) if l < self.nlayer-1 else (n_stream_substrate * npol) # number of streams * nplo in the layer l+1 (lp1)
nslm1npol = (n_stream[l - 1] * npol) if l > 0 else (n_stream0 * npol) # number of streams * npol in the layer l - 1 (lm1)
nslp1npol = (n_stream[l + 1] * npol) if l < self.nlayer - 1 else (n_stream_substrate * npol) # number of streams * nplo in the layer l + 1 (lp1)

# solve the eigenvalue problem for layer l
# TODO: deal with the case phase=0
Expand All @@ -307,7 +309,7 @@ def dort_modem_banded(self, m, n_stream, mu, weight, outmu, n_stream_substrate,

# where we have chosen
# beta>0 : z(0)(l) = z(l) # reference is at the bottom
# beta<0 : z(0)(l) = z(l-1) # reference is at the top
# beta<0 : z(0)(l) = z(l - 1) # reference is at the top
# so that the transmittance are < 1

# few short-cut
Expand All @@ -318,14 +320,14 @@ def dort_modem_banded(self, m, n_stream, mu, weight, outmu, n_stream_substrate,
# -------------------------------------------------------------------------------
# Eq 17 & 19 TOP of layer l

# compute reflection coefficient between l and l-1
# compute reflection coefficient between l and l - 1
if l == 0:
epslm1 = 1
# save these matrix to compute the emerging intensity at the end
Eu_0 = Eu
transt_0 = transt
else:
epslm1 = self.permittivity[l-1]
epslm1 = self.permittivity[l - 1]

Rtop_l = fix_matrix(self.interfaces[l].specular_reflection_matrix(self.sensor.frequency, self.permittivity[l], epslm1,
mu[l, 0:nsl], npol)) # snow-snow
Expand All @@ -334,26 +336,26 @@ def dort_modem_banded(self, m, n_stream, mu, weight, outmu, n_stream_substrate,
todiag(bBC, (il_topl, j), (Ed - Rtop_l * Eu) * transt) # this line perform matrix multiplication between Rtop_l and Eu. Make sure that reflection_matrix return matrix!

if debug_compute_BC:
BC[il_topl:il_topl+nslnpol, j:j+nsl2npol] = (Ed - Rtop_l * Eu) * transt # a mettre en (l,l), theta<0 et * transt # a mettre en (l,l)
BC[il_topl:il_topl + nslnpol, j:j+nsl2npol] = (Ed - Rtop_l * Eu) * transt # a mettre en (l,l), theta<0 et * transt # a mettre en (l,l)

if l < self.nlayer - 1:
ns_ = min(nslnpol, nslp1npol)
Tbottom_lp1 = fix_matrix(self.interfaces[l].coherent_transmission_matrix(self.sensor.frequency, self.permittivity[l], self.permittivity[l+1],
Tbottom_lp1 = fix_matrix(self.interfaces[l].coherent_transmission_matrix(self.sensor.frequency, self.permittivity[l], self.permittivity[l + 1],
mu[l, 0:(ns_//npol)], npol)) # snow-snow
todiag(bBC, (il_top[l+1], j), - Tbottom_lp1 * Ed[0:ns_, :] * transb)
todiag(bBC, (il_top[l + 1], j), - Tbottom_lp1 * Ed[0:ns_, :] * transb)
if debug_compute_BC:
BC[il_top[l+1]:il_top[l+1]+ns_, j:j+nsl2npol] = - Tbottom_lp1 * Ed[0:ns_, :] * transb # a mettre en (l+1,l)
BC[il_top[l + 1]:il_top[l + 1]+ns_, j:j+nsl2npol] = - Tbottom_lp1 * Ed[0:ns_, :] * transb # a mettre en (l + 1,l)

# fill the vector
if m == 0 and self.temperature is not None and self.temperature[l] > 0:
if Rtop_l is 0:
b[il_topl:il_topl+nslnpol, :] -= self.temperature[l] # a mettre en (l)
if is_equal_zero(Rtop_l):
b[il_topl:il_topl + nslnpol, :] -= self.temperature[l] # a mettre en (l)
else:
b[il_topl:il_topl+nslnpol, :] -= ((1.0 - muleye(Rtop_l)) * self.temperature[l])[:, np.newaxis] # a mettre en (l)
b[il_topl:il_topl + nslnpol, :] -= ((1.0 - muleye(Rtop_l)) * self.temperature[l])[:, np.newaxis] # a mettre en (l)
# the muleye comes from the isotropic emission of the black body

if l < self.nlayer - 1 and self.temperature[l] > 0:
b[il_top[l+1]:il_top[l+1]+ns_, :] += (muleye(Tbottom_lp1) * self.temperature[l])[:, np.newaxis] # a mettre en (l+1)
b[il_top[l + 1]:il_top[l + 1]+ns_, :] += (muleye(Tbottom_lp1) * self.temperature[l])[:, np.newaxis] # a mettre en (l + 1)

if l == 0: # Air-snow interface
Tbottom_air_down = fix_matrix(self.interfaces[l].coherent_transmission_matrix(self.sensor.frequency, 1, self.permittivity[l],
Expand All @@ -364,9 +366,9 @@ def dort_modem_banded(self, m, n_stream, mu, weight, outmu, n_stream_substrate,
# -------------------------------------------------------------------------------
# Eq 18 & 22 BOTTOM of layer l

# compute reflection coefficient between l and l-1
# compute reflection coefficient between l and l - 1
if l < self.nlayer-1:
Rbottom_l = fix_matrix(self.interfaces[l].specular_reflection_matrix(self.sensor.frequency, self.permittivity[l], self.permittivity[l+1], mu[l, 0:nsl], npol)) # snow-snow
Rbottom_l = fix_matrix(self.interfaces[l].specular_reflection_matrix(self.sensor.frequency, self.permittivity[l], self.permittivity[l + 1], mu[l, 0:nsl], npol)) # snow-snow
elif self.snowpack.substrate is not None:
Rbottom_l = fix_matrix(self.snowpack.substrate.specular_reflection_matrix(self.sensor.frequency, self.permittivity[l], mu[l, 0:nsl], npol)) # snow-sub
if not compute_coherent_only and hasattr(self.snowpack.substrate, "ft_even_diffuse_reflection_matrix"):
Expand All @@ -382,10 +384,10 @@ def dort_modem_banded(self, m, n_stream, mu, weight, outmu, n_stream_substrate,

if l > 0:
ns_ = min(nslnpol, nslm1npol)
Ttop_lm1 = fix_matrix(self.interfaces[l].coherent_transmission_matrix(self.sensor.frequency, self.permittivity[l], self.permittivity[l-1], mu[l, 0:(ns_//npol)], npol)) # snow-snow
todiag(bBC, (il_bottom[l-1], j), -Ttop_lm1 * Eu[0:ns_, :] * transt)
Ttop_lm1 = fix_matrix(self.interfaces[l].coherent_transmission_matrix(self.sensor.frequency, self.permittivity[l], self.permittivity[l - 1], mu[l, 0:(ns_//npol)], npol)) # snow-snow
todiag(bBC, (il_bottom[l - 1], j), -Ttop_lm1 * Eu[0:ns_, :] * transt)
if debug_compute_BC:
BC[il_bottom[l-1]:il_bottom[l-1]+ns_, j:j+nsl2npol] = -Ttop_lm1 * Eu[0:ns_, :] * transt # a mettre en (l-1)
BC[il_bottom[l - 1]:il_bottom[l - 1]+ns_, j:j+nsl2npol] = -Ttop_lm1 * Eu[0:ns_, :] * transt # a mettre en (l - 1)

# fill the vector
if m == 0 and self.temperature is not None and self.temperature[l] > 0:
Expand All @@ -394,7 +396,7 @@ def dort_modem_banded(self, m, n_stream, mu, weight, outmu, n_stream_substrate,
else:
b[il_bottoml:il_bottoml+nslnpol, :] -= ((1.0 - muleye(Rbottom_l)) * self.temperature[l])[:, np.newaxis] # a mettre en (l)
if l > 0:
b[il_bottom[l-1]:il_bottom[l-1]+ns_, :] += (muleye(Ttop_lm1) * self.temperature[l])[:, np.newaxis] # a mettre en (l-1)
b[il_bottom[l - 1]:il_bottom[l - 1]+ns_, :] += (muleye(Ttop_lm1) * self.temperature[l])[:, np.newaxis] # a mettre en (l - 1)

if m == 0 and l == self.nlayer-1 and self.snowpack.substrate is not None and \
self.snowpack.substrate.temperature is not None and self.temperature is not None:
Expand Down Expand Up @@ -472,7 +474,7 @@ def todiag(bmat, ij, dmat):
ldiag = min(n, m-j)
bmat[u+oi-oj-j, j+oj:j+oj+ldiag] = df[j::m+1][:ldiag]

for i in range(1, min(l+1, n)):
for i in range(1, min(l + 1, n)):
ldiag = min(n-i, m)
bmat[u+oi-oj+i, 0+oj:0+oj+ldiag] = df[i*m::m+1][:ldiag]

Expand Down

0 comments on commit 7f8041b

Please sign in to comment.