plot.py 15.2 KB
Newer Older
Lucas Laplanche's avatar
Lucas Laplanche committed
1
2
3
# -*- coding: utf-8 -*-


Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
4
5
6
import numpy as np
import plotly.graph_objects as go
import plotly.io as pio
Lucas Laplanche's avatar
roucoul    
Lucas Laplanche committed
7
from plotly.subplots import make_subplots
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
8
9


Lucas Laplanche's avatar
Lucas Laplanche committed
10
import pandas_tools as pt
Lucas Laplanche's avatar
Lucas Laplanche committed
11
12


Lucas Laplanche's avatar
Lucas Laplanche committed
13
14


Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
15
16
17
18
19
pio.renderers.default = 'browser'




Lucas Laplanche's avatar
maj    
Lucas Laplanche committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def plot_xy(x, y):
    # create a figure
    fig = go.Figure()


    # add the traces
    fig.add_trace(go.Scatter(
        x=x,
        y=y,
        name='curve'
    ))


    # create axis objects
    fig.update_layout(
        xaxis=dict(
            title='x'
        ),
        yaxis=dict(
            title='y',
            titlefont=dict(
                color='#1f77b4'
            ),
            tickfont=dict(
                color='#1f77b4'
            )
        )
    )


    # update layout properties
    fig.update_layout(
        title_text='y as a function of x',
        width=1600,
    )


    # show the figure
    fig.show()




Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
63
64
65
66
def plot_refra_doping(sl):
    # remove the substrate layer
    sl = sl.drop(sl.shape[0] -1, axis=0)

Lucas Laplanche's avatar
Lucas Laplanche committed
67

Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
68
69
    # check wether the depth column exist
    if not 'depth' in sl:
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
70
        sl.insert(sl.shape[1], 'depth', value=np.nan)
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
71
72


Lucas Laplanche's avatar
Lucas Laplanche committed
73
74
75
76
77
    # duplicate each layer with a 0 thickness layer
    # in order to have two points for each layer
    # at the start and the end of each layer
    for i in range(sl.shape[0]):
        j = 2*i
Lucas Laplanche's avatar
Lucas Laplanche committed
78

Lucas Laplanche's avatar
Lucas Laplanche committed
79
80
        row_to_insert = sl.loc[j]
        row_to_insert['thickness'] = 0.
Lucas Laplanche's avatar
Lucas Laplanche committed
81

Lucas Laplanche's avatar
Lucas Laplanche committed
82
        sl = pt.insert_row(j, sl, row_to_insert)
Lucas Laplanche's avatar
Lucas Laplanche committed
83
84


Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
85
86
87
88
89
90
91
92
93
94
95
96
    # calculate the depth of every layer
    for i in range(sl.shape[0]):
        sl.at[i, 'depth'] = sl.loc[0:i, 'thickness'].sum()


    # create a figure
    fig = go.Figure()


    # add the traces
    fig.add_trace(go.Scatter(
        x=sl['depth'],
Lucas Laplanche's avatar
Lucas Laplanche committed
97
        y=sl['refractive_index'].apply(np.real),
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
98
        name='refractive index'
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
99
100
101
102
103
    ))

    fig.add_trace(go.Scatter(
        x=sl['depth'],
        y=sl['na'],
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
104
105
        name='P doping',
        yaxis='y2'
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
106
107
108
109
110
    ))

    fig.add_trace(go.Scatter(
        x=sl['depth'],
        y=sl['nd'],
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
111
112
        name='N doping',
        yaxis='y2'
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
113
114
115
116
117
    ))


    # create axis objects
    fig.update_layout(
Lucas Laplanche's avatar
Lucas Laplanche committed
118
        xaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
119
            title='depth [m]'
Lucas Laplanche's avatar
Lucas Laplanche committed
120
        ),
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
121
        yaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
122
            title='refractive index',
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
123
            titlefont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
124
                color='#1f77b4'
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
125
126
            ),
            tickfont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
127
                color='#1f77b4'
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
128
129
130
            )
        ),
        yaxis2=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
131
            title='doping [at/cm³]',
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
132
            titlefont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
133
                color='#ff7f0e'
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
134
135
            ),
            tickfont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
