Skip to content

Commit 57a308f

Browse files
committed
Update benchmark plots
1 parent 660b55d commit 57a308f

2 files changed

Lines changed: 127 additions & 29 deletions

File tree

‎docs/standalone_notebooks/benchmarking/benchmarking_sourcefinders.ipynb‎

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"import math\n",
2222
"\n",
2323
"import numpy as np\n",
24+
"import matplotlib as mpl\n",
2425
"import matplotlib.pyplot as plt\n",
2526
"import pandas as pd\n",
2627
"from pytest import approx\n",
@@ -60,7 +61,7 @@
6061
"# Plot image pixels in cartesian ordering (i.e. y-positive == upwards):\n",
6162
"plt.rcParams['image.origin'] = 'lower'\n",
6263
"# Make plots bigger\n",
63-
"plt.rcParams['figure.figsize'] = 8, 8"
64+
"plt.rcParams['figure.figsize'] = 6, 6"
6465
]
6566
},
6667
{
@@ -164,20 +165,22 @@
164165
"outputs": [],
165166
"source": [
166167
"import gc\n",
167-
"import stp_python\n",
168+
"\n",
169+
"\n",
168170
"def time_ceres_sourcefinding(image):\n",
169171
" \n",
170172
"\n",
171173
" ceres_diffmethod = stp_python.CeresDiffMethod.AnalyticDiff\n",
172174
" ceres_solvertype = stp_python.CeresSolverType.TrustRegion_DenseQR\n",
175+
" median_method = stp_python.MedianMethod.ZEROMEDIAN\n",
173176
" \n",
174-
" pars = dict(image_data=image,\n",
177+
" pars = dict(image_data=np.asfortranarray(image),\n",
175178
" detection_n_sigma=detection_n_sigma,\n",
176179
" analysis_n_sigma=analysis_n_sigma,\n",
177180
" rms_est=rms_est,\n",
178181
" find_negative_sources=False,\n",
179182
" sigma_clip_iters=0,\n",
180-
" binapprox_median=True,\n",
183+
" median_method=median_method,\n",
181184
" gaussian_fitting=False,\n",
182185
" generate_labelmap=False,\n",
183186
" ceres_diffmethod=ceres_diffmethod,\n",
@@ -196,8 +199,8 @@
196199
" stp_python.source_find_wrapper(**pars)\n",
197200
" end2=datetime.datetime.now()\n",
198201
"\n",
199-
" extraction_duration=(end2 - start2).total_seconds()\n",
200-
" fitting_duration=(end1 - start1).total_seconds() - extraction_duration\n",
202+
" extraction_duration=(end1 - start1).total_seconds()\n",
203+
" fitting_duration=(end2 - start2).total_seconds() - extraction_duration\n",
201204
"\n",
202205
" return extraction_duration, fitting_duration\n",
203206
"\n"
@@ -254,21 +257,39 @@
254257
"time_ceres_sourcefinding(image)"
255258
]
256259
},
260+
{
261+
"cell_type": "code",
262+
"execution_count": null,
263+
"metadata": {},
264+
"outputs": [],
265+
"source": [
266+
"2**13"
267+
]
268+
},
257269
{
258270
"cell_type": "code",
259271
"execution_count": null,
260272
"metadata": {},
261273
"outputs": [],
262274
"source": [
263275
"# %%time\n",
264-
"small_sizes = (512, 1024, 2048, 4096)\n",
265-
"large_sizes = (512, 1024, 2048, 4096, 8192, 12000, 16384)\n",
276+
"small_sizes = (2**9, 2**10, 2**11, 2**12)\n",
277+
"large_sizes = small_sizes+(2**13, int(2**13.5), 2**14)\n",
266278
"# images_w_64_sources = ( generate_test_image(image_size=sz, n_sources=64)\n",
267279
"# for sz in (512, 1024, 2048, 4096, 8192)]\n",
268280
"def image_set(image_sizes):\n",
269281
" return (generate_test_image(sz, n_sources=n_sources) for sz in image_sizes)"
270282
]
271283
},
284+
{
285+
"cell_type": "code",
286+
"execution_count": null,
287+
"metadata": {},
288+
"outputs": [],
289+
"source": [
290+
"large_sizes"
291+
]
292+
},
272293
{
273294
"cell_type": "code",
274295
"execution_count": null,
@@ -405,24 +426,47 @@
405426
"metadata": {},
406427
"outputs": [],
407428
"source": [
408-
"native = results_to_dataframe(native_results)\n",
409-
"ceres = results_to_dataframe(ceres_results)\n",
410-
"pyse = results_to_dataframe(pyse_results)\n",
411-
"sep = results_to_dataframe(sep_results)\n",
429+
"ticklabels = np.round(np.log2(large_sizes),decimals=1)\n",
430+
"simple_ticklabels = []\n",
431+
"for tl in ticklabels:\n",
432+
" simple_ticklabels.append(int(tl) if tl==int(tl) else tl)\n",
433+
"simple_ticklabels = [\"$2^{{{}}}$\".format(power) for power in simple_ticklabels]\n",
434+
"simple_ticklabels"
435+
]
436+
},
437+
{
438+
"cell_type": "code",
439+
"execution_count": null,
440+
"metadata": {},
441+
"outputs": [],
442+
"source": [
443+
"native_df = results_to_dataframe(native_results)\n",
444+
"ceres_df = results_to_dataframe(ceres_results)\n",
445+
"pyse_df = results_to_dataframe(pyse_results)\n",
446+
"sep_df = results_to_dataframe(sep_results)\n",
412447
"\n",
413-
"native['total']=native.extraction+native.fitting\n",
448+
"native_df['total']=native_df.extraction+native_df.fitting\n",
449+
"ceres_df['total'] = ceres_df.extraction + ceres_df.fitting\n",
414450
"\n",
415451
"ax = plt.gca()\n",
416452
"\n",
417-
"native.plot(ax=ax, y='extraction', label='native_ex')\n",
418-
"native.plot(ax=ax, y='fitting', label='native_fit')\n",
453+
"# native_df.plot(ax=ax, y='extraction', label='native_ex')\n",
454+
"# native_df.plot(ax=ax, y='fitting', label='native_fit')\n",
455+
"native_df.plot(ax=ax, y='total', label='Python ref. code (ex.+fit)')\n",
419456
"# native.plot(ax=ax, y='total', label='native_ex+fit')\n",
420-
"pyse.plot(ax=ax, y='extraction', label='pyse_ex+fit')\n",
421-
"ceres.plot(y='extraction',ax=ax, label='ceres_ex')\n",
422-
"ceres.plot(y='fitting',ax=ax, label='ceres_fit')\n",
423-
"sep.plot(y='extraction',ax=ax, label='sep_ex')\n",
457+
"pyse_df.plot(ax=ax, y='extraction', label='PySE (ex.+fit)')\n",
458+
"ceres_df.plot(y='extraction',ax=ax, label='Ceres (ex.)')\n",
459+
"ceres_df.plot(y='total',ax=ax, label='Ceres (ex.+fit)')\n",
460+
"# ceres.plot(y='fitting',ax=ax, label='ceres_fit')\n",
461+
"sep_df.plot(y='extraction',ax=ax, label='SEP (ex.)')\n",
424462
"ax.set_ylabel('Time [s]')\n",
425-
"plt.savefig('performance_64_sources_2.pdf')"
463+
"for sz in large_sizes:\n",
464+
" ax.axvline(sz, ls=':', alpha=0.3)\n",
465+
"xax = ax.get_xaxis()\n",
466+
"xax.set_ticks(large_sizes)\n",
467+
"# xax.set_ticklabels(large_sizes, rotation=45)\n",
468+
"xax.set_ticklabels(simple_ticklabels, rotation=30)\n",
469+
"plt.savefig('extraction_64_sources_all.pdf')"
426470
]
427471
},
428472
{

‎docs/standalone_notebooks/benchmarking/benchmarking_sourcefinders_cpp_only.ipynb‎

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"# Plot image pixels in cartesian ordering (i.e. y-positive == upwards):\n",
5151
"plt.rcParams['image.origin'] = 'lower'\n",
5252
"# Make plots bigger\n",
53-
"plt.rcParams['figure.figsize'] = 8, 8"
53+
"plt.rcParams['figure.figsize'] = 6,6"
5454
]
5555
},
5656
{
@@ -220,6 +220,21 @@
220220
"time_sep_extraction(image)"
221221
]
222222
},
223+
{
224+
"cell_type": "code",
225+
"execution_count": null,
226+
"metadata": {},
227+
"outputs": [],
228+
"source": [
229+
"import sep\n",
230+
"def time_numpy_fftshift(image):\n",
231+
" start=datetime.datetime.now()\n",
232+
" x = np.copy(np.fft.ifftshift(image))\n",
233+
" end = datetime.datetime.now()\n",
234+
" duration = (end - start).total_seconds()\n",
235+
" return duration"
236+
]
237+
},
223238
{
224239
"cell_type": "code",
225240
"execution_count": null,
@@ -236,9 +251,9 @@
236251
"outputs": [],
237252
"source": [
238253
"# %%time\n",
239-
"small_sizes = (512, 1024, 2048, 4096)\n",
240-
"large_sizes = (512, 1024, 2048, 4096, 8192, 12000, 16384,)\n",
241-
"v_large_sizes = (512, 1024, 2048, 4096, 8192, 12000, 16384,23000, 32768)\n",
254+
"small_sizes = (2**9, 2**10, 2**11, 2**12)\n",
255+
"large_sizes = small_sizes+(2**13, int(2**13.5), 2**14)\n",
256+
"v_large_sizes = large_sizes + (int(2**14.5), 2**15)\n",
242257
"# images_w_64_sources = ( generate_test_image(image_size=sz, n_sources=64)\n",
243258
"# for sz in (512, 1024, 2048, 4096, 8192)]\n",
244259
"def image_set(image_sizes):\n",
@@ -274,6 +289,15 @@
274289
"time_sep_extraction(generate_test_image(large_sizes[-1], n_sources=n_sources))"
275290
]
276291
},
292+
{
293+
"cell_type": "code",
294+
"execution_count": null,
295+
"metadata": {},
296+
"outputs": [],
297+
"source": [
298+
"time_numpy_fftshift(time_sep_extraction(generate_test_image(large_sizes[-1], n_sources=n_sources)))"
299+
]
300+
},
277301
{
278302
"cell_type": "code",
279303
"execution_count": null,
@@ -328,6 +352,20 @@
328352
" return df"
329353
]
330354
},
355+
{
356+
"cell_type": "code",
357+
"execution_count": null,
358+
"metadata": {},
359+
"outputs": [],
360+
"source": [
361+
"ticklabels = np.round(np.log2(v_large_sizes),decimals=1)\n",
362+
"simple_ticklabels = []\n",
363+
"for tl in ticklabels:\n",
364+
" simple_ticklabels.append(int(tl) if tl==int(tl) else tl)\n",
365+
"simple_ticklabels = [\"$2^{{{}}}$\".format(power) for power in simple_ticklabels]\n",
366+
"simple_ticklabels"
367+
]
368+
},
331369
{
332370
"cell_type": "code",
333371
"execution_count": null,
@@ -337,16 +375,32 @@
337375
"ceres_df = results_to_dataframe(ceres_results)\n",
338376
"sep_df = results_to_dataframe(sep_results)\n",
339377
"\n",
340-
"\n",
378+
"ceres_df['total'] = ceres_df.extraction + ceres_df.fitting\n",
341379
"\n",
342380
"ax = plt.gca()\n",
343381
"\n",
344-
"ceres_df.plot(y='extraction',ax=ax, label='ceres_ex')\n",
345-
"ceres_df.plot(y='fitting',ax=ax, label='ceres_fit')\n",
346-
"sep_df.plot(y='extraction',ax=ax, label='sep_ex')\n",
382+
"ceres_df.plot(y='extraction',ax=ax, label='Ceres (ex.)')\n",
383+
"ceres_df.plot(y='total',ax=ax, label='Ceres (ex.+fit)')\n",
384+
"# ceres.plot(y='fitting',ax=ax, label='ceres_fit')\n",
385+
"sep_df.plot(y='extraction',ax=ax, label='SEP (ex.)')\n",
347386
"ax.set_ylabel('Time [s]')\n",
348-
"plt.savefig('performance_64_sources_2.pdf')"
387+
"for sz in v_large_sizes:\n",
388+
" ax.axvline(sz, ls=':', alpha=0.3)\n",
389+
"\n",
390+
"xax = ax.get_xaxis()\n",
391+
"xax.set_ticks(v_large_sizes[1:])\n",
392+
"# xax.set_ticklabels(large_sizes, rotation=45)\n",
393+
"xax.set_ticklabels(simple_ticklabels[1:], rotation=30)\n",
394+
"\n",
395+
"plt.savefig('extraction_64_sources_cpp.pdf')"
349396
]
397+
},
398+
{
399+
"cell_type": "code",
400+
"execution_count": null,
401+
"metadata": {},
402+
"outputs": [],
403+
"source": []
350404
}
351405
],
352406
"metadata": {

0 commit comments

Comments
 (0)