Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
David Bold
IR_data_access
Commits
eeca580b
Commit
eeca580b
authored
Apr 09, 2019
by
Holger Niemann
Browse files
Update 3.2.2: small bugfixes to catch timeouts, needed for the auto scripts
parent
58084775
Changes
1
Hide whitespace changes
Inline
Side-by-side
downloadversionIRdata.py
View file @
eeca580b
...
...
@@ -4,7 +4,7 @@ Created on Wed Oct 25 15:51:46 2017
updated on Tue Aug 21 10:20:00 2018
last update on Fr Nov 23 15:37:00 2018
Version: 3.2.
1
Version: 3.2.
2
(Numbering: #of big changes(OP1.2a download V1, OP1.2b download V2, heatflux V3) . #of updates to add functionalities . #number of updates for bug fixes )
@author: holn
"""
...
...
@@ -76,6 +76,8 @@ def get_latest_version(stream,project="W7X",Test=False,t_from=None,t_to=None,pro
except
urllib
.
error
.
HTTPError
as
ex
:
msg
=
ex
.
read
()
raise
RuntimeError
(
msg
)
except
Exception
as
E
:
raise
RuntimeError
(
E
)
else
:
response
.
close
()
# detect unversioned or non-existing stream
...
...
@@ -116,34 +118,16 @@ def read_program(timestamp_start,timestamp_end=0,tol=60):
print
(
'read_program: Error opening URL'
)
print
(
e
)
return
False
,
0
except
Exception
as
e
:
print
(
'read_program: Error opening URL'
,
e
)
return
False
,
0
else
:
prog_string
=
prog_raw
.
decode
(
encoding
=
'UTF-8'
)
prog_list
=
json
.
loads
(
prog_string
)
pl
=
prog_list
[
'programs'
][
0
]
return
True
,
pl
def
read_restdb_old
(
request_url
):
"""
Reads JSON data from W7-X REST API
Returns:
valid: access ok
t: numpy-array of time
signal: numpy-array of requested signals
by H. Thomsen
"""
try
:
res
=
urllib
.
request
.
urlopen
(
request_url
)
except
urllib
.
error
.
URLError
as
e
:
print
(
'read_restdb_old: Error '
,
e
)
return
False
,
0
,
-
1
else
:
signal_raw
=
res
.
read
()
res
.
close
()
signal_string
=
signal_raw
.
decode
(
encoding
=
'UTF-8'
)
signal_list
=
json
.
loads
(
signal_string
)
signal0
=
np
.
array
(
signal_list
[
'values'
])
t
=
np
.
array
(
signal_list
[
'dimensions'
])
return
True
,
t
,
signal0
def
download_LUT
(
port
,
time
,
exposure
=
0
,
emissivity
=
0
,
camera_filter
=
0
,
version
=
0
,
verbose
=
0
):
"""
...
...
@@ -239,6 +223,9 @@ def download_NUC_by_times(port,starttime,stoptime,exposure,version=0):
except
urllib
.
error
.
URLError
as
e
:
print
(
'download_NUC_by_times: Error! '
,
e
)
goon
=
False
except
Exception
as
e
:
print
(
'download_NUC_by_times: Error! '
,
e
)
goon
=
False
if
goon
:
n
=
0
nuctimes
=
[
0
]
...
...
@@ -450,6 +437,9 @@ def download_hot_cold_reference_by_times(port,exposure,starttime=150390720000000
except
urllib
.
error
.
URLError
as
e
:
print
(
'download_hot_cold_reference_by_times: Error! '
,
e
)
goon
=
False
except
Exception
as
e
:
print
(
'download_hot_cold_reference_by_times: Error! '
,
e
)
goon
=
False
if
goon
:
COLDtime
=
0
HOTtime
=
0
...
...
@@ -509,6 +499,9 @@ def download_background_by_times(port,starttime,stoptime,exposure,camera_filter=
except
urllib
.
error
.
URLError
as
e
:
print
(
'download_background_by_times: Error! '
,
e
)
goon
=
False
except
Exception
as
e
:
print
(
'download_background_by_times: Error! '
,
e
)
goon
=
False
if
goon
:
n
=
0
backtimes
=
[
0
]
...
...
@@ -630,6 +623,8 @@ def download_images_by_times(larchivepath,starttime,stoptime,version=0,intervalS
success
=
True
except
urllib
.
error
.
URLError
as
e
:
print
(
'download_images_by_times: Error in sub-interval {0}! {1}'
.
format
(
i
,
e
))
except
Exception
as
e
:
print
(
'download_images_by_times: Error in sub-interval {0}! {1}'
.
format
(
i
,
e
))
return
success
,
time
,
allimages
else
:
try
:
...
...
@@ -646,6 +641,9 @@ def download_images_by_times(larchivepath,starttime,stoptime,version=0,intervalS
except
urllib
.
error
.
URLError
as
e
:
print
(
'download_images_by_times: Error! '
,
e
)
return
False
,
0
,
-
1
except
Exception
as
e
:
print
(
'download_images_by_times: Error! '
,
e
)
return
False
,
0
,
-
1
if
fastDL
:
def
download_raw_images_by_program_via_png
(
port
,
program
,
time_window
=
0
,
version
=
0
,
threads
=
1
,
verbose
=
0
):
...
...
@@ -1113,6 +1111,9 @@ def download_last_raw_image_by_time(larchivepath,starttime,stoptime,version=0):
except
urllib
.
error
.
URLError
as
e
:
print
(
'download_last_raw_image_by_time: Error querrying {0}
\n
{1}'
.
format
(
url
,
e
))
return
False
,
[
-
1
]
except
Exception
as
e
:
print
(
'download_last_raw_image_by_time: Error querrying {0}
\n
{1}'
.
format
(
url
,
e
))
return
False
,
[
-
1
]
def
download_raw_parlog_by_program
(
port
,
program
,
version
=
0
):
"""
...
...
@@ -1144,6 +1145,9 @@ def download_raw_parlog_by_times(port,starttime,stoptime,version=0):
except
urllib
.
error
.
URLError
as
e
:
print
(
'download_raw_parlog_by_times: Error! '
,
e
)
goon
=
False
except
Exception
as
E
:
print
(
'download_raw_parlog_by_times: Error! '
,
E
)
goon
=
False
if
goon
:
return
True
,
signal_list
[
'dimensions'
],
signal_list
[
'values'
][
0
][
'meta-data'
]
...
...
@@ -1178,6 +1182,9 @@ def get_INFRATEC_filter_by_times(starttime,stoptime,port=50,version=0):
except
urllib
.
error
.
URLError
as
e
:
print
(
'get_INFRATEC_filter_by_times: Error! '
,
e
)
goon
=
False
except
Exception
as
E
:
print
(
'get_INFRATEC_filter_by_times: Error! '
,
E
)
goon
=
False
if
goon
:
return
True
,
signal_list
[
'dimensions'
],
signal_list
[
'values'
][
0
][
'meta-data'
][
'filter'
]
else
:
...
...
@@ -2714,6 +2721,9 @@ def download_heatflux_scene_model_reference(port,timepoint=None,program=None,ver
except
urllib
.
error
.
URLError
as
e
:
print
(
'download_heatflux_scene_model_reference: Error! '
,
e
,
larchivepath_par
+
"/_signal.json?from="
+
str
(
timepoint
)
+
"&upto="
+
str
(
timepoint
))
goon
=
False
except
Exception
as
E
:
print
(
'download_heatflux_scene_model_reference: Error! '
,
E
)
goon
=
False
if
goon
:
timepoint
=
signal_list
[
'values'
][
0
]
exist
,
time
,
frames
=
download_images_by_times
(
larchivepath
,
starttime
=
timepoint
-
10
,
stoptime
=
int
(
timepoint
+
1e8
),
version
=
version
,
verbose
=
verbose
-
1
)
...
...
@@ -3180,10 +3190,36 @@ def download_scene_model(port,program=None,timepoint=None,version=0,verbose=0):
#%% general download functions
"""
the following functions are copied from W7xrest.read_restdb to remove this dependency
the following functions are copied from W7xrest.read_restdb to remove this dependency
and are edit to fit into the other functions
@author: thomsen
"""
def
read_restdb_old
(
request_url
):
"""
Reads JSON data from W7-X REST API
Returns:
valid: access ok
t: numpy-array of time
signal: numpy-array of requested signals
by H. Thomsen
"""
try
:
res
=
urllib
.
request
.
urlopen
(
request_url
)
except
urllib
.
error
.
URLError
as
e
:
print
(
'read_restdb_old: Error '
,
e
)
return
False
,
0
,
-
1
except
Exception
as
e
:
print
(
'read_restdb_old: Error '
,
e
)
return
False
,
0
,
-
1
else
:
signal_raw
=
res
.
read
()
res
.
close
()
signal_string
=
signal_raw
.
decode
(
encoding
=
'UTF-8'
)
signal_list
=
json
.
loads
(
signal_string
)
signal0
=
np
.
array
(
signal_list
[
'values'
])
t
=
np
.
array
(
signal_list
[
'dimensions'
])
return
True
,
t
,
signal0
def
read_restdb
(
request_url
):
"""
Reads JSON data from W7-X REST API
...
...
@@ -3207,6 +3243,9 @@ def read_restdb(request_url):
#print('The server couldn\'t fulfill the request.')
#print('Error code: ', e.code)
return
False
,
[
0
],
[
-
1
]
except
Exception
as
E
:
print
(
'read_restdb: Error! '
,
E
)
return
False
,
[
0
],
[
-
1
]
else
:
# res = urllib.request.urlopen(request_url)
# signal_raw=res.read()
...
...
@@ -3265,7 +3304,10 @@ def get_program_from_PID(instring):
prog_list
=
json
.
loads
(
res
.
read
().
decode
(
'utf-8'
))
res
.
close
()
except
urllib
.
error
.
URLError
as
e
:
print
(
'get_program_from_PID: Error opening URL'
)
print
(
'get_program_from_PID: Error opening URL'
,
e
)
return
False
,
0
except
Exception
as
E
:
print
(
'get_program_from_PID: ERROR appeared'
,
E
)
return
False
,
0
else
:
pl
=
prog_list
[
'programs'
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment