Skip to content

Commit

Permalink
Added force_median_ob. this refs #11
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBilheux committed Aug 11, 2023
1 parent e38b302 commit f6fcd4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion NeuNorm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.5.1"
__version__ = "1.6.2"


class DataType:
Expand Down
31 changes: 22 additions & 9 deletions NeuNorm/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self):
self.export_file_name = None

def load(self, file='', folder='', data=None, data_type='sample', auto_gamma_filter=True,
manual_gamma_filter=False, notebook=False, manual_gamma_threshold=0.1):
manual_gamma_filter=False, notebook=False, manual_gamma_threshold=0.1, check_shape=True):
"""
Function to read individual files, entire files from folder, list of files or event data arrays.
Data are also gamma filtered if requested.
Expand Down Expand Up @@ -94,7 +94,8 @@ def load(self, file='', folder='', data=None, data_type='sample', auto_gamma_fil
data_type=data_type,
auto_gamma_filter=auto_gamma_filter,
manual_gamma_filter=manual_gamma_filter,
manual_gamma_threshold=manual_gamma_threshold)
manual_gamma_threshold=manual_gamma_threshold,
check_shape=check_shape)
elif isinstance(file, list):
if notebook:
# turn on progress bar
Expand All @@ -115,7 +116,8 @@ def load(self, file='', folder='', data=None, data_type='sample', auto_gamma_fil
data_type=data_type,
auto_gamma_filter=auto_gamma_filter,
manual_gamma_filter=manual_gamma_filter,
manual_gamma_threshold=manual_gamma_threshold)
manual_gamma_threshold=manual_gamma_threshold,
check_shape=check_shape)
if notebook:
w1.value = _index + 1
end_time = time.time()
Expand Down Expand Up @@ -151,7 +153,8 @@ def load(self, file='', folder='', data=None, data_type='sample', auto_gamma_fil
data_type=data_type,
auto_gamma_filter=auto_gamma_filter,
manual_gamma_filter=manual_gamma_filter,
manual_gamma_threshold=manual_gamma_threshold)
manual_gamma_threshold=manual_gamma_threshold,
check_shape=check_shape)
if notebook:
# update progress bar
w1.value = _index + 1
Expand Down Expand Up @@ -257,7 +260,8 @@ def __load_individual_data(self, data=None, data_type='sample'):
def load_file(self, file='', data_type='sample',
auto_gamma_filter=True,
manual_gamma_filter=False,
manual_gamma_threshold=0.1):
manual_gamma_threshold=0.1,
check_shape=True):
"""
Function to read data from the specified path, it can read FITS, TIFF and HDF.
Expand Down Expand Up @@ -310,7 +314,8 @@ def load_file(self, file='', data_type='sample',
else:
self.data[data_type]['file_name'].append(file)

self.save_or_check_shape(data=data, data_type=data_type)
if check_shape:
self.save_or_check_shape(data=data, data_type=data_type)

else:
raise OSError("The file name does not exist")
Expand Down Expand Up @@ -413,7 +418,8 @@ def save_or_check_shape(self, data=None, data_type='sample'):
if (not (_prev_width == width)) or (not (_prev_height == height)):
raise IOError("Shape of {} do not match previous loaded data set!".format(data_type))

def normalization(self, roi=None, force=False, force_mean_ob=False, notebook=False, use_only_sample=False):
def normalization(self, roi=None, force=False, force_mean_ob=False, force_median_ob=False,
notebook=False, use_only_sample=False):
"""normalization of the data
Parameters:
Expand Down Expand Up @@ -497,8 +503,15 @@ def normalization(self, roi=None, force=False, force_mean_ob=False, notebook=Fal
# if the number of sample and ob do not match, use mean of obs
nbr_sample = len(self.data['sample']['file_name'])
nbr_ob = len(self.data['ob']['file_name'])
if (nbr_sample != nbr_ob) or force_mean_ob: # work with mean ob
_ob_corrected_normalized = np.mean(_ob_corrected_normalized, axis=0)
if (nbr_sample != nbr_ob) or force_mean_ob or force_median_ob: # work with mean ob

if force_median_ob:
_ob_corrected_normalized = np.nanmedian(_ob_corrected_normalized, axis=0)
elif force_mean_ob:
_ob_corrected_normalized = np.nanmean(_ob_corrected_normalized, axis=0)
else:
_ob_corrected_normalized = np.nanmedian(_ob_corrected_normalized, axis=0)

self.data['ob']['data_mean'] = _ob_corrected_normalized
_working_ob = copy.deepcopy(_ob_corrected_normalized)
_working_ob[_working_ob == 0] = np.NaN
Expand Down

0 comments on commit f6fcd4c

Please sign in to comment.