summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOnderwaater <onderwaa@esrf.fr>2015-12-07 15:47:37 +0100
committerOnderwaater <onderwaa@esrf.fr>2015-12-07 15:47:37 +0100
commit238bf3d8c389b28313009fd37729cfa13bd4abb3 (patch)
tree9bbbe3a624bc48b97c4a60b45624c1ec9184fab8
parent6789d48c0f9343d2d89a8aa544074a6dcbce586d (diff)
introducing weighed averaging API changes!!
-rw-r--r--binoculars/backend.py2
-rw-r--r--binoculars/backends/bm25.py2
-rw-r--r--binoculars/backends/bm32.py12
-rw-r--r--binoculars/backends/example.py11
-rw-r--r--binoculars/backends/id03.py35
-rw-r--r--binoculars/backends/id03_xu.py2
-rw-r--r--binoculars/backends/sixs.py6
-rwxr-xr-xbinoculars/main.py8
-rw-r--r--binoculars/plot.py3
-rwxr-xr-xbinoculars/space.py136
-rw-r--r--test/cfg.py10
-rw-r--r--test/id03.py18
-rw-r--r--test/metadata.py24
13 files changed, 123 insertions, 146 deletions
diff --git a/binoculars/backend.py b/binoculars/backend.py
index b29e12c..68eeafb 100644
--- a/binoculars/backend.py
+++ b/binoculars/backend.py
@@ -40,7 +40,7 @@ class InputBase(util.ConfigurableObject):
def parse_config(self, config):
super(InputBase, self).parse_config(config)
- self.config.target_weight = int(config.pop('target_weight', 0))## approximate number of images per job, only useful when running on the oar cluster
+ self.config.target_weight = int(config.pop('target_weight', 1000))## approximate number of images per job, only useful when running on the oar cluster
def generate_jobs(self, command):
"""Receives command from user, yields Job() instances"""
diff --git a/binoculars/backends/bm25.py b/binoculars/backends/bm25.py
index 0b9b567..d9e8adc 100644
--- a/binoculars/backends/bm25.py
+++ b/binoculars/backends/bm25.py
@@ -210,7 +210,7 @@ class EH2SCD(EDFInput):
# masking
intensity = self.apply_mask(data, self.config.xmask, self.config.ymask)
- return intensity, (mu, th, phi, chi, cty, ctx, ctz, cth, ctr,
+ return intensity, numpy.ones_like(intensity), (mu, th, phi, chi, cty, ctx, ctz, cth, ctr,## weights added to API. Treated here like before
wavelength, UB, self.qconv)
@staticmethod
diff --git a/binoculars/backends/bm32.py b/binoculars/backends/bm32.py
index 79451a5..cf03d3f 100644
--- a/binoculars/backends/bm32.py
+++ b/binoculars/backends/bm32.py
@@ -320,6 +320,8 @@ class EH1(BM32Input):
image = edf.GetData(0)
header = edf.GetHeader(0)
+ weights = numpy.ones_like(image)
+
if not self.config.centralpixel:
self.config.centralpixel = (int(header['y_beam']), int(header['x_beam']))
if not self.config.sdd:
@@ -349,22 +351,28 @@ class EH1(BM32Input):
if self.config.maskmatrix is not None:
if self.config.maskmatrix.shape != data.shape:
raise errors.BackendError('The mask matrix does not have the same shape as the images')
- data = numpy.ma.array(data, mask = ~self.config.maskmatrix)
+ weights *= self.config.maskmatrix
delta_range = delta_range[self.config.ymask]
beta_range = beta_range[self.config.xmask]
+
+ weights = self.apply_mask(weights, self.config.xmask, self.config.ymask)
intensity = self.apply_mask(data, self.config.xmask, self.config.ymask)
intensity = numpy.rot90(intensity)
intensity = numpy.fliplr(intensity)
intensity = numpy.flipud(intensity)
+ weights = numpy.rot90(weights)
+ weights = numpy.fliplr(weights)
+ weights = numpy.flipud(weights)
+
#polarisation correction
delta_grid, beta_grid = numpy.meshgrid(delta_range, beta_range)
Pver = 1 - numpy.sin(delta_grid * numpy.pi / 180.)**2 * numpy.cos(beta_grid * numpy.pi / 180.)**2
#intensity /= Pver
- return intensity, (wavelength, UB, beta_range, delta_range, omega, alfa, chi, phi)
+ return intensity, weights, (wavelength, UB, beta_range, delta_range, omega, alfa, chi, phi)
def get_point_params(self, scan, first, last):
sl = slice(first, last+1)
diff --git a/binoculars/backends/example.py b/binoculars/backends/example.py
index 6475189..c763eb8 100644
--- a/binoculars/backends/example.py
+++ b/binoculars/backends/example.py
@@ -58,15 +58,18 @@ class Input(backend.InputBase):
def process_job(self, job):
'''
- This methods is a generator that returns the intensity and a tuple of coordinates that
+ This methods is a generator that returns the intensity, the weights and a tuple of coordinates that
will be used for projection. The input is a backend.job object. This objects contains attributes that are supplied
- as keyword arguments in the generate_jobs method when backend.Job is instantiated.
+ as keyword arguments in the generate_jobs method when backend.Job is instantiated. You can wet here the weights according
+ the behaviour of your detector. To select normal averaging give the weights the value of ones. This array should be the same shape as
+ the intensity array.
This example backend simulates a random path through angular space starting at the origin.
an example image will be generated using a three dimensional 10-slit interference function.
The angles are with respect to the sample where af and delta are the angular coordinates
of the pixels and ai and omega are the in plane and out of plane angles of the incoming beam.
'''
+ super(Input, self).process_job(job)# call super to fix metadeta handling
scan = job.scan
#reflects a scan with 100 datapoints
@@ -74,7 +77,6 @@ class Input(backend.InputBase):
adelta = numpy.linspace(0, numpy.random.random() * 20, 100)
aai = numpy.linspace(0, numpy.random.random() * 20, 100)
aomega = numpy.linspace(0, numpy.random.random() * 20, 100)
-
for af, delta, ai, omega in zip(aaf, adelta, aai, aomega):
print 'af: {0}, delta: {1}, ai: {2}, omega: {3}'.format(af, delta, ai, omega)
@@ -105,8 +107,9 @@ class Input(backend.InputBase):
#simulating the image
data = numpy.abs(numpy.sin(qx * 10) / numpy.sin(qx) * numpy.sin(qy * 10) / numpy.sin(qy) * numpy.sin(qz * 10) / numpy.sin(qz))**2
+ weights = numpy.ones_like(data)
- yield data.flatten(), (self.config.wavelength, af, delta, omega, ai)
+ yield data, weights, (self.config.wavelength, af, delta, omega, ai)
def parse_config(self, config):
'''
diff --git a/binoculars/backends/id03.py b/binoculars/backends/id03.py
index dbc30df..6e618a2 100644
--- a/binoculars/backends/id03.py
+++ b/binoculars/backends/id03.py
@@ -539,6 +539,8 @@ class EH1(ID03Input):
gamma, delta, theta, chi, phi, mu, mon, transm, hrx, hry = pointparams
wavelength, UB = scanparams
+ weights = numpy.ones_like(image)
+
if self.config.hr:
zerohrx, zerohry = self.config.hr
chi = (hrx - zerohrx) / numpy.pi * 180. / 1000
@@ -568,18 +570,20 @@ class EH1(ID03Input):
if self.config.maskmatrix is not None:
if self.config.maskmatrix.shape != data.shape:
raise errors.BackendError('The mask matrix does not have the same shape as the images')
- data = numpy.ma.array(data, mask = ~self.config.maskmatrix)
+ weights *= self.config.maskmatrix
gamma_range = gamma_range[self.config.ymask]
delta_range = delta_range[self.config.xmask]
intensity = self.apply_mask(data, self.config.xmask, self.config.ymask)
+ weights = self.apply_mask(weights, self.config.xmask, self.config.ymask)
#polarisation correction
delta_grid, gamma_grid = numpy.meshgrid(delta_range, gamma_range)
Pver = 1 - numpy.sin(delta_grid * numpy.pi / 180.)**2 * numpy.cos(gamma_grid * numpy.pi / 180.)**2
intensity /= Pver
- return intensity, (wavelength, UB, gamma_range, delta_range, theta, mu, chi, phi)
+ return intensity, weights, (wavelength, UB, gamma_range, delta_range, theta, mu, chi, phi)
+
def get_point_params(self, scan, first, last):
sl = slice(first, last+1)
@@ -649,9 +653,11 @@ class EH2(ID03Input):
self.config.UB = util.parse_tuple(self.config.UB, length=9, type=float)
def process_image(self, scanparams, pointparams, image):
-
gamma, delta, theta, chi, phi, mu, mon, transm = pointparams
wavelength, UB = scanparams
+
+ weights = numpy.ones_like(image)
+
if self.config.background:
data = image / mon
else:
@@ -675,24 +681,27 @@ class EH2(ID03Input):
delta_range = app[1] * (numpy.arange(data.shape[1]) - centralpixel[1]) + delta
# masking
-
if self.config.maskmatrix is not None:
if self.config.maskmatrix.shape != data.shape:
raise errors.BackendError('The mask matrix does not have the same shape as the images')
- data = numpy.ma.array(data, mask = ~self.config.maskmatrix)
+ weights *= self.config.maskmatrix
gamma_range = gamma_range[self.config.xmask]
delta_range = delta_range[self.config.ymask]
intensity = self.apply_mask(data, self.config.xmask, self.config.ymask)
+ weights = self.apply_mask(weights, self.config.xmask, self.config.ymask)
+
intensity = numpy.fliplr(intensity)
intensity = numpy.rot90(intensity)
+ weights = numpy.fliplr(weights)#TODO: should be done more efficiently. Will prob change with new HKL calculations
+ weights = numpy.rot90(weights)
#polarisation correction
delta_grid, gamma_grid = numpy.meshgrid(delta_range, gamma_range)
Phor = 1 - (numpy.sin(mu * numpy.pi / 180.) * numpy.sin(delta_grid * numpy.pi / 180.) * numpy.cos(gamma_grid* numpy.pi / 180.) + numpy.cos(mu* numpy.pi / 180.) * numpy.sin(gamma_grid* numpy.pi / 180.))**2
intensity /= Phor
- return intensity, (wavelength, UB, gamma_range, delta_range, theta, mu, chi, phi)
+ return intensity, weights, (wavelength, UB, gamma_range, delta_range, theta, mu, chi, phi)
def get_point_params(self, scan, first, last):
sl = slice(first, last+1)
@@ -702,7 +711,6 @@ class EH2(ID03Input):
params[:, CHI] = scan.motorpos('Chi')
params[:, PHI] = scan.motorpos('Phi')
-
if self.is_zap(scan):
if 'th' in scan.alllabels():
th = scan.datacol('th')[sl]
@@ -737,15 +745,13 @@ class EH2(ID03Input):
params[:, MU] = scan.datacol('mucnt')[sl]
return params
-
-
class GisaxsDetector(ID03Input):
monitor_counter = 'mon'
def process_image(self, scanparams, pointparams, image):
ccdy, ccdz, theta, chi, phi, mu, mon, transm= pointparams
- image = numpy.rot90(image, self.config.drotation)
+ weights = numpy.ones_like(image)
wavelength, UB = scanparams
@@ -775,16 +781,21 @@ class GisaxsDetector(ID03Input):
data *= spd**2 / sdd
# masking
+ if self.config.maskmatrix is not None:
+ if self.config.maskmatrix.shape != data.shape:
+ raise errors.BackendError('The mask matrix does not have the same shape as the images')
+ weights *= self.config.maskmatrix
+
gamma_range = gamma_range[self.config.ymask]
delta_range = delta_range[self.config.xmask]
intensity = self.apply_mask(data, self.config.xmask, self.config.ymask)
+ weights = self.apply_mask(weights, self.config.xmask, self.config.ymask)
- return intensity, (wavelength, UB, gamma_range, delta_range, theta, mu, chi, phi)
+ return intensity, weights, (wavelength, UB, gamma_range, delta_range, theta, mu, chi, phi)
def parse_config(self, config):
super(GisaxsDetector, self).parse_config(config)
- self.config.drotation = int(config.pop('drotation', 0)) #Optional; Rotation of the detector, takes standard orientation by default. input 1 for 90 dgree rotation, 2 for 180 and 3 for 270.
self.config.directbeam = util.parse_tuple(config.pop('directbeam'), length=2, type=int)
self.config.directbeam_coords = util.parse_tuple(config.pop('directbeam_coords'), length=2, type=float) #Coordinates of ccdy and ccdz at the direct beam position
diff --git a/binoculars/backends/id03_xu.py b/binoculars/backends/id03_xu.py
index 1bf5a7b..d8c3fe0 100644
--- a/binoculars/backends/id03_xu.py
+++ b/binoculars/backends/id03_xu.py
@@ -227,7 +227,7 @@ class EH2(ID03Input):
# no polarization correction for the moment!
- return intensity, (mu, theta, delta, gamma, gamT,
+ return intensity, numpy.ones_like(intensity), (mu, theta, delta, gamma, gamT,#weights added to API. keeps functionality identical with wights of one
self.ty, wavelength, UB, self.qconv)
def get_point_params(self, scan, first, last):
diff --git a/binoculars/backends/sixs.py b/binoculars/backends/sixs.py
index c42af2d..b7473f4 100644
--- a/binoculars/backends/sixs.py
+++ b/binoculars/backends/sixs.py
@@ -395,10 +395,12 @@ class FlyScanUHV(SIXS):
else:
mask = detector.mask
- intensity = numpy.ma.array(data = dataframe.image[index, ...], mask = mask)
+ intensity = dataframe.image[index, ...]
+ weights = numpy.ones_like(intensity)
+ weights *= ~mask
#util.status('{4}| gamma: {0}, delta: {1}, theta: {2}, mu: {3}'.format(gamma, delta, theta, mu, time.ctime(time.time())))
- return intensity, (index, dataframe, pixels)
+ return intensity, weights, (index, dataframe, pixels)
def get_pixels(self, detector):
detector = ALL_DETECTORS[detector.name]()
diff --git a/binoculars/main.py b/binoculars/main.py
index 963dcca..bac4b7e 100755
--- a/binoculars/main.py
+++ b/binoculars/main.py
@@ -86,9 +86,9 @@ class Main(object):
def generator():
res = self.projection.config.resolution
labels = self.projection.get_axis_labels()
- for intensity, params in self.input.process_job(job):
+ for intensity, weights, params in self.input.process_job(job):
coords = self.projection.project(*params)
- yield space.Space.from_image(res, labels, coords, intensity, limits = self.projection.config.limits)
+ yield space.Space.from_image(res, labels, coords, intensity, weights, limits = self.projection.config.limits)
jobspace = space.chunked_sum(generator(), chunksize=25)
if isinstance(jobspace, space.Space):
jobspace.metadata.add_dataset(self.input.metadata)
@@ -122,9 +122,9 @@ class Split(Main): #completely ignores the dispatcher, just yields a space per i
def process_job(self, job):
res = self.projection.config.resolution
labels = self.projection.get_axis_labels()
- for intensity, params in self.input.process_job(job):
+ for intensity, weights, params in self.input.process_job(job):
coords = self.projection.project(*params)
- yield space.Space.from_image(res, labels, coords, intensity, limits = self.projection.config.limits)
+ yield space.Space.from_image(res, labels, coords, intensity, weights, limits = self.projection.config.limits)
def run(self):
diff --git a/binoculars/plot.py b/binoculars/plot.py
index 78afd3a..da04fae 100644
--- a/binoculars/plot.py
+++ b/binoculars/plot.py
@@ -160,13 +160,12 @@ def plot(space, fig, ax, log=True, loglog = False, clipping=0.0, fit=None, norm=
raise ValueError("For 3D plots, the 'ax' parameter must be an Axes3D instance (use for example gca(projection='3d') to get one)")
cmap = getattr(matplotlib.cm, plotopts.pop('cmap', 'jet'))
- if not norm is None:
+ if norm is None:
norm = get_clipped_norm(space.get_masked(), clipping, log)
data = space.get()
mask = numpy.bitwise_or(~numpy.isfinite(data), data == 0)
gridx, gridy, gridz = tuple(grid[~mask] for grid in space.get_grid())
-
im = ax.scatter(gridx, gridy, gridz, c=cmap(norm(data[~mask])), marker = ',', alpha = 0.7,linewidths = 0)
#p1 = ax.plot_surface(gridx[0,:,:], gridy[0,:,:], gridz[0,:,:], facecolors=cmap(norm(space.project(0).get_masked())), shade=False, cstride=1, rstride=1)
diff --git a/binoculars/space.py b/binoculars/space.py
index a9466f0..a52a1cf 100755
--- a/binoculars/space.py
+++ b/binoculars/space.py
@@ -343,7 +343,7 @@ class Space(object):
self.metadata = metadata
self.photons = numpy.zeros([len(ax) for ax in self.axes], order='C')
- self.contributions = numpy.zeros(self.photons.shape, dtype=numpy.uint32, order='C')
+ self.contributions = numpy.zeros(self.photons.shape, order='C')
@property
def dimension(self):
@@ -457,7 +457,10 @@ class Space(object):
def get_masked(self):
"""Returns photons/contributions, but with divide-by-zero's masked out."""
return numpy.ma.array(data=self.get(), mask=(self.contributions == 0))
-
+
+ def get_variance(self):
+ return numpy.ma.array(data=1 / self.contributions, mask = (self.contributions == 0))
+
def get_grid(self):
"""Returns the data coordinates of each grid point, as n-tuple of n-dimensinonal arrays.
Basically numpy.mgrid() in data coordinates."""
@@ -475,7 +478,7 @@ class Space(object):
return tuple(ax[key] for ax, key in zip(self.axes, numpy.unravel_index(numpy.argmax(array), array.shape)))
def __add__(self, other):
- if isinstance(other, numbers.Number):#to test more advanced background subtraction routines
+ if isinstance(other, numbers.Number):
new = self.copy()
new.photons += other * self.contributions
return new
@@ -490,7 +493,7 @@ class Space(object):
return new
def __iadd__(self, other):
- if isinstance(other, numbers.Number):#to test more advanced background subtraction routines
+ if isinstance(other, numbers.Number):
self.photons += other * self.contributions
return self
if not isinstance(other, Space):
@@ -508,36 +511,21 @@ class Space(object):
return self
def __sub__(self, other):
- if isinstance(other, numbers.Number):#to test more advanced background subtraction routines
- new = self.copy()
- new.photons -= other * self.contributions
- return new
- elif not isinstance(other, Space):
- return NotImplemented
- if self.axes != other.axes or not (self.contributions == other.contributions).all():
- # TODO: we could be a bit more helpful if all axes are compatible
- raise ValueError('cannot subtract spaces that are not identical (axes + contributions)')
- new = self.copy()
- new.photons -= other.photons # don't call __isub__ here because the compatibility check is labourous
- return new
+ return self.__add__(other * -1)
def __isub__(self, other):
- if isinstance(other, numbers.Number):#to test more advanced background subtraction routines
- self.photons -= other * self.contributions
- return self
- elif not isinstance(other, Space):
- return NotImplemented
- if self.axes != other.axes or not (self.contributions == other.contributions).all():
- raise ValueError('cannot subtract spaces that are not identical (axes + contributions)')
- self.photons -= other.photons
- return self
+ return self.__iadd__(other * -1)
- def __mul__(self, other):#to test more advanced background subtraction routines
- if type(other) == float or type(other) == int:
- self.photons *= other
+ def __mul__(self, other):
+ if isinstance(other, numbers.Number):
+ new = self.__class__(self.axes, self.config, self.metadata)
+ #we would like to keep 1/contributions as the variance
+ #var(aX) = a**2var(X)
+ new.photons = self.photons / other
+ new.contributions = self.contributions / other**2
+ return new
else:
return NotImplemented
- return self
def trim(self):
"""Reduce total size of Space by trimming zero-contribution data points on the boundaries."""
@@ -549,35 +537,7 @@ class Space(object):
self.photons = self.photons[slices].copy()
self.contributions = self.contributions[slices].copy()
- def rebin(self, factors):
- """Increase bin size (= decrease resolution).
-
- factor even integer or n-tuple of even integers"""
- if isinstance(factors, int):
- factors = [factors] * len(self.axes)
- elif len(factors) != len(self.axes):
- raise ValueError('dimension mismatch between factors and axes')
- if not all(isinstance(factor, int) for factor in factors) or not all(factor == 1 or factor % 2 == 0 for factor in factors):
- raise ValueError('binning factors must be even integers')
-
- lefts, rights, newaxes = zip(*[ax.rebin(factor) for ax, factor in zip(self.axes, factors)])
- tempshape = tuple(size + left + right + factor for size, left, right, factor in zip(self.photons.shape, lefts, rights, factors))
-
- photons = numpy.zeros(tempshape, order='C')
- contributions = numpy.zeros(tempshape, dtype=numpy.uint32, order='C')
- pad = tuple(slice(left, left+size) for left, factor, size in zip(lefts, factors, self.photons.shape))
- photons[pad] = self.photons
- contributions[pad] = self.contributions
-
- new = self.__class__(newaxes)
- for offsets in itertools.product(*[range(factor) for factor in factors]):
- stride = tuple(slice(offset, offset + len(ax)*factor, factor) for offset, ax, factor in zip(offsets, newaxes, factors))
- new.photons += photons[stride]
- new.contributions += contributions[stride]
-
- return new
-
- def rebin2(self, resolutions):
+ def rebin(self, resolutions):
"""Change bin size.
resolution n-tuple of floats, new resolution of each axis"""
@@ -586,16 +546,11 @@ class Space(object):
if resolutions == tuple(ax.res for ax in self.axes):
return self
- labels = tuple(ax.label for ax in self.axes)
- coordinates = tuple(grid.flatten() for grid in self.get_grid())
-
- contribution_space = self.from_image(resolutions, labels, coordinates, self.contributions.flatten())
- contributions = contribution_space.photons.astype(int)
- del contribution_space
-
- new = self.from_image(resolutions, labels, coordinates, self.photons.flatten())
- new.contributions = contributions
- return new
+ # gather data and transform
+ coords = self.get_grid()
+ intensity = self.get()
+ weights = self.contributions
+ return self.from_image(resolutions, labels, coords, intensity, weights)
def reorder(self, labels):
"""Change order of axes."""
@@ -609,50 +564,44 @@ class Space(object):
def transform_coordinates(self, resolutions, labels, transformation):
# gather data and transform
- intensity = self.get_masked()
+
coords = self.get_grid()
transcoords = transformation(*coords)
+ intensity = self.get()
+ weights = self.contributions
- # get rid of invalids & masked intensities
- valid = ~__builtin__.sum((~numpy.isfinite(t) for t in transcoords), intensity.mask)
+ # get rid of invalid coords
+ valid = reduce(numpy.bitwise_and, intertools.chain((numpy.isfinite(t) for t in transcoords)), (weights > 0, ))
transcoords = tuple(t[valid] for t in transcoords)
- return self.from_image(resolutions, labels, transcoords, intensity[valid])
+ return self.from_image(resolutions, labels, transcoords, intensity[valid], weights[valid])
- def process_image(self, coordinates, intensity):
+ def process_image(self, coordinates, intensity, weights):
"""Load image data into Space.
coordinates n-tuple of data coordinate arrays
- intensity data intensity array"""
+ intensity data intensity array
+ weights weights array, supply numpy.ones_like(intensity) for equal weights"""
if len(coordinates) != len(self.axes):
raise ValueError('dimension mismatch between coordinates and axes')
- if isinstance(intensity, numpy.ma.core.MaskedArray):
- mask = intensity.mask
- intensity = intensity.data
- valid = numpy.bitwise_and(numpy.isfinite(intensity), ~mask)
- else:
- valid = numpy.isfinite(intensity)
-
- intensity = intensity[valid]
- if not intensity.size:
- return
-
- coordinates = tuple(coord[valid] for coord in coordinates)
+ intensity = numpy.nan_to_num(intensity).flatten()#invalids should be handeled by setting weight to 0, this ensures the weights can do that
+ weights = weights.flatten()
indices = numpy.array(tuple(ax.get_index(coord) for (ax, coord) in zip(self.axes, coordinates)))
for i in range(0, len(self.axes)):
for j in range(i+1, len(self.axes)):
indices[i,:] *= len(self.axes[j])
- indices = indices.sum(axis=0).astype(int)
- photons = numpy.bincount(indices, weights=intensity)
- contributions = numpy.bincount(indices)
-
+ indices = indices.sum(axis=0).astype(int).flatten()
+
+ photons = numpy.bincount(indices, weights=intensity * weights)
+ contributions = numpy.bincount(indices, weights=weights)
+
self.photons.ravel()[:photons.size] += photons
- self.contributions.ravel()[:contributions.size] += contributions.astype(self.contributions.dtype)
+ self.contributions.ravel()[:contributions.size] += contributions
@classmethod
- def from_image(cls, resolutions, labels, coordinates, intensity, limits = None):
+ def from_image(cls, resolutions, labels, coordinates, intensity, weights, limits = None):
"""Create Space from image data.
resolutions n-tuple of axis resolutions
@@ -674,10 +623,11 @@ class Space(object):
return EmptySpace()
coordinates = tuple(coord[~invalid] for coord in coordinates)
intensity = intensity[~invalid]
+ weights = weights[~invalid]
axes = tuple(Axis(coord.min(), coord.max(), res, label) for res, label, coord in zip(resolutions, labels, coordinates))
newspace = cls(axes)
- newspace.process_image(coordinates, intensity)
+ newspace.process_image(coordinates, intensity, weights)
return newspace
def tofile(self, filename):
diff --git a/test/cfg.py b/test/cfg.py
index 7909237..9809e3d 100644
--- a/test/cfg.py
+++ b/test/cfg.py
@@ -1,4 +1,4 @@
-import BINoculars.util
+import binoculars.util
import os
import unittest
@@ -6,14 +6,14 @@ import unittest
class TestCase(unittest.TestCase):
def setUp(self):
fn = 'examples/configs/example_config_id03'
- self.cfg = BINoculars.util.ConfigFile.fromtxtfile(fn)
+ self.cfg = binoculars.util.ConfigFile.fromtxtfile(fn)
def test_IO(self):
self.cfg.totxtfile('test.txt')
self.cfg.tofile('test.hdf5')
- print BINoculars.util.ConfigFile.fromfile('test.hdf5')
- self.assertRaises(IOError, BINoculars.util.ConfigFile.fromtxtfile, '')
- self.assertRaises(IOError, BINoculars.util.ConfigFile.fromfile, '')
+ print binoculars.util.ConfigFile.fromfile('test.hdf5')
+ self.assertRaises(IOError, binoculars.util.ConfigFile.fromtxtfile, '')
+ self.assertRaises(IOError, binoculars.util.ConfigFile.fromfile, '')
def tearDown(self):
os.remove('test.txt')
diff --git a/test/id03.py b/test/id03.py
index e7fed8c..1a33d76 100644
--- a/test/id03.py
+++ b/test/id03.py
@@ -1,6 +1,6 @@
-from BINoculars.backends import id03
-import BINoculars.util
-import BINoculars.space
+from binoculars.backends import id03
+import binoculars.util
+import binoculars.space
import os
import numpy
@@ -9,7 +9,7 @@ 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' )
+ 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'
@@ -24,10 +24,14 @@ class TestCase(unittest.TestCase):
jobs = list(self.id03input.generate_jobs(['820']))
destination_opts = self.id03input.get_destination_options(['820'])
imagedata = self.id03input.process_job(jobs[0])
- intensity, coords = imagedata.next()
+ intensity, weights, coords = imagedata.next()
projected = self.projection.project(*coords)
- space = BINoculars.space.Space.from_image((1,1), ('x','y'), projected, intensity)
- print space
+ space1 = binoculars.space.Space.from_image((1,1), ('x','y'), projected, intensity, weights)
+
+ intensity, weights, coords = imagedata.next()
+ projected = self.projection.project(*coords)
+ space2 = binoculars.space.Space.from_image((1,1), ('x','y'), projected, intensity, weights)
+ print space1 - space2
def tearDown(self):
os.remove('mask.npy')
diff --git a/test/metadata.py b/test/metadata.py
index 69a79a7..ceca316 100644
--- a/test/metadata.py
+++ b/test/metadata.py
@@ -1,5 +1,5 @@
-import BINoculars.util
-import BINoculars.space
+import binoculars.util
+import binoculars.space
import os
import numpy
@@ -8,38 +8,38 @@ import unittest
class TestCase(unittest.TestCase):
def setUp(self):
fn = 'examples/configs/example_config_id03'
- self.cfg = BINoculars.util.ConfigFile.fromtxtfile(fn)
+ self.cfg = binoculars.util.ConfigFile.fromtxtfile(fn)
def test_IO(self):
test = {'string' : 'string', 'numpy.array' : numpy.arange(10), 'list' : range(10), 'tuple' : tuple(range(10))}
- metasection = BINoculars.util.MetaBase()
+ metasection = binoculars.util.MetaBase()
metasection.add_section('first', test)
print metasection
- metadata = BINoculars.util.MetaData()
+ metadata = binoculars.util.MetaData()
metadata.add_dataset(metasection)
metadata.add_dataset(self.cfg)
metadata.tofile('test.hdf5')
- metadata += BINoculars.util.MetaData.fromfile('test.hdf5')
+ metadata += binoculars.util.MetaData.fromfile('test.hdf5')
- axis = tuple(BINoculars.space.Axis(0,10,1,label) for label in ['h', 'k', 'l'])
- axes = BINoculars.space.Axes(axis)
- space = BINoculars.space.Space(axes)
+ axis = tuple(binoculars.space.Axis(0,10,1,label) for label in ['h', 'k', 'l'])
+ axes = binoculars.space.Axes(axis)
+ space = binoculars.space.Space(axes)
spacedict = dict(z for z in zip('abcde', range(5)))
- dataset = BINoculars.util.MetaBase('fromspace', spacedict)
+ dataset = binoculars.util.MetaBase('fromspace', spacedict)
space.metadata.add_dataset(dataset)
space.tofile('test2.hdf5')
- testspace = BINoculars.space.Space.fromfile('test2.hdf5')
+ testspace = binoculars.space.Space.fromfile('test2.hdf5')
print (space + testspace).metadata
print '--------------------------------------------------------'
print metadata
print metadata.serialize()
- print BINoculars.util.MetaData.fromserial(metadata.serialize())
+ print binoculars.util.MetaData.fromserial(metadata.serialize())
def tearDown(self):
os.remove('test.hdf5')