Skip to content

Commit

Permalink
Merge pull request #7343 from nabobalis/pep8
Browse files Browse the repository at this point in the history
Ran the autopep8 linter for pyopensci review
  • Loading branch information
nabobalis committed Jan 10, 2024
2 parents 7961e29 + 5fa723f commit 86c517b
Show file tree
Hide file tree
Showing 51 changed files with 174 additions and 159 deletions.
3 changes: 0 additions & 3 deletions .jupyter/jupyter_notebook_config.py

This file was deleted.

1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ exclude tox.ini

prune .circleci
prune .github
prune .jupyter
prune benchmarks
prune binder
prune changelog
Expand Down
1 change: 1 addition & 0 deletions examples/showcase/eclipse_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# Define a function to calculate start/end eclipse times and plot the eclipse
# timeseries within +/- 2 hours of the time of interest.


def plot_eclipse_timeseries(location, time):
# Define an array of observation times centered around the time of interest
times = time + np.concatenate([np.arange(-120, -5) * u.min,
Expand Down
24 changes: 13 additions & 11 deletions examples/showcase/stereoscopic_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,24 @@
# same direction, but at a distance of 1 AU, and then reproject both maps. The
# purpose is to make the Sun exactly the same size in pixels in both maps.


def reproject_to_1au(in_map):
header = sunpy.map.make_fitswcs_header(
(1000, 1000),
SkyCoord(
0*u.arcsec, 0*u.arcsec,
frame='helioprojective',
obstime=in_map.date,
observer=in_map.observer_coordinate.realize_frame(
in_map.observer_coordinate.represent_as('unitspherical') * u.AU
)
),
scale=(2.2, 2.2)*u.arcsec/u.pixel
)
(1000, 1000),
SkyCoord(
0*u.arcsec, 0*u.arcsec,
frame='helioprojective',
obstime=in_map.date,
observer=in_map.observer_coordinate.realize_frame(
in_map.observer_coordinate.represent_as('unitspherical') * u.AU
)
),
scale=(2.2, 2.2)*u.arcsec/u.pixel
)
with Helioprojective.assume_spherical_screen(in_map.observer_coordinate):
return in_map.reproject_to(header)


euvi_map = reproject_to_1au(euvi_map)
aia_map = reproject_to_1au(aia_map)

Expand Down
4 changes: 4 additions & 0 deletions examples/showcase/where_is_stereo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

hee_frame = HeliocentricEarthEcliptic(obstime=obstime)


def get_first_orbit(coord):
lon = coord.transform_to(hee_frame).spherical.lon
shifted = Longitude(lon - lon[0])
Expand All @@ -44,6 +45,7 @@ def get_first_orbit(coord):
return coord[:ends[0]]
return coord


##############################################################################
# Obtain the locations and trajectories of the various planets and spacecraft.
# To ensure that each trajectory contains at least one full orbit, we request
Expand All @@ -68,11 +70,13 @@ def get_first_orbit(coord):
# Define a convenience function for converting coordinates to plot positions
# in the ecliptic plane.


def coord_to_heexy(coord):
coord = coord.transform_to(hee_frame)
coord.representation_type = 'cartesian'
return coord.y.to_value('AU'), coord.x.to_value('AU')


##############################################################################
# Set Matplotlib settings to the desired appearance and initialize the axes.

Expand Down
2 changes: 1 addition & 1 deletion examples/time_series/goes_hek_m25.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Here we are searching for data from the GOES-15 satellite and for the 1-min average time-sampled data.

tr = a.Time('2011-06-07 04:00', '2011-06-07 12:00')
results = Fido.search(tr, a.Instrument.xrs & a.goes.SatelliteNumber(15) & a.Resolution("avg1m") | a.hek.FL & (a.hek.FRM.Name == 'SWPC')) # NOQA
results = Fido.search(tr, a.Instrument.xrs & a.goes.SatelliteNumber(15) & a.Resolution("avg1m") | a.hek.FL & (a.hek.FRM.Name == 'SWPC'))

###############################################################################
# Then download the XRS data and load it into a TimeSeries.
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ extend-ignore = [
"sunpy/util/exceptions.py" = ["TID251"]
"sunpy/util/tests/test_logger.py" = ["TID251"]
"sunpy/util/decorators.py" = ["TID251"]
# Notebook config for binder uses undefined variable
".jupyter/jupyter_notebook_config.py" = ["F821"]

[tool.ruff.pydocstyle]
convention = "numpy"
13 changes: 10 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ use_extension_helpers = true

[tool:pytest]
testpaths = "sunpy" "docs"
norecursedirs = ".tox" "build" "docs[\/]_build" "docs[\/]generated" "*.egg-info" "examples" "sunpy[/\]_dev" ".jupyter" ".history" "tools" "sunpy[\/]extern" "benchmarks"
norecursedirs = ".tox" "build" "docs[\/]_build" "docs[\/]generated" "*.egg-info" "examples" "sunpy[/\]_dev" ".history" "tools" "sunpy[\/]extern" "benchmarks"
doctest_plus = enabled
doctest_optionflags = NORMALIZE_WHITESPACE FLOAT_CMP ELLIPSIS
addopts = --dist no --arraydiff --doctest-rst --doctest-ignore-import-errors -p no:unraisableexception -p no:threadexception -m "not mpl_image_compare"
Expand Down Expand Up @@ -240,10 +240,17 @@ filterwarnings =
# Can be removed when https://github.com/dateutil/dateutil/issues/1314 is resolved
ignore:datetime.datetime.utcfromtimestamp():DeprecationWarning

[pycodestyle]
max_line_length = 110

[flake8]
ignore =
E225, # missing-whitespace-around-operator
E226, # missing-whitespace-around-arithmetic-operator
E501, # line-too-long
F401, # unused-import
F403, # undefined-local-with-import-star
F811, # redefined-while-unused
W503, # Line break occurred before a binary operator
W504, # Line break occurred after a binary operator
max-line-length = 110
exclude =
.git,
Expand Down
6 changes: 3 additions & 3 deletions sunpy/coordinates/_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ def _observers_are_equal(obs_1, obs_2):
"source observer is different.")

return np.atleast_1d(u.allclose(obs_1.lat, obs_2.lat) and
u.allclose(obs_1.lon, obs_2.lon) and
u.allclose(obs_1.radius, obs_2.radius) and
_times_are_equal(obs_1.obstime, obs_2.obstime)).all()
u.allclose(obs_1.lon, obs_2.lon) and
u.allclose(obs_1.radius, obs_2.radius) and
_times_are_equal(obs_1.obstime, obs_2.obstime)).all()


