Skip to content

Commit 81bc73f

Browse files
committed
Removed some debug output
1 parent 8f68ef9 commit 81bc73f

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

srtm/data.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def __init__(self, srtm1_files, srtm3_files, files_directory,
5858
def get_elevation(self, latitude, longitude, approximate=None):
5959
geo_elevation_file = self.get_file(float(latitude), float(longitude))
6060

61-
mod_logging.debug('File for ({0}, {1}) -> {2}'.format(
62-
latitude, longitude, geo_elevation_file))
61+
#mod_logging.debug('File for ({0}, {1}) -> {2}'.format(
62+
# latitude, longitude, geo_elevation_file))
6363

6464
if not geo_elevation_file:
6565
return None
@@ -91,13 +91,15 @@ def get_file(self, latitude, longitude):
9191

9292
def retrieve_or_load_file_data(self, file_name):
9393
data_file_name = '{0}/{1}'.format(self.files_directory, file_name)
94+
zip_data_file_name = '{0}/{1}.zip'.format(self.files_directory, file_name)
9495

9596
if mod_path.exists(data_file_name):
96-
f = open(data_file_name)
97-
data = f.read()
98-
f.close()
99-
100-
return data
97+
with open(data_file_name) as f:
98+
return f.read()
99+
elif mod_path.exists(zip_data_file_name):
100+
with open(zip_data_file_name) as f:
101+
data = f.read()
102+
return mod_utils.unzip(data)
101103

102104
url = None
103105

@@ -107,13 +109,13 @@ def retrieve_or_load_file_data(self, file_name):
107109
url = self.srtm3_files[file_name]
108110

109111
if not url:
110-
mod_logging.error('No file found: {0}'.format(file_name))
112+
#mod_logging.error('No file found: {0}'.format(file_name))
111113
return None
112114

113115
f = mod_urllib.urlopen(url)
114116
mod_logging.info('Retrieving {0}'.format(url))
115117
data = f.read()
116-
mod_logging.info('Retrieved {0}'.format(url))
118+
mod_logging.info('Retrieved {0} ({1} bytes)'.format(url, len(data)))
117119
f.close()
118120

119121
if not data:
@@ -126,13 +128,14 @@ def retrieve_or_load_file_data(self, file_name):
126128
data = self._reduce_file(data, file_name)
127129
data = mod_utils.zip(data, file_name)
128130

129-
with open(data_file_name, 'w') as f:
130-
if self.leave_zipped:
131-
f = open(data_file_name + '.zip', 'w')
132-
else:
131+
if self.leave_zipped:
132+
with open(data_file_name + '.zip', 'w') as f:
133+
f.write(data)
134+
data = mod_utils.unzip(data)
135+
else:
136+
with open(data_file_name, 'w') as f:
133137
data = mod_utils.unzip(data)
134-
f = open(data_file_name, 'w')
135-
f.write(data)
138+
f.write(data)
136139

137140
return data
138141

@@ -171,7 +174,7 @@ def get_file_name(self, latitude, longitude):
171174
east_west, str(int(abs(mod_math.floor(longitude)))).zfill(3))
172175

173176
if not self.srtm1_files.has_key(file_name) and not self.srtm3_files.has_key(file_name):
174-
mod_logging.debug('No file found for ({0}, {1}) (file_name: {2})'.format(latitude, longitude, file_name))
177+
#mod_logging.debug('No file found for ({0}, {1}) (file_name: {2})'.format(latitude, longitude, file_name))
175178
return None
176179

177180
return file_name
@@ -327,7 +330,7 @@ def get_elevation_from_row_and_column(self, row, column):
327330
i = row * (self.square_side) + column
328331
assert i < len(self.data) - 1
329332

330-
mod_logging.debug('{0}, {1} -> {2}'.format(row, column, i))
333+
#mod_logging.debug('{0}, {1} -> {2}'.format(row, column, i))
331334

332335
byte_1 = ord(self.data[i * 2])
333336
byte_2 = ord(self.data[i * 2 + 1])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy