Skip to content

Commit 49c5834

Browse files
committed
Run pre-commit hooks for the first time
1 parent 9eb9b2e commit 49c5834

21 files changed

Lines changed: 759 additions & 508 deletions

astropy_healpix/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Packages may add whatever they like to this file, but
88
# should keep this content at the top.
99
# ----------------------------------------------------------------------------
10-
from ._astropy_init import * # noqa
10+
from ._astropy_init import * # noqa
1111
# ----------------------------------------------------------------------------
1212

1313
from .high_level import * # noqa

astropy_healpix/_astropy_init.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
import os
33

4-
__all__ = ['__version__', 'test']
4+
__all__ = ["__version__", "test"]
55

66
try:
77
from .version import version as __version__
88
except ImportError:
9-
__version__ = ''
9+
__version__ = ""
1010

1111
# Create the test function for self test
1212
from astropy.tests.runner import TestRunner
13+
1314
test = TestRunner.make_test_runner_in(os.path.dirname(__file__))

astropy_healpix/bench.py

Lines changed: 122 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
# Copied from https://github.com/kwgoodman/bottleneck/blob/master/bottleneck/benchmark/autotimeit.py
35-
def autotimeit(stmt, setup='pass', repeat=3, mintime=0.2):
35+
def autotimeit(stmt, setup="pass", repeat=3, mintime=0.2):
3636
timer = timeit.Timer(stmt, setup)
3737
number, time1 = autoscaler(timer, mintime)
3838
time2 = timer.repeat(repeat=repeat - 1, number=number)
@@ -47,89 +47,105 @@ def autoscaler(timer, mintime):
4747
if time > mintime:
4848
return number, time
4949
number *= 10
50-
raise RuntimeError('function is too fast to test')
50+
raise RuntimeError("function is too fast to test")
5151

5252

5353
def get_import(package, function):
54-
if package == 'astropy_healpix':
55-
return f'from astropy_healpix.healpy import {function}'
54+
if package == "astropy_healpix":
55+
return f"from astropy_healpix.healpy import {function}"
5656
else:
57-
return f'from healpy import {function}'
57+
return f"from healpy import {function}"
5858

5959

6060
def bench_pix2ang(size=None, nside=None, nest=None, package=None, fast=False):
61-
setup = '\n'.join([
62-
get_import(package, 'pix2ang'),
63-
'import numpy as np',
64-
f'nside={nside}',
65-
f'ipix=(np.random.random({size}) * 12 * nside ** 2).astype(np.int64)',
66-
f'nest={nest}'])
67-
68-
stmt = 'pix2ang(nside, ipix, nest)'
61+
setup = "\n".join(
62+
[
63+
get_import(package, "pix2ang"),
64+
"import numpy as np",
65+
f"nside={nside}",
66+
f"ipix=(np.random.random({size}) * 12 * nside ** 2).astype(np.int64)",
67+
f"nest={nest}",
68+
]
69+
)
70+
71+
stmt = "pix2ang(nside, ipix, nest)"
6972

7073
return autotimeit(stmt=stmt, setup=setup, repeat=1, mintime=0 if fast else 0.1)
7174

7275

7376
def bench_ang2pix(size=None, nside=None, nest=None, package=None, fast=False):
74-
setup = '\n'.join([
75-
get_import(package, 'ang2pix'),
76-
'import numpy as np',
77-
f'nside={nside}',
78-
f'lon=360 * np.random.random({size})',
79-
f'lat=180 * np.random.random({size}) - 90',
80-
f'nest={nest}'])
81-
82-
stmt = 'ang2pix(nside, lon, lat, nest, lonlat=True)'
77+
setup = "\n".join(
78+
[
79+
get_import(package, "ang2pix"),
80+
"import numpy as np",
81+
f"nside={nside}",
82+
f"lon=360 * np.random.random({size})",
83+
f"lat=180 * np.random.random({size}) - 90",
84+
f"nest={nest}",
85+
]
86+
)
87+
88+
stmt = "ang2pix(nside, lon, lat, nest, lonlat=True)"
8389

8490
return autotimeit(stmt=stmt, setup=setup, repeat=1, mintime=0 if fast else 0.1)
8591

8692

8793
def bench_nest2ring(size=None, nside=None, package=None, fast=False):
88-
setup = '\n'.join([
89-
get_import(package, 'nest2ring'),
90-
'import numpy as np',
91-
f'nside={nside}',
92-
f'ipix=(np.random.random({size}) * 12 * nside ** 2).astype(np.int64)'])
94+
setup = "\n".join(
95+
[
96+
get_import(package, "nest2ring"),
97+
"import numpy as np",
98+
f"nside={nside}",
99+
f"ipix=(np.random.random({size}) * 12 * nside ** 2).astype(np.int64)",
100+
]
101+
)
93102

94-
stmt = 'nest2ring(nside, ipix)'
103+
stmt = "nest2ring(nside, ipix)"
95104

96105
return autotimeit(stmt=stmt, setup=setup, repeat=1, mintime=0 if fast else 0.1)
97106

98107

99108
def bench_ring2nest(size=None, nside=None, package=None, fast=False):
100-
setup = '\n'.join([
101-
get_import(package, 'ring2nest'),
102-
'import numpy as np',
103-
f'nside={nside}',
104-
f'ipix=(np.random.random({size}) * 12 * nside ** 2).astype(np.int64)'])
109+
setup = "\n".join(
110+
[
111+
get_import(package, "ring2nest"),
112+
"import numpy as np",
113+
f"nside={nside}",
114+
f"ipix=(np.random.random({size}) * 12 * nside ** 2).astype(np.int64)",
115+
]
116+
)
105117

106-
stmt = 'ring2nest(nside, ipix)'
118+
stmt = "ring2nest(nside, ipix)"
107119

108120
return autotimeit(stmt=stmt, setup=setup, repeat=1, mintime=0 if fast else 0.1)
109121

110122

111-
def bench_get_interp_weights(size=None, nside=None, nest=None, package=None, fast=False):
112-
setup = '\n'.join([
113-
get_import(package, 'get_interp_weights'),
114-
'import numpy as np',
115-
f'nside={nside}',
116-
f'lon=360 * np.random.random({size})',
117-
f'lat=180 * np.random.random({size}) - 90',
118-
f'nest={nest}'])
123+
def bench_get_interp_weights(
124+
size=None, nside=None, nest=None, package=None, fast=False
125+
):
126+
setup = "\n".join(
127+
[
128+
get_import(package, "get_interp_weights"),
129+
"import numpy as np",
130+
f"nside={nside}",
131+
f"lon=360 * np.random.random({size})",
132+
f"lat=180 * np.random.random({size}) - 90",
133+
f"nest={nest}",
134+
]
135+
)
119136

120-
stmt = 'get_interp_weights(nside, lon, lat, nest=nest, lonlat=True)'
137+
stmt = "get_interp_weights(nside, lon, lat, nest=nest, lonlat=True)"
121138

122139
return autotimeit(stmt=stmt, setup=setup, repeat=1, mintime=0 if fast else 0.1)
123140

124141

125142
def run_single(name, benchmark, fast=False, **kwargs):
126-
127-
time_self = benchmark(package='astropy_healpix', fast=fast, **kwargs)
143+
time_self = benchmark(package="astropy_healpix", fast=fast, **kwargs)
128144
results_single = dict(function=name, time_self=time_self, **kwargs)
129145

130146
if HEALPY_INSTALLED:
131-
time_healpy = bench_ang2pix(package='healpy', fast=fast, **kwargs)
132-
results_single['time_healpy'] = time_healpy
147+
time_healpy = bench_ang2pix(package="healpy", fast=fast, **kwargs)
148+
results_single["time_healpy"] = time_healpy
133149

134150
return results_single
135151

@@ -146,60 +162,99 @@ def bench_run(fast=False):
146162
for nest in [True, False]:
147163
for size in SIZES:
148164
for nside in [1, 128]:
149-
results.append(run_single('pix2ang', bench_pix2ang, fast=fast,
150-
size=size, nside=nside, nest=nest))
165+
results.append(
166+
run_single(
167+
"pix2ang",
168+
bench_pix2ang,
169+
fast=fast,
170+
size=size,
171+
nside=nside,
172+
nest=nest,
173+
)
174+
)
151175

152176
for nest in [True, False]:
153177
for size in SIZES:
154178
for nside in [1, 128]:
155-
results.append(run_single('ang2pix', bench_ang2pix, fast=fast,
156-
size=size, nside=nside, nest=nest))
179+
results.append(
180+
run_single(
181+
"ang2pix",
182+
bench_ang2pix,
183+
fast=fast,
184+
size=size,
185+
nside=nside,
186+
nest=nest,
187+
)
188+
)
157189

