[Git][debian-gis-team/rasterio][upstream] New upstream version 1.0.5
Bas Couwenberg
gitlab at salsa.debian.org
Thu Sep 20 06:39:23 BST 2018
Bas Couwenberg pushed to branch upstream at Debian GIS Project / rasterio
Commits:
16d6e5a7 by Bas Couwenberg at 2018-09-20T05:17:45Z
New upstream version 1.0.5
- - - - -
16 changed files:
- CHANGES.txt
- Makefile
- rasterio/__init__.py
- rasterio/_env.pyx
- rasterio/_io.pyx
- rasterio/env.py
- rasterio/features.py
- rasterio/rio/main.py
- rasterio/session.py
- rasterio/vrt.py
- tests/data/red.tif
- tests/test_boundless_read.py
- tests/test_env.py
- tests/test_features.py
- tests/test_rio_info.py
- tests/test_session.py
Changes:
=====================================
CHANGES.txt
=====================================
@@ -1,6 +1,18 @@
Changes
=======
+1.0.5 (2018-09-19)
+------------------
+
+Bug fixes:
+
+- The fill value for boundless reads was ignored in Rasterio versions 1-1.0.4
+ but now applies (#1471).
+- An invalid shortcut has been eliminated a Rasterio now prroduces a proper
+ mask in the boundless masked read case (#1449).
+- Loss of a row or column in geometry_window() and mask() has been fixed
+ (#1472).
+
1.0.4 (2018-09-17)
------------------
=====================================
Makefile
=====================================
@@ -15,6 +15,9 @@ clean:
find . -name '__pycache__' -delete -print -o -name '*.pyc' -delete -print
touch rasterio/*.pyx
+sdist:
+ python setup.py sdist
+
test:
py.test --maxfail 1 -v --cov rasterio --cov-report html --pdb tests
@@ -22,4 +25,4 @@ docs:
cd docs && make apidocs && make html
doctest:
- py.test --doctest-modules rasterio --doctest-glob='*.rst' docs/*.rst
\ No newline at end of file
+ py.test --doctest-modules rasterio --doctest-glob='*.rst' docs/*.rst
=====================================
rasterio/__init__.py
=====================================
@@ -43,7 +43,7 @@ import rasterio.path
__all__ = ['band', 'open', 'pad', 'Env']
-__version__ = "1.0.4"
+__version__ = "1.0.5"
__gdal_version__ = gdal_version()
# Rasterio attaches NullHandler to the 'rasterio' logger and its
=====================================
rasterio/_env.pyx
=====================================
@@ -181,7 +181,6 @@ cdef class ConfigEnv(object):
while self.options:
key, val = self.options.popitem()
del_gdal_config(key)
- log.debug("Unset option %s in env %r", key, self)
def get_config_options(self):
return {k: get_gdal_config(k) for k in self.options}
=====================================
rasterio/_io.pyx
=====================================
@@ -375,7 +375,7 @@ cdef class DatasetReaderBase(DatasetBase):
else:
vrt_doc = _boundless_vrt_doc(
- self, nodata=ndv, width=max(self.width, window.width) + 1,
+ self, nodata=ndv, hidenodata=bool(fill_value), width=max(self.width, window.width) + 1,
height=max(self.height, window.height) + 1,
transform=self.window_transform(window)).decode('ascii')
@@ -390,12 +390,9 @@ cdef class DatasetReaderBase(DatasetBase):
None, resampling=resampling)
if masked:
- if all_valid:
- mask = np.ma.nomask
- else:
- mask = np.zeros(out.shape, 'uint8')
- mask = ~vrt._read(
- indexes, mask, Window(0, 0, window.width, window.height), None, masks=True).astype('bool')
+ mask = np.zeros(out.shape, 'uint8')
+ mask = ~vrt._read(
+ indexes, mask, Window(0, 0, window.width, window.height), None, masks=True).astype('bool')
kwds = {'mask': mask}
# Set a fill value only if the read bands share a
=====================================
rasterio/env.py
=====================================
@@ -3,6 +3,7 @@
import attr
from functools import wraps, total_ordering
import logging
+import os
import re
import threading
import warnings
@@ -15,7 +16,7 @@ from rasterio.dtypes import check_dtype
from rasterio.errors import (
EnvError, GDALVersionError, RasterioDeprecationWarning)
from rasterio.path import parse_path, UnparsedPath, ParsedPath
-from rasterio.session import Session, AWSSession
+from rasterio.session import Session, AWSSession, DummySession
from rasterio.transform import guard_transform
@@ -105,11 +106,8 @@ class Env(object):
"RASTERIO_ENV": True
}
- def __init__(
- self, session=None, aws_unsigned=False, aws_access_key_id=None,
- aws_secret_access_key=None, aws_session_token=None,
- region_name=None, profile_name=None, session_class=AWSSession,
- **options):
+ def __init__(self, session=None, aws_unsigned=False, profile_name=None,
+ session_class=AWSSession, **options):
"""Create a new GDAL/AWS environment.
Note: this class is a context manager. GDAL isn't configured
@@ -119,16 +117,8 @@ class Env(object):
----------
session : optional
A Session object.
- aws_unsigned : bool, optional (default: False)
- If True, requests will be unsigned.
- aws_access_key_id : str, optional
- An access key id, as per boto3.
- aws_secret_access_key : str, optional
- A secret access key, as per boto3.
- aws_session_token : str, optional
- A session token, as per boto3.
- region_name : str, optional
- A region name, as per boto3.
+ aws_unsigned : bool, optional
+ Do not sign cloud requests.
profile_name : str, optional
A shared credentials profile name, as per boto3.
session_class : Session, optional
@@ -165,6 +155,20 @@ class Env(object):
... print(src.profile)
"""
+ aws_access_key_id = options.pop('aws_access_key_id', None)
+ # Before 1.0, Rasterio only supported AWS. We will special
+ # case AWS in 1.0.x. TODO: warn deprecation in 1.1.
+ if aws_access_key_id:
+ warnings.warn(
+ "Passing abstract session keyword arguments is deprecated. "
+ "Pass a Rasterio AWSSession object instead.",
+ RasterioDeprecationWarning
+ )
+
+ aws_secret_access_key = options.pop('aws_secret_access_key', None)
+ aws_session_token = options.pop('aws_session_token', None)
+ region_name = options.pop('region_name', None)
+
if ('AWS_ACCESS_KEY_ID' in options or
'AWS_SECRET_ACCESS_KEY' in options):
raise EnvError(
@@ -182,14 +186,7 @@ class Env(object):
)
session = AWSSession(session=session)
self.session = session
- else:
- # Before 1.0, Rasterio only supported AWS. We will special
- # case AWS in 1.0.x. TODO: warn deprecation in 1.1.
- warnings.warn(
- "Passing abstract session keyword arguments is deprecated. "
- "Pass a Rasterio AWSSession object instead.",
- RasterioDeprecationWarning
- )
+ elif aws_access_key_id or profile_name or aws_unsigned:
self.session = AWSSession(
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
@@ -197,6 +194,10 @@ class Env(object):
region_name=region_name,
profile_name=profile_name,
aws_unsigned=aws_unsigned)
+ elif 'AWS_ACCESS_KEY_ID' in os.environ:
+ self.session = AWSSession()
+ else:
+ self.session = DummySession()
self.options = options.copy()
self.context_options = {}
@@ -272,7 +273,6 @@ class Env(object):
val = get_gdal_config(key, normalize=False)
if val is not None:
local._discovered_options[key] = val
- log.debug("Discovered option: %s=%s", key, val)
defenv(**self.options)
self.context_options = {}
@@ -299,8 +299,6 @@ class Env(object):
while local._discovered_options:
key, val = local._discovered_options.popitem()
set_gdal_config(key, val, normalize=False)
- log.debug(
- "Set discovered option back to: '%s=%s", key, val)
local._discovered_options = None
log.debug("Exited env context: %r", self)
@@ -337,7 +335,6 @@ def setenv(**options):
raise EnvError("No GDAL environment exists")
else:
local._env.update_config_options(**options)
- log.debug("Updated existing %r with options %r", local._env, options)
def hascreds():
@@ -402,7 +399,6 @@ def ensure_env_credentialled(f):
session = Session.from_path(None)
with env_ctor(session=session):
- log.debug("Credentialized: {!r}".format(getenv()))
return f(*args, **kwds)
return wrapper
=====================================
rasterio/features.py
=====================================
@@ -410,8 +410,10 @@ def geometry_window(dataset, shapes, pad_x=0, pad_y=0, north_up=True,
right, bottom = (right, bottom) * dataset.transform
window = dataset.window(left, bottom, right, top)
- window = window.round_offsets(op='floor', pixel_precision=pixel_precision)
- window = window.round_shape(op='ceil', pixel_precision=pixel_precision)
+ window_floored = window.round_offsets(op='floor', pixel_precision=pixel_precision)
+ w = math.ceil(window.width + window.col_off - window_floored.col_off)
+ h = math.ceil(window.height + window.row_off - window_floored.row_off)
+ window = Window(window_floored.col_off, window_floored.row_off, w, h)
# Make sure that window overlaps raster
raster_window = Window(0, 0, dataset.width, dataset.height)
=====================================
rasterio/rio/main.py
=====================================
@@ -91,11 +91,13 @@ def main_group(
ctx.obj = {}
ctx.obj["verbosity"] = verbosity
ctx.obj["aws_profile"] = aws_profile
- ctx.obj["env"] = rasterio.Env(
- session=AWSSession(
- profile_name=aws_profile,
- aws_unsigned=aws_no_sign_requests,
- requester_pays=aws_requester_pays,
- ),
- CPL_DEBUG=(verbosity > 2)
- )
+ envopts = {"CPL_DEBUG": (verbosity > 2)}
+ if aws_profile or aws_no_sign_requests:
+ ctx.obj["env"] = rasterio.Env(
+ session=AWSSession(
+ profile_name=aws_profile,
+ aws_unsigned=aws_no_sign_requests,
+ requester_pays=aws_requester_pays,
+ ), **envopts)
+ else:
+ ctx.obj["env"] = rasterio.Env(**envopts)
=====================================
rasterio/session.py
=====================================
@@ -146,15 +146,12 @@ class AWSSession(Session):
if session:
self._session = session
else:
- if not aws_access_key_id and not profile_name:
- self._session = boto3.Session()
- else:
- self._session = boto3.Session(
- aws_access_key_id=aws_access_key_id,
- aws_secret_access_key=aws_secret_access_key,
- aws_session_token=aws_session_token,
- region_name=region_name,
- profile_name=profile_name)
+ self._session = boto3.Session(
+ aws_access_key_id=aws_access_key_id,
+ aws_secret_access_key=aws_secret_access_key,
+ aws_session_token=aws_session_token,
+ region_name=region_name,
+ profile_name=profile_name)
self.requester_pays = requester_pays
self.unsigned = aws_unsigned
@@ -164,12 +161,13 @@ class AWSSession(Session):
def credentials(self):
"""The session credentials as a dict"""
creds = {}
- if self._creds.access_key: # pragma: no branch
- creds['aws_access_key_id'] = self._creds.access_key
- if self._creds.secret_key: # pragma: no branch
- creds['aws_secret_access_key'] = self._creds.secret_key
- if self._creds.token:
- creds['aws_session_token'] = self._creds.token
+ if self._creds:
+ if self._creds.access_key: # pragma: no branch
+ creds['aws_access_key_id'] = self._creds.access_key
+ if self._creds.secret_key: # pragma: no branch
+ creds['aws_secret_access_key'] = self._creds.secret_key
+ if self._creds.token:
+ creds['aws_session_token'] = self._creds.token
if self._session.region_name:
creds['aws_region'] = self._session.region_name
if self.requester_pays:
=====================================
rasterio/vrt.py
=====================================
@@ -69,7 +69,7 @@ class WarpedVRT(WarpedVRTReaderBase, WindowMethodsMixin,
self.stop()
-def _boundless_vrt_doc(src_dataset, nodata=None, width=None, height=None, transform=None):
+def _boundless_vrt_doc(src_dataset, nodata=None, hidenodata=False, width=None, height=None, transform=None):
"""Make a VRT XML document."""
nodata = nodata or src_dataset.nodata
@@ -94,6 +94,10 @@ def _boundless_vrt_doc(src_dataset, nodata=None, width=None, height=None, transf
nodatavalue = ET.SubElement(vrtrasterband, 'NoDataValue')
nodatavalue.text = str(nodata)
+ if hidenodata:
+ hidenodatavalue = ET.SubElement(vrtrasterband, 'HideNoDataValue')
+ hidenodatavalue.text = "1"
+
colorinterp = ET.SubElement(vrtrasterband, 'ColorInterp')
colorinterp.text = ci.name.capitalize()
=====================================
tests/data/red.tif
=====================================
Binary files a/tests/data/red.tif and b/tests/data/red.tif differ
=====================================
tests/test_boundless_read.py
=====================================
@@ -59,3 +59,24 @@ def test_hit_ovr(red_green):
image = numpy.moveaxis(data, 0, -1)
assert image[0, 0, 0] == 17
assert image[0, 0, 1] == 204
+
+
+def test_boundless_mask_not_all_valid():
+ """Confirm resolution of issue #1449"""
+ with rasterio.open("tests/data/red.tif") as src:
+ masked = src.read(1, boundless=True, masked=True, window=Window(-1, -1, 66, 66))
+ assert not masked.mask.all()
+ assert masked.mask[:, 0].all()
+ assert masked.mask[:, -1].all()
+ assert masked.mask[0, :].all()
+ assert masked.mask[-1, :].all()
+
+
+def test_boundless_fill_value():
+ """Confirm resolution of issue #1471"""
+ with rasterio.open("tests/data/red.tif") as src:
+ filled = src.read(1, boundless=True, fill_value=5, window=Window(-1, -1, 66, 66))
+ assert (filled[:, 0] == 5).all()
+ assert (filled[:, -1] == 5).all()
+ assert (filled[0, :] == 5).all()
+ assert (filled[-1, :] == 5).all()
=====================================
tests/test_env.py
=====================================
@@ -314,6 +314,7 @@ def test_ensured_env_no_credentializing(gdalenv):
@requires_gdal21(reason="S3 access requires 2.1+")
+ at credentials
@pytest.mark.network
def test_open_https_vsicurl(gdalenv):
"""Read from HTTPS URL."""
@@ -725,3 +726,16 @@ def test_require_gdal_version_chaining():
message = 'parameter "something=else" requires GDAL >= {0}'.format(version)
assert message in exc_info.value.args[0]
+
+
+def test_rio_env_no_credentials(tmpdir, monkeypatch, runner):
+ """Confirm that we can get drivers without any credentials"""
+ credentials_file = tmpdir.join('credentials')
+ monkeypatch.setenv('AWS_SHARED_CREDENTIALS_FILE', str(credentials_file))
+ monkeypatch.delenv('AWS_ACCESS_KEY_ID', raising=False)
+ # Assert that we don't have any AWS credentials by accident.
+ with pytest.raises(Exception):
+ rasterio.open("s3://mapbox/rasterio/RGB.byte.tif")
+
+ with rasterio.Env() as env:
+ assert env.drivers()
=====================================
tests/test_features.py
=====================================
@@ -172,7 +172,7 @@ def test_geometry_window_pixel_precision(basic_image_file):
with rasterio.open(basic_image_file) as src:
window = geometry_window(src, [geom2], north_up=False,
pixel_precision=6)
- assert window.flatten() == (1, 2, 3, 3)
+ assert window.flatten() == (1, 2, 4, 3)
def test_geometry_window_north_up(path_rgb_byte_tif):
@@ -190,7 +190,7 @@ def test_geometry_window_north_up(path_rgb_byte_tif):
with rasterio.open(path_rgb_byte_tif) as src:
window = geometry_window(src, [geometry], north_up=True)
- assert window.flatten() == (326, 256, 167, 167)
+ assert window.flatten() == (326, 256, 168, 167)
def test_geometry_window_pad(basic_image_file, basic_geometry):
=====================================
tests/test_rio_info.py
=====================================
@@ -442,3 +442,14 @@ def test_info_subdatasets():
assert result.exit_code == 0
assert len(result.output) == 93
assert result.output.startswith('netcdf:tests/data/RGB.nc:Band1')
+
+
+def test_info_no_credentials(tmpdir, monkeypatch):
+ credentials_file = tmpdir.join('credentials')
+ monkeypatch.setenv('AWS_SHARED_CREDENTIALS_FILE', str(credentials_file))
+ monkeypatch.delenv('AWS_ACCESS_KEY_ID', raising=False)
+ runner = CliRunner()
+ result = runner.invoke(
+ main_group,
+ ['info', 'tests/data/RGB.byte.tif'])
+ assert result.exit_code == 0
=====================================
tests/test_session.py
=====================================
@@ -111,6 +111,6 @@ def test_foreign_session_factory_s3():
def test_requester_pays():
"""GDAL is configured with requester pays"""
- sesh = AWSSession(requester_pays=True)
+ sesh = AWSSession(aws_access_key_id='foo', aws_secret_access_key='bar', requester_pays=True)
assert sesh._session
assert sesh.get_credential_options()['AWS_REQUEST_PAYER'] == 'requester'
View it on GitLab: https://salsa.debian.org/debian-gis-team/rasterio/commit/16d6e5a73fd97303bdc13fee96d563ee9ee49679
--
View it on GitLab: https://salsa.debian.org/debian-gis-team/rasterio/commit/16d6e5a73fd97303bdc13fee96d563ee9ee49679
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20180920/3c21505d/attachment-0001.html>
More information about the Pkg-grass-devel
mailing list