From 277233bd1a589feeb648947256e34b0b4fb6f540 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Tue, 24 May 2016 11:27:56 +0100 Subject: [PATCH] Fix a bug that caused WCSAxes to crash when trying to transform arrays with zero coordinates. --- CHANGES.md | 3 +++ wcsaxes/transforms.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a02b228..1fcd307 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,9 @@ - Added property getters for color and linewidth in BaseFrame. [#203] +- Fix a bug that caused WCSAxes to crash when trying to transform arrays with + zero coordinates. [#202] + 0.7 (2016-05-06) ---------------- diff --git a/wcsaxes/transforms.py b/wcsaxes/transforms.py index 44d2b76..bc6401a 100644 --- a/wcsaxes/transforms.py +++ b/wcsaxes/transforms.py @@ -95,7 +95,10 @@ def transform(self, world): if world.shape[1] != self.wcs.wcs.naxis: raise ValueError("Second dimension of input values should match number of WCS coordinates") - pixel = self.wcs.wcs_world2pix(world, 1) - 1 + if world.shape[0] == 0: + pixel = np.zeros((0, 2)) + else: + pixel = self.wcs.wcs_world2pix(world, 1) - 1 if self.slice is None: return pixel @@ -162,7 +165,10 @@ def transform(self, pixel): pixel_full += 1 - world = self.wcs.wcs_pix2world(pixel_full, 1) + if pixel_full.shape[0] == 0: + world = np.zeros((0, 2)) + else: + world = self.wcs.wcs_pix2world(pixel_full, 1) # At the moment, one has to manually check that the transformation # round-trips, otherwise it should be considered invalid.