Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
50709ca0
Commit
50709ca0
authored
5 years ago
by
Conor Finn
Browse files
Options
Downloads
Patches
Plain Diff
RE #26848 Add load existing functionality to model
parent
6823df2f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py
+45
-14
45 additions, 14 deletions
...ing/gui/engineering_diffraction/tabs/calibration/model.py
with
45 additions
and
14 deletions
scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py
+
45
−
14
View file @
50709ca0
...
@@ -70,12 +70,23 @@ class CalibrationModel(object):
...
@@ -70,12 +70,23 @@ class CalibrationModel(object):
self
.
create_output_files
(
user_calib_dir
,
difc
,
tzero
,
ceria_path
,
vanadium_path
,
self
.
create_output_files
(
user_calib_dir
,
difc
,
tzero
,
ceria_path
,
vanadium_path
,
instrument
)
instrument
)
def
load_existing_gsas_parameters
(
self
,
file_path
):
if
not
path
.
exists
(
file_path
):
logger
.
warning
(
"
Could not open GSAS calibration file:
"
,
file_path
)
return
try
:
instrument
,
van_no
,
ceria_no
=
self
.
get_info_from_file
(
file_path
)
except
RuntimeError
:
logger
.
error
(
"
Invalid file selected:
"
,
file_path
)
return
return
instrument
,
van_no
,
ceria_no
@staticmethod
@staticmethod
def
update_calibration_params_table
(
params_table
):
def
update_calibration_params_table
(
params_table
):
if
len
(
params_table
)
==
0
:
if
len
(
params_table
)
==
0
:
return
return
# Create blank or clear existing params table.
# Create blank
,
or clear
rows from
existing
,
params table.
if
Ads
.
doesExist
(
CALIB_PARAMS_WORKSPACE_NAME
):
if
Ads
.
doesExist
(
CALIB_PARAMS_WORKSPACE_NAME
):
workspace
=
Ads
.
retrieve
(
CALIB_PARAMS_WORKSPACE_NAME
)
workspace
=
Ads
.
retrieve
(
CALIB_PARAMS_WORKSPACE_NAME
)
workspace
.
setRowCount
(
0
)
workspace
.
setRowCount
(
0
)
...
@@ -193,34 +204,54 @@ class CalibrationModel(object):
...
@@ -193,34 +204,54 @@ class CalibrationModel(object):
"""
"""
if
not
path
.
exists
(
calibration_dir
):
if
not
path
.
exists
(
calibration_dir
):
makedirs
(
calibration_dir
)
makedirs
(
calibration_dir
)
filename
,
vanadium_no
,
ceria_no
=
self
.
_generate_output_file_name
(
vanadium_path
,
filename
=
self
.
_generate_output_file_name
(
vanadium_path
,
ceria_path
,
ceria_path
,
instrument
,
instrument
,
bank
=
"
all
"
)
bank
=
"
all
"
)
# Both Banks
# Both Banks
file_path
=
calibration_dir
+
filename
file_path
=
calibration_dir
+
filename
write_ENGINX_GSAS_iparam_file
(
file_path
,
write_ENGINX_GSAS_iparam_file
(
file_path
,
difc
,
difc
,
tzero
,
tzero
,
ceria_run
=
ceria_
no
,
ceria_run
=
ceria_
path
,
vanadium_run
=
vanadium_
no
)
vanadium_run
=
vanadium_
path
)
# North Bank
# North Bank
file_path
=
calibration_dir
+
self
.
_generate_output_file_name
(
file_path
=
calibration_dir
+
self
.
_generate_output_file_name
(
vanadium_path
,
ceria_path
,
instrument
,
bank
=
"
north
"
)
[
0
]
vanadium_path
,
ceria_path
,
instrument
,
bank
=
"
north
"
)
write_ENGINX_GSAS_iparam_file
(
file_path
,
[
difc
[
0
]],
[
tzero
[
0
]],
write_ENGINX_GSAS_iparam_file
(
file_path
,
[
difc
[
0
]],
[
tzero
[
0
]],
ceria_run
=
ceria_
no
,
ceria_run
=
ceria_
path
,
vanadium_run
=
vanadium_
no
,
vanadium_run
=
vanadium_
path
,
template_file
=
NORTH_BANK_TEMPLATE_FILE
,
template_file
=
NORTH_BANK_TEMPLATE_FILE
,
bank_names
=
[
"
North
"
])
bank_names
=
[
"
North
"
])
# South Bank
# South Bank
file_path
=
calibration_dir
+
self
.
_generate_output_file_name
(
file_path
=
calibration_dir
+
self
.
_generate_output_file_name
(
vanadium_path
,
ceria_path
,
instrument
,
bank
=
"
south
"
)
[
0
]
vanadium_path
,
ceria_path
,
instrument
,
bank
=
"
south
"
)
write_ENGINX_GSAS_iparam_file
(
file_path
,
[
difc
[
1
]],
[
tzero
[
1
]],
write_ENGINX_GSAS_iparam_file
(
file_path
,
[
difc
[
1
]],
[
tzero
[
1
]],
ceria_run
=
ceria_
no
,
ceria_run
=
ceria_
path
,
vanadium_run
=
vanadium_
no
,
vanadium_run
=
vanadium_
path
,
template_file
=
SOUTH_BANK_TEMPLATE_FILE
,
template_file
=
SOUTH_BANK_TEMPLATE_FILE
,
bank_names
=
[
"
South
"
])
bank_names
=
[
"
South
"
])
@staticmethod
def
get_info_from_file
(
file_path
):
# TODO: Find a way to reliably get the instrument from the file without using the filename.
instrument
=
file_path
.
split
(
"
/
"
)[
-
1
].
split
(
"
_
"
,
1
)[
0
]
# Get run numbers from file.
run_numbers
=
""
with
open
(
file_path
)
as
f
:
for
line
in
f
:
if
line
.
startswith
(
"
INS CALIB
"
):
run_numbers
=
line
break
if
run_numbers
==
""
:
raise
RuntimeError
(
"
Invalid file format.
"
)
words
=
run_numbers
.
split
()
ceria_no
=
words
[
2
]
# Run numbers are stored as the 3rd and 4th word in this line.
van_no
=
words
[
3
]
return
instrument
,
van_no
,
ceria_no
@staticmethod
@staticmethod
def
_generate_table_workspace_name
(
bank_num
):
def
_generate_table_workspace_name
(
bank_num
):
return
"
engggui_calibration_bank_
"
+
str
(
bank_num
+
1
)
return
"
engggui_calibration_bank_
"
+
str
(
bank_num
+
1
)
...
@@ -246,4 +277,4 @@ class CalibrationModel(object):
...
@@ -246,4 +277,4 @@ class CalibrationModel(object):
filename
=
filename
+
"
bank_South.prm
"
filename
=
filename
+
"
bank_South.prm
"
else
:
else
:
raise
ValueError
(
"
Invalid bank name entered
"
)
raise
ValueError
(
"
Invalid bank name entered
"
)
return
filename
,
vanadium_no
,
ceria_no
return
filename
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