def _runGridValidity(self, config, gstepx, gsizex, gstepy, gsizey, adjustGridOption, expectedVal=1.): """Method to test the grid validity given an input config. Here we also iterate over scaleByFwhm in (True, False) and ensure that we get more `boxes` when `scaleByFwhm=False` than vice versa. Parameters ---------- config : `ipDiffim.AddAmountImageMapReduceConfig` input AddAmountImageMapReduceConfig gstepx : `float` grid x-direction step size gsizex : `float` grid x-direction box size gstepy : `float` grid y-direction step size gsizey : `float` grid y-direction box size expectedVal : `float` float to add to exposure (to compare for testing) """ config.mapper.addAmount = expectedVal lenBoxes = [0, 0] for scaleByFwhm in (True, False): config.scaleByFwhm = scaleByFwhm if scaleByFwhm: config.gridStepX = float(gstepx) config.cellSizeX = float(gsizex) config.gridStepY = float(gstepy) config.cellSizeY = float(gsizey) else: # otherwise the grid is too fine and elements too small. config.gridStepX = gstepx * 3. config.cellSizeX = gsizex * 3. config.gridStepY = gstepy * 3. config.cellSizeY = gsizey * 3. config.adjustGridOption = adjustGridOption task = ImageMapReduceTask(config) task._generateGrid(self.exposure) ind = 0 if scaleByFwhm else 1 lenBoxes[ind] = len(task.boxes0) newExp = task.run(self.exposure).exposure newMI = newExp.getMaskedImage() newArr = newMI.getImage().getArray() isnan = np.isnan(newArr) self.assertEqual(np.sum(isnan), 0, msg='Failed NaN (%d), on config: %s' % (np.sum(isnan), str(config))) mi = self.exposure.getMaskedImage().getImage().getArray() self.assertFloatsAlmostEqual(mi[~isnan], newArr[~isnan] - expectedVal, msg='Failed on config: %s' % str(config)) self.assertLess(lenBoxes[0], lenBoxes[1], msg='Failed lengths on config: %s' % str(config))
def _runGridValidity(self, config, gstepx, gsizex, gstepy, gsizey, adjustGridOption, expectedVal=1.): """Method to test the grid validity given an input config. Here we also iterate over scaleByFwhm in (True, False) and ensure that we get more `boxes` when `scaleByFwhm=False` than vice versa. Parameters ---------- config : `ipDiffim.AddAmountImageMapReduceConfig` input AddAmountImageMapReduceConfig gstepx : `float` grid x-direction step size gsizex : `float` grid x-direction box size gstepy : `float` grid y-direction step size gsizey : `float` grid y-direction box size expectedVal : `float` float to add to exposure (to compare for testing) """ config.mapper.addAmount = expectedVal lenBoxes = [0, 0] for scaleByFwhm in (True, False): config.scaleByFwhm = scaleByFwhm if scaleByFwhm: config.gridStepX = float(gstepx) config.cellSizeX = float(gsizex) config.gridStepY = float(gstepy) config.cellSizeY = float(gsizey) else: # otherwise the grid is too fine and elements too small. config.gridStepX = gstepx * 3. config.cellSizeX = gsizex * 3. config.gridStepY = gstepy * 3. config.cellSizeY = gsizey * 3. config.adjustGridOption = adjustGridOption task = ImageMapReduceTask(config) task._generateGrid(self.exposure) ind = 0 if scaleByFwhm else 1 lenBoxes[ind] = len(task.boxes0) newExp = task.run(self.exposure).exposure newMI = newExp.getMaskedImage() newArr = newMI.getImage().getArray() isnan = np.isnan(newArr) self.assertEqual(np.sum(isnan), 0, msg='Failed NaN (%d), on config: %s' % (np.sum(isnan), str(config))) mi = self.exposure.getMaskedImage().getImage().getArray() self.assertFloatsAlmostEqual(mi[~isnan], newArr[~isnan] - expectedVal, msg='Failed on config: %s' % str(config)) self.assertLess(lenBoxes[0], lenBoxes[1], msg='Failed lengths on config: %s' % str(config))
def testCellCentroidsWrongLength(self): """Test sample grid task which is provided a set of `cellCentroids` and returns the mean of the subimages surrounding those centroids using 'none' for `reduceOperation`. In this case, we ensure that len(task.boxes0) != len(task.boxes1) and check for ValueError. """ config = GetMeanImageMapReduceConfig() config.reducer.reduceOperation = 'none' config.cellCentroidsX = [i for i in np.linspace(0, 128, 50)] config.cellCentroidsY = [i for i in np.linspace(0, 128, 50)] task = ImageMapReduceTask(config) task._generateGrid(self.exposure) del task.boxes0[-1] # remove the last box with self.assertRaises(ValueError): task.run(self.exposure)
def testCellCentroidsWrongLength(self): """Test sample grid task which is provided a set of `cellCentroids` and returns the mean of the subimages surrounding those centroids using 'none' for `reduceOperation`. In this case, we ensure that len(task.boxes0) != len(task.boxes1) and check for ValueError. """ config = GetMeanImageMapReduceConfig() config.reducer.reduceOperation = 'none' config.cellCentroidsX = [i for i in np.linspace(0, 128, 50)] config.cellCentroidsY = [i for i in np.linspace(0, 128, 50)] task = ImageMapReduceTask(config) task._generateGrid(self.exposure) del task.boxes0[-1] # remove the last box with self.assertRaises(ValueError): task.run(self.exposure)