Package fabio :: Module converters
[hide private]
[frames] | no frames]

Source Code for Module fabio.converters

 1  #!/usr/bin/env python  
 2  #coding: utf8 
 3  """ 
 4  Converter module.  
 5  This is for the moment empty (populated only with almost pass through anonymous functions) 
 6  but aims to be populated with more sofisticated translators ...   
 7   
 8  """ 
 9  __author__ = "Jérôme Kieffer" 
10  __contact__ = "jerome.kieffer@esrf.eu" 
11  __license__ = "GPLv3+" 
12  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
13   
14  import types, logging 
15  logger = logging.getLogger("converter") 
16   
17 -def convert_data_integer(data):
18 """ 19 convert data to integer 20 """ 21 if data is not None: 22 return data.astype(int) 23 else: 24 return data
25 26 27 CONVERSION_HEADER = { 28 ("edfimage", "edfimage"): lambda header:header, 29 } 30 CONVERSION_DATA = { 31 ("edfimage", "edfimage"): lambda data:data, 32 ("edfimage", "cbfimage"): convert_data_integer, 33 ("edfimage", "mar345image"): convert_data_integer, 34 ("edfimage", "fit2dmaskimage"): convert_data_integer, 35 ("edfimage", "kcdimage"): convert_data_integer, 36 ("edfimage", "OXDimage"): convert_data_integer, 37 ("edfimage", "pnmimage"): convert_data_integer, 38 } 39
40 -def convert_data(inp, outp, data):
41 """ 42 Return data converted to the output format ... over-simplistic implementation for the moment ... 43 @param inp,outp: input/output format like "cbfimage" 44 @param data(ndarray): the actual dataset to be transformed 45 """ 46 return CONVERSION_DATA.get((inp, outp), lambda data:data)(data)
47
48 -def convert_header(inp, outp, header):
49 """ 50 return header converted to the output format 51 @param inp,outp: input/output format like "cbfimage" 52 @param header(dict):the actual set of headers to be transformed 53 """ 54 return CONVERSION_HEADER.get((inp, outp), lambda header:header)(header)
55