Skip to content
Snippets Groups Projects
Commit 8c3649d3 authored by whooie's avatar whooie
Browse files

add tags to terminal output

parent 35ea2ba2
No related branches found
No related tags found
No related merge requests found
......@@ -39,62 +39,62 @@ class ImagingData:
def save(self, target: pathlib.Path=None, overwrite: bool=False,
printflag: bool=True):
T = pathlib.Path(self.name) if target is None else target
if printflag: print(f"Saving data to {T}:")
if printflag: print(f"[imaging] Saving data to {T}:")
if not T.is_dir():
if printflag: print(f" :: mkdir {T}")
T.mkdir(parents=True, exist_ok=True)
arrays_file = _fresh_filename(T.joinpath("arrays.npz"), overwrite)
if printflag: print(" save arrays")
if printflag: print("[imaging] save arrays")
np.savez_compressed(arrays_file, **self.arrays)
config_file = _fresh_filename(T.joinpath("config.toml"), overwrite)
if printflag: print(" save camera config")
if printflag: print("[imaging] save camera config")
with config_file.open('w') as outfile:
toml.dump(self.config, outfile)
comments_file = _fresh_filename(T.joinpath("comments.txt"), overwrite)
if printflag: print(" save comments")
if printflag: print("[imaging] save comments")
comments_file.write_text(self.comments)
if self.results is not None:
results_file = _fresh_filename(
T.joinpath("results.toml"), overwrite)
if printflag: print(" save results")
if printflag: print("[imaging] save results")
with results_file.open('w') as outfile:
toml.dump(self.results, outfile)
if printflag: print(" Done.")
#if printflag: print(" Done.")
return self
@staticmethod
def load(target: pathlib.Path, name: str=None, printflag: bool=True):
name = target.stem if name is None else name
if printflag: print(f"Loading data from {target}:")
if printflag: print(f"[imaging] Loading data from {target}:")
if not target.is_dir():
raise Exception(f"Target {target} does not exist")
arrays_file = target.joinpath("arrays.npz")
if printflag: print(" load arrays")
if printflag: print("[imaging] load arrays")
if not arrays_file.is_file():
raise Exception(f"Arrays file {arrays_file} does not exist")
arrays = np.load(arrays_file)
config_file = target.joinpath("config.toml")
if printflag: print(" load camera config")
if printflag: print("[imaging] load camera config")
if not config_file.is_file():
raise Exception(f"Config file {config_file} does not exist")
config = toml.load(config_file)
comments_file = target.joinpath("comments.txt")
if printflag and comments_file.is_file(): print(" load comments")
if printflag and comments_file.is_file(): print("[imaging] load comments")
comments = comments_file.read_text() \
if comments_file.is_file() else str()
results_file = target.joinpath("results.toml")
if printflag and results_file.is_file(): print(" load results")
if printflag and results_file.is_file(): print("[imaging] load results")
results = results_file.read_text() \
if results_file.is_file() else None
if printflag: print(" Done.")
#if printflag: print(" Done.")
return AbsorptionData(name, arrays, config, comments, results)
def render_arrays(self, target: pathlib.Path=None, dx=None,
......@@ -102,12 +102,12 @@ class ImagingData:
T = pathlib.Path(self.name) if target is None else target
T = T.joinpath("images")
_dx = self.config.get("bin_size", 1) * (DEF_DX if dx is None else dx)
if printflag: print(f"Render images to {T}:")
if printflag: print(f"[imaging] Render images to {T}:")
if not T.is_dir():
if printflag: print(f" :: mkdir {T}")
if printflag: print(f"[imaging] :: mkdir {T}")
T.mkdir(parents=True, exist_ok=True)
for label, array in self.arrays.items():
if printflag: print(f" render {label}")
if printflag: print(f"[imaging] render {label}")
if label == "od":
H, W = array.shape
(pd.Plotter()
......@@ -124,7 +124,7 @@ class ImagingData:
)
else:
PIL.Image.fromarray(array).save(T.joinpath(label + ".png"))
if printflag: print(" Done.")
#if printflag: print(" Done.")
return self
def compute_results(self, dA=(2*3.45)**2, printflag: bool=True):
......@@ -134,7 +134,7 @@ class AbsorptionData(ImagingData):
def compute_results(self, dA=(3.45)**2, printflag: bool=True):
_dA = self.config.get("bin_size", 1)**2 \
* (DEF_DX**2 if dA is None else dA)
if printflag: print("Compute results")
if printflag: print("[imaging] Compute results")
OD = compute_od(
self.arrays["shadow"], self.arrays["bright"], self.arrays["dark"])
self.arrays["od"] = OD
......@@ -155,7 +155,7 @@ class FluorescenceData(ImagingData):
def compute_results(self, dA=3.45**2, printflag: bool=True):
_dA = self.config.get("bin_size", 1)**2 \
* (DEF_DX**2 if dA is None else dA)
if printflag: print("Compute results")
if printflag: print("[imaging] Compute results")
for label, array in self.arrays.items():
N = compute_mot_number(
array,
......@@ -180,7 +180,7 @@ class FluorescenceData(ImagingData):
def compute_mot_number(image, QE, gain, exposure_time, solid_angle,
detuning, intensity_parameter):
if image.max() >= 2**16:
print("WARNING: image may contain clipping")
print("[imaging] WARNING: image may contain clipping")
electron_rate = image.sum() * 16
photon_rate = electron_rate \
/ 10**(gain / 10) \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment