Skip to content

Commit c4e2f42

Browse files
committed
Adheres to line length rule
1 parent d867367 commit c4e2f42

File tree

8 files changed

+50
-31
lines changed

8 files changed

+50
-31
lines changed

.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ extend-ignore = [
4949
# flake8-use-pathlib
5050
"PTH123", # open() should be replaced by Path.open()
5151
# Ruff
52+
"RUF003", # Ignore ambiguous quote marks, doesn't allow ' in comments
5253
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
5354
"RUF013", # PEP 484 prohibits implicit `Optional`
5455
"RUF015", # Prefer `next(iter(...))` over single element slice

ndcube/tests/helpers.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@ def get_hash_library_name():
3434
Generate the hash library name for this env.
3535
"""
3636
ft2_version = f"{mpl.ft2font.__freetype_version__.replace('.', '')}"
37-
animators_version = "dev" if (("dev" in mpl_animators.__version__) or ("rc" in mpl_animators.__version__)) else mpl_animators.__version__.replace('.', '')
38-
mpl_version = "dev" if (("dev" in mpl.__version__) or ("rc" in mpl.__version__)) else mpl.__version__.replace('.', '')
39-
astropy_version = "dev" if (("dev" in astropy.__version__) or ("rc" in astropy.__version__)) else astropy.__version__.replace('.', '')
40-
return f"figure_hashes_mpl_{mpl_version}_ft_{ft2_version}_astropy_{astropy_version}_animators_{animators_version}.json"
37+
animators_version = "dev" if (("dev" in mpl_animators.__version__)
38+
or ("rc" in mpl_animators.__version__))\
39+
else mpl_animators.__version__.replace('.', '')
40+
mpl_version = "dev" if (("dev" in mpl.__version__)
41+
or ("rc" in mpl.__version__)) \
42+
else mpl.__version__.replace('.', '')
43+
astropy_version = "dev" if (("dev" in astropy.__version__)
44+
or ("rc" in astropy.__version__)) \
45+
else astropy.__version__.replace('.', '')
46+
return (f"figure_hashes_mpl_{mpl_version}_ft_{ft2_version}"
47+
f"_astropy_{astropy_version}_animators_{animators_version}.json")
4148

4249

4350
def figure_test(test_function):
@@ -107,7 +114,8 @@ def assert_cubes_equal(test_input, expected_cube, check_data=True):
107114
assert np.all(test_input.shape == expected_cube.shape)
108115
assert_metas_equal(test_input.meta, expected_cube.meta)
109116
if type(test_input.extra_coords) is not type(expected_cube.extra_coords):
110-
raise AssertionError(f"NDCube extra_coords not of same type: {type(test_input.extra_coords)} != {type(expected_cube.extra_coords)}")
117+
raise AssertionError(f"NDCube extra_coords not of same type: "
118+
f"{type(test_input.extra_coords)} != {type(expected_cube.extra_coords)}")
111119
if test_input.extra_coords is not None:
112120
assert_extra_coords_equal(test_input.extra_coords, expected_cube.extra_coords)
113121

@@ -147,7 +155,8 @@ def assert_wcs_are_equal(wcs1, wcs2):
147155
# SlicedLowLevelWCS vs BaseHighLevelWCS don't have the same pixel_to_world method
148156
low_level_wcs1 = wcs1.low_level_wcs if isinstance(wcs1, BaseHighLevelWCS) else wcs1
149157
low_level_wcs2 = wcs2.low_level_wcs if isinstance(wcs2, BaseHighLevelWCS) else wcs2
150-
np.testing.assert_array_equal(low_level_wcs1.pixel_to_world_values(*random_idx.T), low_level_wcs2.pixel_to_world_values(*random_idx.T))
158+
np.testing.assert_array_equal(low_level_wcs1.pixel_to_world_values(*random_idx.T),
159+
low_level_wcs2.pixel_to_world_values(*random_idx.T))
151160

152161
def create_sliced_wcs(wcs, item, dim):
153162
"""

ndcube/tests/test_ndcube.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def test_axis_world_coords_empty_ec(ndcube_3d_l_ln_lt_ectime):
199199
# slice the cube so extra_coords is empty, and then try and run axis_world_coords
200200
awc = sub_cube.axis_world_coords(wcs=sub_cube.extra_coords)
201201
assert awc == ()
202-
sub_cube._generate_world_coords(pixel_corners=False, wcs=sub_cube.extra_coords)
202+
sub_cube._generate_world_coords(pixel_corners=False, wcs=sub_cube.extra_coords, units=True)
203203
assert awc == ()
204204

205205

@@ -543,7 +543,7 @@ def test_crop_by_values_with_equivalent_units(ndcube_2d_ln_lt):
543543
lower_corner = [(coord[0]*u.deg).to(u.arcsec) for coord in intervals]
544544
upper_corner = [(coord[-1]*u.deg).to(u.arcsec) for coord in intervals]
545545
expected = ndcube_2d_ln_lt[0:4, 1:7]
546-
output = ndcube_2d_ln_lt.crop_by_values(lower_corner, upper_is this locallycorner)
546+
output = ndcube_2d_ln_lt.crop_by_values(lower_corner, upper_corner)
547547
helpers.assert_cubes_equal(output, expected)
548548

549549

@@ -664,7 +664,7 @@ def test_crop_by_extra_coords_shared_axis(ndcube_3d_ln_lt_l_ec_sharing_axis):
664664
helpers.assert_cubes_equal(output, expected)
665665

666666

667-
def test_crop_by_extra_coords_values_shared_axis(ndcube_3d_ln_is this locallylt_l_ec_sharing_axis):
667+
def test_crop_by_extra_coords_values_shared_axis(ndcube_3d_ln_lt_l_ec_sharing_axis):
668668
cube = ndcube_3d_ln_lt_l_ec_sharing_axis
669669
lower_corner = (1 * u.m, 1 * u.keV)
670670
upper_corner = (2 * u.m, 2 * u.keV)
@@ -784,7 +784,6 @@ def test_reproject_shape_out(ndcube_4d_ln_l_t_lt, wcs_4d_lt_t_l_ln):
784784
wcs_4d_lt_t_l_ln.pixel_shape = None
785785
with pytest.raises(Exception):
786786
_ = ndcube_4d_ln_l_t_lt.reproject_to(wcs_4d_lt_t_l_ln)
787-
is this locally
788787
# should not raise an exception when shape_out is specified
789788
shape = (5, 10, 12, 8)
790789
_ = ndcube_4d_ln_l_t_lt.reproject_to(wcs_4d_lt_t_l_ln, shape_out=shape)
@@ -819,11 +818,11 @@ def test_rebin(ndcube_3d_l_ln_lt_ectime):
819818
expected_uncertainty = None
820819
expected_unit = cube.unit
821820
expected_meta = cube.meta
822-
expected_Tx = np.array([[9.99999999, 19.99999994, 29.99999979, 39.9999995,
821+
expected_tx = np.array([[9.99999999, 19.99999994, 29.99999979, 39.9999995,
823822
49.99999902, 59.99999831, 69.99999731, 79.99999599],
824823
[9.99999999, 19.99999994, 29.99999979, 39.9999995,
825824
49.99999902, 59.99999831, 69.99999731, 79.99999599]]) * u.arcsec
826-
expected_Ty = np.array([[-14.99999996, -14.9999999, -14.99999981, -14.99999969,
825+
expected_ty = np.array([[-14.99999996, -14.9999999, -14.99999981, -14.99999969,
827826
-14.99999953, -14.99999934, -14.99999911, -14.99999885],
828827
[-4.99999999, -4.99999998, -4.99999995, -4.9999999,
829828
-4.99999985, -4.99999979, -4.99999971, -4.99999962]]) * u.arcsec
@@ -836,10 +835,10 @@ def test_rebin(ndcube_3d_l_ln_lt_ectime):
836835
assert np.all(output.data == expected_data)
837836
assert np.all(output.mask == expected_mask)
838837
assert output.uncertainty == expected_uncertainty
839-
assert output.unit == expected_unitis this locally
838+
assert output.unit == expected_unit
840839
assert output.meta == expected_meta
841-
assert u.allclose(output_sc.Tx, expected_Tx)
842-
assert u.allclose(output_sc.Ty, expected_Ty)
840+
assert u.allclose(output_sc.Tx, expected_tx)
841+
assert u.allclose(output_sc.Ty, expected_ty)
843842
assert u.allclose(output_spec, expected_spec)
844843
assert output_time.scale == expected_time.scale
845844
assert output_time.format == expected_time.format
@@ -957,13 +956,15 @@ def test_rebin_no_propagate(ndcube_2d_ln_lt_mask_uncert):
957956
bin_shape = (2, 4)
958957

959958
cube._mask[:] = True
960-
with pytest.warns(NDCubeUserWarning, match="Uncertainties cannot be propagated as all values are masked and operation_ignores_mask is False."):
959+
with pytest.warns(NDCubeUserWarning, match="Uncertainties cannot be propagated as all values "
960+
"are masked and operation_ignores_mask is False."):
961961
output = cube.rebin(bin_shape, operation=np.sum, propagate_uncertainties=True,
962962
operation_ignores_mask=False)
963963
assert output.uncertainty is None
964964

965965
cube._mask = True
966-
with pytest.warns(NDCubeUserWarning, match="Uncertainties cannot be propagated as all values are masked and operation_ignores_mask is False."):
966+
with pytest.warns(NDCubeUserWarning, match="Uncertainties cannot be propagated as all values "
967+
"are masked and operation_ignores_mask is False."):
967968
output = cube.rebin(bin_shape, operation=np.sum, propagate_uncertainties=True,
968969
operation_ignores_mask=False)
969970
assert output.uncertainty is None
@@ -1103,7 +1104,7 @@ def test_cube_arithmetic_rsubtract(ndcube_2d_ln_lt_units, value):
11031104
])
11041105
def test_cube_arithmetic_multiply(ndcube_2d_ln_lt_units, value):
11051106
cube_quantity = u.Quantity(ndcube_2d_ln_lt_units.data, ndcube_2d_ln_lt_units.unit)
1106-
new_cube = ndcube_2d_ln_lt_units * valueis this locally
1107+
new_cube = ndcube_2d_ln_lt_units * value
11071108
check_arithmetic_value_and_units(new_cube, cube_quantity * value)
11081109
# TODO: test that uncertainties scale correctly
11091110

@@ -1148,7 +1149,8 @@ def test_cube_arithmetic_rdivide(ndcube_2d_ln_lt_units, value):
11481149
@pytest.mark.parametrize('value', [1, 2, -1])
11491150
def test_cube_arithmetic_rdivide_uncertainty(ndcube_4d_unit_uncertainty, value):
11501151
cube_quantity = u.Quantity(ndcube_4d_unit_uncertainty.data, ndcube_4d_unit_uncertainty.unit)
1151-
with pytest.warns(NDCubeUserWarning, match="UnknownUncertainty does not support uncertainty propagation with correlation. Setting uncertainties to None."):
1152+
with pytest.warns(NDCubeUserWarning, match="UnknownUncertainty does not support uncertainty "
1153+
"propagation with correlation. Setting uncertainties to None."):
11521154
with np.errstate(divide='ignore'):
11531155
new_cube = value / ndcube_4d_unit_uncertainty
11541156
check_arithmetic_value_and_units(new_cube, value / cube_quantity)
@@ -1187,7 +1189,8 @@ def test_cube_arithmetic_power(ndcube_2d_ln_lt, power):
11871189
@pytest.mark.parametrize('power', [2, -2, 10, 0.5])
11881190
def test_cube_arithmetic_power_unknown_uncertainty(ndcube_4d_unit_uncertainty, power):
11891191
cube_quantity = u.Quantity(ndcube_4d_unit_uncertainty.data, ndcube_4d_unit_uncertainty.unit)
1190-
with pytest.warns(NDCubeUserWarning, match="UnknownUncertainty does not support uncertainty propagation with correlation. Setting uncertainties to None."):
1192+
with pytest.warns(NDCubeUserWarning, match="UnknownUncertainty does not support uncertainty propagation "
1193+
"with correlation. Setting uncertainties to None."):
11911194
with np.errstate(divide='ignore'):
11921195
new_cube = ndcube_4d_unit_uncertainty ** power
11931196
check_arithmetic_value_and_units(new_cube, cube_quantity**power)
@@ -1196,7 +1199,9 @@ def test_cube_arithmetic_power_unknown_uncertainty(ndcube_4d_unit_uncertainty, p
11961199
@pytest.mark.parametrize('power', [2, -2, 10, 0.5])
11971200
def test_cube_arithmetic_power_std_uncertainty(ndcube_2d_ln_lt_uncert, power):
11981201
cube_quantity = u.Quantity(ndcube_2d_ln_lt_uncert.data, ndcube_2d_ln_lt_uncert.unit)
1199-
with pytest.warns(NDCubeUserWarning, match=r"<class 'astropy.nddata.nduncertainty.StdDevUncertainty'> does not support propagation of uncertainties for power. Setting uncertainties to None."):
1202+
with pytest.warns(NDCubeUserWarning, match=r"<class 'astropy.nddata.nduncertainty.StdDevUncertainty'> "
1203+
r"does not support propagation of uncertainties for power. "
1204+
r"Setting uncertainties to None."):
12001205
with np.errstate(divide='ignore'):
12011206
new_cube = ndcube_2d_ln_lt_uncert ** power
12021207
check_arithmetic_value_and_units(new_cube, cube_quantity**power)
@@ -1214,7 +1219,7 @@ def test_to(ndcube_1d_l, new_unit):
12141219

12151220
def test_to_dask(ndcube_2d_dask):
12161221
output = ndcube_2d_dask.to(u.mJ)
1217-
dask_type = dask.array.core.Arrayis this locally
1222+
dask_type = dask.array.core.Array
12181223
assert isinstance(output.data, dask_type)
12191224
assert isinstance(output.uncertainty.array, dask_type)
12201225
assert isinstance(output.mask, dask_type)
@@ -1230,9 +1235,11 @@ def test_squeeze(ndcube_4d_ln_l_t_lt):
12301235

12311236
def test_squeeze_error(ndcube_4d_ln_l_t_lt):
12321237
same = ndcube_4d_ln_l_t_lt.squeeze()[0:1,:,:,:]
1233-
with pytest.raises(ValueError, match="Cannot select any axis to squeeze out, as none of them has size equal to one."):
1238+
with pytest.raises(ValueError, match="Cannot select any axis to squeeze out, "
1239+
"as none of them has size equal to one."):
12341240
same.squeeze([0,1])
1235-
with pytest.raises(ValueError, match="All axes are of length 1, therefore we will not squeeze NDCube to become a scalar. Use `axis=` keyword to specify a subset of axes to squeeze."):
1241+
with pytest.raises(ValueError, match="All axes are of length 1, therefore we will not squeeze NDCube to become "
1242+
"a scalar. Use `axis=` keyword to specify a subset of axes to squeeze."):
12361243
same[0:1,0:1,0:1,0:1].squeeze()
12371244

12381245

ndcube/tests/test_ndcubesequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_index_as_cube(ndc, item, expected_shape):
9393
4))
9494
],
9595
indirect=("ndc",))
96-
def test_explode_along_axis_common_axis_None(ndc, axis, expected_shape):
96+
def test_explode_along_axis_common_axis_none(ndc, axis, expected_shape):
9797
exploded_sequence = ndc.explode_along_axis(axis)
9898
assert np.all(exploded_sequence.shape == expected_shape)
9999
assert exploded_sequence._common_axis is None

ndcube/utils/collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,6 @@ def assert_aligned_axes_compatible(data_dimensions1, data_dimensions2, data_axes
159159
if len(data_axes1) != len(data_axes2):
160160
raise ValueError(f"Number of aligned axes must be equal: {len(data_axes1)} != {len(data_axes2)}")
161161
# Confirm dimension lengths of each aligned axis is the same.
162-
if not all(np.array(data_dimensions1)[np.array(data_axes1)] == np.array(data_dimensions2)[np.array(data_axes2)]):
162+
if not all(np.array(data_dimensions1)[np.array(data_axes1)] ==
163+
np.array(data_dimensions2)[np.array(data_axes2)]):
163164
raise ValueError("All corresponding aligned axes between cubes must be of same length.")

ndcube/utils/sphinx/__init__.py

Whitespace-only changes.

ndcube/utils/tests/test_utils_cube.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def test_propagate_rebin_uncertainties_prod(stacked_pixel_data):
6262

6363
# Build expected output
6464
binned_data = data.prod(axis=0)
65-
expected = np.sqrt(((uncertainty.array / data)**2).sum(axis=0)) * binned_data / 2 # Why do I have to divide by a factor 2 here?
65+
# TODO: Why do I have to divide by a factor 2 here?
66+
expected = np.sqrt(((uncertainty.array / data)**2).sum(axis=0)) * binned_data / 2
6667
expected = StdDevUncertainty(expected)
6768

6869
# Run function

ndcube/visualization/mpl_plotter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ def plot(self, axes=None, plot_axes=None, axes_coordinates=None,
7979
with warnings.catch_warnings():
8080
warnings.simplefilter('ignore', AstropyUserWarning)
8181
if naxis == 1:
82-
ax = self._plot_1D_cube(plot_wcs, axes, axes_coordinates,
82+
ax = self._plot_1d_cube(plot_wcs, axes, axes_coordinates,
8383
axes_units, data_unit, **kwargs)
8484

8585
elif naxis == 2 and 'y' in plot_axes:
86-
ax = self._plot_2D_cube(plot_wcs, axes, plot_axes, axes_coordinates,
86+
ax = self._plot_2d_cube(plot_wcs, axes, plot_axes, axes_coordinates,
8787
axes_units, data_unit, **kwargs)
8888
else:
8989
ax = self._animate_cube(plot_wcs, plot_axes=plot_axes,
@@ -107,7 +107,7 @@ def _apply_axes_coordinates(self, axes, axes_coordinates):
107107
axes.coords[coord_index].set_ticks_visible(False)
108108
axes.coords[coord_index].set_ticklabel_visible(False)
109109

110-
def _plot_1D_cube(self, wcs, axes=None, axes_coordinates=None, axes_units=None,
110+
def _plot_1d_cube(self, wcs, axes=None, axes_coordinates=None, axes_units=None,
111111
data_unit=None, **kwargs):
112112
if axes is None:
113113
axes = plt.subplot(projection=wcs)
@@ -153,7 +153,7 @@ def _plot_1D_cube(self, wcs, axes=None, axes_coordinates=None, axes_units=None,
153153

154154
return axes
155155

156-
def _plot_2D_cube(self, wcs, axes=None, plot_axes=None, axes_coordinates=None,
156+
def _plot_2d_cube(self, wcs, axes=None, plot_axes=None, axes_coordinates=None,
157157
axes_units=None, data_unit=None, **kwargs):
158158
if axes is None:
159159
axes = plt.subplot(projection=wcs, slices=plot_axes)

0 commit comments

Comments
 (0)