Skip to content

Commit 6921b60

Browse files
committed
Fixed by now rejecting tiff with wrong format. this refs #348
1 parent f94bda9 commit 6921b60

4 files changed

Lines changed: 69 additions & 13 deletions

File tree

notebooks/__code/file_handler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import shutil
77
from collections import Counter, OrderedDict, namedtuple
88
from pathlib import Path
9+
import logging
910

1011
import numpy as np
1112
import pandas as pd
@@ -342,6 +343,9 @@ def _convert_epics_timestamp_to_rfc3339_timestamp(epics_timestamp):
342343

343344

344345
def retrieve_time_stamp(list_images, label=""):
346+
347+
logging.info(f"\t -> retrieve_time_stamp for {label} with {len(list_images)} images")
348+
345349
if not list_images:
346350
return {"list_images": None, "list_time_stamp": None, "list_time_stamp_user_format": None}
347351

@@ -376,6 +380,11 @@ def retrieve_time_stamp(list_images, label=""):
376380

377381
box.close()
378382

383+
logging.info(f"\t -> time stamp retrieved for {label}")
384+
logging.info(f"\t -> {list_images =}")
385+
logging.info(f"\t -> {list_time_stamp =}")
386+
logging.info(f"\t -> {list_time_stamp_user_format =}")
387+
379388
return {
380389
"list_images": list_images,
381390
"list_time_stamp": list_time_stamp,

notebooks/__code/normalization/metadata_handler.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import collections
22
from enum import Enum
3+
import logging
34

45
from IPython.display import HTML, display
56

@@ -55,6 +56,8 @@ def retrieve_metadata(list_of_files=None, display_infos=False, label=""):
5556
if not list_of_files:
5657
return {}
5758

59+
logging.info(f"\t -> retrieve_metadata for {label} with {len(list_of_files)} files")
60+
5861
_dict = file_handler.retrieve_time_stamp(list_of_files, label=label)
5962
_time_metadata_dict = MetadataHandler._reformat_dict(dictionary=_dict)
6063

@@ -63,6 +66,8 @@ def retrieve_metadata(list_of_files=None, display_infos=False, label=""):
6366
master_dictionary=_time_metadata_dict, servant_dictionary=_beamline_metadata_dict
6467
)
6568