136
                color='#ff7f0e'
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
137
            ),
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
138
139
140
            anchor='x',
            overlaying='y',
            side='right',
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
141
142
143
144
145
146
        )
    )


    # update layout properties
    fig.update_layout(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
147
        title_text='refractive index and doping along z axis',
Lucas Laplanche's avatar
piou    
Lucas Laplanche committed
148
149
150
151
152
153
        width=1600,
    )


    # show the figure
    fig.show()
Lucas Laplanche's avatar
Lucas Laplanche committed
154
155


156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
def plot_refra(sl):
    # remove the substrate layer
    sl = sl.drop(sl.shape[0] -1, axis=0)


    # check wether the depth column exist
    if not 'depth' in sl:
        sl.insert(sl.shape[1], 'depth', value=np.nan)


    # duplicate each layer with a 0 thickness layer
    # in order to have two points for each layer
    # at the start and the end of each layer
    for i in range(sl.shape[0]):
        j = 2*i

        row_to_insert = sl.loc[j]
        row_to_insert['thickness'] = 0.

        sl = pt.insert_row(j, sl, row_to_insert)


    # calculate the depth of every layer
    for i in range(sl.shape[0]):
        sl.at[i, 'depth'] = sl.loc[0:i, 'thickness'].sum()


    # create a figure
    fig = go.Figure()


    # add the traces
    fig.add_trace(go.Scatter(
        x=sl['depth'],
        y=sl['refractive_index'].apply(np.real),
        name='refractive index'
    ))


    # create axis objects
    fig.update_layout(
        xaxis=dict(
            title='depth [m]'
        ),
        yaxis=dict(
            title='refractive index',
            titlefont=dict(
                color='#1f77b4'
            ),
            tickfont=dict(
                color='#1f77b4'
            )
        ),
    )


    # update layout properties
    fig.update_layout(
        title_text='refractive index along z axis',
        width=1600,
    )


    # show the figure
    fig.show()


Lucas Laplanche's avatar
Lucas Laplanche committed
223
224
225
226
227
228
229
def plot_al_doping(sl):
    # remove the substrate layer
    sl = sl.drop(sl.shape[0] -1, axis=0)


    # check wether the depth column exist
    if not 'depth' in sl:
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
230
        sl.insert(sl.shape[1], 'depth', value=np.nan)
Lucas Laplanche's avatar
Lucas Laplanche committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255


    # duplicate each layer with a 0 thickness layer
    # in order to have two points for each layer
    # at the start and the end of each layer
    for i in range(sl.shape[0]):
        j = 2*i
        row_to_insert = sl.loc[j]
        row_to_insert['thickness'] = 0.
        sl = pt.insert_row(j, sl, row_to_insert)


    # calculate the depth of every layer
    for i in range(sl.shape[0]):
        sl.at[i, 'depth'] = sl.loc[0:i, 'thickness'].sum()


    # create a figure
    fig = go.Figure()


    # add the traces
    fig.add_trace(go.Scatter(
        x=sl['depth'],
        y=sl['al'].apply(np.real),
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
256
        name='aluminium'
Lucas Laplanche's avatar
Lucas Laplanche committed
257
258
259
260
261
    ))

    fig.add_trace(go.Scatter(
        x=sl['depth'],
        y=sl['na'],
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
262
263
        name='P doping',
        yaxis='y2'
Lucas Laplanche's avatar
Lucas Laplanche committed
264
265
266
267
268
    ))

    fig.add_trace(go.Scatter(
        x=sl['depth'],
        y=sl['nd'],
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
269
270
        name='N doping',
        yaxis='y2'
Lucas Laplanche's avatar
Lucas Laplanche committed
271
272
273
274
275
276
    ))


    # create axis objects
    fig.update_layout(
        xaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
277
            title='depth [m]'
Lucas Laplanche's avatar
Lucas Laplanche committed
278
279
        ),
        yaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
280
            title='aluminium content [1]',
Lucas Laplanche's avatar
Lucas Laplanche committed
281
            titlefont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
282
                color='#1f77b4'
Lucas Laplanche's avatar
Lucas Laplanche committed
283
284
            ),
            tickfont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
285
                color='#1f77b4'
Lucas Laplanche's avatar
Lucas Laplanche committed
286
287
288
            )
        ),
        yaxis2=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
289
            title='doping [at/cm³]',
Lucas Laplanche's avatar
Lucas Laplanche committed
290
            titlefont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
291
                color='#ff7f0e'
Lucas Laplanche's avatar
Lucas Laplanche committed
292
293
            ),
            tickfont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
294
                color='#ff7f0e'
Lucas Laplanche's avatar
Lucas Laplanche committed
295
            ),
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
296
297
298
            anchor='x',
            overlaying='y',
            side='right',
Lucas Laplanche's avatar
Lucas Laplanche committed
299
300
301
302
303
304
        )
    )


    # update layout properties
    fig.update_layout(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
305
        title_text='aluminium content and doping along z axis',
Lucas Laplanche's avatar
Lucas Laplanche committed
306
307
308
309
310
311
312
313
        width=1600,
    )


    # show the figure
    fig.show()


Lucas Laplanche's avatar
maj    
Lucas Laplanche committed
314
def plot_refra_em(sl, text_to_display=''):
Lucas Laplanche's avatar
Lucas Laplanche committed
315
316
317
318
319
320
    # remove the substrate layer
    sl = sl.drop(sl.shape[0] -1, axis=0)


    # check wether the depth column exist
    if not 'depth' in sl:
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
321
        sl.insert(sl.shape[1], 'depth', value=np.nan)
Lucas Laplanche's avatar
Lucas Laplanche committed
322
323
324
325
326
327
328
329
330
331
332
333
334
335


    # calculate the depth of every layer
    for i in range(sl.shape[0]):
        sl.at[i, 'depth'] = sl.loc[0:i, 'thickness'].sum()


    # create a figure
    fig = go.Figure()


    # add the traces
    fig.add_trace(go.Scatter(
        x=sl['depth'],
Lucas Laplanche's avatar
Lucas Laplanche committed
336
        y=sl['refractive_index'].apply(np.real),
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
337
        name='refractive index'
Lucas Laplanche's avatar
Lucas Laplanche committed
338
339
340
341
342
    ))

    fig.add_trace(go.Scatter(
        x=sl['depth'],
        y=sl['electromagnetic_amplitude'],
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
343
344
        name='em amplitude',
        yaxis='y2'
Lucas Laplanche's avatar
Lucas Laplanche committed
345
346
347
348
349
350
    ))


    # create axis objects
    fig.update_layout(
        xaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
351
            title='depth [m]'
Lucas Laplanche's avatar
Lucas Laplanche committed
352
353
        ),
        yaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
354
            title='refractive index',
Lucas Laplanche's avatar
Lucas Laplanche committed
355
            titlefont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
356
                color='#1f77b4'
Lucas Laplanche's avatar
Lucas Laplanche committed
357
358
            ),
            tickfont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
359
                color='#1f77b4'
Lucas Laplanche's avatar
Lucas Laplanche committed
360
361
362
            )
        ),
        yaxis2=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
363
            title='electromagnetic amplitude [1]',
Lucas Laplanche's avatar
Lucas Laplanche committed
364
            titlefont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
365
                color='#ff7f0e'
Lucas Laplanche's avatar
Lucas Laplanche committed
366
367
            ),
            tickfont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
368
                color='#ff7f0e'
Lucas Laplanche's avatar
Lucas Laplanche committed
369
            ),
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
370
371
372
            anchor='x',
            overlaying='y',
            side='right',
Lucas Laplanche's avatar
Lucas Laplanche committed
373
374
375
376
377
378
        )
    )


    # update layout properties
    fig.update_layout(
Lucas Laplanche's avatar
maj    
Lucas Laplanche committed
379
        title_text='refractive index and electromagnetic amplitude along z axis ' +text_to_display,
Lucas Laplanche's avatar
Lucas Laplanche committed
380
381
382
383
384
385
386
387
        width=1600,
    )


    # show the figure
    fig.show()


Lucas Laplanche's avatar
Lucas Laplanche committed
388
def plot_refra_clad_coupling_em(sl1, sl2, sl3):
Lucas Laplanche's avatar
maj    
Lucas Laplanche committed
389
    # sl[sl['name'].str.contains('cladding')].reset_index(drop=True).iloc[0]['thickness']
Lucas Laplanche's avatar
Lucas Laplanche committed
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
    # remove the substrate layer
    sl1 = sl1.drop(sl1.shape[0] -1, axis=0)
    sl2 = sl2.drop(sl2.shape[0] - 1, axis=0)
    sl3 = sl3.drop(sl3.shape[0] - 1, axis=0)


    # check wether the depth column exist
    if not 'depth' in sl1:
        sl1.insert(sl1.shape[1], 'depth', value=np.nan)
        sl2.insert(sl2.shape[1], 'depth', value=np.nan)
        sl3.insert(sl3.shape[1], 'depth', value=np.nan)


    # calculate the depth of every layer
    for i in range(sl1.shape[0]):
        sl1.at[i, 'depth'] = sl1.loc[0:i, 'thickness'].sum()
        sl2.at[i, 'depth'] = sl2.loc[0:i, 'thickness'].sum()
        sl3.at[i, 'depth'] = sl3.loc[0:i, 'thickness'].sum()


Lucas Laplanche's avatar
Lucas Laplanche committed
410
411
412
413
414
415
416
417
    # define xaxes, yaxes
    fig = make_subplots(
        rows=3,
        cols=1,
        specs=[[{'secondary_y': True}],
               [{'secondary_y': False}],
               [{'secondary_y': False}]]
    )
Lucas Laplanche's avatar
Lucas Laplanche committed
418
419


Lucas Laplanche's avatar
Lucas Laplanche committed
420
421
    # add traces
    fig.add_scatter(
Lucas Laplanche's avatar
Lucas Laplanche committed
422
423
424
        x=sl1['depth'],
        y=sl1['electromagnetic_amplitude'],
        name='em amplitude1',
Lucas Laplanche's avatar
Lucas Laplanche committed
425
426
427
        row=1,
        col=1
    )
Lucas Laplanche's avatar
Lucas Laplanche committed
428

Lucas Laplanche's avatar
Lucas Laplanche committed
429
430
431
432
433
434
435
436
437
438
    fig.add_scatter(
        x=sl1['depth'],
        y=sl1['refractive_index'].apply(np.real),
        name='refractive index',
        row=1,
        col=1,
        secondary_y=True
    )

    fig.add_scatter(
Lucas Laplanche's avatar
Lucas Laplanche committed
439
440
441
        x=sl2['depth'],
        y=sl2['electromagnetic_amplitude'],
        name='em amplitude2',
Lucas Laplanche's avatar
Lucas Laplanche committed
442
443
444
        row=2,
        col=1
    )
Lucas Laplanche's avatar
Lucas Laplanche committed
445

Lucas Laplanche's avatar
Lucas Laplanche committed
446
    fig.add_scatter(
Lucas Laplanche's avatar
Lucas Laplanche committed
447
448
449
        x=sl3['depth'],
        y=sl3['electromagnetic_amplitude'],
        name='em amplitude3',
Lucas Laplanche's avatar
Lucas Laplanche committed
450
451
452
453
        row=3,
        col=1
    )

Lucas Laplanche's avatar
Lucas Laplanche committed
454
455
456
457

    # update layout properties
    fig.update_layout(
        width=1600,
Lucas Laplanche's avatar
Lucas Laplanche committed
458
        height=900,
Lucas Laplanche's avatar
Lucas Laplanche committed
459
460
461
462
463
464
465
    )


    # show the figure
    fig.show()


Lucas Laplanche's avatar
Lucas Laplanche committed
466
467


Lucas Laplanche's avatar
Lucas Laplanche committed
468
def plot_reflectivity(wavelength, r):
Lucas Laplanche's avatar
Lucas Laplanche committed
469
470
    # create a figure
    fig = go.Figure()
Lucas Laplanche's avatar
Lucas Laplanche committed
471
472


Lucas Laplanche's avatar
Lucas Laplanche committed
473
474
475
476
    # add the traces
    fig.add_trace(go.Scatter(
        x=wavelength,
        y=r,
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
477
        name='reflectance'
Lucas Laplanche's avatar
Lucas Laplanche committed
478
    ))
Lucas Laplanche's avatar
Lucas Laplanche committed
479
480


Lucas Laplanche's avatar
Lucas Laplanche committed
481
482
483
    # create axis objects
    fig.update_layout(
        xaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
484
            title='wavelength [m]'
Lucas Laplanche's avatar
Lucas Laplanche committed
485
486
        ),
        yaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
487
            title='reflectivity [1]',
Lucas Laplanche's avatar
Lucas Laplanche committed
488
            titlefont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
489
                color='#1f77b4'
Lucas Laplanche's avatar
Lucas Laplanche committed
490
491
            ),
            tickfont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
492
                color='#1f77b4'
Lucas Laplanche's avatar
Lucas Laplanche committed
493
494
495
            )
        )
    )
Lucas Laplanche's avatar
Lucas Laplanche committed
496
497


Lucas Laplanche's avatar
Lucas Laplanche committed
498
499
    # update layout properties
    fig.update_layout(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
500
        title_text='reflectivity as a function of wavelength',
Lucas Laplanche's avatar
Lucas Laplanche committed
501
502
        width=1600,
    )
Lucas Laplanche's avatar
Lucas Laplanche committed
503
504


505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
    # show the figure
    fig.show()


def plot_mult_reflectivity(wavelength, r1, wavelength2, r2):
    # create a figure
    fig = go.Figure()


    # add the traces
    fig.add_trace(go.Scatter(
        x=wavelength,
        y=r1,
        name='measurement'
    ))
    fig.add_trace(go.Scatter(
        x=wavelength2,
        y=r2,
        name='theory'
    ))


    # create axis objects
    fig.update_layout(
        xaxis=dict(
            title='wavelength [m]'
        ),
        yaxis=dict(
            title='reflectivity [1]',
            titlefont=dict(
                color='#1f77b4'
            ),
            tickfont=dict(
                color='#1f77b4'
            )
        )
    )


    # update layout properties
    fig.update_layout(
        title_text='reflectivity as a function of wavelength',
547
        font_size=20,
548
549
550
551
        width=1600,
    )


Lucas Laplanche's avatar
Lucas Laplanche committed
552
    # show the figure
Lucas Laplanche's avatar
Lucas Laplanche committed
553
    fig.show()
Lucas Laplanche's avatar
Lucas Laplanche committed
554
555


Lucas Laplanche's avatar
maj    
Lucas Laplanche committed
556
557
558
559
560
561
562
563
564
def plot_std_heatmap(x, y, r):
    fig = go.Figure(data=
                    go.Heatmap(x=x, y=y, z=r, colorscale='jet'))


    # show the figure
    fig.show()


Lucas Laplanche's avatar
Lucas Laplanche committed
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
def plot_2_std_heatmaps(x1, y1, r1, x2, y2, r2):
    # define xaxes, yaxes
    fig = go.Figure(data=
                    go.Heatmap(x=x1, y=y1, z=r1, colorscale='jet'))

    # show the figure
    fig.show()


    fig = go.Figure(data=
                    go.Heatmap(x=x2, y=y2, z=r2, colorscale='jet'))


    # show the figure
    fig.show()


582
def plot_reflectivity_heatmap(time, wavelength, r):
Lucas Laplanche's avatar
Lucas Laplanche committed
583
    fig = go.Figure(data=
584
                    go.Heatmap(x=time, y=wavelength, z=r, colorscale='jet'))
Lucas Laplanche's avatar
Lucas Laplanche committed
585
586
587
588
589
590


    # show the figure
    fig.show()


Lucas Laplanche's avatar
Lucas Laplanche committed
591
592


593
594
595
596
597
598
def plot_psie(lz=0.01e-9):
    # import arrays
    v_e = np.load('v_e.npz')['arr_0']
    psi_e = np.load('psi_e.npz')['arr_0']


Lucas Laplanche's avatar
Lucas Laplanche committed
599
600
601
602
603
604
605
606
607
608
609
610
    # create a figure
    fig = go.Figure()


    # create depth array
    depth = np.arange(0., lz*v_e.shape[0], lz)


    # add the traces
    fig.add_trace(go.Scatter(
        x=depth,
        y=v_e,
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
611
        name='potential_barrier'
Lucas Laplanche's avatar
Lucas Laplanche committed
612
613
614
615
    ))

    fig.add_trace(go.Scatter(
        x=depth,
616
617
        #y=psi_e[0, :],
        y=psi_e,
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
618
619
        name='wavefunction',
        yaxis = 'y2'
Lucas Laplanche's avatar
Lucas Laplanche committed
620
621
622
623
624
625
    ))


    # create axis objects
    fig.update_layout(
        xaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
626
            title='depth [m]'
Lucas Laplanche's avatar
Lucas Laplanche committed
627
628
        ),
        yaxis=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
629
            title='conduction band [eV]',
Lucas Laplanche's avatar
Lucas Laplanche committed
630
            titlefont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
