Commit e573f57d authored by jansen31's avatar jansen31
Browse files

orbital tomography quickfix

parent 9b69f509
...@@ -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("\rProgress: %d%%" % p) sys.stdout.write("\rProgress: %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("\nExtracting data...") print("\nExtracting 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("\nExtracting data...") print("\nExtracting 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('***************************************************************************************')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment