LightwaveExplorer 2025.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- LightwaveExplorer/LightwaveExplorer.py +1152 -0
- LightwaveExplorer/__init__.py +1 -0
- lightwaveexplorer-2025.2.2.dist-info/LICENSE +21 -0
- lightwaveexplorer-2025.2.2.dist-info/METADATA +40 -0
- lightwaveexplorer-2025.2.2.dist-info/RECORD +7 -0
- lightwaveexplorer-2025.2.2.dist-info/WHEEL +5 -0
- lightwaveexplorer-2025.2.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1152 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import re
|
|
3
|
+
import os
|
|
4
|
+
import io
|
|
5
|
+
from scipy.optimize import least_squares
|
|
6
|
+
import yaml
|
|
7
|
+
import urllib.request
|
|
8
|
+
import zipfile
|
|
9
|
+
import tempfile
|
|
10
|
+
import matplotlib.pyplot as plt
|
|
11
|
+
|
|
12
|
+
class lightwaveExplorerResult:
|
|
13
|
+
"""
|
|
14
|
+
A class which contains the result of a Lightwave Explorer simulation
|
|
15
|
+
The parameters of the simulation run are read from the .txt file
|
|
16
|
+
generated by the simulation, and the binaries of the results,
|
|
17
|
+
the electric field vs. time and space, and the spectra, both
|
|
18
|
+
polarization-resolved, are loaded if available.
|
|
19
|
+
|
|
20
|
+
:param filePath: The path to the .txt file describing the simulation result
|
|
21
|
+
:type filePath: str
|
|
22
|
+
|
|
23
|
+
:param loadFieldArray: Set to False in order to not load the electric field
|
|
24
|
+
:type loadFieldArray: bool
|
|
25
|
+
"""
|
|
26
|
+
def __init__(self, filePath: str, loadFieldArray=True):
|
|
27
|
+
|
|
28
|
+
#list of all parameter names in order as they will be found in the simulation file
|
|
29
|
+
parameterNames = ["pulseEnergy1",
|
|
30
|
+
"pulseEnergy2",
|
|
31
|
+
"frequency1",
|
|
32
|
+
"frequency2",
|
|
33
|
+
"bandwidth1",
|
|
34
|
+
"bandwidth2",
|
|
35
|
+
"superGaussianOrder1",
|
|
36
|
+
"superGaussianOrder2",
|
|
37
|
+
"cePhase1",
|
|
38
|
+
"cePhase2",
|
|
39
|
+
"delay1",
|
|
40
|
+
"delay2",
|
|
41
|
+
"gdd1",
|
|
42
|
+
"gdd2",
|
|
43
|
+
"tod1",
|
|
44
|
+
"tod2",
|
|
45
|
+
"phaseMaterialIndex1",
|
|
46
|
+
"phaseMaterialIndex2",
|
|
47
|
+
"phaseMaterialThickness1",
|
|
48
|
+
"phaseMaterialthickness2",
|
|
49
|
+
"BeamModeParameter",
|
|
50
|
+
"beamwaist1",
|
|
51
|
+
"beamwaist2",
|
|
52
|
+
"x01",
|
|
53
|
+
"x02",
|
|
54
|
+
"y01",
|
|
55
|
+
"y02",
|
|
56
|
+
"z01",
|
|
57
|
+
"z02",
|
|
58
|
+
"propagationAngle1",
|
|
59
|
+
"propagationAngle2",
|
|
60
|
+
"propagationAnglePhi1",
|
|
61
|
+
"propagationAnglePhi2",
|
|
62
|
+
"polarizationAngle1",
|
|
63
|
+
"polarizationAngle2",
|
|
64
|
+
"circularity1",
|
|
65
|
+
"circularity2",
|
|
66
|
+
"materialIndex",
|
|
67
|
+
"materialIndexAlternate",
|
|
68
|
+
"crystalTheta",
|
|
69
|
+
"crystalPhi",
|
|
70
|
+
"spatialWidth",
|
|
71
|
+
"spatialHeight",
|
|
72
|
+
"spatialStep",
|
|
73
|
+
"timeSpan",
|
|
74
|
+
"timeStep",
|
|
75
|
+
"crystalThickness",
|
|
76
|
+
"propagationStep",
|
|
77
|
+
"nonlinearAbsorptionStrength",
|
|
78
|
+
"initialCarrierDensity",
|
|
79
|
+
"bandGapElectronVolts",
|
|
80
|
+
"effectiveMass",
|
|
81
|
+
"drudeGamma",
|
|
82
|
+
"symmetryType",
|
|
83
|
+
"batchIndex",
|
|
84
|
+
"batchDestination",
|
|
85
|
+
"Nsims",
|
|
86
|
+
"batchIndex2",
|
|
87
|
+
"batchDestination2",
|
|
88
|
+
"Nsims2"]
|
|
89
|
+
if filePath.endswith(".zip"):
|
|
90
|
+
isZip = True
|
|
91
|
+
archive = zipfile.ZipFile(filePath, 'r')
|
|
92
|
+
directory, archiveName = os.path.split(filePath)
|
|
93
|
+
fileBase, baseExtension = os.path.splitext(archiveName)
|
|
94
|
+
settingsFile = archive.open(fileBase+'.txt')
|
|
95
|
+
settingsFile = io.TextIOWrapper(settingsFile,'utf-8')
|
|
96
|
+
|
|
97
|
+
else:
|
|
98
|
+
isZip = False
|
|
99
|
+
settingsFile = open(filePath, "r")
|
|
100
|
+
fileBase = os.path.splitext(filePath)
|
|
101
|
+
lines = settingsFile.readlines()
|
|
102
|
+
|
|
103
|
+
# Elements in searchList are used to find the correct attribute for a value saved in a result. The elements of searchList can be a string or a list of strings (for backwards compatability).
|
|
104
|
+
# If the beginning of a saved line matches an element in searchList (capitalization is ignored), the value given in the line is added as an attribute. The label of the attribute is the string in parameterNames with the same index as the match in searchList.
|
|
105
|
+
# If multiple lines match an attribute or multiple attributes match a line an error is raised.
|
|
106
|
+
searchList = ["Pulse energy 1",
|
|
107
|
+
"Pulse energy 2",
|
|
108
|
+
"Frequency 1",
|
|
109
|
+
"Frequency 2",
|
|
110
|
+
"Bandwidth 1",
|
|
111
|
+
"Bandwidth 2",
|
|
112
|
+
"SG order 1",
|
|
113
|
+
"SG order 2",
|
|
114
|
+
"CEP 1",
|
|
115
|
+
"CEP 2",
|
|
116
|
+
"Delay 1",
|
|
117
|
+
"Delay 2",
|
|
118
|
+
"GDD 1",
|
|
119
|
+
"GDD 2",
|
|
120
|
+
"TOD 1",
|
|
121
|
+
"TOD 2",
|
|
122
|
+
"Phase material 1 index",
|
|
123
|
+
"Phase material 2 index",
|
|
124
|
+
"Phase material thickness 1",
|
|
125
|
+
"Phase material thickness 2",
|
|
126
|
+
"Beam mode placeholder",
|
|
127
|
+
"Beamwaist 1",
|
|
128
|
+
"Beamwaist 2",
|
|
129
|
+
"x offset 1",
|
|
130
|
+
"x offset 2",
|
|
131
|
+
"y offset 1",
|
|
132
|
+
"y offset 2",
|
|
133
|
+
"z offset 1",
|
|
134
|
+
"z offset 2",
|
|
135
|
+
"NC angle 1",
|
|
136
|
+
"NC angle 2",
|
|
137
|
+
"NC angle phi 1",
|
|
138
|
+
"NC angle phi 2",
|
|
139
|
+
"Polarization 1",
|
|
140
|
+
"Polarization 2",
|
|
141
|
+
"Circularity 1",
|
|
142
|
+
"Circularity 2",
|
|
143
|
+
"Material index",
|
|
144
|
+
"Alternate material index",
|
|
145
|
+
"Crystal theta",
|
|
146
|
+
"Crystal phi",
|
|
147
|
+
"Grid width",
|
|
148
|
+
"Grid height",
|
|
149
|
+
"dx",
|
|
150
|
+
"Time span",
|
|
151
|
+
"dt",
|
|
152
|
+
"Thickness",
|
|
153
|
+
"dz",
|
|
154
|
+
"Nonlinear absorption parameter",
|
|
155
|
+
"Initial carrier density",
|
|
156
|
+
"Band gap",
|
|
157
|
+
"Effective mass",
|
|
158
|
+
"Drude gamma",
|
|
159
|
+
"Propagation mode",
|
|
160
|
+
"Batch mode:",
|
|
161
|
+
"Batch destination:",
|
|
162
|
+
"Batch steps:",
|
|
163
|
+
"Batch mode 2",
|
|
164
|
+
"Batch destination 2",
|
|
165
|
+
"Batch steps 2"]
|
|
166
|
+
|
|
167
|
+
for line in lines:
|
|
168
|
+
foundSearchStr = None
|
|
169
|
+
for searchStr,attributeName in zip(searchList,parameterNames,strict=True):
|
|
170
|
+
if isinstance(searchStr,str): # String case
|
|
171
|
+
if searchStr.lower() == line[:len(searchStr)].lower():
|
|
172
|
+
if foundSearchStr != None:
|
|
173
|
+
raise Exception(f'Imported parameters can\'t be associated uniquely: "{foundSearchStr}" and "{searchStr}" are identified in beginning of "{line}"')
|
|
174
|
+
value = float(line[line.rfind(":")+1:].strip())
|
|
175
|
+
foundSearchStr = searchStr
|
|
176
|
+
assert hasattr(self, attributeName) == False, f'Multiple imported parameter lines are matching for search string "{searchStr}" for attribute "{attributeName}". The second matching line is "{line}"'
|
|
177
|
+
setattr(self,attributeName,value)
|
|
178
|
+
else:
|
|
179
|
+
for subSearchStr in searchStr: # List case
|
|
180
|
+
if subSearchStr.lower() == line[:len(subSearchStr)].lower():
|
|
181
|
+
if foundSearchStr != None:
|
|
182
|
+
raise Exception(f'Imported parameters can\'t be associated uniquely: "{foundSearchStr}" and "{subSearchStr}" are identified in beginning of "{line}"')
|
|
183
|
+
value = float(line[line.rfind(":")+1:].strip())
|
|
184
|
+
foundSearchStr = searchStr
|
|
185
|
+
assert hasattr(self, attributeName) == False, f'Multiple imported parameter lines are matching for search string "{searchStr}" for attribute "{attributeName}". The second matching line is "{line}"'
|
|
186
|
+
setattr(self,attributeName,value)
|
|
187
|
+
break
|
|
188
|
+
|
|
189
|
+
#correct type of integer parameters
|
|
190
|
+
self.Nsims = int(self.Nsims)
|
|
191
|
+
self.Nsims2 = int(self.Nsims2)
|
|
192
|
+
self.symmetryType = int(self.symmetryType)
|
|
193
|
+
self.batchIndex = int(self.batchIndex)
|
|
194
|
+
self.batchIndex2 = int(self.batchIndex2)
|
|
195
|
+
|
|
196
|
+
#Additional derived parameters
|
|
197
|
+
MIN_GRIDDIM=8
|
|
198
|
+
self.Ntime = int(MIN_GRIDDIM * np.round(self.timeSpan / (MIN_GRIDDIM * self.timeStep)))
|
|
199
|
+
self.Nfreq = int(self.Ntime/2 + 1)
|
|
200
|
+
self.fStep = 1.0/(self.Ntime * self.timeStep)
|
|
201
|
+
self.Nspace = int(MIN_GRIDDIM * np.round(self.spatialWidth / (MIN_GRIDDIM * self.spatialStep)))
|
|
202
|
+
if self.symmetryType == 2 or self.symmetryType == 4:
|
|
203
|
+
self.Nspace2 = int(MIN_GRIDDIM * np.round(self.spatialHeight / (MIN_GRIDDIM * self.spatialStep)))
|
|
204
|
+
else:
|
|
205
|
+
self.Nspace2 = 1
|
|
206
|
+
self.Ngrid = int(self.Ntime*self.Nspace*self.Nspace2)
|
|
207
|
+
|
|
208
|
+
#now load the output data from binary format. Note that this will fail if you're using wrong-endian CPUs
|
|
209
|
+
if loadFieldArray:
|
|
210
|
+
if self.symmetryType == 2 or self.symmetryType == 4:
|
|
211
|
+
if isZip:
|
|
212
|
+
file = archive.open(fileBase+'_Ext.dat')
|
|
213
|
+
Ext = np.reshape(np.frombuffer(file.read(),dtype=np.double)[0:(2*self.Ngrid*self.Nsims*self.Nsims2)],(self.Ntime,self.Nspace,self.Nspace2, 2*self.Nsims,self.Nsims2),order='F')
|
|
214
|
+
else:
|
|
215
|
+
Ext = np.reshape(np.fromfile(fileBase[0]+"_Ext.dat",dtype=np.double)[0:(2*self.Ngrid*self.Nsims*self.Nsims2)],(self.Ntime,self.Nspace,self.Nspace2, 2*self.Nsims,self.Nsims2),order='F')
|
|
216
|
+
self.Ext_x = np.squeeze(Ext[:,:,:,0:(2*self.Nsims):2,:])
|
|
217
|
+
self.Ext_y = np.squeeze(Ext[:,:,:,1:(2*self.Nsims + 1):2,:])
|
|
218
|
+
else:
|
|
219
|
+
if isZip:
|
|
220
|
+
file = archive.open(fileBase+'_Ext.dat')
|
|
221
|
+
Ext = np.reshape(np.frombuffer(file.read(),dtype=np.double)[0:(2*self.Ngrid*self.Nsims*self.Nsims2)],(self.Ntime,self.Nspace, 2*self.Nsims, self.Nsims2),order='F')
|
|
222
|
+
else:
|
|
223
|
+
Ext = np.reshape(np.fromfile(fileBase[0]+"_Ext.dat",dtype=np.double)[0:(2*self.Ngrid*self.Nsims*self.Nsims2)],(self.Ntime,self.Nspace, 2*self.Nsims, self.Nsims2),order='F')
|
|
224
|
+
self.Ext_x = np.squeeze(Ext[:,:,0:(2*self.Nsims):2,:])
|
|
225
|
+
self.Ext_y = np.squeeze(Ext[:,:,1:(2*self.Nsims + 1):2,:])
|
|
226
|
+
if isZip:
|
|
227
|
+
file = archive.open(fileBase+'_spectrum.dat')
|
|
228
|
+
RawSpectrum = np.reshape(np.frombuffer(file.read(),dtype=np.double)[0:3*self.Nfreq*self.Nsims*self.Nsims2],(self.Nfreq,3,self.Nsims,self.Nsims2),order='F')
|
|
229
|
+
else:
|
|
230
|
+
RawSpectrum = np.reshape(np.fromfile(fileBase[0]+"_spectrum.dat",dtype=np.double)[0:3*self.Nfreq*self.Nsims*self.Nsims2],(self.Nfreq,3,self.Nsims,self.Nsims2),order='F')
|
|
231
|
+
self.spectrumTotal = np.squeeze(RawSpectrum[:,2,:,:]).T
|
|
232
|
+
self.spectrum_x = np.squeeze(RawSpectrum[:,0,:,:]).T
|
|
233
|
+
self.spectrum_y = np.squeeze(RawSpectrum[:,1,:,:]).T
|
|
234
|
+
|
|
235
|
+
#make scale vector corresponding to the batch scan and correct units of the scan
|
|
236
|
+
#apologies for the ugly elif block
|
|
237
|
+
#double apologies that it appears twice for the two batches
|
|
238
|
+
if self.batchIndex == 0:
|
|
239
|
+
self.batchStart = 0
|
|
240
|
+
elif self.batchIndex == 1:
|
|
241
|
+
self.batchStart = self.pulseEnergy1
|
|
242
|
+
elif self.batchIndex == 2:
|
|
243
|
+
self.batchStart = self.pulseEnergy2
|
|
244
|
+
elif self.batchIndex == 3:
|
|
245
|
+
self.batchStart = self.frequency1
|
|
246
|
+
self.batchDestination *= 1e12
|
|
247
|
+
elif self.batchIndex == 4:
|
|
248
|
+
self.batchStart = self.frequency2
|
|
249
|
+
self.batchDestination *= 1e12
|
|
250
|
+
elif self.batchIndex == 5:
|
|
251
|
+
self.batchStart = self.frequency1
|
|
252
|
+
self.batchDestination *= 1e12
|
|
253
|
+
elif self.batchIndex == 6:
|
|
254
|
+
self.batchStart = self.frequency2
|
|
255
|
+
self.batchDestination *= 1e12
|
|
256
|
+
elif self.batchIndex == 7:
|
|
257
|
+
self.batchStart = self.cePhase1
|
|
258
|
+
self.batchDestination *= np.pi
|
|
259
|
+
elif self.batchIndex == 8:
|
|
260
|
+
self.batchStart = self.cePhase2
|
|
261
|
+
self.batchDestination *= np.pi
|
|
262
|
+
elif self.batchIndex == 9:
|
|
263
|
+
self.batchStart = self.delay1
|
|
264
|
+
self.batchDestination *= 1e-15
|
|
265
|
+
elif self.batchIndex == 10:
|
|
266
|
+
self.batchStart = self.delay2
|
|
267
|
+
self.batchDestination *= 1e-15
|
|
268
|
+
elif self.batchIndex == 11:
|
|
269
|
+
self.batchStart = self.gdd1
|
|
270
|
+
self.batchDestination *= 1e-30
|
|
271
|
+
elif self.batchIndex == 12:
|
|
272
|
+
self.batchStart = self.gdd2
|
|
273
|
+
self.batchDestination *= 1e-30
|
|
274
|
+
elif self.batchIndex == 13:
|
|
275
|
+
self.batchStart = self.tod1
|
|
276
|
+
self.batchDestination *= 1e-45
|
|
277
|
+
elif self.batchIndex == 14:
|
|
278
|
+
self.batchStart = self.tod2
|
|
279
|
+
self.batchDestination *= 1e-45
|
|
280
|
+
elif self.batchIndex == 15:
|
|
281
|
+
self.batchStart = self.phaseMaterialThickness1
|
|
282
|
+
self.batchDestination *= 1e-6
|
|
283
|
+
elif self.batchIndex == 16:
|
|
284
|
+
self.batchStart = self.phaseMaterialThickness2
|
|
285
|
+
self.batchDestination *= 1e-6
|
|
286
|
+
elif self.batchIndex == 17:
|
|
287
|
+
self.batchStart = self.beamwaist1
|
|
288
|
+
self.batchDestination *= 1e-6
|
|
289
|
+
elif self.batchIndex == 18:
|
|
290
|
+
self.batchStart = self.beamwaist2
|
|
291
|
+
self.batchDestination *= 1e-6
|
|
292
|
+
elif self.batchIndex == 19:
|
|
293
|
+
self.batchStart = self.x01
|
|
294
|
+
self.batchDestination *= 1e-6
|
|
295
|
+
elif self.batchIndex == 20:
|
|
296
|
+
self.batchStart = self.x02
|
|
297
|
+
self.batchDestination *= 1e-6
|
|
298
|
+
elif self.batchIndex == 21:
|
|
299
|
+
self.batchStart = self.z01
|
|
300
|
+
self.batchDestination *= 1e-6
|
|
301
|
+
elif self.batchIndex == 22:
|
|
302
|
+
self.batchStart = self.z02
|
|
303
|
+
self.batchDestination *= 1e-6
|
|
304
|
+
elif self.batchIndex == 23:
|
|
305
|
+
self.batchStart = self.propagationAngle1
|
|
306
|
+
self.batchDestination *= (np.pi/180)
|
|
307
|
+
elif self.batchIndex == 24:
|
|
308
|
+
self.batchStart = self.propagationAngle2
|
|
309
|
+
self.batchDestination *= (np.pi/180)
|
|
310
|
+
elif self.batchIndex == 25:
|
|
311
|
+
self.batchStart = self.polarizationAngle1
|
|
312
|
+
self.batchDestination *=(np.pi/180)
|
|
313
|
+
elif self.batchIndex == 26:
|
|
314
|
+
self.batchStart = self.polarizationAngle2
|
|
315
|
+
self.batchDestination *= (np.pi/180)
|
|
316
|
+
elif self.batchIndex == 27:
|
|
317
|
+
self.batchStart = self.circularity1
|
|
318
|
+
elif self.batchIndex == 28:
|
|
319
|
+
self.batchStart = self.circularity2
|
|
320
|
+
elif self.batchIndex == 29:
|
|
321
|
+
self.batchStart = self.crystalTheta
|
|
322
|
+
self.batchDestination *= (np.pi/180)
|
|
323
|
+
elif self.batchIndex == 30:
|
|
324
|
+
self.batchStart = self.crystalPhi
|
|
325
|
+
self.batchDestination *= (np.pi/180)
|
|
326
|
+
elif self.batchIndex == 31:
|
|
327
|
+
self.batchStart = self.nonlinearAbsorptionStrength
|
|
328
|
+
elif self.batchIndex == 32:
|
|
329
|
+
self.batchStart = self.drudeGamma
|
|
330
|
+
self.batchDestination *= 1e12
|
|
331
|
+
elif self.batchIndex == 33:
|
|
332
|
+
self.batchStart = self.effectiveMass
|
|
333
|
+
elif self.batchIndex == 34:
|
|
334
|
+
self.batchStart = self.crystalThickness
|
|
335
|
+
self.batchDestination *= 1e-6
|
|
336
|
+
elif self.batchIndex == 35:
|
|
337
|
+
self.batchStart = self.propagationStep
|
|
338
|
+
self.batchDestination *= 1e-9
|
|
339
|
+
elif self.batchIndex == 36:
|
|
340
|
+
self.batchStart = 0
|
|
341
|
+
elif self.batchIndex == 37:
|
|
342
|
+
self.batchStart = 0
|
|
343
|
+
self.batchVector = np.linspace(self.batchStart,self.batchDestination,self.Nsims)
|
|
344
|
+
|
|
345
|
+
#make second scale vector corresponding to the batch scan and correct units of the scan
|
|
346
|
+
if self.batchIndex2 == 0:
|
|
347
|
+
self.batchStart2 = 0
|
|
348
|
+
elif self.batchIndex2 == 1:
|
|
349
|
+
self.batchStart2 = self.pulseEnergy1
|
|
350
|
+
elif self.batchIndex2 == 2:
|
|
351
|
+
self.batchStart2 = self.pulseEnergy2
|
|
352
|
+
elif self.batchIndex2 == 3:
|
|
353
|
+
self.batchStart2 = self.frequency1
|
|
354
|
+
self.batchDestination2 *= 1e12
|
|
355
|
+
elif self.batchIndex2 == 4:
|
|
356
|
+
self.batchStart2 = self.frequency2
|
|
357
|
+
self.batchDestination2 *= 1e12
|
|
358
|
+
elif self.batchIndex2 == 5:
|
|
359
|
+
self.batchStart2 = self.frequency1
|
|
360
|
+
self.batchDestination2 *= 1e12
|
|
361
|
+
elif self.batchIndex2 == 6:
|
|
362
|
+
self.batchStart2 = self.frequency2
|
|
363
|
+
self.batchDestination2 *= 1e12
|
|
364
|
+
elif self.batchIndex2 == 7:
|
|
365
|
+
self.batchStart2 = self.cePhase1
|
|
366
|
+
self.batchDestination2 *= np.pi
|
|
367
|
+
elif self.batchIndex2 == 8:
|
|
368
|
+
self.batchStart2 = self.cePhase2
|
|
369
|
+
self.batchDestination2 *= np.pi
|
|
370
|
+
elif self.batchIndex2 == 9:
|
|
371
|
+
self.batchStart2 = self.delay1
|
|
372
|
+
self.batchDestination2 *= 1e-15
|
|
373
|
+
elif self.batchIndex2 == 10:
|
|
374
|
+
self.batchStart2 = self.delay2
|
|
375
|
+
self.batchDestination2 *= 1e-15
|
|
376
|
+
elif self.batchIndex2 == 11:
|
|
377
|
+
self.batchStart2 = self.gdd1
|
|
378
|
+
self.batchDestination2 *= 1e-30
|
|
379
|
+
elif self.batchIndex2 == 12:
|
|
380
|
+
self.batchStart2 = self.gdd2
|
|
381
|
+
self.batchDestination2 *= 1e-30
|
|
382
|
+
elif self.batchIndex2 == 13:
|
|
383
|
+
self.batchStart2 = self.tod1
|
|
384
|
+
self.batchDestination2 *= 1e-45
|
|
385
|
+
elif self.batchIndex2 == 14:
|
|
386
|
+
self.batchStart2 = self.tod2
|
|
387
|
+
self.batchDestination2 *= 1e-45
|
|
388
|
+
elif self.batchIndex2 == 15:
|
|
389
|
+
self.batchStart2 = self.phaseMaterialThickness1
|
|
390
|
+
self.batchDestination2 *= 1e-6
|
|
391
|
+
elif self.batchIndex2 == 16:
|
|
392
|
+
self.batchStart2 = self.phaseMaterialThickness2
|
|
393
|
+
self.batchDestination2 *= 1e-6
|
|
394
|
+
elif self.batchIndex2 == 17:
|
|
395
|
+
self.batchStart2 = self.beamwaist1
|
|
396
|
+
self.batchDestination2 *= 1e-6
|
|
397
|
+
elif self.batchIndex2 == 18:
|
|
398
|
+
self.batchStart2 = self.beamwaist2
|
|
399
|
+
self.batchDestination2 *= 1e-6
|
|
400
|
+
elif self.batchIndex2 == 19:
|
|
401
|
+
self.batchStart2 = self.x01
|
|
402
|
+
self.batchDestination2 *= 1e-6
|
|
403
|
+
elif self.batchIndex2 == 20:
|
|
404
|
+
self.batchStart2 = self.x02
|
|
405
|
+
self.batchDestination2 *= 1e-6
|
|
406
|
+
elif self.batchIndex2 == 21:
|
|
407
|
+
self.batchStart2 = self.z01
|
|
408
|
+
self.batchDestination2 *= 1e-6
|
|
409
|
+
elif self.batchIndex2 == 22:
|
|
410
|
+
self.batchStart2 = self.z02
|
|
411
|
+
self.batchDestination2 *= 1e-6
|
|
412
|
+
elif self.batchIndex2 == 23:
|
|
413
|
+
self.batchStart2 = self.propagationAngle1
|
|
414
|
+
self.batchDestination2 *= (np.pi/180)
|
|
415
|
+
elif self.batchIndex2 == 24:
|
|
416
|
+
self.batchStart2 = self.propagationAngle2
|
|
417
|
+
self.batchDestination2 *= (np.pi/180)
|
|
418
|
+
elif self.batchIndex2 == 25:
|
|
419
|
+
self.batchStart2 = self.polarizationAngle1
|
|
420
|
+
self.batchDestination2 *=(np.pi/180)
|
|
421
|
+
elif self.batchIndex2 == 26:
|
|
422
|
+
self.batchStart2 = self.polarizationAngle2
|
|
423
|
+
self.batchDestination2 *= (np.pi/180)
|
|
424
|
+
elif self.batchIndex2 == 27:
|
|
425
|
+
self.batchStart2 = self.circularity1
|
|
426
|
+
elif self.batchIndex2 == 28:
|
|
427
|
+
self.batchStart2 = self.circularity2
|
|
428
|
+
elif self.batchIndex2 == 29:
|
|
429
|
+
self.batchStart2 = self.crystalTheta
|
|
430
|
+
self.batchDestination2 *= (np.pi/180)
|
|
431
|
+
elif self.batchIndex2 == 30:
|
|
432
|
+
self.batchStart2 = self.crystalPhi
|
|
433
|
+
self.batchDestination2 *= (np.pi/180)
|
|
434
|
+
elif self.batchIndex2 == 31:
|
|
435
|
+
self.batchStart2 = self.nonlinearAbsorptionStrength
|
|
436
|
+
elif self.batchIndex2 == 32:
|
|
437
|
+
self.batchStart2 = self.drudeGamma
|
|
438
|
+
self.batchDestination2 *= 1e12
|
|
439
|
+
elif self.batchIndex2 == 33:
|
|
440
|
+
self.batchStart2 = self.effectiveMass
|
|
441
|
+
elif self.batchIndex2 == 34:
|
|
442
|
+
self.batchStart2 = self.crystalThickness
|
|
443
|
+
self.batchDestination2 *= 1e-6
|
|
444
|
+
elif self.batchIndex2 == 35:
|
|
445
|
+
self.batchStart2 = self.propagationStep
|
|
446
|
+
self.batchDestination2 *= 1e-9
|
|
447
|
+
elif self.batchIndex2 == 36:
|
|
448
|
+
self.batchStart2 = 0
|
|
449
|
+
elif self.batchIndex2 == 37:
|
|
450
|
+
self.batchStart2 = 0
|
|
451
|
+
self.batchVector2 = np.linspace(self.batchStart2,self.batchDestination2,self.Nsims2)
|
|
452
|
+
|
|
453
|
+
self.timeVector = self.timeStep*np.arange(0,self.Ntime)
|
|
454
|
+
self.frequencyVector = np.fft.fftfreq(self.Ntime, d=self.timeStep)
|
|
455
|
+
self.frequencyVectorSpectrum = self.frequencyVector[0:self.Nfreq]
|
|
456
|
+
self.frequencyVectorSpectrum[-1] *= -1
|
|
457
|
+
self.spaceVector = self.spatialStep * (np.arange(0,self.Nspace) - self.Nspace/2) + 0.25 * self.spatialStep
|
|
458
|
+
|
|
459
|
+
def fwhm(x: np.ndarray, y: np.ndarray, height: float = 0.5) -> float:
|
|
460
|
+
"""
|
|
461
|
+
Gives the full-width at half-maximum of data in a numpy array pair.
|
|
462
|
+
|
|
463
|
+
:param x: The x-values (e.g. the scale of the vector; has the same units as the return value)
|
|
464
|
+
:type x: np.ndarray
|
|
465
|
+
|
|
466
|
+
:param y: The y-values (to which half-maximum refers)
|
|
467
|
+
:type y: np.ndarray
|
|
468
|
+
|
|
469
|
+
:param height: Instead of half-max, can optionally return height*max (e.g. default 0.5)
|
|
470
|
+
:type height: float
|
|
471
|
+
|
|
472
|
+
:return: The full-width at half-max (units of x)
|
|
473
|
+
:rtype: float
|
|
474
|
+
"""
|
|
475
|
+
heightLevel = np.max(y) * height
|
|
476
|
+
indexMax = np.argmax(y)
|
|
477
|
+
y = np.roll(y, - indexMax + int(np.shape(y)[0]/2),axis=0)
|
|
478
|
+
indexMax = np.argmax(y)
|
|
479
|
+
xLower = np.interp(heightLevel, y[:indexMax], x[:indexMax])
|
|
480
|
+
xUpper = np.interp(heightLevel, np.flip(y[indexMax:]), np.flip(x[indexMax:]))
|
|
481
|
+
return xUpper - xLower
|
|
482
|
+
|
|
483
|
+
def norma(v: np.ndarray):
|
|
484
|
+
"""
|
|
485
|
+
Divide an array by its maximum value.
|
|
486
|
+
|
|
487
|
+
:param v: the array
|
|
488
|
+
:type v: np.ndarray
|
|
489
|
+
|
|
490
|
+
:return: the normalized array
|
|
491
|
+
:rtype: np.ndarray
|
|
492
|
+
"""
|
|
493
|
+
return v/v.max()
|
|
494
|
+
|
|
495
|
+
def normaM(v: np.ndarray):
|
|
496
|
+
"""
|
|
497
|
+
Normalize the columns of a 2D matrix
|
|
498
|
+
|
|
499
|
+
:param v: the array
|
|
500
|
+
:type v: np.ndarray
|
|
501
|
+
|
|
502
|
+
:return: the normalized array
|
|
503
|
+
:rtype: np.ndarray
|
|
504
|
+
"""
|
|
505
|
+
out = np.zeros(np.shape(v))
|
|
506
|
+
for i in range(0,np.shape(out)[0]):
|
|
507
|
+
out[i,:] = norma(v[i,:])
|
|
508
|
+
return out
|
|
509
|
+
|
|
510
|
+
def printSellmeier(sc: np.ndarray, highPrecision=False):
|
|
511
|
+
"""
|
|
512
|
+
print an array containing LWE sellmeier coefficients in a format
|
|
513
|
+
that can be copy-pasted into the CrystalDatabase.txt file
|
|
514
|
+
|
|
515
|
+
:param sc: the coefficients (22-element array)
|
|
516
|
+
:type sc: np.ndarray
|
|
517
|
+
:param highPrecision: if true, use 15 digits for the numbers
|
|
518
|
+
"""
|
|
519
|
+
if highPrecision:
|
|
520
|
+
s = np.array2string(sc, formatter={'float_kind': '{0:.15g}'.format}).replace('\n','').replace('[','').replace(']','')
|
|
521
|
+
else:
|
|
522
|
+
s = np.array2string(sc, formatter={'float_kind': '{0:.6g}'.format}).replace('\n','').replace('[','').replace(']','')
|
|
523
|
+
print(s)
|
|
524
|
+
|
|
525
|
+
def sellmeier(wavelengthMicrons, a: np.ndarray, equationType: int):
|
|
526
|
+
"""
|
|
527
|
+
Use the sellmeier coeffiecients in LWE format to produce a refractive index curve.
|
|
528
|
+
|
|
529
|
+
:param wavelengthMicrons: the wavelength in microns; can be a float or array of floats
|
|
530
|
+
:param a: 22-element numpy array giving the coefficients
|
|
531
|
+
:param equationType: specify the type of equation (0 -> general fitting function, 1->Lorentzians, 2->Gaussians)
|
|
532
|
+
|
|
533
|
+
:return: complex refractive index corresponding to the value(s) of wavelengthMicrons
|
|
534
|
+
"""
|
|
535
|
+
np.seterr(divide='ignore', invalid='ignore')
|
|
536
|
+
w = 2 * np.pi * 2.99792458e8 / (1e-6*wavelengthMicrons)
|
|
537
|
+
ls = wavelengthMicrons**2
|
|
538
|
+
k = 3182.607353999257
|
|
539
|
+
def rectangularBand(w,w0,width,height):
|
|
540
|
+
if width != 0:
|
|
541
|
+
scaledAxis = (w-w0)/width
|
|
542
|
+
else:
|
|
543
|
+
scaledAxis = (w-w0)
|
|
544
|
+
imagPart = np.zeros(w.size)
|
|
545
|
+
imagPart[np.abs(scaledAxis)<0.5] = -height
|
|
546
|
+
realPart = np.zeros(w.size) + 1.0
|
|
547
|
+
realPart[scaledAxis!=0.5] = -height * np.log(np.abs((scaledAxis+0.5)/(scaledAxis-0.5)))/np.pi
|
|
548
|
+
return realPart + 1j*imagPart
|
|
549
|
+
def gaussianBand(w,w0,width,height):
|
|
550
|
+
if width == 0.0 or height == 0:
|
|
551
|
+
return 0 + 1j*0
|
|
552
|
+
scaledF = (w-w0)/(np.sqrt(2.0) * width)
|
|
553
|
+
realPart = np.zeros(np.shape(scaledF))
|
|
554
|
+
if isinstance(scaledF, np.ndarray):
|
|
555
|
+
dawsonArr = np.vectorize(deviceDawson)
|
|
556
|
+
realPart = -dawsonArr(scaledF)/np.sqrt(np.pi)
|
|
557
|
+
else:
|
|
558
|
+
realPart = -deviceDawson(scaledF)/np.sqrt(np.pi)
|
|
559
|
+
imagPart = np.exp(-scaledF*scaledF)
|
|
560
|
+
return np.abs(height) * (realPart - 1j * imagPart)
|
|
561
|
+
|
|
562
|
+
if equationType == 0:
|
|
563
|
+
n = (a[0] + (a[1] + a[2] * ls) / (ls + a[3]) + (a[4] + a[5] * ls) / (ls + a[6]) + (a[7] + a[8] * ls) / (ls + a[9]) + (a[10] + a[11] * ls) / (ls + a[12]) + a[13] * ls + a[14] * ls * ls + a[15] * ls * ls * ls)
|
|
564
|
+
n[n<0] = 1
|
|
565
|
+
n = n + k * a[16] / ((a[17] - w ** 2) + (a[18] * w) * 1j)
|
|
566
|
+
n += k * a[19] / ((a[20] - w ** 2) + (a[21] * w) * 1j)
|
|
567
|
+
elif equationType == 1:
|
|
568
|
+
a = np.abs(a)
|
|
569
|
+
n = a[0] + k * a[1] / ((a[2] - w ** 2) + (a[3] * w) * 1j)
|
|
570
|
+
n += k * a[4] / ((a[5] - w ** 2) + (a[6] * w) * 1j)
|
|
571
|
+
n += k * a[7] / ((a[8] - w ** 2) + (a[9] * w) * 1j)
|
|
572
|
+
n += k * a[10] / ((a[11] - w ** 2) + (a[12] * w) * 1j)
|
|
573
|
+
n += k * a[13] / ((a[14] - w ** 2) + (a[15] * w) * 1j)
|
|
574
|
+
n += k * a[16] / ((a[17] - w ** 2) + (a[18] * w) * 1j)
|
|
575
|
+
n += k * a[19] / ((a[20] - w ** 2) + (a[21] * w) * 1j)
|
|
576
|
+
elif equationType == 2:
|
|
577
|
+
a = np.abs(a)
|
|
578
|
+
n = a[0]
|
|
579
|
+
for i in range(0,7):
|
|
580
|
+
n += gaussianBand(w,a[i*3+1],a[2 + i*3],a[3+i*3])
|
|
581
|
+
|
|
582
|
+
return np.sqrt(n)
|
|
583
|
+
|
|
584
|
+
def load(filePath: str, loadFieldArray=True):
|
|
585
|
+
"""
|
|
586
|
+
A wrapper to the constructor of the lightwaveExplorerResult class. Loads
|
|
587
|
+
The output of a simulation run and stores it in the returned class.
|
|
588
|
+
|
|
589
|
+
:param filePath: The path to the .txt file describing the simulation result
|
|
590
|
+
:type filePath: str
|
|
591
|
+
|
|
592
|
+
:param loadFieldArray: Set to False in order to not load the electric field
|
|
593
|
+
:type loadFieldArray: bool
|
|
594
|
+
|
|
595
|
+
:return: The class contianing the parameters and results
|
|
596
|
+
:rtype: LightwaveExplorerResult
|
|
597
|
+
"""
|
|
598
|
+
s = lightwaveExplorerResult(filePath=filePath,loadFieldArray=loadFieldArray)
|
|
599
|
+
return s
|
|
600
|
+
|
|
601
|
+
def getRII_object(url):
|
|
602
|
+
"""
|
|
603
|
+
Load a yaml file from a URL, such as what one finds on refractiveindex.info
|
|
604
|
+
:param url: The address of the yaml file
|
|
605
|
+
:type url: str
|
|
606
|
+
|
|
607
|
+
:return: the yaml file
|
|
608
|
+
"""
|
|
609
|
+
riiurl = urllib.request.urlopen(url)
|
|
610
|
+
return yaml.safe_load(riiurl)
|
|
611
|
+
|
|
612
|
+
def getSellmeierFromRII(url):
|
|
613
|
+
"""
|
|
614
|
+
Get the sellmeier equation of a material on refractiveindex.info
|
|
615
|
+
|
|
616
|
+
:param url: The address of the yaml file
|
|
617
|
+
:type url: str
|
|
618
|
+
|
|
619
|
+
:return: The 22-element array containing the sellmeier coefficients
|
|
620
|
+
"""
|
|
621
|
+
RIIobj = getRII_object(url)
|
|
622
|
+
types = np.array([x["type"] for x in RIIobj["DATA"]])
|
|
623
|
+
retrievedCoeffs = np.zeros(22)
|
|
624
|
+
|
|
625
|
+
if 'formula 1' in types:
|
|
626
|
+
firstTrue = ((types=='formula 2').cumsum().cumsum()==1).argmax()
|
|
627
|
+
RIIcoeffs = np.fromstring(RIIobj["DATA"][firstTrue]["coefficients"], dtype=float, sep=' ')
|
|
628
|
+
Nresonances = int(np.floor((RIIcoeffs.size-1)/2))
|
|
629
|
+
retrievedCoeffs[0] = RIIcoeffs[0] + 1
|
|
630
|
+
for i in range(0,min(7,Nresonances)):
|
|
631
|
+
retrievedCoeffs[i*3 + 2] = RIIcoeffs[1 + 2*i]
|
|
632
|
+
retrievedCoeffs[i*3 + 3] = -(RIIcoeffs[2 + 2*i]**2)
|
|
633
|
+
elif 'formula 2' in types:
|
|
634
|
+
firstTrue = ((types=='formula 2').cumsum().cumsum()==1).argmax()
|
|
635
|
+
RIIcoeffs = np.fromstring(RIIobj["DATA"][firstTrue]["coefficients"], dtype=float, sep=' ')
|
|
636
|
+
Nresonances = int(np.floor((RIIcoeffs.size-1)/2))
|
|
637
|
+
retrievedCoeffs[0] = RIIcoeffs[0] + 1
|
|
638
|
+
for i in range(0,min(7,Nresonances)):
|
|
639
|
+
retrievedCoeffs[i*3 + 2] = RIIcoeffs[1 + 2*i]
|
|
640
|
+
retrievedCoeffs[i*3 + 3] = -RIIcoeffs[2 + 2*i]
|
|
641
|
+
elif 'formula 4' in types:
|
|
642
|
+
firstTrue = ((types=='formula 4').cumsum().cumsum()==1).argmax()
|
|
643
|
+
RIIcoeffs = np.fromstring(RIIobj["DATA"][firstTrue]["coefficients"], dtype=float, sep=' ')
|
|
644
|
+
Nresonances = int(np.floor((RIIcoeffs.size-1)/4))
|
|
645
|
+
retrievedCoeffs[0] = RIIcoeffs[0]
|
|
646
|
+
for i in range(0,min(Nresonances,2)):
|
|
647
|
+
if RIIcoeffs[2 + 4*i] == 0:
|
|
648
|
+
retrievedCoeffs[i*3 + 1] = RIIcoeffs[1 + 4*i]
|
|
649
|
+
else:
|
|
650
|
+
retrievedCoeffs[i*3 + 2] = RIIcoeffs[1 + 4*i]
|
|
651
|
+
retrievedCoeffs[i*3 + 3] = -(RIIcoeffs[3 + 4*i]**RIIcoeffs[4+4*i])
|
|
652
|
+
if RIIcoeffs.size > 5:
|
|
653
|
+
Npoly = int(np.floor(int(RIIcoeffs.size - 5)/2))
|
|
654
|
+
for i in range(0,Npoly):
|
|
655
|
+
if RIIcoeffs[5 + 2*i + 1] == 2.0:
|
|
656
|
+
retrievedCoeffs[13] = RIIcoeffs[5 + 2*i]
|
|
657
|
+
if RIIcoeffs[5 + 2*i + 1] == 4.0:
|
|
658
|
+
retrievedCoeffs[14] = RIIcoeffs[5 + 2*i]
|
|
659
|
+
if RIIcoeffs[5 + 2*i + 1] == 6.0:
|
|
660
|
+
retrievedCoeffs[15] = RIIcoeffs[5 + 2*i]
|
|
661
|
+
else:
|
|
662
|
+
print("Sorry, this formula hasn't been implemented yet.")
|
|
663
|
+
return retrievedCoeffs
|
|
664
|
+
|
|
665
|
+
def getTabulatedDataFromRII(url):
|
|
666
|
+
"""
|
|
667
|
+
Get a table of (possibly complex) refractive index values from refractiveindex.info
|
|
668
|
+
|
|
669
|
+
:param url: the address of the yaml file on the website
|
|
670
|
+
:type url: str
|
|
671
|
+
|
|
672
|
+
:return: Array containing the retrieved values
|
|
673
|
+
"""
|
|
674
|
+
RIIobj = getRII_object(url)
|
|
675
|
+
types = np.array([x["type"] for x in RIIobj["DATA"]])
|
|
676
|
+
if 'tabulated nk' in types:
|
|
677
|
+
firstTrue = ((types=='tabulated nk').cumsum().cumsum()==1).argmax()
|
|
678
|
+
nkData = np.array([np.array(i.split(' ')).astype(float) for i in str(RIIobj["DATA"][firstTrue]["data"]).strip().split('\n')])
|
|
679
|
+
elif 'tabulated k' in types:
|
|
680
|
+
firstTrue = ((types=='tabulated k').cumsum().cumsum()==1).argmax()
|
|
681
|
+
kData = np.array([np.array(i.split(' ')).astype(float) for i in str(RIIobj["DATA"][firstTrue]["data"]).strip().split('\n')])
|
|
682
|
+
nkData = np.zeros((kData[:,0].size, 3))
|
|
683
|
+
nkData[:,0] = kData[:,0]
|
|
684
|
+
nkData[:,2] = kData[:,1]
|
|
685
|
+
sellCoeffs = getSellmeierFromRII(url)
|
|
686
|
+
nkData[:,1] = np.real(sellmeier(nkData[:,0],sellCoeffs,0))
|
|
687
|
+
elif 'tabulated n' in types:
|
|
688
|
+
firstTrue = ((types=='tabulated n').cumsum().cumsum()==1).argmax()
|
|
689
|
+
nData = np.array([np.array(i.split(' ')).astype(float) for i in str(RIIobj["DATA"][firstTrue]["data"]).strip().split('\n')])
|
|
690
|
+
nkData = np.zeros((kData[:,0].size, 3))
|
|
691
|
+
nkData[:,0] = nData[:,0]
|
|
692
|
+
nkData[:,1] = nData[:,1]
|
|
693
|
+
|
|
694
|
+
return nkData
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
def EOS(s: lightwaveExplorerResult, bandpass=None, filterTransmissionNanometers=None, detectorResponseNanometers=None):
|
|
698
|
+
"""
|
|
699
|
+
Takes a result of a calculation and extracts the electro-optic sampling signal
|
|
700
|
+
The simulation must be done in a way that includes mixing of the signal and local oscillator
|
|
701
|
+
either by fully simulating the waveplate, or by rotating the system of coordinates in
|
|
702
|
+
a sequence (by calling rotate(45))
|
|
703
|
+
|
|
704
|
+
The spectral response of the detection system can be adjusted in three ways:
|
|
705
|
+
1: application of a supergaussian bandpass filter with a three element list:
|
|
706
|
+
bandpass=[centralFrequency, sigma, superGaussianOrder]
|
|
707
|
+
2: application of a measured transmission of the filters and beamline optics:
|
|
708
|
+
filterTransmissionNanometers = np.array([wavelengthsInNanometers, transmissionIntensity])
|
|
709
|
+
3: application of the detector's spectral response (assumed identical for the two photodiodes)
|
|
710
|
+
same format as 2
|
|
711
|
+
|
|
712
|
+
:param s: The loaded simulation result
|
|
713
|
+
:param bandpass: supergaussian bandpass filter with a three element list:
|
|
714
|
+
bandpass=[centralFrequency, sigma, superGaussianOrder]
|
|
715
|
+
:param filterTransmissionNanometers: measured transmission of the filters and beamline optics:
|
|
716
|
+
filterTransmissionNanometers = np.array([wavelengthsInNanometers, transmissionIntensity])
|
|
717
|
+
:param detectorResponseNanometers: detector response function, in the same format as filterTransmissionNanometers
|
|
718
|
+
|
|
719
|
+
:return: The signal vs. delay of the EOS measurement.
|
|
720
|
+
"""
|
|
721
|
+
c = 2.99792458e8
|
|
722
|
+
totalResponse = 1.
|
|
723
|
+
|
|
724
|
+
#make everything numpy arrays
|
|
725
|
+
bandpass = np.array(bandpass)
|
|
726
|
+
filterTransmissionNanometers = np.array(filterTransmissionNanometers)
|
|
727
|
+
detectorResponseNanometers = np.array(detectorResponseNanometers)
|
|
728
|
+
|
|
729
|
+
#resolve the various filters
|
|
730
|
+
if bandpass.any() != None:
|
|
731
|
+
bandpassFilter = np.exp(-(s.frequencyVectorSpectrum-bandpass[0])**bandpass[2]/(2*bandpass[1]**bandpass[2]))
|
|
732
|
+
totalResponse *= bandpassFilter
|
|
733
|
+
|
|
734
|
+
if filterTransmissionNanometers.any() != None:
|
|
735
|
+
sortIndicies = np.argsort(1e9*c/filterTransmissionNanometers[0,:])
|
|
736
|
+
dataFrequencyAxis = np.array([1e9*c/filterTransmissionNanometers[0,sortIndicies], filterTransmissionNanometers[1,sortIndicies]])
|
|
737
|
+
totalResponse *= np.interp(s.frequencyVectorSpectrum, dataFrequencyAxis[0,:], dataFrequencyAxis[1,:])
|
|
738
|
+
|
|
739
|
+
if detectorResponseNanometers.any() != None:
|
|
740
|
+
sortIndicies = np.argsort(1e9*c/detectorResponseNanometers[0,:])
|
|
741
|
+
dataFrequencyAxis = np.array([1e9*c/detectorResponseNanometers[0,sortIndicies], detectorResponseNanometers[1,sortIndicies]])
|
|
742
|
+
totalResponse *= np.interp(s.frequencyVectorSpectrum, dataFrequencyAxis[0,:], dataFrequencyAxis[1,:])
|
|
743
|
+
|
|
744
|
+
#EOS signal is the integral of the difference between the two spectra, multiplied by the total spectral response
|
|
745
|
+
if s.Nsims2>1:
|
|
746
|
+
EOSsignal = np.array([np.sum((totalResponse*(np.squeeze(s.spectrum_x[i,:,:]-s.spectrum_y[i,:,:]))), axis=1) for i in range(s.Nsims2)])
|
|
747
|
+
else:
|
|
748
|
+
EOSsignal = np.sum((totalResponse*(s.spectrum_x-s.spectrum_y)), axis=1)
|
|
749
|
+
return EOSsignal
|
|
750
|
+
|
|
751
|
+
def chi2axisSwap(d: np.ndarray, ax1: int, ax2:int, ax3:int):
|
|
752
|
+
"""
|
|
753
|
+
Swap the axes in the second order nonlinear reduced tensor to a new order.
|
|
754
|
+
You might need to do this if a crystal (probably biaxial) has a different
|
|
755
|
+
arrangement between the optic x,y,z vs the crystal a,b,c axes.
|
|
756
|
+
|
|
757
|
+
:param d: the second order tensor, in 3x6 reduced format
|
|
758
|
+
:param ax1: the first axis (1 means unchanged)
|
|
759
|
+
:param ax2: the second axis (2 means unchanged)
|
|
760
|
+
:param ax3: the third axis (3 means unchanged)
|
|
761
|
+
|
|
762
|
+
:return: the rearranged tensor
|
|
763
|
+
:rtype: np.ndarray
|
|
764
|
+
"""
|
|
765
|
+
lookupVector = [9, 9, 5, 4, 9, 9, 3]
|
|
766
|
+
index = np.zeros((6,1),dtype=int)
|
|
767
|
+
index[0] = ax1-1
|
|
768
|
+
index[1] = ax2-1
|
|
769
|
+
index[2] = ax3-1
|
|
770
|
+
index[3] = lookupVector[ax2*ax3]
|
|
771
|
+
index[4] = lookupVector[ax1*ax3]
|
|
772
|
+
index[5] = lookupVector[ax1*ax2]
|
|
773
|
+
d_swap = np.array(d)
|
|
774
|
+
for i in range(3):
|
|
775
|
+
for j in range(6):
|
|
776
|
+
d_swap[i,j] = d[index[i],index[j]]
|
|
777
|
+
return d_swap
|
|
778
|
+
|
|
779
|
+
def chi2rotate(d: np.ndarray, psi: float, axis: int):
|
|
780
|
+
"""
|
|
781
|
+
Rotate the nonlinear crystal's system of coordinates around either the X or Y axis
|
|
782
|
+
and give the effective second order nonlinear tensor that results from bringing
|
|
783
|
+
the field into and back out of this system.
|
|
784
|
+
May be used to rotate monoclinic systems into an effective orthorhombic one, with the
|
|
785
|
+
approximation that one is neglecting the wavelength-dependence of the rotation angle.
|
|
786
|
+
|
|
787
|
+
:param d: The nonlinear tensor in the crystal frame
|
|
788
|
+
:param psi: The angle by which the dielectric frame is rotated relative to the crystal one (i.e. we are UNDOING this rotation)
|
|
789
|
+
:param axis: X-axis-> 1, Y-axis->2, anything else will emit an error.
|
|
790
|
+
|
|
791
|
+
:return: the rotated tensor
|
|
792
|
+
"""
|
|
793
|
+
#These functions will rotate a row of the tensor and provide the new row
|
|
794
|
+
#based on the field that has been rotated into the crystalline frame
|
|
795
|
+
def newRowX(r, ang):
|
|
796
|
+
s = np.sin(ang)
|
|
797
|
+
c = np.cos(ang)
|
|
798
|
+
row = ([
|
|
799
|
+
r[0],
|
|
800
|
+
r[1]*c*c + r[2]*s*s + 2*r[3]*c*s,
|
|
801
|
+
r[1]*s*s + r[2]*c*c - 2*r[3]*c*s,
|
|
802
|
+
-r[1]*s*c + r[2]*s*c + r[3]*(c*c-s*s),
|
|
803
|
+
r[4]*c - r[5]*s,
|
|
804
|
+
r[4]*s + r[5]*c
|
|
805
|
+
])
|
|
806
|
+
return row
|
|
807
|
+
|
|
808
|
+
def newRowY(r, ang):
|
|
809
|
+
s = np.sin(ang)
|
|
810
|
+
c = np.cos(ang)
|
|
811
|
+
row = ([
|
|
812
|
+
r[0]*c*c + r[2]*s*s - 2*r[4]*c*s,
|
|
813
|
+
r[1],
|
|
814
|
+
r[0]*s*s + r[2]*c*c + 2*r[4]*c*s,
|
|
815
|
+
r[3]*c + r[5]*s,
|
|
816
|
+
r[0]*c*s - r[2]*c*s + r[4]*(c*c - s*s),
|
|
817
|
+
-r[3]*s + r[5]*c
|
|
818
|
+
])
|
|
819
|
+
return row
|
|
820
|
+
|
|
821
|
+
if axis == 1:
|
|
822
|
+
d_rot = np.array([newRowX(d[0,:],-psi),
|
|
823
|
+
newRowX(d[1,:],-psi),
|
|
824
|
+
newRowX(d[2,:],-psi)])
|
|
825
|
+
|
|
826
|
+
#rotate d-frame polarization into field frame
|
|
827
|
+
#normal X rotation matrix by phi
|
|
828
|
+
d_rot = np.array([
|
|
829
|
+
d_rot[0,:],
|
|
830
|
+
(d_rot[1,:] * np.cos(psi) - d_rot[2,:] * np.sin(psi)),
|
|
831
|
+
(d_rot[1,:] * np.sin(psi) + d_rot[2,:] * np.cos(psi))
|
|
832
|
+
])
|
|
833
|
+
return d_rot
|
|
834
|
+
|
|
835
|
+
if axis == 2:
|
|
836
|
+
d_rot = np.array([newRowY(d[0,:],-psi),
|
|
837
|
+
newRowY(d[1,:],-psi),
|
|
838
|
+
newRowY(d[2,:],-psi)])
|
|
839
|
+
|
|
840
|
+
#rotate d-frame polarization into field frame
|
|
841
|
+
#normal Y rotation matrix by phi
|
|
842
|
+
d_rot = np.array([
|
|
843
|
+
d_rot[0,:]*np.cos(psi) + d_rot[2,:]*np.sin(psi),
|
|
844
|
+
d_rot[1,:],
|
|
845
|
+
(-d_rot[0,:] * np.sin(psi) + d_rot[2,:] * np.cos(psi))
|
|
846
|
+
])
|
|
847
|
+
return d_rot
|
|
848
|
+
|
|
849
|
+
assert False, "axis must be 1 or 2"
|
|
850
|
+
|
|
851
|
+
def plotTransmission(coeffs, equation: int, frequency_min: float = 1e12, frequency_max: float = 3000e12, thickness: float = 1e-2):
|
|
852
|
+
"""
|
|
853
|
+
Plot the transmission of a set of sellmeier coefficients
|
|
854
|
+
"""
|
|
855
|
+
f_wide = np.linspace(frequency_min,frequency_max,4096)
|
|
856
|
+
lam_wide = 1e6*2.9979e8/f_wide
|
|
857
|
+
n_wide = sellmeier(lam_wide, coeffs, equation)
|
|
858
|
+
k = 2*np.pi*f_wide*n_wide/2.9979e8
|
|
859
|
+
transmission = np.abs(np.exp(-1j*k*thickness))**2
|
|
860
|
+
fig,ax = plt.subplots(1,1)
|
|
861
|
+
ax.semilogx(lam_wide,100*transmission)
|
|
862
|
+
ax.set_xlabel("Wavelength (microns)")
|
|
863
|
+
ax.set_ylabel("Transmission (%)")
|
|
864
|
+
ax.set_title("Transmission through " + f"{thickness*1e3:.2f}"+"mm")
|
|
865
|
+
return fig
|
|
866
|
+
|
|
867
|
+
def plotSellmeierIntialGuess(tabulatednk, initialGuess, SellmeierEquation):
|
|
868
|
+
"""
|
|
869
|
+
Plot an intial guess to a set of tabulated data (for setting up a calculation using fittSellmeierWithTabulatedData)
|
|
870
|
+
"""
|
|
871
|
+
nFit = sellmeier(tabulatednk[:,0],initialGuess,SellmeierEquation)
|
|
872
|
+
fig = plotFittedSellmeier(tabulatednk, nFit)
|
|
873
|
+
if SellmeierEquation > 0:
|
|
874
|
+
plotTransmission(initialGuess, SellmeierEquation)
|
|
875
|
+
return fig
|
|
876
|
+
|
|
877
|
+
def fitSellmeierWithTabulatedData(tabulatednk, initialGuess, fittedValues, SellmeierEquation: int, absorptionWeight: float = 0.5):
|
|
878
|
+
"""
|
|
879
|
+
Fit a set of Sellmeier coefficients to tabulated data.
|
|
880
|
+
|
|
881
|
+
:param tabulatednk: An Nx3 array containing a refractive index dataset. tabulatednk[:,0] is the wavelength in microns, [:,1] is the refractive index, and [:,2] is the magnitude of the imaginary part kappa.
|
|
882
|
+
:param initialGuess: The initial guess to the coefficients, in the format corresponding to the equation you're using.
|
|
883
|
+
:param SellmeierEquation: The form of the equation to use, defined in the paper. 0: flexible fitting form, 1: Lorentzians, 2: Gaussians
|
|
884
|
+
:param absorptionWeight: weight factor to be applied to the imaginary part of the refractive index. Can be used to nudge the fitting out of a local minimum...
|
|
885
|
+
"""
|
|
886
|
+
#call the fitting routine
|
|
887
|
+
scFit,nFit = sellmeierFit(tabulatednk[:,0], initialGuess, fittedValues, SellmeierEquation, tabulatednk[:,1]-1j*tabulatednk[:,2], absorptionWeight)
|
|
888
|
+
plotFittedSellmeier(tabulatednk, nFit)
|
|
889
|
+
|
|
890
|
+
if SellmeierEquation > 0:
|
|
891
|
+
plotTransmission(scFit,SellmeierEquation)
|
|
892
|
+
return scFit
|
|
893
|
+
|
|
894
|
+
def plotFittedSellmeier(tabulatednk, nFit):
|
|
895
|
+
"""
|
|
896
|
+
Compare a fitted refractive index vs tabulated n and k
|
|
897
|
+
"""
|
|
898
|
+
fig,ax = plt.subplots(3,1,figsize=(6,12))
|
|
899
|
+
ax[0].plot(tabulatednk[:,0],np.real(nFit),label="Fitted")
|
|
900
|
+
ax[0].plot(tabulatednk[:,0],np.real(tabulatednk[:,1]), label="Data")
|
|
901
|
+
ax[0].set_xlabel("Wavelength (microns)")
|
|
902
|
+
ax[0].set_ylabel("n")
|
|
903
|
+
ax[0].legend()
|
|
904
|
+
ax[1].plot(tabulatednk[:,0], np.abs(np.real(tabulatednk[:,1])-np.real(nFit)))
|
|
905
|
+
ax[1].set_xlabel("Wavelength (microns)")
|
|
906
|
+
ax[1].set_ylabel("residual")
|
|
907
|
+
ax[2].semilogy(tabulatednk[:,0],-(np.imag(nFit)),label="Fitted")
|
|
908
|
+
ax[2].plot(tabulatednk[:,0],tabulatednk[:,2],label="Data")
|
|
909
|
+
ax[2].set_ylim(1e-10,1)
|
|
910
|
+
ax[2].set_xlabel("Wavelength (microns)")
|
|
911
|
+
ax[2].set_ylabel("k")
|
|
912
|
+
residval = np.sqrt(np.mean((np.real(tabulatednk[:,1])-np.real(nFit))**2))
|
|
913
|
+
print("rms deviation:")
|
|
914
|
+
print(residval)
|
|
915
|
+
return fig
|
|
916
|
+
|
|
917
|
+
def sellmeierFit(wavelengthMicrons, startingCoefficients, activeElements: np.array, eqnType: int, nTarget, imaginaryWeight):
|
|
918
|
+
"""
|
|
919
|
+
Fit a set of sellmeier coefficents to measured data.
|
|
920
|
+
|
|
921
|
+
:param wavelengthMicrons: array of wavelengths
|
|
922
|
+
:param startingCoeffiecients: starting point of the coefficients, 22-element numpy array of floats
|
|
923
|
+
:param activeElements: array of indexes of the elements that may be adjusted
|
|
924
|
+
:param eqnType: type of Sellmeier equation (0=general fitting, 1=lorentzians, 2=gaussians)
|
|
925
|
+
:param nTarget: refractive index curve to fit to (same size as wavelengthMicrons)
|
|
926
|
+
:param imaginaryWeight: factor by which to change the weighting of the imaginary part of the refractive index
|
|
927
|
+
"""
|
|
928
|
+
fitImaginary = imaginaryWeight != 0
|
|
929
|
+
def expandCoeffs(x):
|
|
930
|
+
x1 = np.array(startingCoefficients)
|
|
931
|
+
for i in range(0,activeElements.size):
|
|
932
|
+
x1[activeElements[i]] = x[i]
|
|
933
|
+
return x1
|
|
934
|
+
def fun_nforx(x):
|
|
935
|
+
return sellmeier(wavelengthMicrons, expandCoeffs(x), eqnType)
|
|
936
|
+
|
|
937
|
+
def fun_residual(x):
|
|
938
|
+
nx = fun_nforx(x)
|
|
939
|
+
if fitImaginary:
|
|
940
|
+
returnVals = 1e3*np.append(np.real(nTarget - nx), np.real(imaginaryWeight*(np.sqrt(-(np.imag(nTarget))) - np.sqrt(-(np.imag(nx))))))
|
|
941
|
+
else:
|
|
942
|
+
returnVals = 1e3*np.real(nTarget - nx)
|
|
943
|
+
return returnVals
|
|
944
|
+
|
|
945
|
+
res = least_squares(fun_residual, startingCoefficients[activeElements], gtol=None, xtol=None, ftol = 1e-12, max_nfev=16384)
|
|
946
|
+
|
|
947
|
+
if (eqnType == 1) or (eqnType == 2):
|
|
948
|
+
res.x = np.abs(res.x)
|
|
949
|
+
print("Resulting coefficients:")
|
|
950
|
+
printSellmeier(expandCoeffs(res.x))
|
|
951
|
+
|
|
952
|
+
return expandCoeffs(res.x), fun_nforx(res.x)
|
|
953
|
+
|
|
954
|
+
#Get the plasma density associated with a field using the ionization model in the simulation
|
|
955
|
+
def getPlasmaDensityAndCurrent(E, dt, pulseFrequency, scoeffs, bandGap, effectiveMass, NLabsorption, gamma):
|
|
956
|
+
"""
|
|
957
|
+
Get the plasma current associated with a field and set of parameters. This is just for testing,
|
|
958
|
+
I wouldn't recommend using it for anything yet....
|
|
959
|
+
"""
|
|
960
|
+
#get the refractive index of the crystal
|
|
961
|
+
f = np.fft.fftfreq(E.size,dt)
|
|
962
|
+
lam = np.array(f)
|
|
963
|
+
for i in range(0,lam.size):
|
|
964
|
+
if f[i] != 0:
|
|
965
|
+
lam[i] = np.abs(2.99792458e8/f[i])
|
|
966
|
+
else:
|
|
967
|
+
lam[i] = 0.0
|
|
968
|
+
n = np.real(sellmeier(lam*1e6, scoeffs, 0))
|
|
969
|
+
|
|
970
|
+
#calculate chi1
|
|
971
|
+
chi1 = n**2 - 1.0
|
|
972
|
+
chi1[chi1<0.0] = 0
|
|
973
|
+
chi1[np.isnan(chi1)]=0.0
|
|
974
|
+
|
|
975
|
+
#plasma generation constants
|
|
976
|
+
plasmaParam2 = 2.817832e-8 / (1.6022e-19 * bandGap * effectiveMass)
|
|
977
|
+
pMax = np.ceil(bandGap * 241.79893e12 / pulseFrequency) - 2
|
|
978
|
+
fieldFactor = 1.0/(chi1 + 1)**0.25
|
|
979
|
+
|
|
980
|
+
#get the linear polarization for applying millers rule to the dispersion of the absorption cross section
|
|
981
|
+
Pol1 = np.real(np.fft.ifft(fieldFactor*chi1*np.fft.fft(E)))
|
|
982
|
+
Esquared = NLabsorption* (Pol1**2)
|
|
983
|
+
|
|
984
|
+
#Jx starts at the absorption current; e.g. the one responsible for the removal of energy from the field
|
|
985
|
+
#as carriers are generated
|
|
986
|
+
Jx = Pol1 * (Esquared**(pMax))
|
|
987
|
+
|
|
988
|
+
#number of carriers is assumed to be equal to the energy removed from the field/bandgap
|
|
989
|
+
#Rate of power loss of the field is E*J
|
|
990
|
+
Ncarriers = dt * np.cumsum(plasmaParam2 * Jx * Pol1)
|
|
991
|
+
|
|
992
|
+
#integrate damped drude response to fill in the rest of the current
|
|
993
|
+
integralx = 0.0
|
|
994
|
+
for i in range(0, E.size):
|
|
995
|
+
expGammaT = np.exp(dt * i * gamma)
|
|
996
|
+
expMinusGammaT = np.exp(-dt * i * gamma)
|
|
997
|
+
integralx += Ncarriers[i] * expGammaT * E[i]
|
|
998
|
+
Jx[i] += expMinusGammaT * integralx
|
|
999
|
+
|
|
1000
|
+
return Ncarriers, dt*Jx
|
|
1001
|
+
|
|
1002
|
+
def deviceDawson(x):
|
|
1003
|
+
"""
|
|
1004
|
+
replica of the dawson function used in the c++ code
|
|
1005
|
+
should provide results similar to the scipy dawson function
|
|
1006
|
+
|
|
1007
|
+
:param x: argument of the dawson function
|
|
1008
|
+
:returns: F(x), the dawson function at x
|
|
1009
|
+
"""
|
|
1010
|
+
|
|
1011
|
+
#parameters determining accuracy (higher n, smaller h -> more accurate but slower)
|
|
1012
|
+
n = 15
|
|
1013
|
+
h = 0.3
|
|
1014
|
+
|
|
1015
|
+
#series expansion for small x
|
|
1016
|
+
if abs(x) < 0.2:
|
|
1017
|
+
x2 = x * x
|
|
1018
|
+
x4 = x2 * x2
|
|
1019
|
+
return x * (1.0 - 2.0 * x2 / 3.0 + 4.0 * x4 / 15.0 - 8.0 * x2 * x4 / 105.0 + (16.0 / 945) * x4 * x4 - (32.0 / 10395) * x4 * x4 * x2)
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
n0 = 2 * (int)(round(0.5 * x / h))
|
|
1023
|
+
x0 = h * n0
|
|
1024
|
+
xp = x - x0
|
|
1025
|
+
d = 0.0
|
|
1026
|
+
for i in range (-n,n):
|
|
1027
|
+
if (i % 2 != 0):
|
|
1028
|
+
d += np.exp(-(xp - i * h) * (xp - i * h)) / (i + n0)
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
return d/np.sqrt(np.pi)
|
|
1032
|
+
|
|
1033
|
+
def loadSplit(baseName: str, Ntotal: int, batchType:str):
|
|
1034
|
+
"""
|
|
1035
|
+
load a set of single simulations and fuse the results together as
|
|
1036
|
+
if they came from a batch. May be useful for getting around memory
|
|
1037
|
+
limitations.
|
|
1038
|
+
|
|
1039
|
+
:param listOfFileNames: list of strings containing the file names to load, in order
|
|
1040
|
+
:param batchType: the attribute being scanned in the batch, e.g. frequency1
|
|
1041
|
+
"""
|
|
1042
|
+
listOfFileNames = [f"{baseName}{i:04d}.txt" for i in range(Ntotal)]
|
|
1043
|
+
baseStructure = load(listOfFileNames[0])
|
|
1044
|
+
stackAxis = len(baseStructure.Ext_x.shape)
|
|
1045
|
+
if stackAxis == 2:
|
|
1046
|
+
tmp = np.array(baseStructure.Ext_x)
|
|
1047
|
+
baseStructure.Ext_x = np.zeros((baseStructure.Ext_x.shape[0],baseStructure.Ext_x.shape[1],Ntotal), dtype=float)
|
|
1048
|
+
baseStructure.Ext_x[:,:,0] = tmp
|
|
1049
|
+
tmp = np.array(baseStructure.Ext_y)
|
|
1050
|
+
baseStructure.Ext_y = np.zeros(baseStructure.Ext_x.shape,dtype=float)
|
|
1051
|
+
baseStructure.Ext_y[:,:,0] = tmp
|
|
1052
|
+
else:
|
|
1053
|
+
tmp = np.array(baseStructure.Ext_x)
|
|
1054
|
+
baseStructure.Ext_x = np.zeros((baseStructure.Ext_x.shape[0],baseStructure.Ext_x.shape[1],baseStructure.Ext_x.shape[2],Ntotal), dtype=float)
|
|
1055
|
+
baseStructure.Ext_x[:,:,:,0] = tmp
|
|
1056
|
+
tmp = np.array(baseStructure.Ext_y)
|
|
1057
|
+
baseStructure.Ext_y = np.zeros(baseStructure.Ext_x.shape,dtype=float)
|
|
1058
|
+
baseStructure.Ext_y[:,:,:,0] = tmp
|
|
1059
|
+
tmp = np.array(baseStructure.spectrum_x)
|
|
1060
|
+
baseStructure.spectrum_x = np.zeros((Ntotal,baseStructure.spectrum_x.shape[0]),dtype=float)#baseStructure.spectrum_x[np.newaxis,:]
|
|
1061
|
+
baseStructure.spectrum_x[0,:] = tmp
|
|
1062
|
+
tmp = np.array(baseStructure.spectrum_y)
|
|
1063
|
+
baseStructure.spectrum_y = np.zeros(baseStructure.spectrum_x.shape,dtype=float)
|
|
1064
|
+
baseStructure.spectrum_y[0,:] = tmp
|
|
1065
|
+
tmp = np.array(baseStructure.spectrumTotal)
|
|
1066
|
+
baseStructure.spectrumTotal = np.zeros(baseStructure.spectrum_x.shape,dtype=float)
|
|
1067
|
+
baseStructure.spectrumTotal[0,:] = tmp
|
|
1068
|
+
|
|
1069
|
+
baseStructure.batchVector = getattr(baseStructure, batchType)
|
|
1070
|
+
baseStructure.batchStart = baseStructure.batchVector
|
|
1071
|
+
|
|
1072
|
+
for i in range(1,Ntotal):
|
|
1073
|
+
newStructure = load(listOfFileNames[i])
|
|
1074
|
+
if stackAxis == 2:
|
|
1075
|
+
baseStructure.Ext_x[:,:,i] = newStructure.Ext_x
|
|
1076
|
+
baseStructure.Ext_y[:,:,i] = newStructure.Ext_y
|
|
1077
|
+
else:
|
|
1078
|
+
baseStructure.Ext_x[:,:,:,i] = newStructure.Ext_x
|
|
1079
|
+
baseStructure.Ext_y[:,:,:,i] = newStructure.Ext_y
|
|
1080
|
+
baseStructure.spectrum_x[i,:] = newStructure.spectrum_x
|
|
1081
|
+
baseStructure.spectrum_y[i,:] = newStructure.spectrum_y
|
|
1082
|
+
baseStructure.spectrumTotal[i,:] = newStructure.spectrumTotal
|
|
1083
|
+
baseStructure.batchVector = np.append(baseStructure.batchVector, getattr(baseStructure, batchType))
|
|
1084
|
+
|
|
1085
|
+
return baseStructure
|
|
1086
|
+
|
|
1087
|
+
def fuseBinaries(outputTextFile: str):
|
|
1088
|
+
"""
|
|
1089
|
+
Combine the binary components of a simulation that was split to run on a cluster.
|
|
1090
|
+
|
|
1091
|
+
:param inputTextFile: The base file name associated with the simulation. If this is Result.Txt, it will
|
|
1092
|
+
combine the files associated with Result0000.txt, Result0001.txt and so on
|
|
1093
|
+
"""
|
|
1094
|
+
def fuseFile(baseName: str, ending: str):
|
|
1095
|
+
|
|
1096
|
+
output_name = baseName+ending
|
|
1097
|
+
if os.path.exists(output_name):
|
|
1098
|
+
os.remove(output_name)
|
|
1099
|
+
print("Fusing "+output_name+" from:")
|
|
1100
|
+
files = [filename for filename in os.listdir() if filename.startswith(baseName) and filename.endswith(ending)]
|
|
1101
|
+
files.sort()
|
|
1102
|
+
print(files)
|
|
1103
|
+
output = open(output_name,'wb')
|
|
1104
|
+
for file in files:
|
|
1105
|
+
current = open(file,'rb')
|
|
1106
|
+
try:
|
|
1107
|
+
while True:
|
|
1108
|
+
piece = current.read(1024*1024*128)
|
|
1109
|
+
if not piece:
|
|
1110
|
+
break
|
|
1111
|
+
output.write(piece)
|
|
1112
|
+
finally:
|
|
1113
|
+
current.close()
|
|
1114
|
+
print(file)
|
|
1115
|
+
output.close()
|
|
1116
|
+
|
|
1117
|
+
base = os.path.splitext(os.path.basename(outputTextFile))[0]
|
|
1118
|
+
|
|
1119
|
+
fuseFile(base,"_Ext.dat")
|
|
1120
|
+
fuseFile(base,"_spectrum.dat")
|
|
1121
|
+
|
|
1122
|
+
def fuseZips(outputFile: str):
|
|
1123
|
+
"""
|
|
1124
|
+
Combine the zip files resulting from a simulation that was split to run on a cluster
|
|
1125
|
+
|
|
1126
|
+
:param outputFile: The zip file created to run on the cluster. If this is Result.zip, it will
|
|
1127
|
+
combine the files Result00000.zip, Result00001.zip and so on
|
|
1128
|
+
"""
|
|
1129
|
+
ending = ".zip"
|
|
1130
|
+
baseName = os.path.splitext(os.path.basename(outputFile))[0]
|
|
1131
|
+
destination = os.path.splitext(outputFile)[0]+ending
|
|
1132
|
+
files = sorted([filename for filename in os.listdir() if filename.startswith(baseName) and filename.endswith(ending) and filename != destination])
|
|
1133
|
+
print(files)
|
|
1134
|
+
print(destination)
|
|
1135
|
+
with zipfile.ZipFile(destination,'a',compression=8) as destinationZip:
|
|
1136
|
+
Ext = tempfile.NamedTemporaryFile(delete=False)
|
|
1137
|
+
spectrum = tempfile.NamedTemporaryFile(delete=False)
|
|
1138
|
+
for sourceFile in files:
|
|
1139
|
+
currentBase = os.path.splitext(os.path.basename(sourceFile))[0]
|
|
1140
|
+
print(currentBase)
|
|
1141
|
+
with zipfile.ZipFile(sourceFile,'r') as sourceZip:
|
|
1142
|
+
spectrum.write(sourceZip.read(currentBase+"_spectrum.dat"))
|
|
1143
|
+
spectrum.flush()
|
|
1144
|
+
Ext.write(sourceZip.read(currentBase+"_Ext.dat"))
|
|
1145
|
+
Ext.flush()
|
|
1146
|
+
destinationZip.write(spectrum.name, baseName+"_spectrum.dat")
|
|
1147
|
+
destinationZip.write(Ext.name, baseName+"_Ext.dat")
|
|
1148
|
+
Ext.close()
|
|
1149
|
+
spectrum.close()
|
|
1150
|
+
os.unlink(Ext.name)
|
|
1151
|
+
os.unlink(spectrum.name)
|
|
1152
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .LightwaveExplorer import *
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Nicholas Karpowicz, Max Planck Institute of Quantum Optics
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: LightwaveExplorer
|
|
3
|
+
Version: 2025.2.2
|
|
4
|
+
Summary: Tools for using Lightwave Explorer results
|
|
5
|
+
Author-email: Nick Karpowicz <nicholas.karpowicz@mpq.mpg.de>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2022 Nicholas Karpowicz, Max Planck Institute of Quantum Optics
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/NickKarpowicz/LightwaveExplorer
|
|
29
|
+
Project-URL: Issues, https://github.com/NickKarpowicz/LightwaveExplorer/issues
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: Operating System :: OS Independent
|
|
32
|
+
Requires-Python: >=3.8
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: numpy
|
|
36
|
+
Requires-Dist: scipy
|
|
37
|
+
Requires-Dist: matplotlib
|
|
38
|
+
|
|
39
|
+
# LightwaveExplorer.py
|
|
40
|
+
This is a Python package to make it easier to work with results from Lightwave Explorer.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LightwaveExplorer/LightwaveExplorer.py,sha256=0fobjEY39yskHViUrP_zfJbDXXAe5f4hnbe19aJKaOY,51159
|
|
2
|
+
LightwaveExplorer/__init__.py,sha256=oiioG-T2-GLVQloWs2Cfx-0AvfdmHSG2ph-EqjveZSI,32
|
|
3
|
+
lightwaveexplorer-2025.2.2.dist-info/LICENSE,sha256=F496ojVKPpmLqev9zdoB6j7ZSWHMx1Kp6Xk_-eR8p_o,1115
|
|
4
|
+
lightwaveexplorer-2025.2.2.dist-info/METADATA,sha256=DiSKqH2YiHHAe-HqgNQGU8N5AUsXiNs9Batw_k4SfD0,1984
|
|
5
|
+
lightwaveexplorer-2025.2.2.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
|
6
|
+
lightwaveexplorer-2025.2.2.dist-info/top_level.txt,sha256=LPIC3dEGbxWZjQlnlVwILNb0brD73rySIi-9Zr_A_dc,18
|
|
7
|
+
lightwaveexplorer-2025.2.2.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
LightwaveExplorer
|