Width Fitting#
napari-bactmeasure provides two fitting methods to calculate the width of a given bacterium, which have been
developed to work with either fluorescence or phase contrast microscopy images.
Fluorescence microscopy fitting method#
fit_ring_profile(x: np.array, y: np.array, psfFWHM: float)
#
Fit the ring profile using a tilted circle model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
np.array
|
values at which the model is evaluated |
required |
y
|
np.array
|
measured ring profile |
required |
psfFWHM
|
float
|
the FWHM of the microscope PSF, in the unit of x_values |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
lmfit.model.ModelResult
|
the result of the fitting |
Source code in src/micromorph/bacteria/fluorescence_fitting.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
gaussian(params: tuple or list, x: np.array) -> np.array
#
Gaussian function with 1 peak.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
tuple or list
|
parameters of the gaussian function [centre, sigma] |
required |
x
|
np.array
|
values at which the model is evaluated |
required |
Returns:
| Name | Type | Description |
|---|---|---|
values |
np.array
|
value(s) of the gaussian at x |
Source code in src/micromorph/bacteria/fluorescence_fitting.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
get_initial_guess(x: np.array, y: np.array)
#
Get initial guess for ring profile model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
np.array
|
values at which the model is evaluated |
required |
y
|
np.array
|
measured ring profile |
required |
Returns:
| Name | Type | Description |
|---|---|---|
initial_guess |
dict
|
initial guess for the parameters, in a dictionary |
Source code in src/micromorph/bacteria/fluorescence_fitting.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
prepare_data(profile: np.array) -> np.array
#
Prepare the data for fitting, normalising the profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
np.array
|
the profile to be prepared |
required |
Returns:
| Name | Type | Description |
|---|---|---|
profile |
np.array
|
the normalised profile |
Source code in src/micromorph/bacteria/fluorescence_fitting.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
ring_profile(x: np.array, psfFWHM: int or float, R: int or float, x0: int or float, offset: int or float, amp: int or float) -> np.array
#
This function produces a line profile of a septum using an explicit 'tilted circle' model. It is based off code written in MATLAB by Séamus Holden, described in Whitley et al. 2021 and hosted in
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
np.array
|
values at which the model is evaluated |
required |
x0
|
int or float
|
the centre of the ring |
required |
R
|
int or float
|
the radius of the ring |
required |
psfFWHM
|
int or float
|
the FWHM of the microscope PSF, in the unit of x_values |
required |
offset
|
int or float
|
the background value |
required |
amp
|
int or float
|
the amplitude of the ring profile |
required |
Returns:
| Name | Type | Description |
|---|---|---|
image_profile |
np.array
|
value(s) of the ring profile at x |
Source code in src/micromorph/bacteria/fluorescence_fitting.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
Phase contrast microscopy fitting method#
fit_phase_contrast_profile(x: np.array, y: np.array)
#
Fit the phase contrast profile using a super gaussian (top-hat) model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
np.array
|
x (independent) values of the profile |
required |
y
|
np.array
|
y values of the profile - this is what gets fitted |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
lmfit object
|
the result of the fitting process, see lmfit documentation for more details |
Source code in src/micromorph/bacteria/phase_contrast_fitting.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
fit_top_hat_profile(x: np.array, y: np.array)
#
Fit the phase contrast profile using a super gaussian (top-hat) model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
np.array
|
x (independent) values of the profile |
required |
y
|
np.array
|
y values of the profile - this is what gets fitted |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
lmfit object
|
the result of the fitting process, see lmfit documentation for more details |
Source code in src/micromorph/bacteria/phase_contrast_fitting.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
get_initial_guess(x: np.array, y: np.array) -> dict
#
Get the initial guess for super gaussian model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
np.array
|
values at which the model is evaluated |
required |
y
|
np.array
|
measured phase contrast profile |
required |
Returns:
| Name | Type | Description |
|---|---|---|
initial_guess |
dict
|
initial guess for the parameters, in a dictionary |
Source code in src/micromorph/bacteria/phase_contrast_fitting.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
invert_profile(profile: np.array) -> np.array
#
Convenience function to invert the profile to make it more suitable for fitting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
np.array
|
the profile to be inverted |
required |
Returns:
| Name | Type | Description |
|---|---|---|
profile |
np.array
|
the inverted profile |
Source code in src/micromorph/bacteria/phase_contrast_fitting.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
super_gaussian(x: np.array, center: float, width: float, amplitude: float, order: float or int, offset: float or int) -> np.array
#
Super Gaussian model (top hat) to be used for fitting phase contrast profiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
np.array
|
values at which the model is evaluated |
required |
center
|
float
|
center of the super gaussian |
required |
width
|
float
|
width of the super gaussian |
required |
amplitude
|
float
|
amplitude of the super gaussian |
required |
order
|
float or int
|
order of the super gaussian (makes it more or less top-hat shaped) |
required |
offset
|
float or int
|
offset of the super gaussian (background) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
value |
np.array
|
value(s) of the super gaussian at x |
Source code in src/micromorph/bacteria/phase_contrast_fitting.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |