Welcome to D-scan’s documentation¶
Graphs¶
a timeline of predictions
first predections¶
the model used for the predictions. There was a problem with the input pipeline that mean that the input and output data that was used to train the network were not aligned. This meant that the model learnt the average of the data points and was not very good.

maxpool predections¶
The model used for these predictions was very simple and was used as a very basic baseline to compare other models from. This has been run on pulses with random quadratic phase profiles. There was no noise in the data.
model¶

training fit¶

testing fit¶

discussion¶
There is a good fitting for the training data however on the testing data there is quite a poor fitting. This tends to happen when there is overfitting of the data. With such a simple model this happens quite quickly however the simplicity of the model also means that it is unable to distinguish between different dscans very well and as such will not generalise well to new pulses.
D_scan_creation¶
__init__¶
-
__init__
(self, control, steps=1024, start=-256, stop=256, E_0=1, omega_0=10, delta=3, glass_dis=5e5, phase_control = "none")¶ the initialisation function.
Parameters: - control ("E_omega" or "E_t") – Takes the values either “E_omega” or “E_t”. It controls whether the pulse is created from a time or frequency space description.
- steps – The number of steps in time. Used to define the time axis.
- start – The start time (fs)
- stop – The stop time (fs)
- E_0 – The maximum amplitude of the electric field.
- omega_0 – The central frequency of the pulse
- delta – If control is “E_t” it is the width of the gaussian in the time axis.
- glass_dis – The maximum insertion distance of the glass in nm
- phase_control ("none" or "phi_quadratic" or "phi_cubic") – “phi_quadratic” gives a random quadratic phase in frequency space and “phi_cubic” gives a random cubic phase in frequency space. “none” results in no phase being added.
Return type: None
my_compress¶
-
my_compress
(self, in_a, compression_ratio_x, compression_ratio_y)¶ -
A custom made compression function that takes the average of the nearest points for a 2-D array
Parameters: - in_a – the array that is to be compressed.
- compression_ratio_x – the factor by which the x axis is to be compressed by.
- compression_ratio_y – the factor by which the y axis is to be compressed by.
Return type: compressed array
h5out¶
-
h5out
(self, arg1) -
Saves the compressed pulse into an hdf5 file in the pulses folder.
Parameters: arg1 – The sub-folder in which the pulse is to be saved in the pulses folder.
make_dscan_all¶
-
make_dscan_all
(self)¶ -
creates a p1color or imshow plot of the compressed dscan trace.
make_E_omega_plot¶
-
make_E_omega_plot
(self)
make_E_omega_plot2¶
-
make_E_omega_plot2
(self)¶ makes a plot of E as a function of omega but sliced above omega = 2 rad/fs
make_plots¶
-
make_plouts
(self, control="all")¶ -
a control function for calling the other plot functions.
Parameters: control ("all" or "dscan") – either generates all the plots or just the dscan.
D_trace¶
-
D_trace
(self, E_omega, k, z, r)¶ Parameters: - E_omega –
- k – Wavevector
- z – Glass insertion distance
- r – Response function
Return type: the dscan at a single glass insertion.
E_gaussian¶
-
E_gaussian
(self, t, E_0, omega_0, delta_t)¶ Parameters: - t –
- E_0 –
- omega_0 –
- delta_t –
Return type: E, A gaussian distributed(in time) E field
E_omega_gen¶
-
E_omega_gen
(self, delta_omega=3, omega_cent=2, E_0=1)¶ Parameters: - delta_omega –
- omega_cent –
- E_0 –
Return type: E_omega a gaussian distributed(in omega) E field
make_phi¶
-
make_phi
(self, control, centred = 2, phi_slope=1.0)¶ Parameters: - control ("phi_quadratic" or "phi_cubic") –
- centred – the central frequency of either the cubic or quadratic function.
- phi_slope – the gradient of the cubic or quadratic function
Return type: phi, The phase of the Electric field in omega.
make_psi¶
-
make_psi
(self, control, t_centred=0, psi_slope=1)¶ Parameters: - control ("psi_quadratic" or "psi_cubic") –
- centred – the central frequency of either the cubic or quadratic function.
- psi_slope – the gradient of the cubic or quadratic function
Return type: psi, The phase of the Electric field in time.
dnn_learn¶
The file responsible for the learning of the model.
-
dnn_learn
()¶ Parameters: - b_n – batch number
- ep – epoch number
- s_p_e – steps per epoch
- validate – bool that controls if validation is run every epoch and learning graph produced.
- d – tensorflow dataset containing glob of pulse file locations
- input_dscan – tensorflow dataset containing the dscan info from each pulse
- input_other – tensorflow dataset containing the other input parameters info from each pulse
- output_d – tensorflow dataset containing the output Electric field that is to be predicted
- dataset – tensorflow dataset that is a zipped dataset of the inputs and output
- test_dataset – tensorflow dataset for validation
- train_dataset – tensorflow dataset for training
- model – tensorflow model that is loaded from file “model.h5”
- history – tensorflow history from model.fit()
-
_set_in_scan
(af)¶ Sets the as_list sizes for the input tensor. These must be set before the dataset is passed to model.fit
Parameters: af – the tensor that will have its shape defined Return type: tensorflow tensor
-
_set_in_other
(af)¶ Sets the as_list sizes for the input tensor. These must be set before the dataset is passed to model.fit
Parameters: af – the tensor that will have its shape defined Return type: tensorflow tensor
-
_set_out
(af)¶ Sets the as_list sizes for the input tensor. These must be set before the dataset is passed to model.fit
Parameters: af – the tensor that will have its shape defined Return type: tensorflow tensor
-
read_in_scan
(filename)¶ opens the hdf5 file (filename) and reads out the array stored in ‘input_scan’
Parameters: filename – Return type: 2D array
-
read_in_other
(filename)¶ opens the hdf5 file (filename) and reads out the array stored in ‘input_other’
Parameters: filename – Return type: 1D array
-
read_out
(filename)¶ opens the hdf5 file (filename) and reads out the array stored in ‘output’
Parameters: filename – Return type: 1D array
dnn_predict¶
-
dnn_predict
()¶ Parameters: - new_model – the tensorflow model loaded from “model.h5”.
- a – contains a tensorflow glob of all the pulses in “pulses/”.
- in1 – is the dscan for a single pulse.
- in2 – is the other inputs for a single pulse.
- o1 – is the output electric field for a single pulse.
- extra_model – a tensorflow model for extracting the value of an arbitrary layer in new_model.
- pred – is the prediction of the arbitrary layer.
- new_predictions – is the prediction of the output given the inputs.
Predicts the phase from a given d-scan trace.
dnn_model¶
A file that generates the model structure.
-
dnn_model
()¶ Parameters: - input1_temp – used to turn grayscale input image into a 3 channels for rgb input
- input1 – The input to the pre-trained models. Note this needs to be of shape 224x224x3.
- input2 – The input for the model that holds the other inputs (L,R_omega_0,sinc_width).
- base_model – A tensorflow.keras.Application model. By default is a Densenet121 implementation with pre-trained weights.
- x – contains the layers that are after the pre-trained model but before the concatination with input2.
- merged_model – the layers that are after the concatination.
- outputs – contains the output layer of the model.
- model – contains the tensorflow model of all the layers. Will be saved to “model.h5”.
-
def vgg_block(layer_in, n_filters, n_conv,filter_size=(3,3),in_activation='relu',in_padding='same')
The functional blocks of the vgg architecture.
Parameters: - layer_in –
- n_filters –
- n_conv –
- filter_size –
- in_activation –
- in_padding –
Return type: tensorflow keras layer
-
inception_module
(layer_in, f1, f2_in, f2_out, f3_in, f3_out, f4_out)¶ Functional blocks of the inception architecture. Be are that this model architecture get very large very fast.
Parameters: - layer_in –
- f1 –
- f2_in –
- f2_out –
- f3_in –
- f3_out –
- f4_out –
-
residual_module
(layer_in, n_filters)¶ Functional block of the residual architecture.
Parameters: - layer_in –
- n_filters –
main¶
a file that generates the pulses that are used in the machine learning
data parsing¶
about¶
This is an MSci physics project by a pair of physics undergraduates at Imperial College London. The aim of the project was to first implement the work done in ‘paper’, and then to apply this to some experimental data. Beyond this there were aims to provide dscan characterisation “in real time”. There are also attempts being made to improve upon the speed and accuracy of the neural network used in the previously mentioned paper.




