"A small example how to adapt a notebook to run with the offline calibration package \"pycalibation\".\n",
"A small example how to adapt a notebook to run with the offline calibration package \"pycalibation\".\n",
"\n",
"\n",
"The first cell contains all parameters that should be exposed to the command line."
"The first cell contains all parameters that should be exposed to the command line.\n",
"\n",
"To run this notebooks with several different input parameters in parallel by submitting multiple slurm jobs, for example for various random seed we can do the following:\n",
"\n",
"xfel-calibrate TUTORIAL TEST --random-seed 1,2,3,4\n",
"\n",
"or\n",
"\n",
"xfel-calibrate TUTORIAL TEST --random-seed 1-5\n",
"\n",
"will produce 4 jobs:\n",
"\n",
"Parsed input 1,2,3,4 to [1, 2, 3, 4]\n",
"\n",
"Submitted job: 1169340\n",
"\n",
"Submitted job: 1169341\n",
"\n",
"Submitted job: 1169342\n",
"\n",
"Submitted job: 1169343\n",
"\n",
"Submitted the following SLURM jobs: 1169340,1169341,1169342,1169343"
"sensor_size = [10, 30] # defining the picture size\n",
"sensor_size = [10, 30] # defining the picture size\n",
"random_seed = 2345 # random seed for filling of fake data array. Change it to produce different results.\n",
"random_seed = [2345] # random seed for filling of fake data array. Change it to produce different results, range allowed\n",
"runs = 500 # how may iterations to fill histograms\n",
"runs = 500 # how may iterations to fill histograms\n",
"cluster_profile = \"tutorial\" "
"cluster_profile = \"tutorial\" "
]
]
...
@@ -32,7 +54,8 @@
...
@@ -32,7 +54,8 @@
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
"source": [
"source": [
"First include what we need and set up the cluster profile. Everything that has a written response in a cell will show up in the report, e.g. prints but also return values or errors."
"First include what we need and set up the cluster profile for parallel processing on one node utilising more than one core.\n",
"Everything that has a written response in a cell will show up in the report, e.g. prints but also return values or errors."
]
]
},
},
{
{
...
@@ -105,16 +128,19 @@
...
@@ -105,16 +128,19 @@
},
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"# in order to run several random seeds in parallel the parameter has to be a list. To use the current single value in this \n",
"# notebook we use the first entry in the list\n",
"Plot the random image. everything we write here in the markup cells will show up as text in the report."
"Create some random images and plot them. Everything we write here in the markup cells will show up as text in the report."
]
]
},
},
{
{
...
@@ -183,7 +209,7 @@
...
@@ -183,7 +209,7 @@
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
"source": [
"source": [
"To parallelise jobs we use the ipyparallel client."
"To parallelise jobs we use the ipyparallel client. This will run on one node an ipcluster with the specified number of cores given in xfel_calibrate/notebooks.py."
]
]
},
},
{
{
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Tutorial Calculation #
# Tutorial Calculation #
Author: Astrid Muennich, Version 0.1
Author: Astrid Muennich, Version 0.1
A small example how to adapt a notebook to run with the offline calibration package "pycalibation".
A small example how to adapt a notebook to run with the offline calibration package "pycalibation".
The first cell contains all parameters that should be exposed to the command line.
The first cell contains all parameters that should be exposed to the command line.
To run this notebooks with several different input parameters in parallel by submitting multiple slurm jobs, for example for various random seed we can do the following:
xfel-calibrate TUTORIAL TEST --random-seed 1,2,3,4
or
xfel-calibrate TUTORIAL TEST --random-seed 1-5
will produce 4 jobs:
Parsed input 1,2,3,4 to [1, 2, 3, 4]
Submitted job: 1169340
Submitted job: 1169341
Submitted job: 1169342
Submitted job: 1169343
Submitted the following SLURM jobs: 1169340,1169341,1169342,1169343
random_seed=2345# random seed for filling of fake data array. Change it to produce different results.
random_seed=[2345]# random seed for filling of fake data array. Change it to produce different results, range allowed
runs=500# how may iterations to fill histograms
runs=500# how may iterations to fill histograms
cluster_profile="tutorial"
cluster_profile="tutorial"
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
First include what we need and set up the cluster profile. Everything that has a written response in a cell will show up in the report, e.g. prints but also return values or errors.
First include what we need and set up the cluster profile for parallel processing on one node utilising more than one core.
Everything that has a written response in a cell will show up in the report, e.g. prints but also return values or errors.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
importmatplotlib
importmatplotlib
%matplotlibinline
%matplotlibinline
importnumpyasnp
importnumpyasnp
importmatplotlib.pyplotasplt
importmatplotlib.pyplotasplt
# if not using slurm: make sure a cluster is running with
# if not using slurm: make sure a cluster is running with
# ipcluster start --n=4 --profile=tutorial
# ipcluster start --n=4 --profile=tutorial
# give it a while to start
# give it a while to start
fromipyparallelimportClient
fromipyparallelimportClient
print("Connecting to profile {}".format(cluster_profile))
print("Connecting to profile {}".format(cluster_profile))
view=Client(profile=cluster_profile)[:]
view=Client(profile=cluster_profile)[:]
view.use_dill()
view.use_dill()
```
```
%% Output
%% Output
Connecting to profile tutorial
Connecting to profile tutorial
<AsyncResult: use_dill>
<AsyncResult: use_dill>
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Create some random data
## Create some random data
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
defdata_creation(random_seed):
defdata_creation(random_seed):
np.random.seed=random_seed
np.random.seed=random_seed
returnnp.random.random((sensor_size))
returnnp.random.random((sensor_size))
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# in order to run several random seeds in parallel the parameter has to be a list. To use the current single value in this
Plot the random image. everything we write here in the markup cells will show up as text in the report.
Create some random images and plot them. Everything we write here in the markup cells will show up as text in the report.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
plt.subplot(211)
plt.subplot(211)
plt.imshow(fake_data[0],interpolation="nearest")
plt.imshow(fake_data[0],interpolation="nearest")
plt.title('Random Image')
plt.title('Random Image')
plt.ylabel('sensor height')
plt.ylabel('sensor height')
plt.subplot(212)
plt.subplot(212)
plt.imshow(fake_data[5],interpolation="nearest")
plt.imshow(fake_data[5],interpolation="nearest")
plt.xlabel('sensor width')
plt.xlabel('sensor width')
plt.ylabel('sensor height')
plt.ylabel('sensor height')
plt.subplots_adjust(bottom=0.1,right=0.8,top=0.9)
plt.subplots_adjust(bottom=0.1,right=0.8,top=0.9)
cax=plt.axes([0.85,0.1,0.075,0.9])
cax=plt.axes([0.85,0.1,0.075,0.9])
plt.colorbar(cax=cax).ax.set_ylabel("# counts")
plt.colorbar(cax=cax).ax.set_ylabel("# counts")
plt.show()
plt.show()
```
```
%% Output
%% Output
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
These plots show two randomly filled sensor images. We can use markup cells also as captions for images.
These plots show two randomly filled sensor images. We can use markup cells also as captions for images.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Simple Analysis
## Simple Analysis
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
mean=[]
mean=[]
std=[]
std=[]
foriminfake_data:
foriminfake_data:
mean.append(im.mean())
mean.append(im.mean())
std.append(im.std())
std.append(im.std())
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
To parallelise jobs we use the ipyparallel client.
To parallelise jobs we use the ipyparallel client. This will run on one node an ipcluster with the specified number of cores given in xfel_calibrate/notebooks.py.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
fromfunctoolsimportpartial
fromfunctoolsimportpartial
defparallel_stats(input):
defparallel_stats(input):
returninput.mean(),input.std()
returninput.mean(),input.std()
p=partial(parallel_stats)
p=partial(parallel_stats)
results=view.map_sync(p,fake_data)
results=view.map_sync(p,fake_data)
p_mean=[x[0]forxinresults]
p_mean=[x[0]forxinresults]
p_std=[x[1]forxinresults]
p_std=[x[1]forxinresults]
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
We calculate the mean value of all images, as well as the standard deviation.
We calculate the mean value of all images, as well as the standard deviation.