Skip to content

Commit

Permalink
Merge pull request #308 from Cadair/black
Browse files Browse the repository at this point in the history
Reformat all Python code using Black
  • Loading branch information
astrofrog authored Oct 5, 2022
2 parents 19c1a31 + 7c7730a commit 03dec93
Show file tree
Hide file tree
Showing 36 changed files with 1,394 additions and 1,020 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ repos:
hooks:
- id: isort
name: isort (python)
args:
- "--filter-files"

- repo: https://github.com/asottile/pyupgrade
rev: v2.38.2
Expand Down Expand Up @@ -64,5 +66,10 @@ repos:
]
exclude: ".*(data.*|extern.*|cextern)$"

- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black

ci:
autofix_prs: false
74 changes: 36 additions & 38 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,28 @@
try:
from sphinx_astropy.conf.v1 import * # noqa
except ImportError:
print('ERROR: the documentation requires the sphinx-astropy package to be installed')
print("ERROR: the documentation requires the sphinx-astropy package to be installed")
sys.exit(1)

# Get configuration information from setup.cfg
from configparser import ConfigParser

conf = ConfigParser()

conf.read([os.path.join(os.path.dirname(__file__), '..', 'setup.cfg')])
setup_cfg = dict(conf.items('metadata'))
conf.read([os.path.join(os.path.dirname(__file__), "..", "setup.cfg")])
setup_cfg = dict(conf.items("metadata"))

# -- General configuration ----------------------------------------------------

# By default, highlight as Python 3.
highlight_language = 'python3'
highlight_language = "python3"

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.1'
# needs_sphinx = '1.1'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns.append('_templates')
exclude_patterns.append("_templates")

# This is added to the end of RST files - a good place to put substitutions to
# be used globally.
Expand All @@ -62,20 +63,19 @@
# -- Project information ------------------------------------------------------

# This does not *have* to match the package name, but typically does
project = setup_cfg['name']
author = setup_cfg['author']
copyright = '{}, {}'.format(
datetime.datetime.now().year, setup_cfg['author'])
project = setup_cfg["name"]
author = setup_cfg["author"]
copyright = "{}, {}".format(datetime.datetime.now().year, setup_cfg["author"])

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.

import_module(setup_cfg['name'])
package = sys.modules[setup_cfg['name']]
import_module(setup_cfg["name"])
package = sys.modules[setup_cfg["name"]]

# The short X.Y version.
version = package.__version__.split('-', 1)[0]
version = package.__version__.split("-", 1)[0]
# The full version, including alpha/beta/rc tags.
release = package.__version__

Expand All @@ -90,63 +90,61 @@
# global configuration are listed below, commented out.

html_theme_options = {
'logotext1': 're', # white, semi-bold
'logotext2': 'project', # orange, light
'logotext3': ':docs' # white, light
}
"logotext1": "re", # white, semi-bold
"logotext2": "project", # orange, light
"logotext3": ":docs", # white, light
}

# Add any paths that contain custom themes here, relative to this directory.
# To use a different custom theme, add the directory containing the theme.
#html_theme_path = []
# html_theme_path = []

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. To override the custom theme, set this to the
# name of a builtin theme or the name of a custom theme in html_theme_path.
#html_theme = None
# html_theme = None

# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# html_sidebars = {}

# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = ''
# html_favicon = ''

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = ''
# html_last_updated_fmt = ''

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
html_title = f'{project} v{release}'
html_title = f"{project} v{release}"

# Output file base name for HTML help builder.
htmlhelp_basename = project + 'doc'
htmlhelp_basename = project + "doc"


# -- Options for LaTeX output --------------------------------------------------

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [('index', project + '.tex', project + ' Documentation',
author, 'manual')]
latex_documents = [("index", project + ".tex", project + " Documentation", author, "manual")]


# -- Options for manual page output --------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [('index', project.lower(), project + ' Documentation',
[author], 1)]
man_pages = [("index", project.lower(), project + " Documentation", [author], 1)]


## -- Options for the edit_on_github extension ----------------------------------------

