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

Fix for 107: allow user to ignore non-square pixel error #113

Merged
merged 1 commit into from
Jul 31, 2022
Merged
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions pvextractor/pvextractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def extract_pv_slice(cube, path, wcs=None, spacing=1.0, order=3,
respect_nan=True):
respect_nan=True, assert_square=True):
"""
Given a position-position-velocity cube with dimensions (nv, ny, nx), and
a path, extract a position-velocity slice.
Expand Down Expand Up @@ -49,6 +49,11 @@ def extract_pv_slice(cube, path, wcs=None, spacing=1.0, order=3,
the slices. If set to `True`, in the case of line paths a second
computation is performed to ignore the NaN value while interpolating,
and set the output values of NaNs to NaN.
assert_square : bool
If True, the WCS-loader will check whether the pixels are square.
If the pixels are not square, the interpretation of the X-axis in
the extracted PV diagram is ambiguous. In some cases, it may be
necessary to disable this check, though.

Returns
-------
Expand All @@ -75,7 +80,12 @@ def extract_pv_slice(cube, path, wcs=None, spacing=1.0, order=3,
wcs = sanitize_wcs(wcs)

if not isinstance(cube, np.ndarray) or wcs is not None:
scale = get_spatial_scale(wcs)
try:
scale = get_spatial_scale(wcs, assert_square=assert_square)
except AssertionError as ex:
print("Pixels are non-square. See error below. You may "
"disable this check by setting assert_square=False.")
raise ex
if isinstance(spacing, u.Quantity):
pixel_spacing = (spacing / scale).decompose()
world_spacing = spacing
Expand Down