Skip to content

Commit

Permalink
PEP8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-richard committed May 15, 2023
1 parent 2ee0b9c commit 5edad23
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 76 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ repos:
args:
- --rcfile
- setup.cfg
- --disable
- import-error
- --output-format
- colorized

68 changes: 33 additions & 35 deletions pyrfu/lp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,47 @@ def __init__(
assert not r_wire or np.atleast_1d(r_wire) <= 2, message

self.name = name
self.surface = surface
self.r_sphere = r_sphere
self.r_wire = np.atleast_1d(r_wire)
self.l_wire = l_wire
self.wire = {"l": l_wire, "r": np.atleast_1d(r_wire)}
self.sphere = {"r": r_sphere, "surface": surface}
self.s_photoemission = s_photoemission

# Probe type according to the specified parameters: Sphere + Wire or
# Wire or Sphere
self._get_probe_type()
self.get_probe_type()

# Get probe area
self._get_probe_area()
self.get_probe_area()

# Get probe capacitance
self._get_probe_capa()
self.get_probe_capa()

def _get_probe_type(self):
def get_probe_type(self):
r"""Define probe type according to the specified parameters."""
if self.r_sphere and self.r_wire and self.l_wire:
if self.sphere["r"] and self.wire["r"] and self.wire["l"]:
self.probe_type = "sphere+wire"
elif self.r_wire and self.l_wire:
elif self.wire["r"] and self.wire["l"]:
self.probe_type = "wire"
elif self.r_sphere:
elif self.sphere["r"]:
self.probe_type = "sphere"
else:
self.probe_type = None

def _get_probe_area(self):
def get_probe_area(self):
r"""Computes probe area."""
a_sphere_sunlit, a_sphere_total = [0, 0]
a_wire_sunlit, a_wire_total = [0, 0]

if isinstance(self.r_sphere, (float, int)):
a_sphere_sunlit = np.pi * self.r_sphere**2
if isinstance(self.sphere["r"], (float, int)):
a_sphere_sunlit = np.pi * self.sphere["r"] ** 2
a_sphere_total = 4 * a_sphere_sunlit

if (
self.r_wire
and isinstance(self.r_wire, (float, int, list))
and self.l_wire
and isinstance(self.l_wire, (float, int))
self.wire["r"]
and isinstance(self.wire["r"], (float, int, list))
and self.wire["l"]
and isinstance(self.wire["l"], (float, int))
):
a_wire_sunlit = 2 * np.mean(self.r_wire) * self.l_wire
a_wire_sunlit = 2 * np.mean(self.wire["r"]) * self.wire["l"]
a_wire_total = np.pi * a_wire_sunlit

self.area = {
Expand All @@ -123,7 +121,7 @@ def _get_probe_area(self):
self.area["total_sunlit"] = self.area["total"] / self.area["sunlit"]
self.area["sunlit_total"] = 1 / self.area["total_sunlit"]

def _get_probe_capa(self):
def get_probe_capa(self):
r"""Computes probe capacitance.
Raises
Expand All @@ -137,36 +135,36 @@ def _get_probe_capa(self):
"""

c_wire = 0
c_sphere = estimate("capacitance_sphere", self.r_sphere)
c_sphere = estimate("capacitance_sphere", self.sphere["r"])

if (
self.r_wire
and isinstance(self.r_wire, (float, int, list))
and self.l_wire
and isinstance(self.l_wire, (float, int))
self.wire["r"]
and isinstance(self.wire["r"], (float, int, list))
and self.wire["l"]
and isinstance(self.wire["l"], (float, int))
):
if self.l_wire > 10 * list([self.r_wire]):
if self.wire["l"] > 10 * list([self.wire["r"]]):
c_wire = estimate(
"capacitance_wire",
np.mean(self.r_wire),
self.l_wire,
np.mean(self.wire["r"]),
self.wire["l"],
)
elif self.l_wire > list(self.r_wire):
elif self.wire["l"] > list(self.wire["r"]):
c_wire = estimate(
"capacitance_cylinder",
np.mean(self.r_wire),
self.l_wire,
np.mean(self.wire["r"]),
self.wire["l"],
)
else:
raise ValueError(
"estimate of capacitance for cylinder " "requires length > radius",
"estimate of capacitance for cylinder requires length > radius",
)

self.capacitance = np.sum([c_sphere, c_wire])

def _get_probe_surface_photoemission(self):
def get_probe_surface_photoemission(self):
r"""Computes (or get) surface photo emission."""
if self.surface:
if self.sphere["surface"]:
self.s_photoemission = self.s_photoemission
else:
self.s_photoemission = photo_current(1.0, 0.0, 1.0, self.surface)
self.s_photoemission = photo_current(1.0, 0.0, 1.0, self.sphere["surface"])
3 changes: 2 additions & 1 deletion pyrfu/lp/thermal_current.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# 3rd party imports
import numpy as np

from scipy import special, constants
from scipy import constants
from scipy import special

__author__ = "Louis Richard"
__email__ = "[email protected]"
Expand Down
6 changes: 1 addition & 5 deletions pyrfu/mms/eis_ang_ang.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ def eis_ang_ang(inp_allt, en_chan: list = None, defatt: xr.Dataset = None):
coordinates_system = "GSE>Geocentric Solar Magnetospheric"

# Domain [-180, 180], 0 = sunward (GSE)
"""
phi[i, :] = (
np.rad2deg(np.arctan2(d_xyz.data[:, 1], d_xyz.data[:, 0]))
)
"""
# phi[i, :] = (np.rad2deg(np.arctan2(d_xyz.data[:, 1], d_xyz.data[:, 0])))
# Domain [0, 360], 0 = sunward (GSE)
phi[i, :] = np.rad2deg(np.arctan2(d_xyz.data[:, 1], d_xyz.data[:, 0])) + 180.0
# Domain [-90, 90], Positive is look direction northward
Expand Down
4 changes: 1 addition & 3 deletions pyrfu/mms/get_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def _shift_epochs(file, epoch):
message = " units are not clear, assume s"
warnings.warn(message)
else:
message = (
"Epoch_plus_var/Epoch_minus_var units are not " "clear, assume s"
)
message = "Epoch_plus_var/Epoch_minus_var units are not clear, assume s"
warnings.warn(message)

flag_minus, flag_plus = flags_vars
Expand Down
4 changes: 1 addition & 3 deletions pyrfu/mms/get_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def _shift_epochs(file, epoch):
message = " units are not clear, assume s"
warnings.warn(message)
else:
message = (
"Epoch_plus_var/Epoch_minus_var units are not " "clear, assume s"
)
message = "Epoch_plus_var/Epoch_minus_var units are not clear, assume s"
warnings.warn(message)

flag_minus, flag_plus = flags_vars
Expand Down
1 change: 0 additions & 1 deletion pyrfu/pyrf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
"time_clip",
"timevec2iso8601",
"trace",
"transformation_indices.json",
"ts_append",
"ts_scalar",
"ts_skymap",
Expand Down
61 changes: 33 additions & 28 deletions pyrfu/pyrf/ebsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _checksampling(e_xyz, db_xyz, b_xyz, b_bgd, flag_no_resamp):

fs_e, fs_b = [calc_fs(e_xyz), calc_fs(db_xyz)]

resample_b_options = dict(f_s=fs_b)
resample_b_options = {"f_s": fs_b}

if flag_no_resamp:
assert fs_e == fs_b
Expand Down Expand Up @@ -167,7 +167,7 @@ def _freq_int(freq_int, delta_b):
return any_range, freq_int, fs_out, out_time


@numba.jit(cache=True, nogil=True, parallel=True, nopython=True)
@numba.jit(cache=True, nogil=True, parallel=True, nopython=True, fastmath=True)
def _average_data(data=None, x=None, y=None, av_window=None):
# average data with time x to time y using window

Expand Down Expand Up @@ -217,7 +217,7 @@ def _ee_xxyyzzss(power_ex_plot, power_ey_plot, power_ez_plot, power_2e_plot):
return np.real(ee_xxyyzzss)


@numba.jit(cache=True, nogil=True, parallel=True, nopython=True)
@numba.jit(cache=True, nogil=True, parallel=True, nopython=True, fastmath=True)
def _censure_plot(inp, idx_nan, censure, n_data, a_):
out = inp.copy()

Expand Down Expand Up @@ -372,24 +372,24 @@ def ebsp(e_xyz, db_xyz, b_xyz, b_bgd, xyz, freq_int, **kwargs):

want_ee = e_xyz is not None

res = dict(
t=None,
f=None,
flagFac=0,
bb_xxyyzzss=None,
ee_xxyyzzss=None,
ee_ss=None,
pf_xyz=None,
pf_rtp=None,
dop=None,
dop2d=None,
planarity=None,
ellipticity=None,
k_tp=None,
full_b=b_xyz,
b0=b_bgd,
r=xyz,
)
res = {
"t": None,
"f": None,
"flagFac": 0,
"bb_xxyyzzss": None,
"ee_xxyyzzss": None,
"ee_ss": None,
"pf_xyz": None,
"pf_rtp": None,
"dop": None,
"dop2d": None,
"planarity": None,
"ellipticity": None,
"k_tp": None,
"full_b": b_xyz,
"b0": b_bgd,
"r": xyz,
}

want_polarization = kwargs.get("polarization", False)

Expand Down Expand Up @@ -446,7 +446,7 @@ def ebsp(e_xyz, db_xyz, b_xyz, b_bgd, xyz, freq_int, **kwargs):

if want_ee and e_xyz.shape[1] < 3 and not flag_de_dot_b0:
raise ValueError(
"E must have all 3 components or flag de_dot_db=0 " "must be given"
"E must have all 3 components or flag de_dot_db=0 must be given"
)

if len(db_xyz) % 2:
Expand All @@ -473,8 +473,9 @@ def ebsp(e_xyz, db_xyz, b_xyz, b_bgd, xyz, freq_int, **kwargs):
b_x, b_y, b_z = [b_xyz[:, i].data for i in range(3)]

# Remove the last sample if the total number of samples is odd
temp_ = _b_elevation(b_x, b_y, b_z, angle_b_elevation_max)
angle_b_elevation, idx_b_par_spin_plane = temp_
# temp_ = _b_elevation(b_x, b_y, b_z, angle_b_elevation_max)
# angle_b_elevation, idx_b_par_spin_plane = temp_
_, idx_b_par_spin_plane = _b_elevation(b_x, b_y, b_z, angle_b_elevation_max)

# If E has all three components, transform E and B waveforms to a magnetic
# field aligned coordinate (FAC) and save eisr for computation of e_sum.
Expand All @@ -493,7 +494,7 @@ def ebsp(e_xyz, db_xyz, b_xyz, b_bgd, xyz, freq_int, **kwargs):
idx_nan_eisr2 = np.isnan(eisr2.data)

if e_xyz.shape[1] < 3:
raise TypeError("E must be a 3D vector to be rotated to " "FAC")
raise TypeError("E must be a 3D vector to be rotated to FAC")

if fac_matrix is None:
e_xyz = convert_fac(e_xyz, b_bgd, xyz)
Expand Down Expand Up @@ -596,8 +597,8 @@ def ebsp(e_xyz, db_xyz, b_xyz, b_bgd, xyz, freq_int, **kwargs):

censure = np.floor(2 * a_ * out_sampling / in_sampling * n_wave_period_to_average)

for ind_a in range(len(a_)):
new_freq_mat = w_0 / a_[ind_a]
for ind_a, a_0 in enumerate(a_):
new_freq_mat = w_0 / a_0

# resample to 1 second sampling for Pc1-2 or 1 minute sampling for
# Pc3-5 average top frequencies to 1 second/1 minute below will be
Expand All @@ -610,22 +611,26 @@ def ebsp(e_xyz, db_xyz, b_xyz, b_bgd, xyz, freq_int, **kwargs):
av_window = n_wave_period_to_average / frequency_vec[ind_a]

# Get the wavelet transform by backward FFT
w_exp_mat = np.exp(-sigma * sigma * ((a_[ind_a] * w_ - w_0) ** 2) / 2)
w_exp_mat = np.exp(-sigma * sigma * ((a_0 * w_ - w_0) ** 2) / 2)
w_exp_mat2 = np.tile(w_exp_mat[:, np.newaxis], (1, 2))
w_exp_mat = np.tile(w_exp_mat[:, np.newaxis], (1, 3))

wb = fft.ifft(np.sqrt(1) * swb * w_exp_mat, axis=0, workers=os.cpu_count())
wb = np.array(wb) # Make sure it's an array (scipy.fft.ifft returns Any type)
wb[idx_nan_b] = np.nan

we, w_eisr2 = [None, None]

if want_ee:
we = fft.ifft(np.sqrt(1) * sw_e * w_exp_mat, axis=0, workers=os.cpu_count())
we = np.array(we)
we[idx_nan_e] = np.nan

if flag_want_fac and not flag_de_dot_b0:
w_eisr2 = fft.ifft(
np.sqrt(1) * sw_eisr2 * w_exp_mat2, axis=0, workers=os.cpu_count()
)
w_eisr2 = np.array(w_eisr2)
w_eisr2[idx_nan_eisr2] = np.nan

# Power spectrum of E, power = (2*pi)*conj(W).*W./new_freq_mat
Expand Down

0 comments on commit 5edad23

Please sign in to comment.