if eval(setup_cfg.get('edit_on_github')):
extensions += ['astropy_helpers.sphinx.ext.edit_on_github']
if eval(setup_cfg.get("edit_on_github")):
extensions += ["astropy_helpers.sphinx.ext.edit_on_github"]

versionmod = __import__(setup_cfg['package_name'] + '.version')
edit_on_github_project = setup_cfg['github_project']
versionmod = __import__(setup_cfg["package_name"] + ".version")
edit_on_github_project = setup_cfg["github_project"]
if versionmod.version.release:
edit_on_github_branch = "v" + versionmod.version.version
else:
Expand All @@ -158,12 +156,12 @@
nitpicky = True

plot_rcparams = {}
plot_rcparams['figure.figsize'] = (8, 6)
plot_rcparams['savefig.facecolor'] = 'none'
plot_rcparams['savefig.bbox'] = 'tight'
plot_rcparams['axes.labelsize'] = 'large'
plot_rcparams['figure.subplot.hspace'] = 0.5
plot_rcparams["figure.figsize"] = (8, 6)
plot_rcparams["savefig.facecolor"] = "none"
plot_rcparams["savefig.bbox"] = "tight"
plot_rcparams["axes.labelsize"] = "large"
plot_rcparams["figure.subplot.hspace"] = 0.5

plot_apply_rcparams = True
plot_html_show_source_link = False
plot_formats = ['png', 'svg', 'pdf']
plot_formats = ["png", "svg", "pdf"]
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ skip = "cp36-* pp* *-musllinux* cp310-win32"
test-skip = "*-macosx_arm64 *-manylinux_aarch64"

[tool.isort]
profile = "black"
multi_line_output = 3
extend_skip_glob = [
"docs/*",
"setup.py"]
line_length = 100
known_third_party = ["astropy"]
known_first_party = ["reproject"]
multi_line_output = 4
group_by_package = true
indented_import_headings = false
length_sort_sections = ["future", "stdlib"]

[tool.black]
line-length = 100
target-version = ['py38']
60 changes: 38 additions & 22 deletions reproject/adaptive/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from ..wcs_utils import efficient_pixel_to_pixel, efficient_pixel_to_pixel_with_roundtrip
from .deforest import map_coordinates

__all__ = ['_reproject_adaptive_2d']
__all__ = ["_reproject_adaptive_2d"]


class CoordinateTransformer:

def __init__(self, wcs_in, wcs_out, roundtrip_coords):
self.wcs_in = wcs_in
self.wcs_out = wcs_out
Expand All @@ -19,22 +18,32 @@ def __call__(self, pixel_out):
pixel_out = pixel_out[:, :, 0], pixel_out[:, :, 1]
if self.roundtrip_coords:
pixel_in = efficient_pixel_to_pixel_with_roundtrip(
self.wcs_out, self.wcs_in, *pixel_out)
self.wcs_out, self.wcs_in, *pixel_out
)
else:
pixel_in = efficient_pixel_to_pixel(
self.wcs_out, self.wcs_in, *pixel_out)
pixel_in = efficient_pixel_to_pixel(self.wcs_out, self.wcs_in, *pixel_out)
pixel_in = np.array(pixel_in).transpose().swapaxes(0, 1)
return pixel_in


