Skip to content
Snippets Groups Projects

WIP: Dssc methods as

Closed Rafael Gort requested to merge DSSC_methods_AS into DevelopmentRG
2 files
+ 115
71
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -22,14 +22,12 @@ import xarray as xr
@@ -22,14 +22,12 @@ import xarray as xr
from ..load import load_run
from ..load import load_run
from ..util.exceptions import ToolBoxValueError, ToolBoxFileError
from ..util.exceptions import ToolBoxValueError, ToolBoxFileError
from .dssc_data import (
from .dssc_data import (
save_xarray, load_xarray, save_attributes_h5,
save_xarray, load_xarray, save_attributes_h5,
search_files, get_data_formatted)
search_files, get_data_formatted)
from .dssc_misc import (
from .dssc_misc import load_dssc_info, get_xgm_formatted
load_dssc_info, get_xgm_formatted)
from .dssc_geodat import tile_geodat, module_geodat, quad_geodat
from .dssc_processing import (
from .dssc_processing import bin_data, create_empty_dataset
bin_data, create_empty_dataset)
from .dssc_geometry import convert_hex2cart
from .dssc_geometry import (
convert_hex2cart)
__all__ = ["DSSCBinner", "DSSCFormatter", "DSSC_Generator"]
__all__ = ["DSSCBinner", "DSSCFormatter", "DSSC_Generator"]
log = logging.getLogger(__name__)
log = logging.getLogger(__name__)
@@ -341,45 +339,14 @@ class DSSCFormatter:
@@ -341,45 +339,14 @@ class DSSCFormatter:
class DSSC_Generator:
class DSSC_Generator:
# geomtry = None
tile_geodat = np.zeros((16, 2, 2), dtype='int')
module_geodat = np.zeros((16, 2), dtype='int')
quad_geodat = np.zeros((4, 2), dtype='int')
# tile_geodat: [[voffset, hoffset], [is_flip, axis]]
# axis= 0, flip up-down
# axis= 1, flip left-right
# fractional shifts not included so far
tile_geodat[0:8, :, :] = [[0, 8], [1, 1]]
tile_geodat[8::, :, :] = [[0, 8], [1, 0]]
module_geodat[0, :] = [0, 0]
module_geodat[1, :] = [19, 0]
module_geodat[2, :] = [18, 0]
module_geodat[3, :] = [19, 0]
module_geodat[4, :] = [0, 0]
module_geodat[5, :] = [19, 0]
module_geodat[6, :] = [19, 0]
module_geodat[7, :] = [18, 0]
module_geodat[11, :] = [0, 0]
module_geodat[10, :] = [19, 0]
module_geodat[9, :] = [18, 0]
module_geodat[8, :] = [19, 0]
module_geodat[15, :] = [0, 0]
module_geodat[14, :] = [19, 0]
module_geodat[13, :] = [19, 0]
module_geodat[12, :] = [18, 0]
quad_geodat[0, :] = [10, 17] # [quadrant 1, insert, gap]
quad_geodat[1, :] = [8, 26] # [quadrant 2, insert, gap]
quad_geodat[2, :] = [-9, 19] # [quadrant 3, insert, gap]
quad_geodat[3, :] = [-9, 25] # [quadrant 4, insert, gap]
def __init__(self):
def __init__(self):
pass
# tile_geodat: [[voffset, hoffset], [is_flip, axis]]
 
# axis= 0, flip up-down
 
# axis= 1, flip left-right
 
# fractional shifts not included so far
 
self.tile_geodat = tile_geodat
 
self.module_geodat = module_geodat
 
self.quad_geodat = quad_geodat
def read_geometry(self, filename):
def read_geometry(self, filename):
pass
pass
@@ -390,7 +357,8 @@ class DSSC_Generator:
@@ -390,7 +357,8 @@ class DSSC_Generator:
def full_detector(self, dssc_data):
def full_detector(self, dssc_data):
print('assemble full detector: ')
print('assemble full detector: ')
# assemble full detector
# assemble full detector
q_data = joblib.Parallel(n_jobs=4)(joblib.delayed(self.quadrant)(i, dssc_data) for i in [1,2,3,4])
q_data = joblib.Parallel(n_jobs=4) \
 
(joblib.delayed(self.quadrant)(i, dssc_data) for i in [1, 2, 3, 4])
# determine dimensions
# determine dimensions
[qdimy, qdimx] = q_data[0].shape
[qdimy, qdimx] = q_data[0].shape
@@ -406,27 +374,54 @@ class DSSC_Generator:
@@ -406,27 +374,54 @@ class DSSC_Generator:
full_dssc = np.zeros((fdimy, fdimx))
full_dssc = np.zeros((fdimy, fdimx))
# quadrant 2
# quadrant 2
full_dssc[self.quad_geodat[1, 0]:qdimy+self.quad_geodat[1, 0], 0:qdimx ] \
y0 = self.quad_geodat[1, 0]
= q_data[1]
y1 = qdimy+self.quad_geodat[1, 0]
 
