Skip to content

Commit

Permalink
kymograph tutorial: add section on photon counts
Browse files Browse the repository at this point in the history
  • Loading branch information
aafkevandenberg committed Jan 7, 2025
1 parent 88906c3 commit 73c2788
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions docs/tutorial/kymographs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,40 +142,43 @@ This returns a new (but flipped) :class:`~lumicks.pylake.kymo.Kymo`::

Extracting photon counts
------------------------

Photon counts can be extracted from the raw image, for example for stoichiometry analysis.
First, select a region for which the photon counts have to be determined::

kymo_selection = kymo["88.5s":"93s"].crop_by_distance(21.4,22.3)
kymo_selection = kymo["88.5s":"93s"].crop_by_distance(21.4, 22.3)

plt.figure()
kymo_selection.plot("rgb", adjustment=lk.ColorAdjustment(0, 98, mode="percentile"))

Get the raw data (photon counts for each pixel) for the selected region::

selection_green = kymo_selection.get_image(channel = 'green')
selection_green = kymo_selection.get_image(channel="green")

.. image:: figures/kymographs/kymograph_selection.png

If the background has to be subtracted, choose a region without binding events as background::

background = kymo["92.1s":"100s"].crop_by_distance(21.4,22.3)
background = kymo["92.1s":"100s"].crop_by_distance(21.4, 22.3)
plt.figure()
background.plot("rgb", adjustment=lk.ColorAdjustment(0, 98, mode="percentile"))

.. image:: figures/kymographs/background.png

Subtract the background and sum over the vertical axis (along the width of the binding event) to obtain the photon counts over time::
Sum over the vertical axis (along the width of the binding event) to obtain the total photon counts over the selected regions.
Since every pixel has an average background signal of `background_mean`, we need to sum the background over the same region to obtain the total background.

background_mean = np.mean(background.get_image(channel = "green"))
photon_counts = np.sum(selection_green-background_mean, axis = 0)
time = np.arange(len(photon_counts))*kymo.line_time_seconds
summed_photon_counts = np.sum(selection_green, axis=0)
background_mean = np.mean(background.get_image(channel="green"))
summed_background = background_mean * selection_green.shape[0]
time = np.arange(len(photon_counts)) * kymo.line_time_seconds

plt.figure()
plt.plot(time, photon_counts)
plt.plot(time, summed_photon_counts - summed_background)
plt.xlabel("time (s)")
plt.ylabel("Photon counts")
plt.title("Photon counts along binding event")
plt.ylabel("Signal Intensity")
plt.title("Photon counts along binding event minus background")

.. image:: figures/kymographs/photon_counts.png

Expand Down

0 comments on commit 73c2788

Please sign in to comment.