Skip to content

Commit

Permalink
ruff tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
carleyjmartin committed Aug 1, 2024
1 parent 50a3be2 commit f5e9eef
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 60 deletions.
4 changes: 1 addition & 3 deletions pydarn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
module, classes, and functions.
"""
# KEEP THIS FILE AS MINIMAL AS POSSIBLE!

import os

# ruff: noqa: F401
# version file
from .version import __version__

Expand Down
2 changes: 0 additions & 2 deletions pydarn/plotting/acf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
# supplemented by the additional permissions listed below.


import copy

import matplotlib.markers
import matplotlib.pyplot as plt
import numpy as np
Expand Down
63 changes: 31 additions & 32 deletions pydarn/plotting/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
Grid plots, mapped to AACGM coordinates in a polar format
"""

import cartopy.crs as ccrs
import datetime as dt
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -579,7 +578,7 @@ def plot_mapdata(cls, dmap_data: List[dict], ax=None,
}

@classmethod
def index_legendre(cls, l: int, m: int):
def index_legendre(cls, el: int, m: int):
"""
not a 100% how this works some black magic
Expand All @@ -594,8 +593,8 @@ def index_legendre(cls, l: int, m: int):
------
legendre index?
"""
return (m == 0 and l**2) or ((l != 0)
and (m != 0) and l**2 + 2 * m - 1) or 0
return (m == 0 and el**2) or ((el != 0)
and (m != 0) and el**2 + 2 * m - 1) or 0