def _check_observer_defined(frame):
Expand Down
7 changes: 3 additions & 4 deletions sunpy/coordinates/spice.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ def __init_subclass__(cls, **kwargs):
f"Origin: '{cls._center_name}'\n\n"
"Parameters\n----------\n"
f"obstime : {_variables_for_parse_time_docstring()['parse_time_types']}\n"
" The time of the observation. This is used to determine the\n"
" position of solar-system bodies (e.g., the Sun and the Earth) as\n"
" needed to define the origin and orientation of the frame.\n")

" The time of the observation. This is used to determine the\n"
" position of solar-system bodies (e.g., the Sun and the Earth) as\n"
" needed to define the origin and orientation of the frame.\n")

def to_helioprojective(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions sunpy/coordinates/tests/test_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ def test_hcc_default_observer():


@pytest.mark.parametrize(('x', 'y', 'psi'), [(0*u.km, -1*u.km, 270*u.deg),
(0*u.km, 1*u.km, 90*u.deg),
(-1*u.km, 0*u.km, 180*u.deg)])
(0*u.km, 1*u.km, 90*u.deg),
(-1*u.km, 0*u.km, 180*u.deg)])
def test_heliocentric_radial_psi(x, y, psi):
# The cylindrical representation of HCC is Heliocentric Radial
# Test that the `psi` component is represented as desired
Expand Down
6 changes: 3 additions & 3 deletions sunpy/coordinates/tests/test_metaframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_class_creation(indirect_fixture):
assert base_class.__name__ in rot_class.__name__

# Check that the base class is in fact the specified class
assert type(rot_frame.base) == base_class
assert type(rot_frame.base) == base_class # NOQA: E721

# Check that the new class does *not* have the `obstime` frame attribute
assert 'obstime' not in rot_frame.frame_attributes
Expand All @@ -114,7 +114,7 @@ def test_as_base(rot_hgs):
# Check the as_base() method
a = rot_hgs[1].as_base()

assert type(a) == type(rot_hgs[1].base) # noqa: E721
assert type(a) == type(rot_hgs[1].base) # NOQA: E721

assert_longitude_allclose(a.lon, rot_hgs[1].lon)
assert_quantity_allclose(a.lat, rot_hgs[1].lat)
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_base_skycoord(rot_hgs):
s = SkyCoord(1*u.deg, 2*u.deg, 3*u.AU, frame=f.HeliographicStonyhurst, obstime='2001-01-01')
r = RotatedSunFrame(base=s)

assert type(r) == type(rot_hgs[1]) # noqa: E721
assert type(r) == type(rot_hgs[1]) # NOQA: E721
assert r.has_data
assert not r.base.has_data

