Skip to content

Commit

Permalink
Brought resolution metadata back to (resx, resy) but kept keyword res…
Browse files Browse the repository at this point in the history
…olution as a single number. Still unsure what the best way is. All 92 tests pass an app works.
  • Loading branch information
uniomni committed Oct 28, 2011
1 parent 2cc6243 commit ec0d729
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
21 changes: 12 additions & 9 deletions impact/storage/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ def get_metadata_from_layer(layer):
geotransform = extract_geotransform(layer)
metadata['geotransform'] = geotransform
metadata['resolution'] = geotransform2resolution(geotransform,
isotropic=True)
# Get both resx
# and resy
isotropic=False)
else:
metadata['resolution'] = None
metadata['geotransform'] = None
Expand All @@ -249,21 +251,22 @@ def get_metadata_from_layer(layer):
else:
for keyword in layer.keywords:
if keyword is not None:
# FIXME (Ole): Why would this be None sometimes?

for keyword_string in keyword.split(','):
if ':' in keyword_string:
key, value = keyword_string.strip().split(':')
keyword_dict[key] = value
else:
keyword_dict[keyword_string] = None

# Add resolution (as a string) so that layer "remembers"
# its original resolution
keyword_dict['resolution'] = str(metadata['resolution'])
# Add resolution (as a string with one element) so that layer "remembers"
# its original resolution,
# FIXME (Ole): What is the best way of collapsing 2D resolution to
# one number - resx and resy are not always identical!
if metadata['resolution'] is not None:
keyword_dict['resolution'] = str(metadata['resolution'][0])

# FIXME (Ole): This does not cause an Exception, and nothing is written to the log file
# See issue #170
# FIXME (Ole): The statement below does not raise an Exception,
# and nothing is written to the log file. See issue #170
#raise Exception('weird')

# Record all keywords as part of the metadata and return
Expand Down Expand Up @@ -549,7 +552,7 @@ def download(server_url, layer_name, bbox, resolution=None):
if resolution is None:
# Get native resolution and use that
resolution = layer_metadata['resolution']
resolution = (resolution, resolution) #FIXME (Ole): Make nicer
#resolution = (resolution, resolution) #FIXME (Ole): Make nicer

# Download raster using specified bounding box and resolution
template = WCS_TEMPLATE
Expand Down
9 changes: 5 additions & 4 deletions impact/storage/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ def write_keywords(keywords, filename):
'I got %s with type %s' % (k, str(type(k))[1:-1]))
assert isinstance(k, basestring), msg

msg = ('Keyword value must be a string. '
'For key %s, I got %s with type %s' % (k, v, str(type(v))[1:-1]))
assert isinstance(v, basestring), msg

key = k.strip()

msg = ('Key in keywords dictionary must not contain the ":" '
Expand All @@ -194,6 +190,11 @@ def write_keywords(keywords, filename):
if v is None:
fid.write('%s\n' % key)
else:
msg = ('Keyword value must be a string. '
'For key %s, I got %s with type %s'
% (k, v, str(type(v))[1:-1]))
assert isinstance(v, basestring), msg

val = v.strip()

msg = ('Value in keywords dictionary must be a string or None. '
Expand Down
16 changes: 11 additions & 5 deletions impact/tests/test_geonode_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,16 +867,21 @@ def test_keywords_download(self):
geo_keywords = metadata['keywords']
msg = ('Uploaded keywords were not as expected: I got %s '
'but expected %s' % (geo_keywords, ref_keywords))
assert ref_keywords == geo_keywords, msg
for kw in ref_keywords:
# Check that all keywords were uploaded
# It is OK for new automatic keywords to have appeared
# (e.g. resolution)
assert kw in geo_keywords, msg
assert ref_keywords[kw] == geo_keywords[kw], msg

# Download data
bbox = get_bounding_box_string(paths[i])
H = download(INTERNAL_SERVER_URL, layer_name, bbox)

dwn_keywords = H.get_keywords()
msg = ('Downloaded keywords were not as expected: I got %s '
'but expected %s' % (dwn_keywords, ref_keywords))
assert ref_keywords == dwn_keywords, msg
'but expected %s' % (dwn_keywords, geo_keywords))
assert geo_keywords == dwn_keywords, msg

# Check that the layer and its .keyword file is there.
msg = 'Downloaded layer %s was not found' % H.filename
Expand All @@ -888,10 +893,11 @@ def test_keywords_download(self):

# Check that keywords are OK when reading downloaded file
L = read_layer(H.filename)
read_keywords = L.get_keywords()
msg = ('Keywords in downloaded file %s were not as expected: '
'I got %s but expected %s'
% (kw_filename, dwn_keywords, ref_keywords))
assert L.get_keywords() == ref_keywords, msg
% (kw_filename, read_keywords, geo_keywords))
assert read_keywords == geo_keywords, msg



Expand Down
6 changes: 5 additions & 1 deletion impact/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ def calculate(request, save_output=save_to_geonode):
raster_resolution = None
else:
# Take the minimum
raster_resolution = min(haz_res, exp_res)
resx = min(haz_res[0], exp_res[0])
resy = min(haz_res[1], exp_res[1])

raster_resolution = (resx, resy)
#raster_resolution = min(haz_res, exp_res)

# New bounding box for data common to hazard, exposure and viewport
# Download only data within this intersection
Expand Down

0 comments on commit ec0d729

Please sign in to comment.