158190
for size in SIZES:
159191
for nside in [1, 128]:
160-
results.append(run_single('nest2ring', bench_nest2ring, fast=fast,
161-
size=size, nside=nside))
192+
results.append(
193+
run_single(
194+
"nest2ring", bench_nest2ring, fast=fast, size=size, nside=nside
195+
)
196+
)
162197

163198
for size in SIZES:
164199
for nside in [1, 128]:
165-
results.append(run_single('ring2nest', bench_ring2nest, fast=fast,
166-
size=size, nside=nside))
200+
results.append(
201+
run_single(
202+
"ring2nest", bench_ring2nest, fast=fast, size=size, nside=nside
203+
)
204+
)
167205

168206
for nest in [True, False]:
169207
for size in SIZES:
170208
for nside in [1, 128]:
171-
results.append(run_single('get_interp_weights', bench_get_interp_weights,
172-
fast=fast, size=size,
173-
nside=nside, nest=nest))
209+
results.append(
210+
run_single(
211+
"get_interp_weights",
212+
bench_get_interp_weights,
213+
fast=fast,
214+
size=size,
215+
nside=nside,
216+
nest=nest,
217+
)
218+
)
174219

175220
return results
176221

177222

178223
def bench_report(results):
179224
"""Print a report for given benchmark results to the console."""
180225

181-
table = Table(names=['function', 'nest', 'nside', 'size',
182-
'time_healpy', 'time_self', 'ratio'],
183-
dtype=['S20', bool, int, int, float, float, float], masked=True)
226+
table = Table(
227+
names=[
228+
"function",
229+
"nest",
230+
"nside",
231+
"size",
232+
"time_healpy",
233+
"time_self",
234+
"ratio",
235+
],
236+
dtype=["S20", bool, int, int, float, float, float],
237+
masked=True,
238+
)
184239
for row in results:
185240
table.add_row(row)
186241

187-
table['time_self'].format = '10.7f'
242+
table["time_self"].format = "10.7f"
188243

189244
if HEALPY_INSTALLED:
190-
table['ratio'] = table['time_self'] / table['time_healpy']
191-
table['time_healpy'].format = '10.7f'
192-
table['ratio'].format = '7.2f'
245+
table["ratio"] = table["time_self"] / table["time_healpy"]
246+
table["time_healpy"].format = "10.7f"
247+
table["ratio"].format = "7.2f"
193248

194249
table.pprint(max_lines=-1)
195250

196251

197252
def main(fast=False):
198253
"""Run all benchmarks and print report to the console."""
199-
print('Running benchmarks...\n')
254+
print("Running benchmarks...\n")
200255
results = bench_run(fast=fast)
201256
bench_report(results)
202257

203258

204-
if __name__ == '__main__':
259+
if __name__ == "__main__":
205260
main()

astropy_healpix/conftest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
try:
1515
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
16+
1617
ASTROPY_HEADER = True
1718
except ImportError:
1819
ASTROPY_HEADER = False
@@ -27,24 +28,24 @@ def pytest_configure(config):
2728
2829
"""
2930
if ASTROPY_HEADER:
30-
3131
config.option.astropy_header = True
3232

3333
# Customize the following lines to add/remove entries from the list of
3434
# packages for which version numbers are displayed when running the tests.
35-
PYTEST_HEADER_MODULES.pop('h5py', None)
36-
PYTEST_HEADER_MODULES.pop('Pandas', None)
37-
PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
38-
PYTEST_HEADER_MODULES['healpy'] = 'healpy'
35+
PYTEST_HEADER_MODULES.pop("h5py", None)
36+
PYTEST_HEADER_MODULES.pop("Pandas", None)
37+
PYTEST_HEADER_MODULES["Astropy"] = "astropy"
38+
PYTEST_HEADER_MODULES["healpy"] = "healpy"
3939

4040
from . import __version__
41+
4142
packagename = os.path.basename(os.path.dirname(__file__))
4243
TESTED_VERSIONS[packagename] = __version__
4344

4445
# Set the Numpy print style to a fixed version to make doctest outputs
4546
# reproducible.
4647
try:
47-
np.set_printoptions(legacy='1.13')
48+
np.set_printoptions(legacy="1.13")
4849
except TypeError:
4950
# On older versions of Numpy, the unrecognized 'legacy' option will
5051
# raise a TypeError.

0 commit comments

Comments
 (0)