Expand Down
13 changes: 7 additions & 6 deletions sunpy/coordinates/tests/test_sun.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def test_L0_astronomical_almanac():
'2013-04-01': 221.44,
'2013-05-01': 185.30,
'2013-06-01': 135.30,
'2013-07-01': 98.22, # NOQA
'2013-08-01': 48.03, # NOQA
'2013-07-01': 98.22,
'2013-08-01': 48.03,
'2013-09-01': 358.28,
'2013-10-01': 322.22,
'2013-11-01': 273.31,
Expand All @@ -288,8 +288,8 @@ def test_L0_jpl_horizons():
'2013-04-01': 221.440599,
'2013-05-01': 185.306476,
'2013-06-01': 135.303097,
'2013-07-01': 98.221806, # NOQA
'2013-08-01': 48.035951, # NOQA
'2013-07-01': 98.221806,
'2013-08-01': 48.035951,
'2013-09-01': 358.289921,
'2013-10-01': 322.226009,
'2013-11-01': 273.315206,
Expand Down Expand Up @@ -488,7 +488,7 @@ def test_carrington_rotation_time_longitude(crot, longitude, crot_fractional):
[180, 90]), np.array([2000.5, 2000.75])),
(2000, np.array([180, 90]), np.array([2000.5, 2000.75])),
(np.array([2000, 2000]), 180, np.array([2000.5, 2000.5]))
])
])
def test_carrington_rotation_time_longitude_numpy(crot, longitude, crot_fractional):
assert all(sun.carrington_rotation_time(crot*u.one, longitude*u.deg) ==
sun.carrington_rotation_time(crot_fractional*u.one))
Expand All @@ -500,7 +500,7 @@ def test_carrington_rotation_time_longitude_numpy(crot, longitude, crot_fraction
(2000, -10),
(2000, 400),
(2000.5, 180),
])
])
def test_carrington_rotation_time_longitude_err(crot, longitude):
with pytest.raises(ValueError):
sun.carrington_rotation_time(crot*u.one, longitude*u.deg)
Expand Down Expand Up @@ -541,6 +541,7 @@ def test_eclipse_amount(use_DE440s):
assert sun.eclipse_amount(location.get_itrs(Time('2024-04-08 19:55:58'))) > 0
assert sun.eclipse_amount(location.get_itrs(Time('2024-04-08 19:56:01'))) == 0


@pytest.mark.remote_data
@pytest.mark.filterwarnings("ignore:Tried to get polar motions for times after IERS data is valid.")
@pytest.mark.filterwarnings("ignore:.*times are outside of range covered by IERS table.")
Expand Down
32 changes: 16 additions & 16 deletions sunpy/coordinates/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@


@pytest.mark.parametrize(("start", "end"), [((0, 0), (0, 45)),
((0, 0), (45, 0)),
((0, 45), (0, 0)),
((45, 0), (0, 0)),
((12, 13), (12, 58)),
((-10, 6), (-10, 51)),
((-20, -50), (-20, -5)),
((10, -50), (87.53163324626676, -55))])
((0, 0), (45, 0)),
((0, 45), (0, 0)),
((45, 0), (0, 0)),
((12, 13), (12, 58)),
((-10, 6), (-10, 51)),
((-20, -50), (-20, -5)),
((10, -50), (87.53163324626676, -55))])
def test_great_arc_calculable(start, end):
c = SkyCoord(start[0]*u.degree, start[1]*u.degree, frame=frames.HeliographicStonyhurst,
observer=frames.HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU))
Expand Down Expand Up @@ -251,14 +251,14 @@ def rectangle_args():


def test_rectangle_incomplete_input(rectangle_args):
bottom_left, top_right, width, height = rectangle_args
bottom_left, _, _, height = rectangle_args

with pytest.raises(ValueError):
get_rectangle_coordinates(bottom_left, height=height)


def test_rectangle_invalid_input(rectangle_args):
bottom_left, top_right, width, height = rectangle_args
_, _, width, height = rectangle_args

with pytest.raises(TypeError):
get_rectangle_coordinates(width, height=height)
Expand All @@ -272,24 +272,24 @@ def test_rectangle_all_parameters_passed(rectangle_args):


def test_rectangle_width_height(rectangle_args):
bottom_left, top_right, width, height = rectangle_args
bottom_left, _, width, height = rectangle_args

bottom_left_1, top_right_1 = get_rectangle_coordinates(bottom_left, width=width, height=height)
_, top_right_1 = get_rectangle_coordinates(bottom_left, width=width, height=height)

assert bottom_left.spherical.lon + width == top_right_1.spherical.lon
assert bottom_left.spherical.lat + height == top_right_1.spherical.lat


def test_rectangle_mismatching_frames_missing_parameters(rectangle_args):
bottom_left, top_right, width, height = rectangle_args
bottom_left, top_right, _, _ = rectangle_args
top_right = SkyCoord(10 * u.arcsec, 10 * u.arcsec, frame='heliographic_carrington')

with pytest.raises(ConvertError):
bottom_left, top_right = get_rectangle_coordinates(bottom_left, top_right=top_right)


