Commit 2e3605ae authored by myron's avatar myron

take_radios

parent 3676d338
Pipeline #23904 passed with stage
in 51 seconds
......@@ -15,7 +15,6 @@ except ImportError:
class DoubleFlatField:
def __init__(self,
radios,
res_dtype = np.float32,
sub_region = None,
input_is_mlog = True,
......@@ -31,8 +30,6 @@ class DoubleFlatField:
Parameters
----------
radios: np.array
a stack of images
res_dtype: dtype, optional( default np.float32)
the wished dtype for the double flat field
input_is_mlog: boolean, default True
......@@ -61,7 +58,6 @@ class DoubleFlatField:
assert( not (storeW_url and storeR_url) )
self.radios = radios
self.res_dtype = res_dtype
self.sub_region = sub_region
self.input_is_mlog = input_is_mlog
......@@ -72,21 +68,12 @@ class DoubleFlatField:
self.sigma_filter = sigma_filter
self.filter_mode = filter_mode
self.setup()
def setup(self):
""" initialise according to the parameters that hav been passed to the constructor """
if self.storeR_url is not None:
myreader = reader.Readers[ get_ftype( self.storeR_url ) ]()
self.mydata = myreader.get_data(self.storeR_url)
return
if self.storeW_url is not None:
mystorewriter= writer.Writers[ get_ftype( self.storeW_url ) ]
self.mystorewriter= writer.Writers[ get_ftype( self.storeW_url ) ]
else:
mystorewriter = None
self.mystorewriter = None
proc = (lambda x: x)
if( self.input_is_mlog):
if(not self.average_is_on_log):
......@@ -102,35 +89,47 @@ class DoubleFlatField:
else:
if(self.average_is_on_log):
postproc = (lambda x: np.exp(-x) )
self.proc = proc
self.postproc = postproc
if self.sub_region is None:
sub_region = None,None,None,None
else:
region = self.sub_region
slice0 = slice( *(sub_region[0:2]) )
slice1 = slice( *(sub_region[2:4]) )
self.slice0 = slice( *(sub_region[0:2]) )
self.slice1 = slice( *(sub_region[2:4]) )
def take_radios(self, radios=None):
""" initialise according to the parameters that hav been passed to the constructor """
if self.storeR_url is not None:
myreader = reader.Readers[ get_ftype( self.storeR_url ) ]()
self.mydata = myreader.get_data(self.storeR_url)
return
acc = None
tmpdat = None
for ima in self.radios:
data = ima[slice0,slice1]
for ima in radios:
data = ima[self.slice0,self.slice1]
if acc is None:
acc = np.zeros(data.shape, self.res_dtype)
tmpdat = np.zeros(data.shape, self.res_dtype)
tmpdat[:] = proc(data)
tmpdat[:] = self.proc(data)
acc += tmpdat
acc /= self.radios.shape[0]
acc /= radios.shape[0]
if self.sigma_filter is not None:
acc = acc -gaussian_filter(acc,self.sigma_filter, mode=self.filter_mode)
self.mydata = postproc(acc)
self.mydata = self.postproc(acc)
if mystorewriter is not None:
mystorewriter(self.storeW_url).write(self.mydata,"double_flat_field")
if self.mystorewriter is not None:
self.mystorewriter(self.storeW_url).write(self.mydata,"double_flat_field")
......
......@@ -47,18 +47,17 @@ class TestDoubleFlatField:
# Create a dataset with 10 projections of 100x100 pixels.
# Radio number k is filled with k.
ddf = DoubleFlatField( self.radios,
sub_region = None,
ddf = DoubleFlatField( sub_region = None,
res_dtype = np.float32,
storeW_url = path.join(self.dname, "image.h5"),
storeR_url = None
)
ddf.take_radios(self.radios)
ddf2 = DoubleFlatField(None,
ddf2 = DoubleFlatField(
storeR_url = DataUrl("silx://"+path.join(self.dname, "image.h5") +"?/entry/double_flat_field/results")
)
ddf2.take_radios()
mydf = ddf.get_doubleflatfield()
mydf2 = ddf2.get_doubleflatfield()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment