Skip to content

Commit

Permalink
improving pixel shift plot
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmejia committed Mar 28, 2024
1 parent 30c8b85 commit 860243d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions python/lvmdrp/core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,21 @@ def create_subplots(to_display, flatten_axes=True, **subplots_params):
return fig, axs


def plot_image_shift(ax, image, column_shift, pos=(0.0,1.0-0.32), box=(0.3,0.3), cmap="gray"):
def plot_image_shift(ax, image, column_shift, xpos=None, inset_pos=(0.0,1.0-0.32), inset_box=(0.3,0.3), cmap="gray"):
"""plots the pixel shifts of the given image along the given column shifts positions"""
xh = image.shape[1]//2
if xpos is None:
xpos = image.shape[1]//2
deltas = np.gradient(column_shift)
irows = np.where(deltas == 1)[0][::2][::-1]
irows = np.where(deltas > 0)[0][::2][::-1]
axis = []
for i, irow in enumerate(irows):
iy, fy, ix, fx = xh-30, xh+30, irow-30, irow+30
axi = ax.inset_axes((pos[0],pos[1]-i/3.2, *box))
axi.imshow(image[ix:fx, iy:fy], extent=[iy,fy,ix,fx], origin="lower", cmap=cmap, vmin=0, vmax=np.mean(image)+3*np.std(image))
iy, fy, ix, fx = xpos-30, xpos+30, irow-30, irow+30
image_region = image[ix:fx, iy:fy]
vmin = np.abs(np.nanmean(image_region)-3*np.nanstd(image_region))
vmax = np.abs(np.nanmean(image_region)+3*np.nanstd(image_region))

axi = ax.inset_axes((inset_pos[0],inset_pos[1]-i/3.2, *inset_box))
axi.imshow(image_region, extent=[iy,fy,ix,fx], origin="lower", cmap=cmap, vmin=vmin, vmax=vmax)
axi.tick_params(axis="both", labelsize=10)
if i == 0 and irows.size > 1:
axi.tick_params(axis="both", labelbottom=False)
Expand Down
2 changes: 1 addition & 1 deletion python/lvmdrp/functions/imageMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,7 @@ def fix_pixel_shifts(in_image, ref_image, threshold=1.15, fill_gaps=20, dry_run=
ax.set_xlabel("Y (pixel)")
ax.set_ylabel("Shift (pixel)")
plot_image_shift(ax, image._data, shift_column, cmap="Reds")
axis = plot_image_shift(ax, image_out._data, shift_column, cmap="Blues", pos=(0.14,1.0-0.32))
axis = plot_image_shift(ax, image_out._data, shift_column, cmap="Blues", inset_pos=(0.14,1.0-0.32))
plt.setp(axis, yticklabels=[], ylabel="")
save_fig(
fig,
Expand Down

0 comments on commit 860243d

Please sign in to comment.