|
a |
|
b/docs/utils/main.html |
|
|
1 |
<!doctype html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
|
|
6 |
<meta name="generator" content="pdoc 0.10.0" /> |
|
|
7 |
<title>pymskt.utils.main API documentation</title> |
|
|
8 |
<meta name="description" content="" /> |
|
|
9 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
|
|
10 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
|
|
11 |
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
|
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
|
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
|
15 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
|
|
16 |
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
|
|
17 |
</head> |
|
|
18 |
<body> |
|
|
19 |
<main> |
|
|
20 |
<article id="content"> |
|
|
21 |
<header> |
|
|
22 |
<h1 class="title">Module <code>pymskt.utils.main</code></h1> |
|
|
23 |
</header> |
|
|
24 |
<section id="section-intro"> |
|
|
25 |
<details class="source"> |
|
|
26 |
<summary> |
|
|
27 |
<span>Expand source code</span> |
|
|
28 |
</summary> |
|
|
29 |
<pre><code class="python">import vtk |
|
|
30 |
import numpy as np |
|
|
31 |
import os |
|
|
32 |
import errno |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
def l2n(l): |
|
|
37 |
""" |
|
|
38 |
convert list to numpy array |
|
|
39 |
|
|
|
40 |
Parameters |
|
|
41 |
---------- |
|
|
42 |
l : list |
|
|
43 |
list to convert to numpy array |
|
|
44 |
|
|
|
45 |
Returns |
|
|
46 |
------- |
|
|
47 |
numpy.ndarray |
|
|
48 |
array created from inputted list `l` |
|
|
49 |
""" |
|
|
50 |
return np.array(l) |
|
|
51 |
|
|
|
52 |
|
|
|
53 |
def n2l(n): |
|
|
54 |
""" |
|
|
55 |
convert numpy array into list |
|
|
56 |
|
|
|
57 |
Parameters |
|
|
58 |
---------- |
|
|
59 |
n : numpy.ndarray |
|
|
60 |
array to convert into list. |
|
|
61 |
|
|
|
62 |
Returns |
|
|
63 |
------- |
|
|
64 |
list |
|
|
65 |
list created from inputted numpy array `n`. |
|
|
66 |
""" |
|
|
67 |
return list(n) |
|
|
68 |
|
|
|
69 |
|
|
|
70 |
def create_4x4_from_3x3(three_by_three, translation=None): |
|
|
71 |
""" |
|
|
72 |
Create a 4x4 transformation matrix from a 3x3 transformation matrix. |
|
|
73 |
|
|
|
74 |
Parameters |
|
|
75 |
---------- |
|
|
76 |
three_by_three : numpy.ndarray |
|
|
77 |
3x3 transformation matrix to convert into a 4x4 |
|
|
78 |
translation : numpy.ndarray, optional |
|
|
79 |
translation to include in the 4x4, by default None |
|
|
80 |
|
|
|
81 |
Returns |
|
|
82 |
------- |
|
|
83 |
numpy.ndarray |
|
|
84 |
4x4 transformation matrix created from inputted |
|
|
85 |
`three_by_three` and `translation`. |
|
|
86 |
""" |
|
|
87 |
if len(three_by_three) == 9: |
|
|
88 |
three_by_three = np.reshape(three_by_three, (3, 3)) |
|
|
89 |
four_by_four = np.identity(4) |
|
|
90 |
four_by_four[:3, :3] = three_by_three |
|
|
91 |
|
|
|
92 |
# if translation is provided, put it in the last column |
|
|
93 |
if translation is not None: |
|
|
94 |
four_by_four[:3, 3] = translation |
|
|
95 |
return four_by_four |
|
|
96 |
|
|
|
97 |
|
|
|
98 |
def copy_image_transform_to_mesh(mesh, image, verbose=False): |
|
|
99 |
""" |
|
|
100 |
Copy the transformation matrix from image to mesh. |
|
|
101 |
This is the same as the function `meshTransform.copy_image_transform_to_mesh` and |
|
|
102 |
`meshTransform.apply_transform`. |
|
|
103 |
|
|
|
104 |
Parameters |
|
|
105 |
---------- |
|
|
106 |
mesh : vtk.vtkPolyData |
|
|
107 |
Surface mesh to transform. |
|
|
108 |
image : SimpleITK.Image |
|
|
109 |
Image who's transform to apply to the `mesh`. |
|
|
110 |
verbose : bool, optional |
|
|
111 |
Whether or not to print the transform to console, by default False |
|
|
112 |
|
|
|
113 |
Returns |
|
|
114 |
------- |
|
|
115 |
[type] |
|
|
116 |
[description] |
|
|
117 |
""" |
|
|
118 |
transform_array = create_4x4_from_3x3(image.GetDirection()) |
|
|
119 |
transform_array[:3, 3] = image.GetOrigin() |
|
|
120 |
transform = vtk.vtkTransform() |
|
|
121 |
transform.SetMatrix(transform_array.flatten()) |
|
|
122 |
# transform.Translate(image.GetOrigin()) |
|
|
123 |
|
|
|
124 |
if verbose is True: |
|
|
125 |
print(transform) |
|
|
126 |
|
|
|
127 |
transformer = vtk.vtkTransformPolyDataFilter() |
|
|
128 |
transformer.SetTransform(transform) |
|
|
129 |
transformer.SetInputData(mesh) |
|
|
130 |
transformer.Update() |
|
|
131 |
return transformer.GetOutput() |
|
|
132 |
|
|
|
133 |
|
|
|
134 |
def sigma2fwhm(sigma): |
|
|
135 |
""" |
|
|
136 |
Converting sigma to Full Width Half Maximum (FWHM). |
|
|
137 |
|
|
|
138 |
Parameters |
|
|
139 |
---------- |
|
|
140 |
sigma : float |
|
|
141 |
The standard deviation (sigma) to convert to FWHM |
|
|
142 |
|
|
|
143 |
Returns |
|
|
144 |
------- |
|
|
145 |
float |
|
|
146 |
The FWHM that is equivalent to the inputted sigma. |
|
|
147 |
""" |
|
|
148 |
return sigma * np.sqrt(8 * np.log(2)) |
|
|
149 |
|
|
|
150 |
def fwhm2sigma(fwhm): |
|
|
151 |
""" |
|
|
152 |
Convert a Full Width Half Maximum into sigma. |
|
|
153 |
|
|
|
154 |
Parameters |
|
|
155 |
---------- |
|
|
156 |
fwhm : float |
|
|
157 |
The FWHM to convert to sigma. |
|
|
158 |
|
|
|
159 |
Returns |
|
|
160 |
------- |
|
|
161 |
float |
|
|
162 |
The sigma that is equivalent to the inputted FWHM. |
|
|
163 |
""" |
|
|
164 |
return fwhm / np.sqrt(8 * np.log(2)) |
|
|
165 |
|
|
|
166 |
def safely_delete_tmp_file(location, |
|
|
167 |
filename): |
|
|
168 |
""" |
|
|
169 |
Function to safely remove a temporary file. |
|
|
170 |
|
|
|
171 |
Parameters |
|
|
172 |
---------- |
|
|
173 |
location : str |
|
|
174 |
location of the temporary file to remove |
|
|
175 |
filename : str |
|
|
176 |
the filename of the temporary file to delete |
|
|
177 |
""" |
|
|
178 |
try: |
|
|
179 |
os.remove(os.path.join(location, filename)) |
|
|
180 |
except OSError as exc: |
|
|
181 |
if exc.errno != errno.ENOENT: |
|
|
182 |
raise |
|
|
183 |
pass</code></pre> |
|
|
184 |
</details> |
|
|
185 |
</section> |
|
|
186 |
<section> |
|
|
187 |
</section> |
|
|
188 |
<section> |
|
|
189 |
</section> |
|
|
190 |
<section> |
|
|
191 |
<h2 class="section-title" id="header-functions">Functions</h2> |
|
|
192 |
<dl> |
|
|
193 |
<dt id="pymskt.utils.main.copy_image_transform_to_mesh"><code class="name flex"> |
|
|
194 |
<span>def <span class="ident">copy_image_transform_to_mesh</span></span>(<span>mesh, image, verbose=False)</span> |
|
|
195 |
</code></dt> |
|
|
196 |
<dd> |
|
|
197 |
<div class="desc"><p>Copy the transformation matrix from image to mesh. |
|
|
198 |
This is the same as the function <code>meshTransform.copy_image_transform_to_mesh</code> and |
|
|
199 |
<code>meshTransform.apply_transform</code>. </p> |
|
|
200 |
<h2 id="parameters">Parameters</h2> |
|
|
201 |
<dl> |
|
|
202 |
<dt><strong><code>mesh</code></strong> : <code>vtk.vtkPolyData</code></dt> |
|
|
203 |
<dd>Surface mesh to transform.</dd> |
|
|
204 |
<dt><strong><code>image</code></strong> : <code>SimpleITK.Image</code></dt> |
|
|
205 |
<dd>Image who's transform to apply to the <code>mesh</code>.</dd> |
|
|
206 |
<dt><strong><code>verbose</code></strong> : <code>bool</code>, optional</dt> |
|
|
207 |
<dd>Whether or not to print the transform to console, by default False</dd> |
|
|
208 |
</dl> |
|
|
209 |
<h2 id="returns">Returns</h2> |
|
|
210 |
<p>[type] |
|
|
211 |
[description]</p></div> |
|
|
212 |
<details class="source"> |
|
|
213 |
<summary> |
|
|
214 |
<span>Expand source code</span> |
|
|
215 |
</summary> |
|
|
216 |
<pre><code class="python">def copy_image_transform_to_mesh(mesh, image, verbose=False): |
|
|
217 |
""" |
|
|
218 |
Copy the transformation matrix from image to mesh. |
|
|
219 |
This is the same as the function `meshTransform.copy_image_transform_to_mesh` and |
|
|
220 |
`meshTransform.apply_transform`. |
|
|
221 |
|
|
|
222 |
Parameters |
|
|
223 |
---------- |
|
|
224 |
mesh : vtk.vtkPolyData |
|
|
225 |
Surface mesh to transform. |
|
|
226 |
image : SimpleITK.Image |
|
|
227 |
Image who's transform to apply to the `mesh`. |
|
|
228 |
verbose : bool, optional |
|
|
229 |
Whether or not to print the transform to console, by default False |
|
|
230 |
|
|
|
231 |
Returns |
|
|
232 |
------- |
|
|
233 |
[type] |
|
|
234 |
[description] |
|
|
235 |
""" |
|
|
236 |
transform_array = create_4x4_from_3x3(image.GetDirection()) |
|
|
237 |
transform_array[:3, 3] = image.GetOrigin() |
|
|
238 |
transform = vtk.vtkTransform() |
|
|
239 |
transform.SetMatrix(transform_array.flatten()) |
|
|
240 |
# transform.Translate(image.GetOrigin()) |
|
|
241 |
|
|
|
242 |
if verbose is True: |
|
|
243 |
print(transform) |
|
|
244 |
|
|
|
245 |
transformer = vtk.vtkTransformPolyDataFilter() |
|
|
246 |
transformer.SetTransform(transform) |
|
|
247 |
transformer.SetInputData(mesh) |
|
|
248 |
transformer.Update() |
|
|
249 |
return transformer.GetOutput()</code></pre> |
|
|
250 |
</details> |
|
|
251 |
</dd> |
|
|
252 |
<dt id="pymskt.utils.main.create_4x4_from_3x3"><code class="name flex"> |
|
|
253 |
<span>def <span class="ident">create_4x4_from_3x3</span></span>(<span>three_by_three, translation=None)</span> |
|
|
254 |
</code></dt> |
|
|
255 |
<dd> |
|
|
256 |
<div class="desc"><p>Create a 4x4 transformation matrix from a 3x3 transformation matrix. </p> |
|
|
257 |
<h2 id="parameters">Parameters</h2> |
|
|
258 |
<dl> |
|
|
259 |
<dt><strong><code>three_by_three</code></strong> : <code>numpy.ndarray</code></dt> |
|
|
260 |
<dd>3x3 transformation matrix to convert into a 4x4</dd> |
|
|
261 |
<dt><strong><code>translation</code></strong> : <code>numpy.ndarray</code>, optional</dt> |
|
|
262 |
<dd>translation to include in the 4x4, by default None</dd> |
|
|
263 |
</dl> |
|
|
264 |
<h2 id="returns">Returns</h2> |
|
|
265 |
<dl> |
|
|
266 |
<dt><code>numpy.ndarray</code></dt> |
|
|
267 |
<dd>4x4 transformation matrix created from inputted |
|
|
268 |
<code>three_by_three</code> and <code>translation</code>.</dd> |
|
|
269 |
</dl></div> |
|
|
270 |
<details class="source"> |
|
|
271 |
<summary> |
|
|
272 |
<span>Expand source code</span> |
|
|
273 |
</summary> |
|
|
274 |
<pre><code class="python">def create_4x4_from_3x3(three_by_three, translation=None): |
|
|
275 |
""" |
|
|
276 |
Create a 4x4 transformation matrix from a 3x3 transformation matrix. |
|
|
277 |
|
|
|
278 |
Parameters |
|
|
279 |
---------- |
|
|
280 |
three_by_three : numpy.ndarray |
|
|
281 |
3x3 transformation matrix to convert into a 4x4 |
|
|
282 |
translation : numpy.ndarray, optional |
|
|
283 |
translation to include in the 4x4, by default None |
|
|
284 |
|
|
|
285 |
Returns |
|
|
286 |
------- |
|
|
287 |
numpy.ndarray |
|
|
288 |
4x4 transformation matrix created from inputted |
|
|
289 |
`three_by_three` and `translation`. |
|
|
290 |
""" |
|
|
291 |
if len(three_by_three) == 9: |
|
|
292 |
three_by_three = np.reshape(three_by_three, (3, 3)) |
|
|
293 |
four_by_four = np.identity(4) |
|
|
294 |
four_by_four[:3, :3] = three_by_three |
|
|
295 |
|
|
|
296 |
# if translation is provided, put it in the last column |
|
|
297 |
if translation is not None: |
|
|
298 |
four_by_four[:3, 3] = translation |
|
|
299 |
return four_by_four</code></pre> |
|
|
300 |
</details> |
|
|
301 |
</dd> |
|
|
302 |
<dt id="pymskt.utils.main.fwhm2sigma"><code class="name flex"> |
|
|
303 |
<span>def <span class="ident">fwhm2sigma</span></span>(<span>fwhm)</span> |
|
|
304 |
</code></dt> |
|
|
305 |
<dd> |
|
|
306 |
<div class="desc"><p>Convert a Full Width Half Maximum into sigma. </p> |
|
|
307 |
<h2 id="parameters">Parameters</h2> |
|
|
308 |
<dl> |
|
|
309 |
<dt><strong><code>fwhm</code></strong> : <code>float</code></dt> |
|
|
310 |
<dd>The FWHM to convert to sigma.</dd> |
|
|
311 |
</dl> |
|
|
312 |
<h2 id="returns">Returns</h2> |
|
|
313 |
<dl> |
|
|
314 |
<dt><code>float</code></dt> |
|
|
315 |
<dd>The sigma that is equivalent to the inputted FWHM.</dd> |
|
|
316 |
</dl></div> |
|
|
317 |
<details class="source"> |
|
|
318 |
<summary> |
|
|
319 |
<span>Expand source code</span> |
|
|
320 |
</summary> |
|
|
321 |
<pre><code class="python">def fwhm2sigma(fwhm): |
|
|
322 |
""" |
|
|
323 |
Convert a Full Width Half Maximum into sigma. |
|
|
324 |
|
|
|
325 |
Parameters |
|
|
326 |
---------- |
|
|
327 |
fwhm : float |
|
|
328 |
The FWHM to convert to sigma. |
|
|
329 |
|
|
|
330 |
Returns |
|
|
331 |
------- |
|
|
332 |
float |
|
|
333 |
The sigma that is equivalent to the inputted FWHM. |
|
|
334 |
""" |
|
|
335 |
return fwhm / np.sqrt(8 * np.log(2))</code></pre> |
|
|
336 |
</details> |
|
|
337 |
</dd> |
|
|
338 |
<dt id="pymskt.utils.main.l2n"><code class="name flex"> |
|
|
339 |
<span>def <span class="ident">l2n</span></span>(<span>l)</span> |
|
|
340 |
</code></dt> |
|
|
341 |
<dd> |
|
|
342 |
<div class="desc"><p>convert list to numpy array</p> |
|
|
343 |
<h2 id="parameters">Parameters</h2> |
|
|
344 |
<dl> |
|
|
345 |
<dt><strong><code>l</code></strong> : <code>list</code></dt> |
|
|
346 |
<dd>list to convert to numpy array</dd> |
|
|
347 |
</dl> |
|
|
348 |
<h2 id="returns">Returns</h2> |
|
|
349 |
<dl> |
|
|
350 |
<dt><code>numpy.ndarray</code></dt> |
|
|
351 |
<dd>array created from inputted list <code>l</code></dd> |
|
|
352 |
</dl></div> |
|
|
353 |
<details class="source"> |
|
|
354 |
<summary> |
|
|
355 |
<span>Expand source code</span> |
|
|
356 |
</summary> |
|
|
357 |
<pre><code class="python">def l2n(l): |
|
|
358 |
""" |
|
|
359 |
convert list to numpy array |
|
|
360 |
|
|
|
361 |
Parameters |
|
|
362 |
---------- |
|
|
363 |
l : list |
|
|
364 |
list to convert to numpy array |
|
|
365 |
|
|
|
366 |
Returns |
|
|
367 |
------- |
|
|
368 |
numpy.ndarray |
|
|
369 |
array created from inputted list `l` |
|
|
370 |
""" |
|
|
371 |
return np.array(l)</code></pre> |
|
|
372 |
</details> |
|
|
373 |
</dd> |
|
|
374 |
<dt id="pymskt.utils.main.n2l"><code class="name flex"> |
|
|
375 |
<span>def <span class="ident">n2l</span></span>(<span>n)</span> |
|
|
376 |
</code></dt> |
|
|
377 |
<dd> |
|
|
378 |
<div class="desc"><p>convert numpy array into list</p> |
|
|
379 |
<h2 id="parameters">Parameters</h2> |
|
|
380 |
<dl> |
|
|
381 |
<dt><strong><code>n</code></strong> : <code>numpy.ndarray</code></dt> |
|
|
382 |
<dd>array to convert into list.</dd> |
|
|
383 |
</dl> |
|
|
384 |
<h2 id="returns">Returns</h2> |
|
|
385 |
<dl> |
|
|
386 |
<dt><code>list</code></dt> |
|
|
387 |
<dd>list created from inputted numpy array <code>n</code>.</dd> |
|
|
388 |
</dl></div> |
|
|
389 |
<details class="source"> |
|
|
390 |
<summary> |
|
|
391 |
<span>Expand source code</span> |
|
|
392 |
</summary> |
|
|
393 |
<pre><code class="python">def n2l(n): |
|
|
394 |
""" |
|
|
395 |
convert numpy array into list |
|
|
396 |
|
|
|
397 |
Parameters |
|
|
398 |
---------- |
|
|
399 |
n : numpy.ndarray |
|
|
400 |
array to convert into list. |
|
|
401 |
|
|
|
402 |
Returns |
|
|
403 |
------- |
|
|
404 |
list |
|
|
405 |
list created from inputted numpy array `n`. |
|
|
406 |
""" |
|
|
407 |
return list(n)</code></pre> |
|
|
408 |
</details> |
|
|
409 |
</dd> |
|
|
410 |
<dt id="pymskt.utils.main.safely_delete_tmp_file"><code class="name flex"> |
|
|
411 |
<span>def <span class="ident">safely_delete_tmp_file</span></span>(<span>location, filename)</span> |
|
|
412 |
</code></dt> |
|
|
413 |
<dd> |
|
|
414 |
<div class="desc"><p>Function to safely remove a temporary file. </p> |
|
|
415 |
<h2 id="parameters">Parameters</h2> |
|
|
416 |
<dl> |
|
|
417 |
<dt><strong><code>location</code></strong> : <code>str</code></dt> |
|
|
418 |
<dd>location of the temporary file to remove</dd> |
|
|
419 |
<dt><strong><code>filename</code></strong> : <code>str</code></dt> |
|
|
420 |
<dd>the filename of the temporary file to delete</dd> |
|
|
421 |
</dl></div> |
|
|
422 |
<details class="source"> |
|
|
423 |
<summary> |
|
|
424 |
<span>Expand source code</span> |
|
|
425 |
</summary> |
|
|
426 |
<pre><code class="python">def safely_delete_tmp_file(location, |
|
|
427 |
filename): |
|
|
428 |
""" |
|
|
429 |
Function to safely remove a temporary file. |
|
|
430 |
|
|
|
431 |
Parameters |
|
|
432 |
---------- |
|
|
433 |
location : str |
|
|
434 |
location of the temporary file to remove |
|
|
435 |
filename : str |
|
|
436 |
the filename of the temporary file to delete |
|
|
437 |
""" |
|
|
438 |
try: |
|
|
439 |
os.remove(os.path.join(location, filename)) |
|
|
440 |
except OSError as exc: |
|
|
441 |
if exc.errno != errno.ENOENT: |
|
|
442 |
raise |
|
|
443 |
pass</code></pre> |
|
|
444 |
</details> |
|
|
445 |
</dd> |
|
|
446 |
<dt id="pymskt.utils.main.sigma2fwhm"><code class="name flex"> |
|
|
447 |
<span>def <span class="ident">sigma2fwhm</span></span>(<span>sigma)</span> |
|
|
448 |
</code></dt> |
|
|
449 |
<dd> |
|
|
450 |
<div class="desc"><p>Converting sigma to Full Width Half Maximum (FWHM). </p> |
|
|
451 |
<h2 id="parameters">Parameters</h2> |
|
|
452 |
<dl> |
|
|
453 |
<dt><strong><code>sigma</code></strong> : <code>float</code></dt> |
|
|
454 |
<dd>The standard deviation (sigma) to convert to FWHM</dd> |
|
|
455 |
</dl> |
|
|
456 |
<h2 id="returns">Returns</h2> |
|
|
457 |
<dl> |
|
|
458 |
<dt><code>float</code></dt> |
|
|
459 |
<dd>The FWHM that is equivalent to the inputted sigma.</dd> |
|
|
460 |
</dl></div> |
|
|
461 |
<details class="source"> |
|
|
462 |
<summary> |
|
|
463 |
<span>Expand source code</span> |
|
|
464 |
</summary> |
|
|
465 |
<pre><code class="python">def sigma2fwhm(sigma): |
|
|
466 |
""" |
|
|
467 |
Converting sigma to Full Width Half Maximum (FWHM). |
|
|
468 |
|
|
|
469 |
Parameters |
|
|
470 |
---------- |
|
|
471 |
sigma : float |
|
|
472 |
The standard deviation (sigma) to convert to FWHM |
|
|
473 |
|
|
|
474 |
Returns |
|
|
475 |
------- |
|
|
476 |
float |
|
|
477 |
The FWHM that is equivalent to the inputted sigma. |
|
|
478 |
""" |
|
|
479 |
return sigma * np.sqrt(8 * np.log(2))</code></pre> |
|
|
480 |
</details> |
|
|
481 |
</dd> |
|
|
482 |
</dl> |
|
|
483 |
</section> |
|
|
484 |
<section> |
|
|
485 |
</section> |
|
|
486 |
</article> |
|
|
487 |
<nav id="sidebar"> |
|
|
488 |
<h1>Index</h1> |
|
|
489 |
<div class="toc"> |
|
|
490 |
<ul></ul> |
|
|
491 |
</div> |
|
|
492 |
<ul id="index"> |
|
|
493 |
<li><h3>Super-module</h3> |
|
|
494 |
<ul> |
|
|
495 |
<li><code><a title="pymskt.utils" href="index.html">pymskt.utils</a></code></li> |
|
|
496 |
</ul> |
|
|
497 |
</li> |
|
|
498 |
<li><h3><a href="#header-functions">Functions</a></h3> |
|
|
499 |
<ul class=""> |
|
|
500 |
<li><code><a title="pymskt.utils.main.copy_image_transform_to_mesh" href="#pymskt.utils.main.copy_image_transform_to_mesh">copy_image_transform_to_mesh</a></code></li> |
|
|
501 |
<li><code><a title="pymskt.utils.main.create_4x4_from_3x3" href="#pymskt.utils.main.create_4x4_from_3x3">create_4x4_from_3x3</a></code></li> |
|
|
502 |
<li><code><a title="pymskt.utils.main.fwhm2sigma" href="#pymskt.utils.main.fwhm2sigma">fwhm2sigma</a></code></li> |
|
|
503 |
<li><code><a title="pymskt.utils.main.l2n" href="#pymskt.utils.main.l2n">l2n</a></code></li> |
|
|
504 |
<li><code><a title="pymskt.utils.main.n2l" href="#pymskt.utils.main.n2l">n2l</a></code></li> |
|
|
505 |
<li><code><a title="pymskt.utils.main.safely_delete_tmp_file" href="#pymskt.utils.main.safely_delete_tmp_file">safely_delete_tmp_file</a></code></li> |
|
|
506 |
<li><code><a title="pymskt.utils.main.sigma2fwhm" href="#pymskt.utils.main.sigma2fwhm">sigma2fwhm</a></code></li> |
|
|
507 |
</ul> |
|
|
508 |
</li> |
|
|
509 |
</ul> |
|
|
510 |
</nav> |
|
|
511 |
</main> |
|
|
512 |
<footer id="footer"> |
|
|
513 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p> |
|
|
514 |
</footer> |
|
|
515 |
</body> |
|
|
516 |
</html> |