def test_rectangle_top_right(rectangle_args):
bottom_left, top_right, width, height = rectangle_args
bottom_left, top_right, _, _ = rectangle_args

bottom_left_1, top_right_1 = get_rectangle_coordinates(bottom_left, top_right=top_right)

Expand All @@ -300,20 +300,20 @@ def test_rectangle_top_right(rectangle_args):


def test_rectangle_bottom_left_different_types(rectangle_args):
bottom_left, top_right, width, height = rectangle_args
bottom_left, _, width, height = rectangle_args

bottom_left_1, top_right_1 = get_rectangle_coordinates(
bottom_left.frame, width=width, height=height)

assert bottom_left.spherical.lon + width == top_right_1.spherical.lon
assert bottom_left.spherical.lat + height == top_right_1.spherical.lat
assert type(bottom_left_1) == type(top_right_1) == type(bottom_left.frame) # noqa: E721
assert type(bottom_left_1) == type(top_right_1) == type(bottom_left.frame) # NOQA: E721

bottom_left_2, top_right_2 = get_rectangle_coordinates(bottom_left, width=width, height=height)

assert bottom_left.spherical.lon + width == top_right_2.spherical.lon
assert bottom_left.spherical.lat + height == top_right_2.spherical.lat
assert type(bottom_left_2) == type(top_right_2) == type(bottom_left)
assert type(bottom_left_2) == type(top_right_2) == type(bottom_left) # NOQA: E721


def test_rectangle_bottom_left_vector():
Expand Down
10 changes: 5 additions & 5 deletions sunpy/coordinates/tests/test_wcs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@


@pytest.mark.parametrize(('ctype', 'frame'), [[['HPLN', 'HPLT'], Helioprojective],
[['HPLT', 'HPLN'], Helioprojective],
[['HGLN', 'HGLT'], HeliographicStonyhurst],
[['CRLN', 'CRLT'], HeliographicCarrington],
[['SOLX', 'SOLY'], Heliocentric]
])
[['HPLT', 'HPLN'], Helioprojective],
[['HGLN', 'HGLT'], HeliographicStonyhurst],
[['CRLN', 'CRLT'], HeliographicCarrington],
[['SOLX', 'SOLY'], Heliocentric]
])
def test_wcs_frame_mapping(ctype, frame):
wcs = WCS(naxis=2)
wcs.wcs.ctype = ctype
Expand Down
4 changes: 2 additions & 2 deletions sunpy/coordinates/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ def get_rectangle_coordinates(bottom_left, *, top_right=None,
"Invalid input, bottom_left must be of type SkyCoord or BaseCoordinateFrame.")

if (top_right is not None and not (hasattr(top_right, 'transform_to') and
hasattr(top_right, 'shape') and
hasattr(top_right, 'spherical'))):
hasattr(top_right, 'shape') and
hasattr(top_right, 'spherical'))):
raise TypeError("Invalid input, top_right must be of type SkyCoord or BaseCoordinateFrame.")

if bottom_left.shape == (2,) and any(x is not None for x in (width, height, top_right)):
Expand Down
6 changes: 1 addition & 5 deletions sunpy/coordinates/wcs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ def obsgeo_to_frame(obsgeo, obstime):
non-finite values included.
"""
if (obsgeo is None
or len(obsgeo) != 6
or np.all(np.array(obsgeo) == 0)
or np.all(~np.isfinite(obsgeo))
): # NOQA
if obsgeo is None or len(obsgeo) != 6 or np.all(np.array(obsgeo) == 0) or np.all(~np.isfinite(obsgeo)):
raise ValueError(f"Can not parse the 'obsgeo' location ({obsgeo}). "
"obsgeo should be a length 6 non-zero, finite numpy array")

Expand Down
2 changes: 1 addition & 1 deletion sunpy/data/data_manager/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def override_file_tester(manager):
with manager.override_file('test_file', f'file://{folder}/another_file', MOCK_HASH):
data_function(override_file_tester)

with pytest.raises(ValueError): # noqa: PT012
with pytest.raises(ValueError, match="Hash provided to override_file does not match hash of the file."):
# check if functions errors with the wrong hash
with manager.override_file('test_file', f'file://{folder}/another_file', 'wrong_hash'):
# Inside the file is replaced
Expand Down
2 changes: 1 addition & 1 deletion sunpy/data/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@


# file_dict and file_list are not normal variables; see __getattr__() below
__all__ = list(sorted(_SAMPLE_DATA.keys())) + ['download_all', 'file_dict', 'file_list'] # noqa: F822
__all__ = list(sorted(_SAMPLE_DATA.keys())) + ['download_all', 'file_dict', 'file_list'] # NOQA: F822


# See PEP 562 (https://peps.python.org/pep-0562/) for module-level __dir__()
Expand Down

0 comments on commit 86c517b

Please sign in to comment.