def getTestImagePaths(dir, mjd, file): """Return the infile and outfile associated with this filename.""" infile = guiderTester.getTestFile(dir, mjd, file) outfile = guiderTester.getTestFile(dir, mjd, 'proc-' + file, raiseError=False) return infile, outfile
def test_compare_c_code_0040(self): """Test GuiderImageAnalysis.__call__() vs the old expected values.""" self.outFile = self._test_call(mjd=57357, plateid=7660, fscan_mjd=57356, fscan_id=1, frameid=40, gprobes_disabled=[11]) dataExpect = guiderTester.getTestFile('gcam', 57357, 'expect-gimg-0040.fits.gz') self._compareBinTables(self.outFile, dataExpect)
def test_compare_c_code_0042(self): """Same as test_compare_c_code_0040 but with 0042. To test consistency in the dRA/dDec difference between images taken using the same cart and flat, on the same night. """ self.outFile = self._test_call(mjd=57357, plateid=7660, fscan_mjd=57356, fscan_id=1, frameid=42, gprobes_disabled=[11]) dataExpect = guiderTester.getTestFile('gcam', 57357, 'expect-gimg-0042.fits.gz') self._compareBinTables(self.outFile, dataExpect)
def test_analyzeFlat(self): """Test GuiderImageAnalysis.analyzeFlat()""" self.init_probes(mjd=57357, plateid=7660, fscan_mjd=57356, fscan_id=1) inFile, self.outFile = getTestImagePaths('gcam', 57357, 'gimg-0003.fits.gz') flatExpect = guiderTester.getTestFile('gcam', 57357, 'expect-gimg-0003.fits.gz') self.gi.analyzeFlat(inFile, self.gState.gprobes, cmd=self.cmd) self.assertTrue(os.path.exists(self.outFile)) # First, we compare with the proc-gimg file generated using the C # code. We will tell us if our figure are in the ballpark. # TODO: the current expected results file is missing fiber 11 because # it's damaged. If we fix the code to deal with that per #2357 we'll # need a test that knows about that fiber! result = pyfits.open(self.outFile) expect = pyfits.open(flatExpect) for column in result[6].data.names: if column == 'fiber_type': # Trouble testing numpy string arrays self.assertTrue( (result[6].data[column] == expect[6].data[column]).all(), '{0} has a mismatch'.format(column)) elif column not in ['rotStar2Sky', 'ugriz', 'ref_mag']: # TODO: remove the if rotStar2Sky once we have a better test! # The problem is rotStar2Sky was never saved for old flats. # TODO: don't have ugriz data for these to test, # but could add some. Would have to pull it from the database. np.testing.assert_allclose( result[6].data[column], expect[6].data[column], err_msg='{0} has a mismatch'.format(column)) self._check_overwriting(inFile, self.outFile, self.gi.analyzeFlat, [self.gState.gprobes])
def test_call_iraf(self): """Test GuiderImageAnalysis.__call__() vs values measured with IRAF.""" self.outFile = self._test_call(mjd=57357, plateid=7660, fscan_mjd=57356, fscan_id=1, frameid=40, gprobes_disabled=[3, 11]) dataIRAF_file = guiderTester.getTestFile('gcam', 57357, 'expected_7660-57356-1.json') dataIRAF = json.load(open(dataIRAF_file)) result = pyfits.open(self.outFile) data = result[6].data # Loads expected values measured using IRAF's imexam # Removes 0.5 to make measurements 0-indexed and centred on the pixel. imexam_xystar = np.array(dataIRAF['57357']['imexam_xstar_ystar'], np.float32) - 0.5 # Fiber 11 was disabled, so we make it nan in IRAF imexam_xystar[10, :] = np.nan # import ipdb; ipdb.set_trace() # FIXME: These tests fails, as the relative difference with the # PyGuide centroids is still significant. np.testing.assert_allclose(data['xstar'], imexam_xystar[:, 0], rtol=5e-3, err_msg='xstar does not match.') np.testing.assert_allclose(data['ystar'], imexam_xystar[:, 1], rtol=5e-3, err_msg='ystar does not match.')
import guiderActor.myGlobals as myGlobals import guiderTester from actorcore import TestHelper from guiderActor import masterThread from guiderActor.gimg import guiderImage def updateModel(name, model): """Update the named actorState model with new parameters.""" myGlobals.actorState.models[name] = TestHelper.Model(name, model) mjd = 57357 darkFile = guiderTester.getTestFile('gcam/', mjd, 'gimg-0001.fits.gz') flatFile = guiderTester.getTestFile('gcam/', mjd, 'gimg-0003.fits.gz') dataFile = guiderTester.getTestFile('gcam/', mjd, 'gimg-0040.fits.gz') gTester = guiderTester.GuiderTester() gTester.attachCmdSets = False gTester.setUp() # force the gi instance to be at location=APO. gTester.gi = guiderImage.GuiderImageAnalysis(gTester.setPoint_good, 'APO') # setup to use all 16 "real" probes gTester.init_probes(mjd, 7660, 57356, 1, camera='gcam') updateModel('mcp', TestHelper.mcpState['boss_science']) gTester.actorState.bypassDark = False # pre-process the dark and flat. gTester.gi.analyzeDark(darkFile, cmd=gTester.cmd)
from __future__ import division, print_function import json import numpy as np from astropy.io import fits from matplotlib import pyplot as plt from guiderTester import getTestFile from PyGuide import CCDInfo, findStars # This script plots the contours for a processed guider image and overlays # the star centroids as measured using a number of methods. # Loads a processed gimg generated using guiderActor and PyGuide. ff = fits.open(getTestFile('gcam', 57357, 'processed/proc-gimg-0040.fits.gz')) data = np.clip(ff[0].data, 400, 10500) plt.contour(data, levels=np.arange(500, 10000, 1000), origin='lower', colors='k', linewidths=0.1) # Plots the centres of the centroids as calculated for the previous image. xstar = ff[-1].data['xstar'] ystar = ff[-1].data['ystar'] guider_PyGuide = plt.scatter(xstar, ystar, marker='x', color='r',