def test_shape_error(self): ''' Test for various shape errors ''' mygridder = cygrid.SlGrid(self.target_x, self.target_y) mygridder.set_kernel(*self.kernel_args) with pytest.raises(cygrid.ShapeError): mygridder.grid(self.xcoords, self.ycoords[:, np.newaxis], self.signal) with pytest.raises(cygrid.ShapeError): # this should not work, as the second call to grid has # incompatible shape mygridder.grid(self.xcoords, self.ycoords, self.signal) mygridder.grid(self.xcoords, self.ycoords, self.signal[:, np.newaxis]) # now test with user-provided data cube dcube = np.zeros_like(self.test_sls[0]) mygridder = cygrid.SlGrid(self.target_x, self.target_y, datacube=dcube) mygridder.set_kernel(*self.kernel_args) with pytest.raises(cygrid.ShapeError): mygridder.grid(self.xcoords, self.ycoords, self.signal[:, np.newaxis])
def test_gridding2d(self): mygridder = cygrid.SlGrid(self.target_x, self.target_y) mygridder.set_kernel(*self.kernel_args) mygridder.grid(self.xcoords, self.ycoords, self.signal2) assert_allclose(mygridder.get_datacube(), self.test_sls[0], atol=1.e-6)
def test_gridding3d(self): mygridder = cygrid.SlGrid(self.target_x, self.target_y) mygridder.set_kernel(*self.kernel_args) mygridder.grid(self.xcoords, self.ycoords, self.signal3) if False: np.save('/tmp/cygrid_test_sightlines.npy', mygridder.get_datacube()) assert_allclose(mygridder.get_datacube(), self.test_sls, atol=1.e-6)
def test_c_contiguous(self): ''' Cygrid should autocast to C-contiguous if necessary and raise an error if user-provided datacube is not C-contiguous ''' signal2_f_cont = np.require(self.signal2, self.signal2.dtype, 'F') mygridder = cygrid.SlGrid(self.target_x, self.target_y) mygridder.set_kernel(*self.kernel_args) mygridder.grid(self.xcoords, self.ycoords, signal2_f_cont) assert_allclose(mygridder.get_datacube(), self.test_sls[0], atol=1.e-6) dcube_f_cont = np.require(np.zeros_like(self.test_sls[0, 0]), 'F') mygridder = cygrid.SlGrid(self.target_x, self.target_y, datacube=dcube_f_cont) mygridder.set_kernel(*self.kernel_args) with pytest.raises(TypeError): mygridder.grid(self.xcoords, self.ycoords, self.signal)
def test_user_datacube_memorycell(self): ''' If user provides a data cube, it must be made sure that cygrid writes to the correct memory cell (even though, the `get_unweighted_datacube` method can have a different object id due to internal reshaping) ''' dcube = np.zeros_like(self.test_sls[0, 0]) # float64 mygridder = cygrid.SlGrid(self.target_x, self.target_y, datacube=dcube) mygridder.set_kernel(*self.kernel_args) mygridder.grid(self.xcoords, self.ycoords, self.signal) assert_allclose(mygridder.get_datacube(), self.test_sls[0, 0], atol=1.e-6) assert_allclose(mygridder.get_unweighted_datacube(), dcube, atol=1.e-6)
def test_dtype_warning(self): ''' Test for dtype warning In fact, at the moment there is only one possible warning, as everything else should be properly casted, etc. ''' dcube = np.zeros_like(self.test_sls[0, 0]) # float32 mygridder = cygrid.SlGrid(self.target_x, self.target_y, datacube=dcube, dtype=np.float64) mygridder.set_kernel(*self.kernel_args) with pytest.warns(UserWarning): mygridder.grid(self.xcoords, self.ycoords, self.signal)
def test_byteorder_warning(self): ''' Test for byteorder warning Apparently astroquery.skyview can return wrong (non-native) byteorder. ''' dcube = np.zeros_like(self.test_sls[0, 0]) # float32 mygridder = cygrid.SlGrid(self.target_x, self.target_y, datacube=dcube, dtype=np.float64) mygridder.set_kernel(*self.kernel_args) signal_swapped = self.signal.byteswap().newbyteorder() with pytest.warns(UserWarning): mygridder.grid(self.xcoords, self.ycoords, signal_swapped)
def test_kernel_not_set_error(self): mygridder = cygrid.SlGrid(self.target_x, self.target_y) with pytest.raises(RuntimeError): mygridder.grid(self.xcoords, self.ycoords, self.signal)