x0 = 0
 
x1 = qdimx
 
full_dssc[y0:y1, x0:x1] = q_data[1]
# quadrant 1
# quadrant 1
full_dssc[qdimy+self.quad_geodat[1, 0]+self.quad_geodat[1, 1]:2*qdimy+self.quad_geodat[1, 0]+self.quad_geodat[1, 1],
y0 = qdimy+self.quad_geodat[1, 0]+self.quad_geodat[1, 1]
self.quad_geodat[0, 0]:self.quad_geodat[0, 0]+qdimx] \
y1 = 2*qdimy+self.quad_geodat[1, 0]+self.quad_geodat[1, 1]
= q_data[0]
x0 = self.quad_geodat[0, 0]
 
x1 = self.quad_geodat[0, 0]+qdimx
 
full_dssc[y0:y1, x0:x1] = q_data[0]
# quadrant 4
# quadrant 4
dummy1 = [qdimy + self.quad_geodat[1, 0] + self.quad_geodat[1, 1] + self.quad_geodat[3, 0],
y0 = qdimy \
2 * qdimy + self.quad_geodat[1, 0] + self.quad_geodat[1, 1] + self.quad_geodat[3, 0]]
+ self.quad_geodat[1, 0] \
dummy2 = [self.quad_geodat[0, 0] + self.quad_geodat[0, 1] + qdimx,
+ self.quad_geodat[1, 1] \
self.quad_geodat[0, 0] + self.quad_geodat[0, 1] + 2*qdimx]
+ self.quad_geodat[3, 0]
full_dssc[dummy1[0]:dummy1[1], dummy2[0]:dummy2[1]] = q_data[3]
y1 = 2 * qdimy \
 
+ self.quad_geodat[1, 0] \
 
+ self.quad_geodat[1, 1] \
 
+ self.quad_geodat[3, 0]
 
x0 = self.quad_geodat[0, 0] \
 
+ self.quad_geodat[0, 1] \
 
+ qdimx
 
x1 = self.quad_geodat[0, 0] \
 
+ self.quad_geodat[0, 1] \
 
+ 2*qdimx
 
full_dssc[y0:y1, x0:x1] = q_data[3]
# quadrant 3
# quadrant 3
dummy3 = [self.quad_geodat[1, 0] + self.quad_geodat[1, 1] + self.quad_geodat[3, 0] - self.quad_geodat[3, 1],
y0 = self.quad_geodat[1, 0] \
qdimy+self.quad_geodat[1, 0] + self.quad_geodat[1, 1] + self.quad_geodat[3, 0] - self.quad_geodat[3, 1]]
+ self.quad_geodat[1, 1] \
dummy4 = [self.quad_geodat[0, 0] + self.quad_geodat[0, 1] + qdimx + self.quad_geodat[2, 0],
+ self.quad_geodat[3, 0] \
self.quad_geodat[0, 0] + self.quad_geodat[0, 1] + 2*qdimx + self.quad_geodat[2, 0]]
- self.quad_geodat[3, 1]
full_dssc[dummy3[0]:dummy3[1],dummy4[0]:dummy4[1]] = q_data[2]
y1 = qdimy + self.quad_geodat[1, 0] \
 
+ self.quad_geodat[1, 1] \
 
+ self.quad_geodat[3, 0] \
 
- self.quad_geodat[3, 1]
 
x0 = self.quad_geodat[0, 0] \
 
+ self.quad_geodat[0, 1] \
 
+ qdimx \
 
+ self.quad_geodat[2, 0]
 
x1 = self.quad_geodat[0, 0] \
 
+ self.quad_geodat[0, 1] \
 
+ 2*qdimx \
 
+ self.quad_geodat[2, 0]
 
