Skip to content

Commit 7072c93

Browse files
authored
Merge pull request #3 from tinabe/nanoseg-demo
updates to the segmentation demo.
2 parents f4647a8 + 5c36d3b commit 7072c93

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

06 Nanocrystal segmentation in SPED data - Demonstration on partly overlapping MgO cubes.ipynb

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"metadata": {},
8484
"outputs": [],
8585
"source": [
86-
"dp = pxm.load_hspy('MgO2_16_TX5_c_bin2,2.hdf5',\n",
86+
"dp = pxm.load_hspy('SPED_data_of_MgO_nanoparticles_bin2,2,1,1.hdf5',\n",
8787
" lazy=False,\n",
8888
" assign_to='electron_diffraction2d')"
8989
]
@@ -167,7 +167,7 @@
167167
"metadata": {},
168168
"outputs": [],
169169
"source": [
170-
"dp.align2D(shifts=shifts, crop=False, fill_value=0)"
170+
"dp.align2D(shifts=shifts, crop=True)"
171171
]
172172
},
173173
{
@@ -183,8 +183,8 @@
183183
"metadata": {},
184184
"outputs": [],
185185
"source": [
186-
"scale = 0.03246\n",
187-
"scale_real = 2.56\n",
186+
"scale = 0.03246 \n",
187+
"scale_real = 3.03\n",
188188
"dp.set_diffraction_calibration(scale)\n",
189189
"dp.set_scan_calibration(scale_real)\n",
190190
"\n",
@@ -284,7 +284,7 @@
284284
"cell_type": "code",
285285
"execution_count": null,
286286
"metadata": {
287-
"scrolled": true
287+
"scrolled": false
288288
},
289289
"outputs": [],
290290
"source": [
@@ -392,12 +392,9 @@
392392
"metadata": {},
393393
"outputs": [],
394394
"source": [
395-
"gmags = unique_peaks.get_magnitudes()\n",
396-
"gmags.data[gmags.data<10*scale] = 0\n",
397-
"Gs = unique_peaks.data[np.where(gmags)]\n",
398-
"Gs = pxm.DiffractionVectors(Gs)\n",
399-
"print(np.shape(Gs)[0], ' unique vectors.')\n",
400-
"Gs.axes_manager.set_signal_dimension(0)"
395+
"Gs = unique_peaks.filter_vector_magnitudes(\n",
396+
" min_magnitude=10*scale, max_magnitude=np.inf)\n",
397+
"print(np.shape(Gs)[0], ' unique vectors.')"
401398
]
402399
},
403400
{
@@ -427,12 +424,7 @@
427424
"cell_type": "markdown",
428425
"metadata": {},
429426
"source": [
430-
"Optionally save and load the unique peaks\n",
431-
"\n",
432-
"`np.save('peaks.npy', Gs.data)\n",
433-
"Gs = np.load('peaks.npy', allow_pickle=True)\n",
434-
"Gs = pxm.DiffractionVectors(Gs)\n",
435-
"Gs.axes_manager.set_signal_dimension(0)`"
427+
"Optionally save and load the unique peaks"
436428
]
437429
},
438430
{
@@ -523,7 +515,7 @@
523515
"source": [
524516
"min_distance = 5.5\n",
525517
"min_size = 10\n",
526-
"max_size = None\n",
518+
"max_size = np.inf\n",
527519
"max_number_of_grains = np.inf\n",
528520
"marker_radius = 2\n",
529521
"exclude_border = 2"
@@ -535,7 +527,7 @@
535527
"metadata": {},
536528
"outputs": [],
537529
"source": [
538-
"i = 27\n",
530+
"i = 26\n",
539531
"sep_i = separate_watershed(\n",
540532
" VDFs.inav[i].data, min_distance=min_distance, min_size=min_size,\n",
541533
" max_size=max_size, max_number_of_grains=max_number_of_grains,\n",
@@ -653,7 +645,9 @@
653645
{
654646
"cell_type": "code",
655647
"execution_count": null,
656-
"metadata": {},
648+
"metadata": {
649+
"scrolled": true
650+
},
657651
"outputs": [],
658652
"source": [
659653
"hs.plot.plot_images(corrsegs.segments, cmap='magma_r', axes_decor='off',\n",
@@ -688,7 +682,6 @@
688682
"cell_type": "markdown",
689683
"metadata": {},
690684
"source": [
691-
"#### Create a signal mask for the direct beam\n",
692685
"Create a signal mask so that the region in the centre of each PED pattern, including the direct beam, can be excluded in the machine learning. "
693686
]
694687
},
@@ -707,7 +700,7 @@
707700
"cell_type": "markdown",
708701
"metadata": {},
709702
"source": [
710-
"#### Perform single value decomposition (SVD)"
703+
"Perform single value decomposition (SVD)"
711704
]
712705
},
713706
{
@@ -736,7 +729,7 @@
736729
"cell_type": "markdown",
737730
"metadata": {},
738731
"source": [
739-
"#### Investigate the scree plot and use it as a guide to determine the number of components"
732+
"Investigate the scree plot and use it as a guide to determine the number of components"
740733
]
741734
},
742735
{
@@ -757,7 +750,7 @@
757750
"cell_type": "markdown",
758751
"metadata": {},
759752
"source": [
760-
"### NMF"
753+
"NMF"
761754
]
762755
},
763756
{
@@ -870,7 +863,6 @@
870863
"cell_type": "markdown",
871864
"metadata": {},
872865
"source": [
873-
"#### Investigate the normalised cross-correlations\n",
874866
"Calculate the matrix of normalised cross-correlation for both the loadings and patterns first, to find suitable correlation threshold values. "
875867
]
876868
},
@@ -890,7 +882,15 @@
890882
"metadata": {},
891883
"outputs": [],
892884
"source": [
893-
"ncc_nmf = learn.get_ncc_matrix()\n",
885+
"ncc_nmf = learn.get_ncc_matrix()"
886+
]
887+
},
888+
{
889+
"cell_type": "code",
890+
"execution_count": null,
891+
"metadata": {},
892+
"outputs": [],
893+
"source": [
894894
"ncc_nmf.plot(scalebar=False, cmap='RdBu')"
895895
]
896896
},

0 commit comments

Comments
 (0)