def _reproject_adaptive_2d(array, wcs_in, wcs_out, shape_out,
return_footprint=True, center_jacobian=False,
roundtrip_coords=True, conserve_flux=False,
kernel='Gaussian', kernel_width=1.3,
sample_region_width=4,
boundary_mode='strict', boundary_fill_value=0,
boundary_ignore_threshold=0.5,
x_cyclic=False, y_cyclic=False):
def _reproject_adaptive_2d(
array,
wcs_in,
wcs_out,
shape_out,
return_footprint=True,
center_jacobian=False,
roundtrip_coords=True,
conserve_flux=False,
kernel="Gaussian",
kernel_width=1.3,
sample_region_width=4,
boundary_mode="strict",
boundary_fill_value=0,
boundary_ignore_threshold=0.5,
x_cyclic=False,
y_cyclic=False,
):
"""
Reproject celestial slices from an n-d array from one WCS to another
using the DeForest (2004) algorithm [1]_, and assuming all other dimensions
Expand Down Expand Up @@ -111,15 +120,22 @@ def _reproject_adaptive_2d(array, wcs_in, wcs_out, shape_out,
array_out = np.zeros(shape_out)

transformer = CoordinateTransformer(wcs_in, wcs_out, roundtrip_coords)
map_coordinates(array_in, array_out, transformer, out_of_range_nan=True,
center_jacobian=center_jacobian,
conserve_flux=conserve_flux,
kernel=kernel, kernel_width=kernel_width,
sample_region_width=sample_region_width,
boundary_mode=boundary_mode,
boundary_fill_value=boundary_fill_value,
boundary_ignore_threshold=boundary_ignore_threshold,
x_cyclic=x_cyclic, y_cyclic=y_cyclic)
map_coordinates(
array_in,
array_out,
transformer,
out_of_range_nan=True,
center_jacobian=center_jacobian,
conserve_flux=conserve_flux,
kernel=kernel,
kernel_width=kernel_width,
sample_region_width=sample_region_width,
boundary_mode=boundary_mode,
boundary_fill_value=boundary_fill_value,
boundary_ignore_threshold=boundary_ignore_threshold,
x_cyclic=x_cyclic,
y_cyclic=y_cyclic,
)

if return_footprint:
return array_out, (~np.isnan(array_out)).astype(float)
Expand Down
57 changes: 37 additions & 20 deletions reproject/adaptive/high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
from ..utils import parse_input_data, parse_output_projection
from .core import _reproject_adaptive_2d

__all__ = ['reproject_adaptive']
__all__ = ["reproject_adaptive"]


def reproject_adaptive(input_data, output_projection, shape_out=None, hdu_in=0,
return_footprint=True, center_jacobian=False,
roundtrip_coords=True, conserve_flux=False,
kernel='gaussian', kernel_width=1.3,
sample_region_width=4,
boundary_mode='strict', boundary_fill_value=0,
boundary_ignore_threshold=0.5, x_cyclic=False,
y_cyclic=False):
def reproject_adaptive(
input_data,
output_projection,
shape_out=None,
hdu_in=0,
return_footprint=True,
center_jacobian=False,
roundtrip_coords=True,
conserve_flux=False,
kernel="gaussian",
kernel_width=1.3,
sample_region_width=4,
boundary_mode="strict",
boundary_fill_value=0,
boundary_ignore_threshold=0.5,
x_cyclic=False,
y_cyclic=False,
):
"""
Reproject a 2D array from one WCS to another using the DeForest (2004)
adaptive, anti-aliased resampling algorithm, with optional flux
Expand Down Expand Up @@ -145,14 +155,21 @@ def reproject_adaptive(input_data, output_projection, shape_out=None, hdu_in=0,
array_in, wcs_in = parse_input_data(input_data, hdu_in=hdu_in)
wcs_out, shape_out = parse_output_projection(output_projection, shape_out=shape_out)

return _reproject_adaptive_2d(array_in, wcs_in, wcs_out, shape_out,
return_footprint=return_footprint,
center_jacobian=center_jacobian,
roundtrip_coords=roundtrip_coords,
conserve_flux=conserve_flux,
kernel=kernel, kernel_width=kernel_width,
sample_region_width=sample_region_width,
boundary_mode=boundary_mode,
boundary_fill_value=boundary_fill_value,
boundary_ignore_threshold=boundary_ignore_threshold,
x_cyclic=x_cyclic, y_cyclic=y_cyclic)
return _reproject_adaptive_2d(
array_in,
wcs_in,
wcs_out,
shape_out,
return_footprint=return_footprint,
center_jacobian=center_jacobian,
roundtrip_coords=roundtrip_coords,
conserve_flux=conserve_flux,
kernel=kernel,
kernel_width=kernel_width,
sample_region_width=sample_region_width,
boundary_mode=boundary_mode,
boundary_fill_value=boundary_fill_value,
boundary_ignore_threshold=boundary_ignore_threshold,
x_cyclic=x_cyclic,
y_cyclic=y_cyclic,
)
Loading

0 comments on commit 03dec93

Please sign in to comment.