geowatch.utils.util_resolution module¶
- class geowatch.utils.util_resolution.ExtendedTransformer(visit_tokens: bool = True)[source]¶
Bases:
Transformer
Enriches the Transformer with parse and parser classmethods which rely on a __grammar__ attribute
- class geowatch.utils.util_resolution.ResolvedTransformer(visit_tokens: bool = True)[source]¶
Bases:
ExtendedTransformer
Base class for resolving a resolution 1D scalar or 2D window.
- class geowatch.utils.util_resolution.ResolvedUnitTransformer(visit_tokens: bool = True)[source]¶
Bases:
ResolvedTransformer
Transform for
ResolvedUnit
- class geowatch.utils.util_resolution.ResolvedScalarTransformer(visit_tokens: bool = True)[source]¶
Bases:
ResolvedTransformer
Transform for
ResolvedScalar
- class geowatch.utils.util_resolution.ResolvedWindowTransformer(visit_tokens: bool = True)[source]¶
Bases:
ResolvedTransformer
Transform for
ResolvedWindow
- class geowatch.utils.util_resolution.Resolved[source]¶
Bases:
DictProxy2
Base class for all resolved objects. Must define the
__transformer__
attribute.
- class geowatch.utils.util_resolution.ResolvedUnit(mag, unit)[source]¶
-
Holds just the unit information (e.g. X GSD)
Example
>>> from geowatch.utils import util_resolution >>> self = util_resolution.ResolvedUnit.parse('8GSD') >>> print('self = {}'.format(ub.urepr(self, nl=1, si=1))) self = <ResolvedUnit(8 GSD)>
- classmethod coerce(data, default_unit=None)[source]¶
Example
>>> from geowatch.utils.util_resolution import * # NOQA >>> self1 = ResolvedUnit.coerce(8, default_unit='GSD') >>> self2 = ResolvedUnit.coerce('8', default_unit='GSD') >>> self3 = ResolvedUnit.coerce('8GSD') >>> assert self1 == self2 >>> import pytest >>> with pytest.raises(ValueError): >>> ResolvedUnit.coerce(8)
Example
>>> import kwutil >>> # Test loading from YAML. >>> # https://github.com/lark-parser/lark_cython/issues/36 >>> from geowatch.utils.util_resolution import ResolvedUnit >>> text = kwutil.Yaml.coerce('key: "1 mGSD"')['key'] >>> ResolvedUnit.coerce(text)
- class geowatch.utils.util_resolution.ResolvedScalar(scalar, resolution)[source]¶
-
Example
>>> from geowatch.utils.util_resolution import * # NOQA >>> self1 = ResolvedScalar.parse("128@10GSD") >>> self2 = ResolvedScalar.parse("128 @ 10 GSD") >>> print('self1 = {}'.format(ub.urepr(self1, sv=1, nl=1))) >>> print('self2 = {}'.format(ub.urepr(self2, sv=1, nl=1))) self1 = <ResolvedScalar(128 @ 10 GSD)> self2 = <ResolvedScalar(128 @ 10 GSD)>
- at_resolution(new_resolution)[source]¶
Update the resolution
- Parameters:
new_resolution (dict | ResolvedUnit) – new base resolution unit to use.
- Returns:
The same scalar but in terms of the new resolution.
- Return type:
Example
>>> new_resolution = {'mag': 1, 'unit': 'GSD'} >>> self = ResolvedScalar.parse("128@10GSD") >>> print(self.at_resolution(new_resolution)) >>> print(self.at_resolution({'mag': 20, 'unit': 'GSD'})) <ResolvedScalar(1280.0 @ 1 GSD)> <ResolvedScalar(64.0 @ 20 GSD)>
- class geowatch.utils.util_resolution.ResolvedWindow(window, resolution)[source]¶
-
Parse a window size at a particular resolution
Example
>>> from geowatch.utils.util_resolution import * # NOQA >>> data = "128x128@10GSD" >>> self1 = ResolvedWindow.parse(data) >>> self2 = ResolvedWindow.parse("128 , 128 @ 10 GSD") >>> self3 = ResolvedWindow.parse("128@10GSD") >>> print('self1 = {}'.format(ub.urepr(self1, nl=1, sv=1))) >>> print('self2 = {}'.format(ub.urepr(self2, nl=1, sv=1))) >>> print('self3 = {}'.format(ub.urepr(self3, nl=1, sv=1))) self1 = <ResolvedWindow((128, 128) @ 10 GSD)> self2 = <ResolvedWindow((128, 128) @ 10 GSD)> self3 = <ResolvedWindow((128, 128) @ 10 GSD)>
- at_resolution(new_resolution)[source]¶
Update the resolution
- Parameters:
new_resolution (dict | ResolvedUnit) – new base resolution unit to use.
- Returns:
The same window but in terms of the new resolution.
- Return type:
Example
>>> from geowatch.utils.util_resolution import * # NOQA >>> new_resolution = {'mag': 1, 'unit': 'GSD'} >>> self = ResolvedWindow.parse("128x64@10GSD") >>> print(self.at_resolution(new_resolution)) >>> print(self.at_resolution({'mag': 20, 'unit': 'GSD'})) <ResolvedWindow((1280.0, 640.0) @ 1 GSD)> <ResolvedWindow((64.0, 32.0) @ 20 GSD)>