forked from cinek810/refractiveindex.info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchRef.py
executable file
·146 lines (101 loc) · 3.26 KB
/
searchRef.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/python
import numpy as np
import yaml
from getData import *
#TODO this function is generally dirty, but works so...
#it will wait infinite time to be changed
def searchRef(yamlFile,bookName,nmin,nmax):
#List for result
result=[]
#Function used only internally to display material parameters values
#ATTENTION!!! comment is not only a comment is like command for this function (yes, it's dirty ;))
# def printParams(paramsArray,paramList,comment):
# for param in paramList:
# sys.stdout.write(str(paramsArray[-1][param])+" ");
# sys.stdout.write(comment+"\n");
# if comment.find("start_range")!=-1:
# printParams.lastStart=paramsArray[-1]["l"]
# elif comment.find("end_range")!=-1:
# result.append((printParams.lastStart,paramsArray[-1]["l"]))
#printParams.lastStart=0;
#Just some boolen, if the firs element is OK it may not be shown
#it's defined only for first material for the rest it's undefined at the begining
print_in_my_range=False;
#This parameter decides additional output about parameters inside range have been met
my_range=False;
yamlStream=open(yamlFile,'r')
allData=yaml.load(yamlStream);
materialData=allData["DATA"][0]
#dataRange - where we can check the data
dataRange=getRange(yamlFile)
if dataRange[0]==0:
return []
#wavelengths to check for this material:
#HERE WE DEFINE THE SAMPLING
lambdas=np.linspace(dataRange[0],dataRange[1],100)
#refractive indx
nList=np.empty((1,0))
# try:
nList=getData(yamlFile,lambdas[:])
if len(nList) == 1:
return []
eps=np.zeros(len(nList),dtype="complex")
for i in range(0,len(nList)):
eps[i]=nList[i]*nList[i]
# except UnsupportedDataType as e:
# sys.stderr.write(e)
if len(nList)<100:
return result
inRange=False
rangeStart=0
for i in range(0,len(lambdas)):
if eps[i].real>nmin and eps[i].real<nmax:
if inRange==False:
inRange=True
rangeStart=lambdas[i]
elif inRange:
result.append((rangeStart,lambdas[i]))
inRange=False
return result
if __name__ == "__main__":
import sys
if len( sys.argv )!=3:
sys.stderr.write("You have to give exactly two arguments- eps_min and eps_max\n")
sys.exit(1)
prefix="database/"
lib=yaml.load(open(prefix+"library.yml",'r'))
#List for resulted ranges
resrange=[]
#List for material names
resnames=[]
for schelf in lib:
for materials in schelf["content"]:
bookName="NoBookSet"
if(materials.keys()[0]=="content"):
bookName=materials["BOOK"]
smallRes=dict()
for myFileIsIn in materials["content"]:
fileName=prefix+myFileIsIn["path"]
# if bookName=="NoBookSet":
# raise Exception("NoBookSet");
result=searchRef(fileName,bookName,float(sys.argv[1]),float(sys.argv[2]))
if len(result)>0:
for oneTuple in result:
try:
smallRes[fileName].append(oneTuple)
except KeyError:
smallRes[fileName]=[]
smallRes[fileName].append(oneTuple)
if len(smallRes)>0:
resrange.append(smallRes)
import pickle
f=open("temporary-range-res.sav",'w')
pickle.dump(resrange,f);
f.close();
# f=open("temporary-names-res.sav",'w')
# pickle.dump(resnames,f);
# f.close();
f=open("temporary-lims-res.sav",'w')
pickle.dump((float(sys.argv[1]),float(sys.argv[2])),f);
f.close();
print ("You can now call plot-ranges.py")