69+
logging.info(f"\t after combining the time metadata and the beamline metadata, the dict is: {_metadata_dict =}")
70+
6671
if display_infos:
6772
display(
6873
HTML('<span style="font-size: 20px; color:blue">Nbr of images: ' + str(len(_metadata_dict)) + "</span")
@@ -93,11 +98,16 @@ def retrieve_beamline_metadata(list_files):
9398
- slits positions ->
9499
- aperture value
95100
"""
101+
102+
logging.info(f"\t -> retrieve_beamline_metadata for {len(list_files)} files")
103+
96104
list_metadata = METADATA_KEYS["all"]
97105
_dict = metadata_handler.MetadataHandler.retrieve_metadata(
98106
list_files=list_files, list_metadata=list_metadata, using_enum_object=True
99107
)
100108

109+
logging.info(f"\t -> beamline metadata retrieved: {_dict =}")
110+
101111
for _file_key in _dict.keys():
102112
_file_dict = {}
103113
for _pv in list_metadata:
@@ -113,6 +123,9 @@ def retrieve_beamline_metadata(list_files):
113123
else:
114124
_file_dict[_pv.value] = {}
115125
_dict[_file_key] = _file_dict
126+
127+
logging.info(f"\t returning the divt {_dict =}")
128+
116129
return _dict
117130

118131
@staticmethod

notebooks/__code/normalization/normalization_with_simplify_selection.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def retrieve_sample_metadata(self, list_of_images):
147147
self.match_files()
148148
self.calculate_first_and_last_ob()
149149
self.calculate_time_range()
150+
150151
# self.display_time_range_selection_widgets()
151152

152153
def select_ob_folder(self):
@@ -157,11 +158,11 @@ def retrieve_ob_metadata(self, selected_folder):
157158
self.ob_metadata_dict = MetadataHandler.retrieve_metadata(list_of_files=list_of_ob_files)
158159

159160
def auto_retrieve_ob_metadata(self):
160-
logging.info("> auto_retrieve_ob_metadata")
161+
logging.info("> auto_retrieve_ob_metadata - WORKING WITH OB")
161162
folder = os.path.join(self.working_dir, "raw", "ob")
162-
logging.info(f"-> folder: {folder}")
163+
logging.info(f"\t-> folder: {folder}")
163164
list_of_ob_files = file_handler.get_list_of_all_files_in_subfolders(folder=folder, extensions=["tiff", "tif"])
164-
logging.info(f"-> nbr of ob files found: {len(list_of_ob_files)}")
165+
logging.info(f"\t-> nbr of ob files found: {len(list_of_ob_files)}")
165166
self.ob_metadata_dict = MetadataHandler.retrieve_metadata(list_of_files=list_of_ob_files, label="ob")
166167

167168
# logging.info(f"ob metadata dict")
@@ -185,6 +186,7 @@ def retrieve_df_metadata(self, selected_folder):
185186
self.df_metadata_dict = MetadataHandler.retrieve_metadata(list_of_files=list_of_df_files)
186187

187188
def auto_retrieve_df_metadata(self):
189+
logging.info("> auto_retrieve_df_metadata - WORKING WITH DF")
188190
folder_df = os.path.join(self.working_dir, "raw", "df")
189191
folder_dc = os.path.join(self.working_dir, "raw", "dc")
190192
list_of_df_files = file_handler.get_list_of_all_files_in_subfolders(
@@ -196,12 +198,14 @@ def auto_retrieve_df_metadata(self):
196198
list_of_files = list_of_df_files + list_of_dc_files
197199
logging.info(f"-> nbr of dc files found: {len(list_of_files)}")
198200
self.df_metadata_dict = MetadataHandler.retrieve_metadata(list_of_files=list_of_files, label="df")
201+
logging.info(f"\t -> df metadata dict: {self.df_metadata_dict}")
199202

200203
def match_files(self):
201204
"""This is where the files will be associated with their respective OB, DC by using the metadata"""
202205

203206
if not JSON_DEBUGGING:
204207
self.create_master_sample_dict()
208+
logging.info(f"\t -> after creating master sample dict, final_full_master_dict: {self.final_full_master_dict}")
205209

206210
self.match_ob()
207211
self.match_df()
@@ -210,7 +214,7 @@ def match_files(self):
210214
# for debugging only, exporting the json
211215
import json
212216

213-
with open("/Users/j35/Desktop/which_ob_and_df_to_use.json", "w") as outfile:
217+
with open("/SNS/users/j35/Desktop/which_ob_and_df_to_use.json", "w") as outfile:
214218
json.dump(self.final_full_master_dict, outfile)
215219

216220
def match_ob(self):
@@ -219,21 +223,35 @@ def match_ob(self):
219223
- detector type
220224
- aperture
221225
"""
226+
logging.info("> entering match_ob")
222227
list_ob_dict = self.ob_metadata_dict
223228
final_full_master_dict = self.final_full_master_dict
224229
list_of_sample_acquisition = final_full_master_dict.keys()
225230

231+
if JSON_DEBUGGING:
232+
import json
233+
with open("/SNS/users/j35/Desktop/list_ob_dict.json", "w") as outfile:
234+
json.dump(list_ob_dict, outfile)
235+
226236
for _index_ob in list_ob_dict.keys():
227237
_all_ob_instrument_metadata = Get.get_instrument_metadata_only(list_ob_dict[_index_ob])
228238
_ob_instrument_metadata = utilities.isolate_instrument_metadata(_all_ob_instrument_metadata)
229-
_acquisition_time = _all_ob_instrument_metadata[MetadataName.EXPOSURE_TIME.value]["value"]
239+
240+
_acquisition_time = _all_ob_instrument_metadata[MetadataName.EXPOSURE_TIME.value].get("value", None)
241+
if _acquisition_time is None:
242+
logging.warning(f"\t -> OB file {list_ob_dict[_index_ob]['filename']} does not have acquisition time metadata, skipping it for the matching with the sample")
243+
continue
244+
else:
245+
logging.info(f"\t -> OB file {list_ob_dict[_index_ob]['filename']} has acquisition time {_acquisition_time}, trying to match with sample metadata")
246+
230247
if _acquisition_time in list_of_sample_acquisition:
231248
for _config_id in final_full_master_dict[_acquisition_time].keys():
232249
_sample_metadata_infos = final_full_master_dict[_acquisition_time][_config_id]["metadata_infos"]
233250
if utilities.all_metadata_match(_sample_metadata_infos, _ob_instrument_metadata):
234251
final_full_master_dict[_acquisition_time][_config_id]["list_ob"].append(list_ob_dict[_index_ob])
235252

236253
self.final_full_master_dict = final_full_master_dict
254+
logging.info(f"\t -> after matching ob, final_full_master_dict: {self.final_full_master_dict}")
237255

238256
def match_df(self):
239257
"""
@@ -242,14 +260,19 @@ def match_df(self):
242260
- detector type used
243261
- acquisition time
244262
"""
263+
logging.info("> entering match_df")
245264
list_df_dict = self.df_metadata_dict
246265
final_full_master_dict = self.final_full_master_dict
247266
list_of_sample_acquisition = final_full_master_dict.keys()
248267

249268
for _index_df in list_df_dict.keys():
250269
_all_df_instrument_metadata = Get.get_instrument_metadata_only(list_df_dict[_index_df])
251270
_df_instrument_metadata = utilities.isolate_instrument_metadata(_all_df_instrument_metadata)
252-
_acquisition_time = _all_df_instrument_metadata[MetadataName.EXPOSURE_TIME.value]["value"]
271+
_acquisition_time = _all_df_instrument_metadata[MetadataName.EXPOSURE_TIME.value].get("value", None)
272+
273+
if _acquisition_time is None:
274+
logging.warning(f"\t -> DF file {list_df_dict[_index_df]['filename']} does not have acquisition time metadata, skipping it for the matching with the sample")
275+
continue
253276

254277
if _acquisition_time in list_of_sample_acquisition:
255278
for _config_id in final_full_master_dict[_acquisition_time].keys():
@@ -263,6 +286,7 @@ def match_df(self):
263286
final_full_master_dict[_acquisition_time][_config_id]["list_df"].append(list_df_dict[_index_df])
264287

265288
self.final_full_master_dict = final_full_master_dict
289+
logging.info(f"\t -> after matching df, final_full_master_dict: {self.final_full_master_dict}")
266290

267291
def create_master_sample_dict(self):
268292
final_full_master_dict = collections.OrderedDict()

notebooks/normalization_with_simplify_selection.ipynb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
},
2020
"source": [
21-
"# Select Your IPTS "
21+
"# <font color='red'>Select Your IPTS</font>"
2222
]
2323
},
2424
{
@@ -41,7 +41,7 @@
4141
"source": [
4242
"from __code.normalization.normalization_with_simplify_selection import NormalizationWithSimplifySelection\n",
4343
"from __code import system\n",
44-
"system.System.select_working_dir(notebook='normalization_with_simplify_selection', ipts=\"IPTS-35409\",instrument_to_exclude=[\"VENUS\", \"SNAP\"])\n",
44+
"system.System.select_working_dir(notebook='normalization_with_simplify_selection', ipts=\"IPTS-35248\",instrument_to_exclude=[\"VENUS\", \"SNAP\"])\n",
4545
"from __code.__all import custom_style\n",
4646
"custom_style.style()"
4747
]
@@ -60,7 +60,7 @@
6060
},
6161
"outputs": [],
6262
"source": [
63-
"# %gui qt"
63+
"%gui qt"
6464
]
6565
},
6666
{
@@ -72,7 +72,7 @@
7272
}
7373
},
7474
"source": [
75-
"# Select List of Images to Normalize "
75+
"# <font color='red'>Select List of Images to Normalize "
7676
]
7777
},
7878
{
@@ -84,6 +84,16 @@
8484
"Change the time range if needed!"
8585
]
8686
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"metadata": {},
91+
"outputs": [],
92+
"source": [
93+
"#DEBUGGING\n",
94+
"# use 2026_04_05_dryCal_AEM"
95+
]
96+
},
8797
{
8898
"cell_type": "code",
8999
"execution_count": null,
@@ -114,7 +124,7 @@
114124
}
115125
},
116126
"source": [
117-
"# Define normalization parameters"
127+
"# <font color='red'>Define normalization parameters"
118128
]
119129
},
120130
{
@@ -138,7 +148,7 @@
138148
"cell_type": "markdown",
139149
"metadata": {},
140150
"source": [
141-
"# Normalization workflow summary "
151+
"# <font color='red'>Normalization workflow summary "
142152
]
143153
},
144154
{
@@ -162,7 +172,7 @@
162172
"cell_type": "markdown",
163173
"metadata": {},
164174
"source": [
165-
"# Select Output Folder "
175+
"# <font color='red'>Select Output Folder "
166176
]
167177
},
168178
{

0 commit comments

Comments
 (0)