Commit f6101b4b authored by Alexander Dornheim's avatar Alexander Dornheim
Browse files

Implemented chentral function to download input data GetData.getData for...

Implemented chentral function to download input data GetData.getData for Phase, CT and Ptychography. Added comments to the GetData module. All functions are now in GetData.py.
JWST_dataprocessor is using the central getData function, other data processors not yet.
parent 4dcf492f
......@@ -28,29 +28,11 @@ from numpy.fft import fftshift
import proxtoolbox.Utilities as Utilities
#for loading data
from pathlib import Path
import proxtoolbox.Utilities.GetData as GetData
import urllib.request
import tarfile
def JWST_data_processor(config):
my_file = Path("../InputData/Phase/pupil.pmod")
if not(my_file.is_file()):
print("Phase input data is missing.")
if GetData.query_yes_no("Do you want to download the phase input data?"):
urllib.request.urlretrieve(" http://vaopt.math.uni-goettingen.de/data/Phase.tar.gz","../InputData/Phase.tar.gz", reporthook=GetData.dlProgress)
print("\nExtracting data...")
tar = tarfile.open("../InputData/Phase.tar.gz", "r:gz")
tar.extractall("../InputData/Phase")
tar.close()
if not(my_file.is_file()):
print('***************************************************************************************')
print('* Input data still missing. Please try automatic download again or manually download *')
print('* http://vaopt.math.uni-goettingen.de/data/Phase.tar.gz *')
print('* Save and unpack the Phase.tar.gz datafile in the *')
print('* ProxMatlab/InputData subdirectory *')
print('***************************************************************************************')
GetData.getData('Phase')
#moved here from JWST_in since if statements not possible in dictonary
if 'distance' in config:
......
from pathlib import Path
import sys
import urllib.request
import tarfile
#shows progress of download
def dlProgress(counter, blocksize, size):
p = counter*blocksize*100.0/size
sys.stdout.write("\rProgress: %d%%" % p)
sys.stdout.flush()
#function to ask permission for donwload from user
def query_yes_no(question):
choices = "[y/n] "
valid_answer = {'y':True, 'ye':True, 'yes':True, 'n':False, 'ne':False}
while True:
sys.stdout.write(question + choices)
answer = input().lower()
if answer in valid_answer:
return valid_answer[answer]
else:
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
def getData(problemFamily):
if problemFamily == 'Phase':
my_file = Path("../InputData/Phase/pupil.pmod")
elif problemFamily == 'CT':
my_file = Path("../InputData/CT/ART_SheppLogan.mat")
elif problemFamily == 'Ptychography':
my_file = Path("../InputData/Ptychography/gaenseliesel.png")
else:
print("Invalid input in GetData.GetData. problemFamily has to be Phase, CT or Ptychography")
return -1
if not(my_file.is_file()):
print(problemFamily + " input data is missing.")
if query_yes_no("Do you want to download the " + problemFamily + " input data?"):
urllib.request.urlretrieve(" http://vaopt.math.uni-goettingen.de/data/" + problemFamily + ".tar.gz","../InputData/" + problemFamily + ".tar.gz", reporthook=dlProgress)
print("\nExtracting data...")
tar = tarfile.open("../InputData/" + problemFamily + ".tar.gz", "r:gz")
tar.extractall("../InputData/" + problemFamily)
tar.close()
if not(my_file.is_file()):
print('***************************************************************************************')
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('* Save and unpack the ' + problemFamily + '.tar.gz datafile in the *')
print('* ProxMatlab/InputData subdirectory *')
print('***************************************************************************************')
"""
The "Utilities.GetData"-module contains various ...
The "Utilities.GetData"-module contains functions to download the InputData for the example problems
"""
from .query_yes_no import *
from .dlProgress import *
from .GetData import *
__all__ = ["dlProgress", "query_yes_no"]
__all__ = ["dlProgress", "query_yes_no", "getData"]
import sys
def dlProgress(counter, blocksize, size):
p = counter*blocksize*100.0/size
sys.stdout.write("\rProgress: %d%%" % p)
sys.stdout.flush()
import sys
def query_yes_no(question):
choices = "[y/n] "
valid_answer = {'y':True, 'ye':True, 'yes':True, 'n':False, 'ne':False}
while True:
sys.stdout.write(question + choices)
answer = input().lower()
if answer in valid_answer:
return valid_answer[answer]
else:
sys.stdout.write("Please respond with 'yes' or 'no'. \n")
Supports Markdown
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