Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NP_TMcode
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Giacomo Mulas
NP_TMcode
Commits
d6e28991
Commit
d6e28991
authored
2 months ago
by
Giovanni La Mura
Browse files
Options
Downloads
Patches
Plain Diff
Use exception handling in optical constant file management
parent
a0d40d53
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/scripts/model_maker.py
+136
-120
136 additions, 120 deletions
src/scripts/model_maker.py
with
136 additions
and
120 deletions
src/scripts/model_maker.py
+
136
−
120
View file @
d6e28991
...
@@ -69,11 +69,14 @@ def main():
...
@@ -69,11 +69,14 @@ def main():
# \return result: `int` An exit code (0 if successful).
# \return result: `int` An exit code (0 if successful).
def
interpolate_constants
(
sconf
):
def
interpolate_constants
(
sconf
):
result
=
0
result
=
0
err_arg
=
""
try
:
for
i
in
range
(
sconf
[
'
configurations
'
]):
for
i
in
range
(
sconf
[
'
configurations
'
]):
for
j
in
range
(
sconf
[
'
nshl
'
][
i
]):
for
j
in
range
(
sconf
[
'
nshl
'
][
i
]):
file_idx
=
sconf
[
'
dielec_id
'
][
i
][
j
]
file_idx
=
sconf
[
'
dielec_id
'
][
i
][
j
]
dielec_path
=
Path
(
sconf
[
'
dielec_path
'
],
sconf
[
'
dielec_file
'
][
int
(
file_idx
)
-
1
])
dielec_path
=
Path
(
sconf
[
'
dielec_path
'
],
sconf
[
'
dielec_file
'
][
int
(
file_idx
)
-
1
])
file_name
=
str
(
dielec_path
)
err_arg
=
str
(
dielec_path
)
file_name
=
err_arg
dielec_file
=
open
(
file_name
,
'
r
'
)
dielec_file
=
open
(
file_name
,
'
r
'
)
wavelengths
=
[]
wavelengths
=
[]
rpart
=
[]
rpart
=
[]
...
@@ -126,6 +129,9 @@ def interpolate_constants(sconf):
...
@@ -126,6 +129,9 @@ def interpolate_constants(sconf):
else
:
else
:
print
(
"
ERROR: file %s does not cover requested wavelengths!
"
%
file_name
)
print
(
"
ERROR: file %s does not cover requested wavelengths!
"
%
file_name
)
return
2
return
2
except
FileNotFoundError
as
ex
:
print
(
"
ERROR: file not found %s!
"
%
err_arg
)
return
3
return
result
return
result
## \brief Create tha calculation configuration structure from YAML input.
## \brief Create tha calculation configuration structure from YAML input.
...
@@ -262,12 +268,16 @@ def load_model(model_file):
...
@@ -262,12 +268,16 @@ def load_model(model_file):
[
0.0
for
k
in
range
(
sconf
[
'
nxi
'
])]
for
j
in
range
(
sconf
[
'
configurations
'
])
[
0.0
for
k
in
range
(
sconf
[
'
nxi
'
])]
for
j
in
range
(
sconf
[
'
configurations
'
])
]
for
i
in
range
(
max_layers
)
]
for
i
in
range
(
max_layers
)
]
]
interpolate_constants
(
sconf
)
check
=
interpolate_constants
(
sconf
)
if
(
check
!=
0
):
return
(
None
,
None
)
else
:
# sconf[idfc] != 0 and scaling on wavelength
else
:
# sconf[idfc] != 0 and scaling on wavelength
print
(
"
ERROR: for wavelength scaling, optical constants must be tabulated!
"
)
print
(
"
ERROR: for wavelength scaling, optical constants must be tabulated!
"
)
return
(
None
,
None
)
return
(
None
,
None
)
elif
(
model
[
'
material_settings
'
][
'
match_mode
'
]
==
"
GRID
"
):
elif
(
model
[
'
material_settings
'
][
'
match_mode
'
]
==
"
GRID
"
):
match_grid
(
sconf
)
check
=
match_grid
(
sconf
)
if
(
check
!=
0
):
return
(
None
,
None
)
else
:
else
:
print
(
"
ERROR: %s is not a recognized match mode!
"
%
(
model
[
'
material_settings
'
][
'
match_mode
'
]))
print
(
"
ERROR: %s is not a recognized match mode!
"
%
(
model
[
'
material_settings
'
][
'
match_mode
'
]))
return
(
None
,
None
)
return
(
None
,
None
)
...
@@ -466,6 +476,8 @@ def match_grid(sconf):
...
@@ -466,6 +476,8 @@ def match_grid(sconf):
max_layers
=
0
max_layers
=
0
nxi
=
0
nxi
=
0
sconf
[
'
vec_xi
'
]
=
[]
sconf
[
'
vec_xi
'
]
=
[]
err_arg
=
""
try
:
for
i
in
range
(
sconf
[
'
configurations
'
]):
for
i
in
range
(
sconf
[
'
configurations
'
]):
layers
=
sconf
[
'
nshl
'
][
i
]
layers
=
sconf
[
'
nshl
'
][
i
]
if
(
sconf
[
'
application
'
]
==
"
INCLUSION
"
and
i
==
0
):
if
(
sconf
[
'
application
'
]
==
"
INCLUSION
"
and
i
==
0
):
...
@@ -473,7 +485,8 @@ def match_grid(sconf):
...
@@ -473,7 +485,8 @@ def match_grid(sconf):
for
j
in
range
(
layers
):
for
j
in
range
(
layers
):
file_idx
=
sconf
[
'
dielec_id
'
][
i
][
j
]
file_idx
=
sconf
[
'
dielec_id
'
][
i
][
j
]
dielec_path
=
Path
(
sconf
[
'
dielec_path
'
],
sconf
[
'
dielec_file
'
][
int
(
file_idx
)
-
1
])
dielec_path
=
Path
(
sconf
[
'
dielec_path
'
],
sconf
[
'
dielec_file
'
][
int
(
file_idx
)
-
1
])
file_name
=
str
(
dielec_path
)
err_arg
=
str
(
dielec_path
)
file_name
=
err_arg
dielec_file
=
open
(
file_name
,
'
r
'
)
dielec_file
=
open
(
file_name
,
'
r
'
)
wavelengths
=
[]
wavelengths
=
[]
rpart
=
[]
rpart
=
[]
...
@@ -532,6 +545,9 @@ def match_grid(sconf):
...
@@ -532,6 +545,9 @@ def match_grid(sconf):
wi
+=
1
wi
+=
1
sconf
[
'
rdc0
'
][
j
][
i
][
dci
]
=
ry
sconf
[
'
rdc0
'
][
j
][
i
][
dci
]
=
ry
sconf
[
'
idc0
'
][
j
][
i
][
dci
]
=
iy
sconf
[
'
idc0
'
][
j
][
i
][
dci
]
=
iy
except
FileNotFoundError
as
ex
:
print
(
"
ERROR: file not found %s!
"
%
err_arg
)
return
3
return
result
return
result
## \brief Parse the command line arguments.
## \brief Parse the command line arguments.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment