Skip to content

Commit

Permalink
Merge pull request #32 from anananacr/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
anananacr authored May 29, 2024
2 parents f27d921 + 2b43316 commit 780342b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 114 deletions.
1 change: 0 additions & 1 deletion bblib/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
azimuthal_average,
gaussian_lin,
get_fwhm_map_global_min,
get_distance_map_global_min,
correct_polarization,
visualize_single_panel,
)
Expand Down
21 changes: 6 additions & 15 deletions bblib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,16 @@ def set_geometry_from_file(self, geometry_filename: str = None):
self.ss_in_rows = True
else:
self.ss_in_rows = False

## The transformation matrix here are only for visualization purposes. Small stretching factors won't have an impact on the visualization of the images (slabby data).
self.transformation_matrix = [
[
detector_panels[panel_name]["fsx"],
detector_panels[panel_name]["fsy"],
int(detector_panels[panel_name]["fsx"]),
int(detector_panels[panel_name]["fsy"]),
],
[
detector_panels[panel_name]["ssx"],
detector_panels[panel_name]["ssy"],
],
]

self.transformation_matrix = [
[
detector_panels[panel_name]["fsx"],
detector_panels[panel_name]["fsy"],
],
[
detector_panels[panel_name]["ssx"],
detector_panels[panel_name]["ssy"],
int(detector_panels[panel_name]["ssx"]),
int(detector_panels[panel_name]["ssy"]),
],
]

Expand Down
98 changes: 0 additions & 98 deletions bblib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,104 +360,6 @@ def get_fwhm_map_global_min(
plt.close()
return [np.round(xc, 0), np.round(yc, 0)]


def get_distance_map_global_min(
lines: list, output_folder: str, label: str, pixel_step: int, plots_flag: bool
) -> tuple:
"""
Open distance minimization plot, fit projections in both axis to get the point of minimum distance.
Parameters
----------
lines: list
Output of grid search for FWHM optmization, each line should contain a dictionary contaning entries for xc, yc and fwhm_over_radius.
"""

n = int(math.sqrt(len(lines)))
pixel_step /= 2
merged_dict = {}
for dictionary in lines[:]:
for key, value in dictionary.items():
if key in merged_dict:
merged_dict[key].append(value)
else:
merged_dict[key] = [value]

# Create a figure with three subplots
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20, 5))

# Extract x, y, and z from merged_dict

x = np.array(merged_dict["xc"]).reshape((n, n))[0]
y = np.array(merged_dict["yc"]).reshape((n, n))[:, 0]
z = np.array(merged_dict["d"], dtype=np.float64).reshape((n, n))
z = np.nan_to_num(z)

pos1 = ax1.imshow(z, cmap="rainbow")
step = 20
n = z.shape[0]
ax1.set_xticks(np.arange(0, n, step, dtype=float))
ax1.set_yticks(np.arange(0, n, step, dtype=float))
step = round(step * (abs(x[0] - x[1])), 1)
ax1.set_xticklabels(
np.arange(round(x[0], 1), round(x[-1] + step, 1), step, dtype=int), rotation=45
)
ax1.set_yticklabels(
np.arange(round(y[0], 1), round(y[-1] + step, 1), step, dtype=int)
)

ax1.set_ylabel("yc [px]")
ax1.set_xlabel("xc [px]")
ax1.set_title("Distance [px]")

proj_x = np.sum(z, axis=0)
# print('proj',len(proj_x))
x = np.arange(x[0], x[-1] + pixel_step, pixel_step)

# print('x',len(x))
if len(proj_x) == len(x):
index_x = np.unravel_index(np.argmin(proj_x, axis=None), proj_x.shape)
xc = x[index_x]
ax2.scatter(x, proj_x + pixel_step, color="b")
ax2.scatter(xc, proj_x[index_x], color="r", label=f"xc: {np.round(xc,1)}")
ax2.set_ylabel("Average distance [px]")
ax2.set_xlabel("xc [px]")
ax2.set_title("Distance projection in x")
ax2.legend()
else:
converged = 0
xc = -1
yc = -1

proj_y = np.sum(z, axis=1)
x = np.arange(y[0], y[-1] + pixel_step, pixel_step)
if len(proj_y) == len(x):
index_y = np.unravel_index(np.argmin(proj_y, axis=None), proj_y.shape)
yc = x[index_y]
ax3.scatter(x, proj_y, color="b")
ax3.scatter(yc, proj_y[index_y], color="r", label=f"yc: {np.round(yc,1)}")
ax3.set_ylabel("Average Distance [px]")
ax3.set_xlabel("yc [px]")
ax3.set_title("Distance projection in y")
ax3.legend()
fig.colorbar(pos1, ax=ax1, shrink=0.6)
else:
converged = 0
xc = -1
yc = -1

if int(np.sum(proj_y)) == 0 or int(np.sum(proj_x)) == 0:
converged = 0
xc = -1
yc = -1
else:
converged = 1
if plots_flag:
plt.savefig(f"{output_folder}/distance_map/{label}.png")
plt.close()
return [np.round(xc, 1), np.round(yc, 1)]


def circle_mask(data: np.ndarray, center: tuple, radius: int) -> np.ndarray:
"""
Make a ring mask for the data
Expand Down

0 comments on commit 780342b

Please sign in to comment.