#!/usr/bin/env python # -*- coding: utf-8 -*- import datetime import numpy as np import pyopencl as cl from bumps.names import Parameter from sans.dataloader.loader import Loader from sans.dataloader.manipulations import Ringcut, Boxcut TIC = None def tic(): global TIC TIC = datetime.datetime.now() def toc(): now = datetime.datetime.now() return (now-TIC).total_seconds() def load_data(filename): loader = Loader() data = loader.load(filename) if data is None: raise IOError("Data %r could not be loaded"%filename) return data def set_precision(src, qx, qy, dtype): qx = np.ascontiguousarray(qx, dtype=dtype) qy = np.ascontiguousarray(qy, dtype=dtype) if np.dtype(dtype) == np.dtype('float32'): header = """\ #define REAL(x) (x##f) #define real float """ else: header = """\ #pragma OPENCL EXTENSION cl_khr_fp64: enable #define REAL(x) (x) #define real double """ return header+src, qx, qy def set_precision_1d(src, q, dtype): q = np.ascontiguousarray(q, dtype=dtype) if np.dtype(dtype) == np.dtype('float32'): header = """\ #define real float """ else: header = """\ #pragma OPENCL EXTENSION cl_khr_fp64: enable #define real double """ return header+src, q def set_beam_stop(data, radius, outer=None): if hasattr(data, 'qx_data'): data.mask = Ringcut(0, radius)(data) if outer is not None: data.mask += Ringcut(outer,np.inf)(data) else: data.mask = (data.x>=radius) if outer is not None: data.mask &= (data.x