Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ dist/*
.pixi/*
!.pixi/config.toml

notebooks/pleiades_logs
notebooks/pleiades_logs
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: "^pixi.lock$"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-added-large-files
args: [--maxkb=8192]
Expand All @@ -16,21 +16,21 @@ repos:
- id: trailing-whitespace
exclude: "notebooks/.*\\.ipynb$"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.14.10
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
exclude: "notebooks/.*\\.ipynb$"
- id: ruff-format
exclude: "notebooks/.*\\.ipynb$"
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
exclude: "notebooks/.*\\.ipynb$"
args: ["--skip=*.js,*.html,*.css"]
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
rev: v1.37.1
hooks:
- id: yamllint
- repo: https://github.com/ComPWA/taplo-pre-commit
Expand Down
6 changes: 5 additions & 1 deletion notebooks/__code/_utilities/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def reject_outliers(array=None):
if len(array) < 3:
return array

new_array = [_value for _value in array if (not (_value == np.min(array))) and (not (_value == np.max(array)))]
new_array = [
_value
for _value in array
if (not (_value == np.min(array))) and (not (_value == np.max(array)))
]
return new_array


Expand Down
116 changes: 91 additions & 25 deletions notebooks/__code/_utilities/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ def make_or_increment_folder_name(folder_name):
if not os.path.exists(folder_name):
os.makedirs(folder_name)
else:
new_folder_name = "_".join([folder_name, get_current_time_in_special_file_name_format()])
new_folder_name = "_".join(
[folder_name, get_current_time_in_special_file_name_format()]
)
if os.path.exists(new_folder_name):
os.removedirs(new_folder_name)
os.makedirs(new_folder_name)
Expand All @@ -205,7 +207,9 @@ def copy_files_to_folder(list_files=[], output_folder=""):
shutil.copy(_file, output_folder)


def copy_and_rename_files_to_folder(list_files=[], new_list_files_names=[], output_folder=""):
def copy_and_rename_files_to_folder(
list_files=[], new_list_files_names=[], output_folder=""
):
for _index_file, _original_file in enumerate(list_files):
_new_file = os.path.join(output_folder, new_list_files_names[_index_file])
shutil.copy(_original_file, _new_file)
Expand Down Expand Up @@ -250,7 +254,9 @@ def append_to_file(data=[], output_file_name=""):
f.write(_line + "\n")


def make_ascii_file_from_2dim_array(metadata=None, col1=None, col2=None, output_file_name=None, sep=", "):
def make_ascii_file_from_2dim_array(
metadata=None, col1=None, col2=None, output_file_name=None, sep=", "
):
with open(output_file_name, "w") as f:
for _meta in metadata:
_line = _meta + "\n"
Expand Down Expand Up @@ -315,7 +321,9 @@ def retrieve_metadata_from_dsc_list_files(list_files=[]):

metadata = {}
for _index, _file in enumerate(list_files):
metadata[os.path.basename(_file)] = retrieve_metadata_from_dsc_file(filename=_file)
metadata[os.path.basename(_file)] = retrieve_metadata_from_dsc_file(
filename=_file
)
w.value = _index + 1

return metadata
Expand Down Expand Up @@ -426,7 +434,9 @@ def retrieve_time_stamp(list_images, label=""):
box = widgets.HBox(
[
widgets.Label(message, layout=widgets.Layout(width="20%")),
widgets.IntProgress(min=0, max=len(list_images), value=0, layout=widgets.Layout(width="50%")),
widgets.IntProgress(
min=0, max=len(list_images), value=0, layout=widgets.Layout(width="50%")
),
]
)
progress_bar = box.children[1]
Expand Down Expand Up @@ -494,21 +504,33 @@ def read_bragg_edge_fitting_ascii_format(full_file_name):
regular = r"^#fitting peak range in file index: \[(?P<left_index>\d+), (?P<right_index>\d+)\]$"
m = re.search(regular, line.strip())
if m:
metadata["bragg_edge_range"] = [int(m.group("left_index")), int(m.group("right_index"))]
metadata["bragg_edge_range"] = [
int(m.group("left_index")),
int(m.group("right_index")),
]
else:
metadata["bragg_edge_range"] = [None, None]
line_number += 1
continue
if "#distance detector-sample: " in line:
metadata["distance_detector_sample"] = line.split("#distance detector-sample: ")[1].strip()
metadata["distance_detector_sample"] = line.split(
"#distance detector-sample: "
)[1].strip()
line_number += 1
continue
if "#detector offset: " in line:
metadata["detector_offset"] = line.split("#detector offset: ")[1].strip()
metadata["detector_offset"] = line.split("#detector offset: ")[
1
].strip()
line_number += 1
continue
if "#kropff fitting procedure started: " in line:
result = True if line.split("#kropff fitting procedure started: ")[1].strip() == "True" else False
result = (
True
if line.split("#kropff fitting procedure started: ")[1].strip()
== "True"
else False
)
metadata["kropff fitting procedure started"] = result
line_number += 1
continue
Expand All @@ -524,7 +546,12 @@ def read_bragg_edge_fitting_ascii_format(full_file_name):
continue
if "#march-dollase fitting procedure started: " in line:
result = (
True if line.split("#march-dollase fitting procedure started: ")[1].strip() == "True" else False
True
if line.split("#march-dollase fitting procedure started: ")[
1
].strip()
== "True"
else False
)
metadata["march-dollase fitting procedure started"] = result
line_number += 1
Expand All @@ -533,11 +560,17 @@ def read_bragg_edge_fitting_ascii_format(full_file_name):
regular = r"^#Bragg peak selection range: \[(?P<left_index>\d+), (?P<right_index>\d+)\]$"
m = re.search(regular, line.strip())
if m:
metadata["bragg_peak_selection_range"] = [int(m.group("left_index")), int(m.group("right_index"))]
metadata["bragg_peak_selection_range"] = [
int(m.group("left_index")),
int(m.group("right_index")),
]
line_number += 1
continue
if "#kropff " in line:
regular = r"^#kropff (?P<type>\w+) selection range: \[(?P<left_index>\d+), " r"(?P<right_index>\d+)\]$"
regular = (
r"^#kropff (?P<type>\w+) selection range: \[(?P<left_index>\d+), "
r"(?P<right_index>\d+)\]$"
)
m = re.search(regular, line.strip())
if m:
metadata["kropff_{}".format(m.group("type"))] = [
Expand All @@ -547,17 +580,23 @@ def read_bragg_edge_fitting_ascii_format(full_file_name):
line_number += 1
continue
if "#fitting algorithm selected: " in line:
metadata["fitting_algorithm_selected"] = line.split("#fitting algorithm selected: ")[1].strip()
metadata["fitting_algorithm_selected"] = line.split(
"#fitting algorithm selected: "
)[1].strip()
line_number += 1
continue
if "#march-dollase history table row " in line:
_row_and_list_flag = line.split("#march-dollase history table row ")[1].strip()
_row_and_list_flag = line.split("#march-dollase history table row ")[
1
].strip()
[_row, list_flag] = _row_and_list_flag.split(":")
march_history_table[_row] = list_flag
line_number += 1
continue
if "#march-dollase history init " in line:
_parameter_and_value = line.split("#march-dollase history init ")[1].strip()
_parameter_and_value = line.split("#march-dollase history init ")[
1
].strip()
[_parameter, _value] = _parameter_and_value.split(":")
march_history_init[_parameter] = _value
line_number += 1
Expand Down Expand Up @@ -648,7 +687,9 @@ def read_bragg_edge_fitting_ascii_format(full_file_name):
metadata["march-dollase history table"] = march_history_table
metadata["march-dollase history init"] = march_history_init

pd_data = pd.read_csv(full_file_name, skiprows=line_number, header=0, names=col_label)
pd_data = pd.read_csv(
full_file_name, skiprows=line_number, header=0, names=col_label
)
return {"data": pd_data, "metadata": metadata}


Expand All @@ -661,7 +702,9 @@ def __init__(self, working_dir=""):
def get_list_of_files(self):
list_of_input_files = glob.glob(os.path.join(self.working_dir, "*"))
list_of_input_files.sort()
self.list_of_base_name = [os.path.basename(_file) for _file in list_of_input_files]
self.list_of_base_name = [
os.path.basename(_file) for _file in list_of_input_files
]

def get_counter_of_extension(self):
counter_extension = Counter()
Expand All @@ -686,7 +729,11 @@ def get_dominant_extension(self):

def check_uniqueness_of_dominant_extension(self):
# check if there are several ext with the same max number
indices = [i for i, x in enumerate(self.list_of_number_of_ext) if x == self.dominant_number]
indices = [
i
for i, x in enumerate(self.list_of_number_of_ext)
if x == self.dominant_number
]
if len(indices) > 1: # found several majority ext
self.uniqueness = False
else:
Expand All @@ -701,21 +748,34 @@ def calculate(self):

def retrieve_parameters(self):
if self.uniqueness:
list_of_input_files = glob.glob(os.path.join(self.working_dir, "*" + self.dominant_extension))
list_of_input_files = glob.glob(
os.path.join(self.working_dir, "*" + self.dominant_extension)
)
list_of_input_files.sort()

self.result = self.Result(list_files=list_of_input_files, ext=self.dominant_extension, uniqueness=True)
self.result = self.Result(
list_files=list_of_input_files,
ext=self.dominant_extension,
uniqueness=True,
)

else:
list_of_maj_ext = [
_ext for _ext in self.counter_extension.keys() if self.counter_extension[_ext] == self.dominant_number
_ext
for _ext in self.counter_extension.keys()
if self.counter_extension[_ext] == self.dominant_number
]

box = widgets.HBox(
[
widgets.Label("Select Extension to work with", layout=widgets.Layout(width="20%")),
widgets.Label(
"Select Extension to work with",
layout=widgets.Layout(width="20%"),
),
widgets.Dropdown(
options=list_of_maj_ext, layout=widgets.Layout(width="20%"), value=list_of_maj_ext[0]
options=list_of_maj_ext,
layout=widgets.Layout(width="20%"),
value=list_of_maj_ext[0],
),
]
)
Expand All @@ -728,7 +788,13 @@ def get_files_of_selected_ext(self):

else:
_ext_selected = self.dropdown_ui.value
list_of_input_files = glob.glob(os.path.join(self.working_dir, "*" + _ext_selected))
list_of_input_files = glob.glob(
os.path.join(self.working_dir, "*" + _ext_selected)
)
list_of_input_files.sort()

return self.Result(list_files=list_of_input_files, ext=self.dominant_extension, uniqueness=True)
return self.Result(
list_files=list_of_input_files,
ext=self.dominant_extension,
uniqueness=True,
)
4 changes: 3 additions & 1 deletion notebooks/__code/_utilities/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import numpy as np


def get_list_of_folders_with_specified_file_type(list_of_folders_to_check=None, file_extension=["tiff", "tif"]):
def get_list_of_folders_with_specified_file_type(
list_of_folders_to_check=None, file_extension=["tiff", "tif"]
):
"""
check in the list of folder given (list_of_folders_to_check) if files of the type specified are there.
If no file can be found in that folder with that type, the folder name is removed from the list
Expand Down
4 changes: 3 additions & 1 deletion notebooks/__code/_utilities/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def _init_arr_from_stack(list_files, ext=".tiff", slc=None):
_arr = dxchange.read_tiff(first_file)
f_type = "tif"
else:
raise ValueError(f"'{first_file}', only '.tif/.tiff' and '.fits' are supported.")
raise ValueError(
f"'{first_file}', only '.tif/.tiff' and '.fits' are supported."
)
size = (number_of_files, _arr.shape[0], _arr.shape[1])
return np.empty(size, dtype=_arr.dtype), f_type

Expand Down
16 changes: 10 additions & 6 deletions notebooks/__code/_utilities/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
def legend() -> None:
display(HTML("<hr style='height:2px'/>"))
display(HTML("<h2>Legend</h2>"))
display(HTML("<ul>"
"<li><b><font color='red'>Mandatory steps</font></b> must be performed to ensure proper data processing.</li>"
"<li><b><font color='orange'>Optional but recommended steps</font></b> are not mandatory but should be performed to ensure proper data processing.</li>"
"<li><b><font color='purple'>Optional steps</font></b> are not mandatory but highly recommended to improve the quality of your data processing.</li>"
"</ul>"))
display(HTML("<hr style='height:2px'/>"))
display(
HTML(
"<ul>"
"<li><b><font color='red'>Mandatory steps</font></b> must be performed to ensure proper data processing.</li>"
"<li><b><font color='orange'>Optional but recommended steps</font></b> are not mandatory but should be performed to ensure proper data processing.</li>"
"<li><b><font color='purple'>Optional steps</font></b> are not mandatory but highly recommended to improve the quality of your data processing.</li>"
"</ul>"
)
)
display(HTML("<hr style='height:2px'/>"))
16 changes: 12 additions & 4 deletions notebooks/__code/_utilities/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def are_those_two_lists_identical_within_tolerance(list1, list2, tolerance=0.01)
return True


def are_those_two_lists_of_lists_identical_within_tolerance(list1, list2, tolerance=0.01):
def are_those_two_lists_of_lists_identical_within_tolerance(
list1, list2, tolerance=0.01
):
"""
check that 2 lists composed of lists are identical

Expand All @@ -44,7 +46,9 @@ def are_those_two_lists_of_lists_identical_within_tolerance(list1, list2, tolera
return True

for list_item1, list_item2 in zip(list1, list2, strict=False):
if not are_those_two_lists_identical_within_tolerance(list_item1, list_item2, tolerance=tolerance):
if not are_those_two_lists_identical_within_tolerance(
list_item1, list_item2, tolerance=tolerance
):
return False

return True
Expand All @@ -60,10 +64,14 @@ def is_this_list_already_in_those_lists_within_tolerance(list1, list2, tolerance
:return:
"""
if (not (type(list1) == list)) or (not (type(list2) == list)):
raise TypeError("First argument should be a list of floats, second argument a list of lists")
raise TypeError(
"First argument should be a list of floats, second argument a list of lists"
)

for target_list in list2:
if are_those_two_lists_identical_within_tolerance(list1, target_list, tolerance=tolerance):
if are_those_two_lists_identical_within_tolerance(
list1, target_list, tolerance=tolerance
):
return True

return False
Expand Down
1 change: 0 additions & 1 deletion notebooks/__code/_utilities/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


def display_dictionary_in_logging(dictionary):

for key, value in dictionary.items():
logging.info(f"\t {key}: {value}")
logging.info("") # Add an empty line for better readability
Loading
Loading