@classmethod
def calculated_fitted_velocities(cls, mlats: np.array, mlons: np.array,
Expand Down Expand Up @@ -673,14 +672,14 @@ def calculated_fitted_velocities(cls, mlats: np.array, mlons: np.array,
# coefficients for elec. Field
fit_coefficient_flat = fit_coefficient.flatten()
for m in range(fit_order + 1):
for l in range(m, fit_order + 1):
k3 = cls.index_legendre(l, m)
k4 = cls.index_legendre(l, m)
for el in range(m, fit_order + 1):
k3 = cls.index_legendre(el, m)
k4 = cls.index_legendre(el, m)

if k3 >= 0:
thetas_ecoeffs[k4, q_prime] =\
thetas_ecoeffs[k4, q_prime] -\
fit_coefficient_flat[k3] * alpha * l *\
fit_coefficient_flat[k3] * alpha * el *\
np.cos(thetas_prime[q_prime]) / \
np.sin(thetas_prime[q_prime]) / Re_meters
phi_ecoeffs[k4, q] = phi_ecoeffs[k4, q] - \
Expand All @@ -690,17 +689,17 @@ def calculated_fitted_velocities(cls, mlats: np.array, mlons: np.array,
fit_coefficient_flat[k3] * m /\
np.sin(thetas[q]) / Re_meters

if l < fit_order:
k1 = cls.index_legendre(l+1, m)
if el < fit_order:
k1 = cls.index_legendre(el+1, m)
else:
k1 = -1

k2 = cls.index_legendre(l, m)
k2 = cls.index_legendre(el, m)

if k1 >= 0:
thetas_ecoeffs[k2, q_prime] =\
thetas_ecoeffs[k2, q_prime] + \
fit_coefficient_flat[k1] * alpha * (l + 1 + m) / \
fit_coefficient_flat[k1] * alpha * (el + 1 + m) / \
np.sin(thetas_prime[q_prime]) / Re_meters

if m > 0:
Expand All @@ -715,24 +714,24 @@ def calculated_fitted_velocities(cls, mlats: np.array, mlons: np.array,
if k3 >= 0:
thetas_ecoeffs[k4, q_prime] =\
thetas_ecoeffs[k4, q_prime] \
- fit_coefficient_flat[k3] * alpha * l * \
- fit_coefficient_flat[k3] * alpha * el * \
np.cos(thetas_prime[q_prime]) / \
np.sin(thetas_prime[q_prime]) / Re_meters

if k1 >= 0:
thetas_ecoeffs[k2, q_prime] = \
thetas_ecoeffs[k2, q_prime] \
+ fit_coefficient_flat[k1] * alpha *\
(l + 1 + m) / np.sin(thetas_prime[q_prime]) /\
(el + 1 + m) / np.sin(thetas_prime[q_prime]) /\
Re_meters

# Calculate the Electric field positions
thetas_ecomp = np.zeros(thetas.shape)
phi_ecomp = np.zeros(thetas.shape)

for m in range(fit_order + 1):
for l in range(m, fit_order + 1):
k = cls.index_legendre(l, m)
for el in range(m, fit_order + 1):
k = cls.index_legendre(el, m)
# Now in the IDL code we use
# legendre_poly[:,l,m] instead of
# legendre_poly[:,m,l] like here, this is
Expand All @@ -742,17 +741,17 @@ def calculated_fitted_velocities(cls, mlats: np.array, mlons: np.array,
# stores values in arrays...
if m == 0:
thetas_ecomp = thetas_ecomp + thetas_ecoeffs[k, :] * \
legendre_poly[:, m, l]
legendre_poly[:, m, el]
phi_ecomp = phi_ecomp + phi_ecoeffs[k, :] * \
legendre_poly[:, m, l]
legendre_poly[:, m, el]
else:
thetas_ecomp = thetas_ecomp + thetas_ecoeffs[k, :] * \
legendre_poly[:, m, l] * np.cos(m * phi) + \
thetas_ecoeffs[k+1, :] * legendre_poly[:, m, l] * \
legendre_poly[:, m, el] * np.cos(m * phi) + \
thetas_ecoeffs[k+1, :] * legendre_poly[:, m, el] * \
np.sin(m * phi)
phi_ecomp = phi_ecomp + phi_ecoeffs[k, :] * \
legendre_poly[:, m, l] * np.cos(m * phi) + \
phi_ecoeffs[k+1, :] * legendre_poly[:, m, l] * \
legendre_poly[:, m, el] * np.cos(m * phi) + \
phi_ecoeffs[k+1, :] * legendre_poly[:, m, el] * \
np.sin(m * phi)

# Store the two components of Efield into a single array
Expand Down Expand Up @@ -990,14 +989,14 @@ def calculate_potentials(cls, fit_coefficient: list, lat_min: list,

coeff_fit_flat = fit_coefficient.flatten()
for m in range(lmax):
for l in range(m, lmax):
k = cls.index_legendre(l, m)
for el in range(m, lmax):
k = cls.index_legendre(el, m)
if m == 0:
v = v + coeff_fit_flat[k] * plm_fit[:, 0, l]
v = v + coeff_fit_flat[k] * plm_fit[:, 0, el]
else:
v = v + coeff_fit_flat[k] * np.cos(m * phi) \
* plm_fit[:, m, l] + coeff_fit_flat[k+1] \
* np.sin(m * phi) * plm_fit[:, m, l]
* plm_fit[:, m, el] + coeff_fit_flat[k+1] \
* np.sin(m * phi) * plm_fit[:, m, el]

pot_arr = np.zeros((num_lons, num_lats))
pot_arr = np.reshape(v, pot_arr.shape) / 1000.0
Expand Down Expand Up @@ -1092,14 +1091,14 @@ def calculate_potentials_pos(cls, mlat, mlon, fit_coefficient: list,

coeff_fit_flat = fit_coefficient.flatten()
for m in range(lmax):
for l in range(m, lmax):
k = cls.index_legendre(l, m)
for el in range(m, lmax):
k = cls.index_legendre(el, m)
if m == 0:
v = v + coeff_fit_flat[k] * plm_fit[:, 0, l]
v = v + coeff_fit_flat[k] * plm_fit[:, 0, el]
else:
v = v + coeff_fit_flat[k] * np.cos(m * phi) \
* plm_fit[:, m, l] + coeff_fit_flat[k + 1] \
* np.sin(m * phi) * plm_fit[:, m, l]
* plm_fit[:, m, el] + coeff_fit_flat[k + 1] \
* np.sin(m * phi) * plm_fit[:, m, el]

# Convert from V to kV
v /= 1000
Expand Down
5 changes: 1 addition & 4 deletions pydarn/plotting/projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
Code which generates axis objects for use in plotting functions
"""
import aacgmv2
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.feature.nightshade import Nightshade
Expand All @@ -34,10 +33,8 @@
from matplotlib import axes
import matplotlib.ticker as mticker
import numpy as np
from packaging import version

from pydarn import (Hemisphere, plot_exceptions, Re,
nightshade_warning)
from pydarn import (Hemisphere, Re, nightshade_warning)


def convert_geo_coastline_to_mag(geom, date, alt: float = 0.0, mag_lon: bool = False):
Expand Down
2 changes: 0 additions & 2 deletions pydarn/utils/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
np.float32: 'f',
np.float64: 'd',
str: 's',
str: 's',
str: 's',
np.int64: 'q',
np.uint8: 'B',
np.uint16: 'H',
Expand Down
2 changes: 1 addition & 1 deletion pydarn/utils/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def __do_filter__(self, scans, params_to_run_filter=["v", "w_l",
beam.copy(b)

for key in beam.__dict__.keys():
if type(getattr(beam, key)) == np.ndarray:
if type(getattr(beam, key)) is np.ndarray:
setattr(beam, key, [])

for r in range(0, b.nrang):
Expand Down
2 changes: 0 additions & 2 deletions pydarn/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import enum
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
import warnings

from typing import List
Expand Down
19 changes: 8 additions & 11 deletions pydarn/utils/terminator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
# Modification:
#

import aacgmv2

import numpy as np
import datetime as dt
import matplotlib.pyplot as plt

from pydarn import Re

Expand Down Expand Up @@ -151,11 +148,11 @@ def solar_geometric_mean_longitude(centuries):
"""
# Mean longitude of sun at base julian date = 280.46646 degrees
# Corrections from J.Meeus Astronomical Algorithms book
l = (280.46646 + centuries * (36000.76983 + centuries * 0.0003032)) % 360
el = (280.46646 + centuries * (36000.76983 + centuries * 0.0003032)) % 360
# Give value between 0 and 360
if l < 0:
l = l + 360
mean_long = np.radians(l)
if el < 0:
el = el + 360
mean_long = np.radians(el)
return mean_long


Expand Down Expand Up @@ -234,11 +231,11 @@ def equation_of_time(centuries):
# http://www.esrl.noaa.gov/gmd/grad/solcalc/
e = eccentricity_earths_orbit(centuries)
m = solar_geometric_mean_anomaly(centuries)
l = solar_geometric_mean_longitude(centuries)
el = solar_geometric_mean_longitude(centuries)
y = np.tan(obliquity_correction(centuries) /2)
time_eq = y * np.sin(2 * l) - 2 * e * np.sin(m) + 4 * e * y * np.sin(m)\
* np.cos(2 * l) - 0.5 * y * y * np.sin(4 * l)\
- 1.25 * e * e * np.sin(2 * m);
time_eq = y * np.sin(2 * el) - 2 * e * np.sin(m) + 4 * e * y * np.sin(m)\
* np.cos(2 * el) - 0.5 * y * y * np.sin(4 * el)\
- 1.25 * e * e * np.sin(2 * m)
return time_eq


Expand Down
1 change: 0 additions & 1 deletion test/test_Grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# and conditions of version 3 of the GNU General Public License,
# supplemented by the additional permissions listed below.

import bz2
import datetime as dt
import matplotlib.pyplot as plt
import pytest
Expand Down
1 change: 0 additions & 1 deletion test/test_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# and conditions of version 3 of the GNU General Public License,
# supplemented by the additional permissions listed below.

import datetime as dt
import matplotlib.pyplot as plt
import pytest
import warnings
Expand Down
1 change: 0 additions & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import bz2
import datetime as dt
import matplotlib.pyplot as plt
import pytest
import warnings

Expand Down

0 comments on commit f5e9eef

Please sign in to comment.