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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177 | def __read(self):
# TODO: import of csv files (single column)
# wavelength
if isinstance(self.config["parameters"]["wavelength"]["data"], list):
self.wavelength = self.config["parameters"]["wavelength"]["data"]
elif isinstance(self.config["parameters"]["wavelength"]["data"], dict):
self.wavelength = np.arange(
self.config["parameters"]["wavelength"]["data"]["start"],
self.config["parameters"]["wavelength"]["data"]["stop"],
self.config["parameters"]["wavelength"]["data"]["step"],
)
else:
raise Exception(
"Please provide the wavelength data as an array, or the (start, stop, step) numpy.arange parameters."
)
self.wavelength_scale = (
self.config["parameters"]["wavelength"]["scale"]
if "scale" in self.config["parameters"]["wavelength"]
else 1
)
# TODO: move the interpolation of data into config and away from the YASF function
# NOTE: Kinda done, but needs to be checked!
# refractive indices of particles
self.material = generate_refractive_index_table(
[mat["url"] for mat in self.config["particles"]["material"]]
)
self.material_scale = [
mat["scale"] for mat in self.config["particles"]["material"]
]
# refractive index of medium
medium_url = (
self.config["parameters"]["medium"]["url"]
if "url" in self.config["parameters"]["medium"]
else self.config["parameters"]["medium"]
)
self.medium = Handler(url=medium_url)
# self.medium = generate_refractive_index_table([medium_url])
# self.medium_scale = (
# self.config["parameters"]["medium"]["scale"]
# if "scale" in self.config["parameters"]["medium"]
# else 1
# )
# particle geometry
delim = (
self.config["particles"]["geometry"]["delimiter"]
if "delimiter" in self.config["particles"]["geometry"]
else ","
)
delim = r"\s+" if delim == "whitespace" else delim
spheres = pd.read_csv(
# self.config["particles"]["geometry"]["file"],
self.path_cluster,
header=None,
sep=delim,
)
if spheres.shape[1] < 4:
raise Exception(
"The particle geometry file needs at least 4 columns (x, y, z, r) and an optinal refractive index column"
)
elif spheres.shape[1] == 4:
self.log.info(
"4 columns have been provided. Implying that all particles belong to the same material."
)
spheres[4] = np.zeros((spheres.shape[0], 1))
elif spheres.shape[1] >= 5:
self.log.warning(
"More than 5 columns have been provided. Everything after the 5th will be ignored!"
)
self.particles_scale = (
self.config["particles"]["geometry"]["scale"]
if "scale" in self.config["particles"]["geometry"]
else 1
)
self.spheres = spheres.to_numpy()
# NOTE: Scale the distnaces and radii to the wavelength
# This should make the size parameter correct
self.spheres[:, :4] = (
self.spheres[:, :4] * self.particles_scale / self.wavelength_scale
)
self.log.info(
f"Particles have been scaled by {self.particles_scale / self.wavelength_scale} to match the wavelength"
)
if "optics" in self.config:
self.config["optics"] = (
self.config["optics"]
if isinstance(self.config["optics"], bool)
else True
)
else:
self.config["optics"] = True
if "points" in self.config:
points = dict(x=np.array([0]), y=np.array([0]), z=np.array([0]))
for key, value in self.config["points"].items():
if isinstance(value, Number):
points[key] = np.array([value])
elif isinstance(value, list):
points[key] = np.array(value)
elif isinstance(value, dict):
points[key] = np.arange(
value["start"], value["stop"], value["step"]
)
else:
raise Exception(
f"The key {key} is not a valid type. Numbers, list of numbers and arange dicts are permited"
)
x, y, z = np.meshgrid(points["x"], points["y"], points["z"], indexing="ij")
points = dict(x=x.ravel(), y=y.ravel(), z=z.ravel())
self.config["points"] = points
self.config["points_shape"] = x.shape
|