full_dssc[y0:y1, x0:x1] = q_data[2]
return full_dssc
return full_dssc
@@ -441,28 +436,36 @@ class DSSC_Generator:
@@ -441,28 +436,36 @@ class DSSC_Generator:
mdimx = module0.shape[1]
mdimx = module0.shape[1]
qu = [module0]
qu = [module0]
for n in range(1, 4):
for n in range(1, 4):
qu.append(np.zeros((self.module_geodat[n, 0], mdimx), dtype='float32'))
qu.append(np.zeros(
 
(self.module_geodat[n, 0], mdimx),
 
dtype='float32'))
qu.append(self.convert_module(n, dssc_data[n, :, :]))
qu.append(self.convert_module(n, dssc_data[n, :, :]))
elif q == 2:
elif q == 2:
module0 = self.convert_module(4, dssc_data[4, :, :])
module0 = self.convert_module(4, dssc_data[4, :, :])
mdimx = module0.shape[1]
mdimx = module0.shape[1]
qu = [module0]
qu = [module0]
for n in range(5, 8):
for n in range(5, 8):
qu.append(np.zeros((self.module_geodat[n, 0], mdimx), dtype='float32'))
qu.append(np.zeros(
 
(self.module_geodat[n, 0], mdimx),
 
dtype='float32'))
qu.append(self.convert_module(n, dssc_data[n, :, :]))
qu.append(self.convert_module(n, dssc_data[n, :, :]))
elif q == 3:
elif q == 3:
module0 = self.convert_module(11, dssc_data[11, :, :])
module0 = self.convert_module(11, dssc_data[11, :, :])
mdimx = module0.shape[1]
mdimx = module0.shape[1]
qu = [module0]
qu = [module0]
for n in range(10, 7, -1):
for n in range(10, 7, -1):
qu.append(np.zeros((self.module_geodat[n, 0], mdimx), dtype='float32'))
qu.append(np.zeros(
 
(self.module_geodat[n, 0], mdimx),
 
dtype='float32'))
qu.append(self.convert_module(n, dssc_data[n, :, :]))
qu.append(self.convert_module(n, dssc_data[n, :, :]))
elif q == 4:
elif q == 4:
module0 = self.convert_module(15, dssc_data[15, :, :])
module0 = self.convert_module(15, dssc_data[15, :, :])
mdimx = module0.shape[1]
mdimx = module0.shape[1]
qu = [module0]
qu = [module0]
for n in range(14, 11, -1):
for n in range(14, 11, -1):
qu.append(np.zeros((self.module_geodat[n, 0], mdimx), dtype='float32'))
qu.append(np.zeros(
 
(self.module_geodat[n, 0], mdimx),
 
dtype='float32'))
qu.append(self.convert_module(n, dssc_data[n, :, :]))
qu.append(self.convert_module(n, dssc_data[n, :, :]))
return np.vstack(qu)
return np.vstack(qu)
@@ -472,19 +475,23 @@ class DSSC_Generator:
@@ -472,19 +475,23 @@ class DSSC_Generator:
convert hex to cartesian
convert hex to cartesian
add gap according to geometry file
add gap according to geometry file
flip according to geometry file
flip according to geometry file
returns the module in cartesian coordinates with the correct gap between tiles
returns the module in cartesian coordinates with the correct gap
 
between tiles
"""
"""
print("processing module: " + str(m))
print("processing module: " + str(m))
tile_hex = self.split_module(module_hex)
tile_hex = self.split_module(module_hex)
offset, flip_module = self._get_tile_geodat(m)
offset, flip_module = self._get_tile_geodat(m)
module_cart = np.zeros((120 + offset[0], 2*276 + offset[1]), dtype='float32')
module_cart = np.zeros(
 
(120 + offset[0], 2*276 + offset[1]),
 
dtype='float32')
module_cart[0:120, 0:276] = convert_hex2cart(tile_hex[0, :, :])
module_cart[0:120, 0:276] = convert_hex2cart(tile_hex[0, :, :])
module_cart[0:120, 276 + offset[1]:552 + offset[1]] = convert_hex2cart(tile_hex[1, :, :])
module_cart[0:120, 276 + offset[1]:552 + offset[1]] \
 
= convert_hex2cart(tile_hex[1, :, :])
if flip_module[0]:
if flip_module[0]:
module_cart = np.flip(module_cart, axis=flip_module[1])
module_cart = np.flip(module_cart, axis=flip_module[1])
#print('flipped module: ' + str(flip_module[1]))
# print('flipped module: ' + str(flip_module[1]))
return module_cart
return module_cart
@@ -506,4 +513,5 @@ class DSSC_Generator:
@@ -506,4 +513,5 @@ class DSSC_Generator:
# 2) split module into its tiles
# 2) split module into its tiles
# 3) convert tiles from hex to cart
# 3) convert tiles from hex to cart
# 4) reposition tiles according to offsets (from geometry file)
# 4) reposition tiles according to offsets (from geometry file)
# 5) figure out orientation and flip up-down or left-right (flag in geometry file)
# 5) figure out orientation and flip up-down or left-right (flag in geometry
 
# file)
Loading