631
                color='#1f77b4'
Lucas Laplanche's avatar
Lucas Laplanche committed
632
633
            ),
            tickfont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
634
                color='#1f77b4'
Lucas Laplanche's avatar
Lucas Laplanche committed
635
636
637
            )
        ),
        yaxis2 = dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
638
            title='electron wavefunction [1]',
Lucas Laplanche's avatar
Lucas Laplanche committed
639
            titlefont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
640
                color='#ff7f0e'
Lucas Laplanche's avatar
Lucas Laplanche committed
641
642
            ),
            tickfont=dict(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
643
                color='#ff7f0e'
Lucas Laplanche's avatar
Lucas Laplanche committed
644
            ),
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
645
646
647
            anchor='x',
            overlaying='y',
            side='right',
Lucas Laplanche's avatar
Lucas Laplanche committed
648
649
650
651
652
653
        )
    )


    # update layout properties
    fig.update_layout(
Lucas Laplanche's avatar
aspicot    
Lucas Laplanche committed
654
        title_text='electron wavefunction vs depth',
Lucas Laplanche's avatar
Lucas Laplanche committed
655
656
657
658
659
        width=1600,
    )


    # show the figure
Lucas Laplanche's avatar
roucoul    
Lucas Laplanche committed
660
661
662
663
664
    fig.show()




665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
def plot_refra_bench(al, wavelength, indices_array):
    # create a figure
    fig = go.Figure()


    # add the traces
    for x in range(al.size):
        fig.add_trace(go.Scatter(
            x=wavelength,
            y=indices_array[x],
            name='refracitve_index_al=' +str(al[x])
        ))


    # create axis objects
    fig.update_layout(
        xaxis=dict(
            title='wavelength [m]'
        ),
        yaxis=dict(
            title='refractive index [1]',
            titlefont=dict(
                color='#1f77b4'
            ),
            tickfont=dict(
                color='#1f77b4'
            )
        )
    )


    # update layout properties
    fig.update_layout(
        title_text='refractive indices as a function of wavelength',
        width=1600,
    )


    # show the figure
    fig.show()




Lucas Laplanche's avatar
roucoul    
Lucas Laplanche committed
709
710
711
712
713
714
def plot_eos_spectrum_gold_plate(wavelength, data_mean_sample, data_empty, data_diff):
    fig = make_subplots(rows=1, cols=2)

    fig.add_trace(
        go.Scatter(x=wavelength,
                   y=data_mean_sample),
Lucas Laplanche's avatar
Lucas Laplanche committed
715
                   name = 'With sample',
Lucas Laplanche's avatar
roucoul    
Lucas Laplanche committed
716
717
718
719
720
721
        row=1, col=1
    )

    fig.add_trace(
        go.Scatter(x=wavelength,
                   y=data_empty),
Lucas Laplanche's avatar
Lucas Laplanche committed
722
                   name='Without sample (scaled)',
Lucas Laplanche's avatar
roucoul    
Lucas Laplanche committed
723
724
725
726
727
728
        row=1, col=1
    )

    fig.add_trace(
        go.Scatter(x=wavelength,
                   y=data_diff),
Lucas Laplanche's avatar
Lucas Laplanche committed
729
                   name='Delta',
Lucas Laplanche's avatar
roucoul    
Lucas Laplanche committed
730
731
732
733
        row=1, col=2
    )

    fig.update_layout(width=1600, title_text="Optical emission spectroscopy")
Lucas Laplanche's avatar
Lucas Laplanche committed
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
    fig.show()




# function that returns default yaxis domain for each subplot and the additional yaxes positions
def xyaxes_dom_yaxes_pos(gap=0.1, rows=2):
    if rows < 2:
        raise ValueError('This function works for subplots with  rows>2 and cols=1')
    h_window = (1 - gap) / rows  # window height
    d = 3 / 10 / 2
    # xaxis{k} has the domain [w[2],w[-3]] k=1,...rows
    # w[1], w[-2] give the left, resp right yaxes position associated to the default yaxis of the plot window
    yd = []
    for k in range(rows):
        start = k * (h_window + gap)
        end = start + h_window
        yd.append([start, end])
    w = [0, d, 2 * d, 1 - 2 * d, 1 - d, 1]

    return w, yd[::-1]  # yd[::-1] contains the domains of the default yaxes