Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding stcal-alignment sub-package. #196

Merged
merged 133 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 98 commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
856ffba
Update .gitignore file.
mairanteodoro Jun 29, 2023
a4fed92
Create subpackage and initial module structure.
mairanteodoro Jun 29, 2023
f57851a
Add methods to alignment.util.
mairanteodoro Jun 30, 2023
556279d
Update .gitignore.
mairanteodoro Jul 5, 2023
1a3628e
Remove unused modules.
mairanteodoro Jul 5, 2023
a09e0cb
Clean module.
mairanteodoro Jul 6, 2023
9ab2e44
Update .gitignore.
mairanteodoro Jul 6, 2023
9441dd4
Add methods necessary for resample.
mairanteodoro Jul 6, 2023
f0013aa
Small changes to accommodate both JWST and RST datamodels.
mairanteodoro Jul 7, 2023
66ea089
Add CHANGES.rst entry.
mairanteodoro Jul 7, 2023
48e3d60
Add PR number to CHANGES.rst entry.
mairanteodoro Jul 7, 2023
66ba3fe
use protocols
nden Jul 9, 2023
3906abf
temp
nden Jul 9, 2023
3467f81
add dependencies
nden Jul 9, 2023
13c342f
add CI testing to alignment branch
nden Jul 9, 2023
42423d3
add CI testing to alignment branch
nden Jul 9, 2023
b8b8cc0
fix test
nden Jul 10, 2023
fa86a3e
Add setting of number_extended_events (#178)
mwregan2 Jul 7, 2023
0eea0e5
Rename variables with FITS keywords names.
mairanteodoro Jul 10, 2023
7c136a7
Style reformating.
mairanteodoro Jul 10, 2023
cc7d689
Update docs to include stcal.alignment.
mairanteodoro Jul 12, 2023
f4f379d
Revert "Rename variables with FITS keywords names."
mairanteodoro Jul 12, 2023
afa9e7a
Updates to address most comments.
mairanteodoro Jul 12, 2023
0cd3621
Fix misplaced comment.
mairanteodoro Jul 12, 2023
a8839a9
Code refactoring and additional unit test.
mairanteodoro Jul 13, 2023
47f785b
Silencing style check warning F403.
mairanteodoro Jul 13, 2023
424fd38
Small style refactoring.
mairanteodoro Jul 13, 2023
d67e0b9
Set minimum asdf version.
mairanteodoro Jul 13, 2023
1229f02
Update matplotlib's inventory URL.
mairanteodoro Jul 13, 2023
500479a
Set lower version for gwcs.
mairanteodoro Jul 13, 2023
eeccb1b
Bump astropy version to >= 5.1.
mairanteodoro Jul 13, 2023
7e6dbf3
Fix docs style issues.
mairanteodoro Jul 14, 2023
d52c609
Style check fix.
mairanteodoro Jul 14, 2023
0a1fa45
Add methods necessary for resample.
mairanteodoro Jul 6, 2023
846d6f0
Small changes to accommodate both JWST and RST datamodels.
mairanteodoro Jul 7, 2023
ec98251
Add CHANGES.rst entry.
mairanteodoro Jul 7, 2023
d74b115
Add PR number to CHANGES.rst entry.
mairanteodoro Jul 7, 2023
57a3ef9
use protocols
nden Jul 9, 2023
727c7a1
temp
nden Jul 9, 2023
233ce46
add dependencies
nden Jul 9, 2023
c723e32
add CI testing to alignment branch
nden Jul 9, 2023
da051fb
add CI testing to alignment branch
nden Jul 9, 2023
520464f
fix test
nden Jul 10, 2023
07912e0
Add setting of number_extended_events (#178)
mwregan2 Jul 7, 2023
22d46e9
Rename variables with FITS keywords names.
mairanteodoro Jul 10, 2023
3f1f677
Style reformating.
mairanteodoro Jul 10, 2023
66840c3
Update docs to include stcal.alignment.
mairanteodoro Jul 12, 2023
dddbea6
Revert "Rename variables with FITS keywords names."
mairanteodoro Jul 12, 2023
2c0d44e
Updates to address most comments.
mairanteodoro Jul 12, 2023
376f7fe
Fix misplaced comment.
mairanteodoro Jul 12, 2023
d78b736
Code refactoring and additional unit test.
mairanteodoro Jul 13, 2023
b72978b
Silencing style check warning F403.
mairanteodoro Jul 13, 2023
8f1828a
Small style refactoring.
mairanteodoro Jul 13, 2023
9c7ee1e
Set minimum asdf version.
mairanteodoro Jul 13, 2023
f2d5e21
Update matplotlib's inventory URL.
mairanteodoro Jul 13, 2023
6649fa5
Set lower version for gwcs.
mairanteodoro Jul 13, 2023
f83f041
Bump astropy version to >= 5.1.
mairanteodoro Jul 13, 2023
ae168c0
Fix docs style issues.
mairanteodoro Jul 14, 2023
dc47316
Style check fix.
mairanteodoro Jul 14, 2023
bc7fdbc
Fix issue with bounding boxes in tests.
mairanteodoro Jul 18, 2023
6fe6df8
Fix issue with bounding boxes in tests.
mairanteodoro Jul 18, 2023
b97a839
Merge branch 'stcal-alignment' of github.com:mairanteodoro/stcal into…
mairanteodoro Jul 18, 2023
f03a11c
Fix issue with bounding box when creating WCS for tests. (#181)
mairanteodoro Aug 2, 2023
c09bd55
Add new methods required by resample_step.
mairanteodoro Aug 10, 2023
176845f
Small refactoring and clean ups.
mairanteodoro Aug 17, 2023
bc706e9
RCAL-632: add unit tests for new methods.
mairanteodoro Aug 17, 2023
53571f1
Resolve conflicts.
mairanteodoro Aug 17, 2023
0522779
Fix style check errors.
mairanteodoro Aug 17, 2023
3baee3b
Set sphinx version for compatibility with sphinx-rtd-theme.
mairanteodoro Aug 17, 2023
7d03957
Added working module.
s-goldman Aug 17, 2023
88e90f5
Added functional unit testing
s-goldman Aug 21, 2023
f81fbd9
Merge branch 'stcal-alignment' into stcal-alignment
mairanteodoro Aug 22, 2023
474d917
Added reproject.
s-goldman Aug 22, 2023
142e276
removed print statement
s-goldman Aug 22, 2023
2d12e10
Merge remote-tracking branch 'upstream/stcal-alignment' into stcal-al…
mairanteodoro Aug 22, 2023
665f1b3
Fix style issues.
mairanteodoro Aug 22, 2023
a89196b
Revert reproject commit.
mairanteodoro Aug 22, 2023
8acd94c
HLA-1096: Added Reproject function (#193)
s-goldman Aug 22, 2023
4644bdc
Resolve conflicts.
mairanteodoro Aug 22, 2023
77bbf75
RCAL-632: add unit tests for additional methods. (#190)
mairanteodoro Aug 22, 2023
4ebe12a
Merge remote-tracking branch 'upstream/stcal-alignment' into stcal-al…
mairanteodoro Aug 22, 2023
34ea51a
Small changes to accommodate both JWST and RST datamodels.
mairanteodoro Jul 7, 2023
1edc1c8
fix test
nden Jul 10, 2023
e238120
Rename variables with FITS keywords names.
mairanteodoro Jul 10, 2023
a26f046
Revert "Rename variables with FITS keywords names."
mairanteodoro Jul 12, 2023
97dccaf
Code refactoring and additional unit test.
mairanteodoro Jul 13, 2023
578fac3
Bump astropy version to >= 5.1.
mairanteodoro Jul 13, 2023
2a46a49
Fix docs style issues.
mairanteodoro Jul 14, 2023
3f31c44
Small refactoring and clean ups.
mairanteodoro Aug 17, 2023
759f796
Fix style issues.
mairanteodoro Aug 22, 2023
9ac8694
Revert reproject commit.
mairanteodoro Aug 22, 2023
220656f
Revert "Revert reproject commit."
mairanteodoro Aug 22, 2023
97c798f
Fix issue caused by bad conflict resolution.
mairanteodoro Aug 22, 2023
b42a922
Fix duplicate code.
mairanteodoro Aug 22, 2023
3771110
Style check fixes. (#194)
mairanteodoro Aug 23, 2023
8fa6112
Merge remote-tracking branch 'upstream/stcal-alignment' into stcal-al…
mairanteodoro Aug 23, 2023
10bb2a4
Merge branch 'main' into stcal-alignment
mairanteodoro Aug 23, 2023
497789d
Syncing stcal-alignment and main. (#195)
mairanteodoro Aug 23, 2023
3f32679
Moved test for alignment.reproject, remove ipynb.
s-goldman Aug 23, 2023
1bb82fc
Merge branch 'stcal-alignment' into alignment
s-goldman Aug 24, 2023
e0fad8c
Removed unnecessary file.
mairanteodoro Aug 24, 2023
9109381
Update test_alignment.py
s-goldman Aug 24, 2023
6a75ddc
Added astropy.io.fits
s-goldman Aug 24, 2023
55f0a31
Added import for highlevel WCS
s-goldman Aug 28, 2023
0f29409
Small text change.
s-goldman Aug 28, 2023
161d9fd
Files moved, added calculate_pixmap
s-goldman Aug 28, 2023
d426201
Ken's suggestions.
s-goldman Aug 28, 2023
23f2003
consistently named imports
s-goldman Aug 28, 2023
15c3ecd
formatting
s-goldman Aug 28, 2023
d6818d6
formatting
s-goldman Aug 28, 2023
87d732b
using pixel shape instead of bounding box
s-goldman Aug 28, 2023
b8a3b9c
Update src/stcal/alignment/resample_utils.py
s-goldman Aug 29, 2023
6c5242e
Update src/stcal/alignment/util.py
s-goldman Aug 29, 2023
bed60fa
Added correct shape, gwcs.WCS instead of WCS
s-goldman Aug 29, 2023
6b2ba14
Merge remote-tracking branch 'upstream/stcal-alignment' into alignment
s-goldman Aug 29, 2023
9753c59
added test_calc_pixmap
s-goldman Aug 29, 2023
ab413c0
relative import of util
s-goldman Aug 29, 2023
6281ba2
tests passing
s-goldman Aug 29, 2023
dc0e521
removed doubly imported reproject
s-goldman Sep 5, 2023
d6df8d4
output shape corrected
s-goldman Sep 7, 2023
6502ad7
Removed whitespace
s-goldman Sep 12, 2023
0381ab2
Added Nadia's code suggestions
s-goldman Sep 14, 2023
a841505
HLA-1096: Added reproject and calculate_pixmap functions with high-le…
s-goldman Sep 14, 2023
4751d30
Merge branch 'main' into stcal-alignment
mairanteodoro Sep 27, 2023
e7801dd
Fix docstring returned type issue.
mairanteodoro Sep 28, 2023
2626396
use PyPI upload workflow from OpenAstronomy (#214)
zacharyburnett Sep 28, 2023
af275b0
download WebbPSF data for downstream tests
zacharyburnett Sep 28, 2023
5c4dff9
pass env var
zacharyburnett Sep 28, 2023
7735528
Merge branch 'main' into stcal-alignment
mairanteodoro Sep 29, 2023
bab0c14
expand build matrix with more Python versions (#219)
zacharyburnett Oct 2, 2023
e0cc4f2
Updates to docs and CI.
mairanteodoro Oct 5, 2023
bef042f
Merge branch 'main' into stcal-alignment
mairanteodoro Oct 5, 2023
88d659e
Move CHANGES.rst entry.
mairanteodoro Oct 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
branches:
- main
- '*x'
- stcal-alignment
tags:
- '*'
pull_request:
branches:
- main
- stcal-alignment
mairanteodoro marked this conversation as resolved.
Show resolved Hide resolved
schedule:
# Weekly Monday 9AM build
- cron: "0 9 * * 1"
Expand Down
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ coverage.xml
.hypothesis/
.pytest_cache/
cover/
coverage/
cov.xml

# Translations
*.mo
Expand Down Expand Up @@ -86,7 +88,7 @@ ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down Expand Up @@ -143,4 +145,7 @@ src/stcal/_version.py

# auto-generated API docs
docs/source/api
.DS_Store
.DS_Store

# VSCode stuff
.vscode
13 changes: 13 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
1.4.3 (unreleased)
==================

- Added ``alignment`` sub-package. [#179]
mairanteodoro marked this conversation as resolved.
Show resolved Hide resolved

Other
-----

Expand Down Expand Up @@ -50,6 +52,17 @@ Bug Fixes
jump
~~~~

- Added setting of number_extended_events for non-multiprocessing
mode. This is the value that is put into the header keyword EXTNCRS. [#178]

1.4.1 (2023-06-29)

Bug Fixes
---------

jump
~~~~

- Added statement to prevent the number of cores used in multiprocessing from
being larger than the number of rows. This was causing some CI tests to fail. [#176]

Expand Down
2 changes: 2 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
BUILDDIR = _build
APIDIR = api

# Internal variables
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
Expand All @@ -25,6 +26,7 @@ help:

clean:
-rm -rf $(BUILDDIR)/*
-rm -rf $(APIDIR)/*

html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
Expand Down
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
stcall API
stcal API
==========

.. automodapi:: stcal
35 changes: 29 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from pathlib import Path

import stsci_rtd_theme

if sys.version_info < (3, 11):
import tomli as tomllib
else:
import tomllib


def setup(app):
try:
Expand All @@ -27,7 +28,7 @@ def setup(app):
# values here:
with open(REPO_ROOT / "pyproject.toml", "rb") as configuration_file:
conf = tomllib.load(configuration_file)
setup_metadata = conf['project']
setup_metadata = conf["project"]

project = setup_metadata["name"]
primary_author = setup_metadata["authors"][0]
Expand All @@ -38,19 +39,41 @@ def setup(app):
version = package.__version__.split("-", 1)[0]
release = package.__version__

# Configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://numpy.org/devdocs", None),
"scipy": ("http://scipy.github.io/devdocs", None),
"matplotlib": ("https://matplotlib.org/stable", None),
"gwcs": ("https://gwcs.readthedocs.io/en/latest/", None),
"astropy": ("https://docs.astropy.org/en/stable/", None),
"stdatamodels": ("https://stdatamodels.readthedocs.io/en/latest/", None),
mairanteodoro marked this conversation as resolved.
Show resolved Hide resolved
}

extensions = [
"pytest_doctestplus.sphinx.doctestplus",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.inheritance_diagram",
"sphinx.ext.viewcode",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx_automodapi.automodapi",
"numpydoc",
"sphinx_automodapi.automodsumm",
"sphinx_automodapi.autodoc_enhancements",
"sphinx_automodapi.smart_resolver",
"sphinx_asdf",
"sphinx.ext.mathjax",
]

autosummary_generate = True
numpydoc_show_class_members = False
autoclass_content = "both"

html_theme = "stsci_rtd_theme"
html_theme_options = {
"collapse_navigation": True
}
html_theme_options = {"collapse_navigation": True}
html_theme_path = [stsci_rtd_theme.get_html_theme_path()]
html_domain_indices = True
html_sidebars = {"**": ["globaltoc.html", "relations.html", "searchbox.html"]}
Expand Down
4 changes: 4 additions & 0 deletions docs/stcal/alignment/description.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Description
============

This sub-package contains all the modules common to all missions.
12 changes: 12 additions & 0 deletions docs/stcal/alignment/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. _alignment:

===============
Alignment Utils
===============

.. toctree::
:maxdepth: 2

description.rst

.. automodapi:: stcal.alignment
1 change: 1 addition & 0 deletions docs/stcal/package_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Package Index

jump/index.rst
ramp_fitting/index.rst
alignment/index.rst
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ dependencies = [
'scipy >=1.6.0',
'numpy >=1.20',
'opencv-python-headless >=4.6.0.66',
'asdf >=2.15.0',
'gwcs >= 0.18.1',
]
dynamic = ['version']

[project.optional-dependencies]
docs = [
'numpydoc',
'packaging >=17',
'sphinx',
'sphinx<7.0.0',
'sphinx-asdf',
'sphinx-astropy',
'sphinx-rtd-theme',
'stsci-rtd-theme',
'tomli; python_version <"3.11"',
'tomli; python_version <="3.11"',
]
test = [
'psutil',
Expand Down
1 change: 1 addition & 0 deletions src/stcal/alignment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .util import * # noqa: F403
89 changes: 89 additions & 0 deletions src/stcal/alignment/reproject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import gwcs
import numpy as np
from astropy import wcs as fitswcs
from astropy.modeling import Model
from typing import Union


def reproject_coords(wcs1, wcs2):
"""
Given two WCSs or transforms return a function which takes pixel
coordinates in the first WCS or transform and computes them in pixel coordinates
in the second one. It performs the forward transformation of ``wcs1`` followed by the
inverse of ``wcs2``.

Parameters
----------
wcs1, wcs2 : `~astropy.wcs.WCS` or `~gwcs.wcs.WCS` or `~astropy.modeling.Model`
WCS objects.

Returns
-------
_reproject : func
Function to compute the transformations. It takes x, y
positions in ``wcs1`` and returns x, y positions in ``wcs2``.
"""

def _get_forward_transform_func(wcs1):
"""Get the forward transform function from the input WCS. If the wcs is a
fitswcs.WCS object all_pix2world requres three inputs, the x (str, ndarrray),
y (str, ndarray), and origin (int). The origin should be between 0, and 1
https://docs.astropy.org/en/latest/wcs/index.html#loading-wcs-information-from-a-fits-file
)
""" # noqa : E501
if isinstance(wcs1, fitswcs.WCS):
forward_transform = wcs1.all_pix2world
elif isinstance(wcs1, gwcs.WCS):
forward_transform = wcs1.forward_transform
elif issubclass(wcs1, Model):
forward_transform = wcs1
else:
raise TypeError(
"Expected input to be astropy.wcs.WCS or gwcs.WCS "
"object or astropy.modeling.Model subclass"
)
return forward_transform

def _get_backward_transform_func(wcs2):
if isinstance(wcs2, fitswcs.WCS):
backward_transform = wcs2.all_world2pix
elif isinstance(wcs2, gwcs.WCS):
backward_transform = wcs2.backward_transform
elif issubclass(wcs2, Model):
backward_transform = wcs2.inverse
else:
raise TypeError(
"Expected input to be astropy.wcs.WCS or gwcs.WCS "
"object or astropy.modeling.Model subclass"
)
return backward_transform

def _reproject(x: Union[str, np.ndarray], y: Union[str, np.ndarray]) -> tuple:
"""
Reprojects the input coordinates from one WCS to another.

Parameters:
-----------
x : str or np.ndarray
Array of x-coordinates to be reprojected.
y : str or np.ndarray
Array of y-coordinates to be reprojected.

Returns:
--------
tuple
Tuple of reprojected x and y coordinates.
"""
# example inputs to resulting function (12, 13, 0) # third number is origin
if not isinstance(x, list):
x = [x]
if not isinstance(y, list):
y = [y]
if len(x) != len(y):
raise ValueError("x and y must be the same length")
sky = _get_forward_transform_func(wcs1)(x, y, 0)
sky_back = np.array(_get_backward_transform_func(wcs2)(sky[0], sky[1], 0))
new_sky = tuple(sky_back[:, :1].flatten())
return tuple(new_sky)

return _reproject
mairanteodoro marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
79 changes: 79 additions & 0 deletions src/stcal/alignment/testing_reproject.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from reproject import reproject_coords\n",
"from stwcs.wcsutil import HSTWCS\n",
"from astropy.wcs import WCS\n",
"from astropy.io import fits\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(2999.9999999998668, 2999.9999999999286)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hdu1=fits.open('hst_12546_22_acs_wfc_f606w_jbt122x1_drc.fits')\n",
"hdu2=fits.open('hst_12546_22_acs_wfc_f814w_jbt122_drc.fits')\n",
"wcs1=WCS(hdu1[1].header)\n",
"wcs2=WCS(hdu2[1].header)\n",
"# wcs2 = HSTWCS('jcdm74guq_drc.fits', ext=1)\n",
"f = reproject_coords(wcs1, wcs2)\n",
"f([3000], [3000])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading