# Path: condor/utils/log.py
# def log(logger, message, lvl, exception=None, rollback=1):
# def log_execution_time(logger):
#     def st_time(func):
#         def st_func(*args, **keyArgs):


    from urllib2 import urlopen
    from urllib.request import urlopen
    from StringIO import StringIO ## for Python 2
    from io import BytesIO as StringIO ## for Python 3
from .log import log_and_raise_error,log_warning,log_info,log_debug
import gzip
import numpy
import scipy.ndimage
import scipy.stats
import scipy.ndimage.measurements
import logging
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------------------------------
# General note:
# All variables are in SI units by default. Exceptions explicit by variable name.
# -----------------------------------------------------------------------------------------------------

from __future__ import print_function, absolute_import # Compatibility with python 2 and 3
try:
except ImportError:

try:
except ImportError:
    




logger = logging.getLogger(__name__)


def fetch_map(emd_id):
    url = "ftp://ftp.ebi.ac.uk/pub/databases/emdb/structures/EMD-%s/map/emd_%s.map.gz" % (str(emd_id),str(emd_id))
    log_debug(logger, "Downloading file for EMDID %s from URL %s" % (emd_id, url))
    filename = "./emd_%s.map" % str(emd_id)
    response = urlopen(url)
    compressedFile = StringIO()
    compressedFile.write(response.read())
    compressedFile.seek(0)
    decompressedFile = gzip.GzipFile(fileobj=compressedFile, mode='rb')

# Path: condor/utils/log.py
# def log(logger, message, lvl, exception=None, rollback=1):
# def log_execution_time(logger):
#     def st_time(func):
#         def st_func(*args, **keyArgs):


# Path: condor/utils/emdio.py
    from urllib2 import urlopen
    from urllib.request import urlopen
    from StringIO import StringIO ## for Python 2
    from io import BytesIO as StringIO ## for Python 3
from .log import log_and_raise_error,log_warning,log_info,log_debug
import gzip
import numpy
import scipy.ndimage
import scipy.stats
import scipy.ndimage.measurements
import logging

# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------------------------------
# General note:
# All variables are in SI units by default. Exceptions explicit by variable name.
# -----------------------------------------------------------------------------------------------------

from __future__ import print_function, absolute_import # Compatibility with python 2 and 3
try:
except ImportError:

try:
except ImportError:
    




logger = logging.getLogger(__name__)


def fetch_map(emd_id):
    url = "ftp://ftp.ebi.ac.uk/pub/databases/emdb/structures/EMD-%s/map/emd_%s.map.gz" % (str(emd_id),str(emd_id))
    log_debug(logger, "Downloading file for EMDID %s from URL %s" % (emd_id, url))
    filename = "./emd_%s.map" % str(emd_id)
    response = urlopen(url)
    compressedFile = StringIO()
    compressedFile.write(response.read())
    compressedFile.seek(0)
    decompressedFile = gzip.GzipFile(fileobj=compressedFile, mode='rb')

    log_debug(logger, "Download of %s ended." % (filename))