Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
nam
ProxPython
Commits
e573f57d
Commit
e573f57d
authored
Oct 01, 2021
by
jansen31
Browse files
orbital tomography quickfix
parent
9b69f509
Changes
1
Hide whitespace changes
Inline
Side-by-side
proxtoolbox/utils/GetData/GetData.py
View file @
e573f57d
...
@@ -7,68 +7,70 @@ import shutil
...
@@ -7,68 +7,70 @@ import shutil
datadir
=
Path
(
__file__
).
parent
.
parent
.
parent
.
parent
/
'InputData'
datadir
=
Path
(
__file__
).
parent
.
parent
.
parent
.
parent
/
'InputData'
#shows progress of download
# shows progress of download
def
dlProgress
(
counter
,
blocksize
,
size
):
def
dlProgress
(
counter
,
blocksize
,
size
):
p
=
counter
*
blocksize
*
100.0
/
size
p
=
counter
*
blocksize
*
100.0
/
size
sys
.
stdout
.
write
(
"
\r
Progress: %d%%"
%
p
)
sys
.
stdout
.
write
(
"
\r
Progress: %d%%"
%
p
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
#function to ask permission for donwload from user
# function to ask permission for donwload from user
def
query_yes_no
(
question
):
def
query_yes_no
(
question
):
choices
=
"[y/n] "
choices
=
"[y/n] "
valid_answer
=
{
'y'
:
True
,
'ye'
:
True
,
'yes'
:
True
,
'n'
:
False
,
'ne'
:
False
}
valid_answer
=
{
'y'
:
True
,
'ye'
:
True
,
'yes'
:
True
,
'n'
:
False
,
'ne'
:
False
,
'no'
:
False
}
while
True
:
while
True
:
sys
.
stdout
.
write
(
question
+
choices
)
sys
.
stdout
.
write
(
question
+
choices
)
answer
=
input
().
lower
()
answer
=
input
().
lower
()
if
answer
in
valid_answer
:
if
answer
in
valid_answer
:
return
valid_answer
[
answer
]
return
valid_answer
[
answer
]
else
:
else
:
sys
.
stdout
.
write
(
"Please respond with 'yes' or 'no'.
\n
"
)
sys
.
stdout
.
write
(
"Please respond with 'yes' or 'no'.
\n
"
)
#downloads the input data to the InputData folder. problemFamily has to be either Phase, CT or Ptychography
# downloads the input data to the InputData folder. problemFamily has to be either Phase, CT or Ptychography
def
getData
(
problemFamily
):
def
getData
(
problemFamily
):
if
problemFamily
==
'Phase'
:
if
problemFamily
==
'Phase'
:
my_file
=
datadir
/
'Phase'
/
'pupil.pmod'
my_file
=
datadir
/
'Phase'
/
'pupil.pmod'
elif
problemFamily
==
'CT'
:
elif
problemFamily
==
'CT'
:
my_file
=
datadir
/
'CT'
/
'ART_SheppLogan.mat'
my_file
=
datadir
/
'CT'
/
'ART_SheppLogan.mat'
elif
problemFamily
==
'Ptychography'
:
elif
problemFamily
==
'Ptychography'
:
my_file
=
datadir
/
'Ptychography'
/
'gaenseliesel.png'
my_file
=
datadir
/
'Ptychography'
/
'gaenseliesel.png'
elif
problemFamily
==
'OrbitalTomog'
:
elif
problemFamily
==
'OrbitalTomog'
:
errMsg
=
'OrbitalTomog downloader is yet a work in progress'
my_file
=
datadir
/
'OrbitalTomog'
/
'coronene_homo1.tif'
raise
IOError
(
errMsg
)
elif
problemFamily
==
'Elser'
:
elif
problemFamily
==
'Elser'
:
my_file
=
datadir
/
'Elser'
/
'data100E'
my_file
=
datadir
/
'Elser'
/
'data100E'
else
:
else
:
print
(
"Invalid input in GetData.GetData. problemFamily has to be Phase, CT or Ptychography"
)
print
(
"Invalid input in GetData.GetData. problemFamily has to be Phase, CT or Ptychography"
)
return
-
1
return
-
1
if
not
(
my_file
.
is_file
()):
if
not
(
my_file
.
is_file
()):
print
(
problemFamily
+
" input data is missing."
)
print
(
problemFamily
+
" input data is missing."
)
if
query_yes_no
(
"Do you want to download the "
+
problemFamily
+
" input data?"
):
if
query_yes_no
(
"Do you want to download the "
+
problemFamily
+
" input data?"
):
if
problemFamily
==
'Elser'
:
if
problemFamily
==
'Elser'
:
link
=
'https://github.com/veitelser/phase-retrieval-benchmarks/archive/master.zip'
link
=
'https://github.com/veitelser/phase-retrieval-benchmarks/archive/master.zip'
urllib
.
request
.
urlretrieve
(
link
,
datadir
/
(
problemFamily
+
'.zip'
),
reporthook
=
dlProgress
)
urllib
.
request
.
urlretrieve
(
link
,
datadir
/
(
problemFamily
+
'.zip'
),
reporthook
=
dlProgress
)
print
(
"
\n
Extracting data..."
)
print
(
"
\n
Extracting data..."
)
with
ZipFile
(
datadir
/
(
problemFamily
+
'.zip'
),
'r'
)
as
zipObj
:
with
ZipFile
(
datadir
/
(
problemFamily
+
'.zip'
),
'r'
)
as
zipObj
:
names
=
zipObj
.
namelist
()
names
=
zipObj
.
namelist
()
for
name
in
names
:
for
name
in
names
:
if
name
.
startswith
(
'phase-retrieval-benchmarks-master/data/data'
):
if
name
.
startswith
(
'phase-retrieval-benchmarks-master/data/data'
):
zipObj
.
extract
(
name
,
datadir
/
problemFamily
)
zipObj
.
extract
(
name
,
datadir
/
problemFamily
)
name_end
=
name
.
replace
(
'phase-retrieval-benchmarks-master/data/'
,
''
)
name_end
=
name
.
replace
(
'phase-retrieval-benchmarks-master/data/'
,
''
)
shutil
.
move
(
datadir
/
problemFamily
/
name
,
datadir
/
problemFamily
/
name_end
)
shutil
.
move
(
datadir
/
problemFamily
/
name
,
datadir
/
problemFamily
/
name_end
)
shutil
.
rmtree
(
datadir
/
problemFamily
/
'phase-retrieval-benchmarks-master/'
)
shutil
.
rmtree
(
datadir
/
problemFamily
/
'phase-retrieval-benchmarks-master/'
)
else
:
else
:
link
=
" http://vaopt.math.uni-goettingen.de/data/"
+
problemFamily
+
".tar.gz"
link
=
" http://vaopt.math.uni-goettingen.de/data/"
+
problemFamily
+
".tar.gz"
urllib
.
request
.
urlretrieve
(
link
,
datadir
/
(
problemFamily
+
'.tar.gz'
),
reporthook
=
dlProgress
)
urllib
.
request
.
urlretrieve
(
link
,
datadir
/
(
problemFamily
+
'.tar.gz'
),
reporthook
=
dlProgress
)
print
(
"
\n
Extracting data..."
)
print
(
"
\n
Extracting data..."
)
tar
=
tarfile
.
open
(
datadir
/
(
problemFamily
+
'.tar.gz'
),
"r:gz"
)
tar
=
tarfile
.
open
(
datadir
/
(
problemFamily
+
'.tar.gz'
),
"r:gz"
)
tar
.
extractall
(
datadir
/
problemFamily
)
tar
.
extractall
(
datadir
/
problemFamily
)
tar
.
close
()
tar
.
close
()
if
not
(
my_file
.
is_file
()):
if
not
(
my_file
.
is_file
()):
print
(
'***************************************************************************************'
)
print
(
'***************************************************************************************'
)
print
(
'* Input data still missing. Please try automatic download again or manually download *'
)
print
(
'* Input data still missing. Please try automatic download again or manually download *'
)
print
(
'* http://vaopt.math.uni-goettingen.de/data/'
+
problemFamily
+
'.tar.gz *'
)
print
(
'* http://vaopt.math.uni-goettingen.de/data/'
+
problemFamily
+
'.tar.gz *'
)
print
(
'* Save and unpack the '
+
problemFamily
+
'.tar.gz datafile in the *'
)
print
(
'* Save and unpack the '
+
problemFamily
+
'.tar.gz datafile in the *'
)
print
(
'* ProxMatlab/InputData subdirectory *'
)
print
(
'* ProxMatlab/InputData subdirectory *'
)
print
(
'***************************************************************************************'
)
print
(
'***************************************************************************************'
)
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