diff options
author | Onderwaater <onderwaa@esrf.fr> | 2015-08-20 10:31:02 +0200 |
---|---|---|
committer | Onderwaater <onderwaa@esrf.fr> | 2015-08-20 10:31:02 +0200 |
commit | 2fb48c4288b75b122dfa8e1bf03be019dd3fdb1e (patch) | |
tree | 8fbb6b31e3fb649fa637644ea04d38843093ff0d | |
parent | f2f629ccfd6a7cf967f4af856c47fe8482f92a8b (diff) |
small mods in the backend + unit testing of backend
-rw-r--r-- | BINoculars/backend.py | 2 | ||||
-rw-r--r-- | BINoculars/backends/id03.py | 112 | ||||
-rw-r--r-- | test/id03.py | 31 |
3 files changed, 88 insertions, 57 deletions
diff --git a/BINoculars/backend.py b/BINoculars/backend.py index 4c267d4..dcbe5a9 100644 --- a/BINoculars/backend.py +++ b/BINoculars/backend.py @@ -41,7 +41,7 @@ class InputBase(util.ConfigurableObject): """Receives command from user, yields Job() instances""" raise NotImplementedError - def process_jobs(self, job): + def process_job(self, job): """Receives a Job() instance, yields (intensity, args_to_be_sent_to_a_Projection_instance) Job()s could have been pickle'd and distributed over a cluster""" diff --git a/BINoculars/backends/id03.py b/BINoculars/backends/id03.py index 507df77..434b81c 100644 --- a/BINoculars/backends/id03.py +++ b/BINoculars/backends/id03.py @@ -344,62 +344,6 @@ class ID03Input(backend.InputBase): return wavelength, UB - def get_point_params(self, scan, first, last): - sl = slice(first, last+1) - - GAM, DEL, TH, CHI, PHI, MU, MON, TRANSM, HRX, HRY = range(10) - params = numpy.zeros((last - first + 1, 10)) # gamma delta theta chi phi mu mon transm - params[:, CHI] = scan.motorpos('Chi') - params[:, PHI] = scan.motorpos('Phi') - - try: - params[:, HRX] = scan.motorpos('hrx') - params[:, HRY] = scan.motorpos('hry') - except: - raise errors.BackendError('The specfile does not accept hrx and hry as a motor label. Have you selected the right hutch? Scannumber = {0}, pointnumber = {1}'.format(self.dbg_scanno, self.dbg_pointno)) - - - if self.is_zap(scan): - if 'th' in scan.alllabels(): - th = scan.datacol('th')[sl] - if len(th) > 1: - sign = numpy.sign(th[1] - th[0]) - else: - sign = 1 - # correction for difference between back and forth in th motor - params[:, TH] = th + sign * self.config.th_offset - else: - params[:, TH] = scan.motorpos('Theta') - - - params[:, GAM] = scan.motorpos('Gam') - params[:, DEL] = scan.motorpos('Delta') - params[:, MU] = scan.motorpos('Mu') - - params[:, MON] = scan.datacol('zap_mon')[sl] - - transm = scan.datacol('zap_transm') - transm[-1] = transm[-2] # bug in specfile - params[:, TRANSM] = transm[sl] - else: - if 'hrx' in scan.alllabels(): - params[:, HRX] = scan.datacol('hrx')[sl] - if 'hry' in scan.alllabels(): - params[:, HRY] = scan.datacol('hry')[sl] - - params[:, TH] = scan.datacol('thcnt')[sl] - params[:, GAM] = scan.datacol('gamcnt')[sl] - params[:, DEL] = scan.datacol('delcnt')[sl] - - try: - params[:, MON] = scan.datacol(self.monitor_counter)[sl] # differs in EH1/EH2 - except: - raise errors.BackendError('The specfile does not accept {2} as a monitor label. Have you selected the right hutch? Scannumber = {0}, pointnumber = {1}'.format(self.dbg_scanno, self.dbg_pointno, self.monitor_counter)) - - params[:, TRANSM] = scan.datacol('transm')[sl] - params[:, MU] = scan.datacol('mucnt')[sl] - - return params def get_images(self, scan, first, last, dry_run=False): if self.config.background: @@ -525,6 +469,62 @@ class EH1(ID03Input): return intensity, (wavelength, UB, gamma_range, delta_range, theta, mu, chi, phi) + def get_point_params(self, scan, first, last): + sl = slice(first, last+1) + + GAM, DEL, TH, CHI, PHI, MU, MON, TRANSM, HRX, HRY = range(10) + params = numpy.zeros((last - first + 1, 10)) # gamma delta theta chi phi mu mon transm + params[:, CHI] = scan.motorpos('Chi') + params[:, PHI] = scan.motorpos('Phi') + + try: + params[:, HRX] = scan.motorpos('hrx') + params[:, HRY] = scan.motorpos('hry') + except: + raise errors.BackendError('The specfile does not accept hrx and hry as a motor label. Have you selected the right hutch? Scannumber = {0}, pointnumber = {1}'.format(self.dbg_scanno, self.dbg_pointno)) + + + if self.is_zap(scan): + if 'th' in scan.alllabels(): + th = scan.datacol('th')[sl] + if len(th) > 1: + sign = numpy.sign(th[1] - th[0]) + else: + sign = 1 + # correction for difference between back and forth in th motor + params[:, TH] = th + sign * self.config.th_offset + else: + params[:, TH] = scan.motorpos('Theta') + + + params[:, GAM] = scan.motorpos('Gam') + params[:, DEL] = scan.motorpos('Delta') + params[:, MU] = scan.motorpos('Mu') + + params[:, MON] = scan.datacol('zap_mon')[sl] + + transm = scan.datacol('zap_transm') + transm[-1] = transm[-2] # bug in specfile + params[:, TRANSM] = transm[sl] + else: + if 'hrx' in scan.alllabels(): + params[:, HRX] = scan.datacol('hrx')[sl] + if 'hry' in scan.alllabels(): + params[:, HRY] = scan.datacol('hry')[sl] + + params[:, TH] = scan.datacol('thcnt')[sl] + params[:, GAM] = scan.datacol('gamcnt')[sl] + params[:, DEL] = scan.datacol('delcnt')[sl] + + try: + params[:, MON] = scan.datacol(self.monitor_counter)[sl] # differs in EH1/EH2 + except: + raise errors.BackendError('The specfile does not accept {2} as a monitor label. Have you selected the right hutch? Scannumber = {0}, pointnumber = {1}'.format(self.dbg_scanno, self.dbg_pointno, self.monitor_counter)) + + params[:, TRANSM] = scan.datacol('transm')[sl] + params[:, MU] = scan.datacol('mucnt')[sl] + + return params class EH2(ID03Input): monitor_counter = 'Monitor' diff --git a/test/id03.py b/test/id03.py new file mode 100644 index 0000000..6b365e8 --- /dev/null +++ b/test/id03.py @@ -0,0 +1,31 @@ +from BINoculars.backends import id03 +import BINoculars.util +import os + +import unittest + +class TestCase(unittest.TestCase): + def setUp(self): + cfg_unparsed = {} + specfile = os.path.join(os.path.split(os.getcwd())[0], 'BINoculars-binaries/examples/dataset/sixc_tutorial.spec' ) + cfg_unparsed['specfile'] = specfile + cfg_unparsed['sdd'] = '1000' + cfg_unparsed['pixelsize'] = '0.055, 0.055' + cfg_unparsed['imagefolder'] = specfile.replace('sixc_tutorial.spec', 'images') + cfg_unparsed['centralpixel'] = '50 ,50' + self.id03input = id03.EH2(cfg_unparsed) + self.projection = id03.pixels({'resolution' : '1'}) + + def test_IO(self): + jobs = list(self.id03input.generate_jobs(['820'])) + destination_opts = self.id03input.get_destination_options(['820']) + imagedata = self.id03input.process_job(jobs[0]) + self.projection.project(*imagedata.next()[1]) + + def tearDown(self): + pass + +if __name__ == '__main__': + unittest.main() + + |