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
78f094ba
Commit
78f094ba
authored
10 years ago
by
Marina Ganeva
Browse files
Options
Downloads
Patches
Plain Diff
parse_header added to DNS data loader
parent
f2b26872
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Mantid/Framework/PythonInterface/plugins/algorithms/dnsdata.py
+22
-13
22 additions, 13 deletions
...d/Framework/PythonInterface/plugins/algorithms/dnsdata.py
with
22 additions
and
13 deletions
Code/Mantid/Framework/PythonInterface/plugins/algorithms/dnsdata.py
+
22
−
13
View file @
78f094ba
import
os
,
sys
import
os
,
sys
,
re
import
numpy
as
np
import
numpy
as
np
import
datetime
import
datetime
...
@@ -71,21 +71,21 @@ class DNSdata:
...
@@ -71,21 +71,21 @@ class DNSdata:
# parse each block
# parse each block
# parse block 0 (header)
# parse block 0 (header)
# [TODO:] rewrite to get rid of dependence on parse
res
=
parse_header
(
blocks
[
0
])
res
=
parse
(
"
# DNS Data userid={userid},exp={exp_id},file={run_number},sample={sample_name}
"
,
blocks
[
0
])
#[TODO:]
#
[TODO:]
raise
e
xception
on the
wrong file format
#
if not res:
raise
E
xception
"
wrong file format
" else
#if not res
:
try
:
#
print "Wrong file format."
self
.
run_number
=
res
[
'
file
'
]
#
s
ys.exit()
s
elf
.
experiment_number
=
res
[
'
exp
'
]
self
.
run_number
=
res
[
'
run_number
'
]
self
.
sample_name
=
res
[
'
sample
'
]
self
.
experiment_number
=
res
[
'
exp_
id
'
]
self
.
userid
=
res
[
'
user
id
'
]
self
.
sample_name
=
res
[
'
sample_name
'
]
except
:
self
.
userid
=
res
[
'
userid
'
]
raise
ValueError
(
"
The file %s does not contain valid DNS data format.
"
%
filename
)
# parse block 1 (general information)
# parse block 1 (general information)
b1splitted
=
map
(
str
.
strip
,
blocks
[
1
].
split
(
'
#
'
))
b1splitted
=
map
(
str
.
strip
,
blocks
[
1
].
split
(
'
#
'
))
b1rest
=
[
el
for
el
in
b1splitted
]
# otherwise unexpected behaviour due to the removed lines
b1rest
=
[
el
for
el
in
b1splitted
]
# otherwise unexpected behaviour due to the removed lines
#[TODO:] get rid of parse
for
line
in
b1splitted
:
for
line
in
b1splitted
:
res
=
parse
(
'
User: {user_name}
'
,
line
)
res
=
parse
(
'
User: {user_name}
'
,
line
)
if
res
:
if
res
:
...
@@ -183,7 +183,16 @@ class DNSdata:
...
@@ -183,7 +183,16 @@ class DNSdata:
self
.
start_time
=
datetime
.
datetime
.
strptime
(
b7splitted
[
5
],
sinfmt
).
strftime
(
outfmt
)
self
.
start_time
=
datetime
.
datetime
.
strptime
(
b7splitted
[
5
],
sinfmt
).
strftime
(
outfmt
)
self
.
end_time
=
datetime
.
datetime
.
strptime
(
b7splitted
[
6
],
einfmt
).
strftime
(
outfmt
)
self
.
end_time
=
datetime
.
datetime
.
strptime
(
b7splitted
[
6
],
einfmt
).
strftime
(
outfmt
)
def
parse_header
(
h
):
"""
parses the header string and returns the parsed dictionary
"""
d
=
{}
regexp
=
re
.
compile
(
"
(\w+)=(\w+)
"
)
result
=
regexp
.
finditer
(
h
)
for
r
in
result
:
d
[
r
.
groups
()[
0
]]
=
r
.
groups
()[
1
]
return
d
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
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