kwcoco.sensorchan_spec module

This is an extension of kwcoco.channel_spec, which augments channel information with an associated sensor attribute. Eventually, this will entirely replace the channel spec.

class kwcoco.sensorchan_spec.Transformer[source]

Bases: object

class kwcoco.sensorchan_spec.SensorChanSpec(spec: str)[source]

Bases: NiceRepr

The public facing API for the sensor / channel specification

Example

>>> # xdoctest: +REQUIRES(module:lark)
>>> from kwcoco.sensorchan_spec import SensorChanSpec
>>> self = SensorChanSpec('(L8,S2):BGR,WV:BGR,S2:nir,L8:land.0:4')
>>> s1 = self.normalize()
>>> s2 = self.concise()
>>> streams = self.streams()
>>> print(s1)
>>> print(s2)
>>> print('streams = {}'.format(ub.repr2(streams, sv=1, nl=1)))
<SensorChanSpec(L8:BGR,S2:BGR,WV:BGR,S2:nir,L8:land.0|land.1|land.2|land.3)>
<SensorChanSpec((L8,S2,WV):BGR,L8:land:4,S2:nir)>
streams = [
    <SensorChanSpec(L8:BGR)>,
    <SensorChanSpec(S2:BGR)>,
    <SensorChanSpec(WV:BGR)>,
    <SensorChanSpec(S2:nir)>,
    <SensorChanSpec(L8:land.0|land.1|land.2|land.3)>,
]

Example

>>> # Check with generic sensors
>>> # xdoctest: +REQUIRES(module:lark)
>>> from kwcoco.sensorchan_spec import SensorChanSpec
>>> import kwcoco
>>> self = SensorChanSpec('(*):BGR,*:BGR,*:nir,*:land.0:4')
>>> self.concise().normalize()
>>> s1 = self.normalize()
>>> s2 = self.concise()
>>> print(s1)
>>> print(s2)
<SensorChanSpec(*:BGR,*:BGR,*:nir,*:land.0|land.1|land.2|land.3)>
<SensorChanSpec((*,*):BGR,*:(nir,land:4))>
>>> import kwcoco
>>> c = kwcoco.ChannelSpec.coerce('BGR,BGR,nir,land.0:8')
>>> c1 = c.normalize()
>>> c2 = c.concise()
>>> print(c1)
>>> print(c2)
classmethod coerce(data)[source]

Attempt to interpret the data as a channel specification

Returns

SensorChanSpec

Example

>>> # xdoctest: +REQUIRES(module:lark)
>>> from kwcoco.sensorchan_spec import *  # NOQA
>>> from kwcoco.sensorchan_spec import SensorChanSpec
>>> data = SensorChanSpec.coerce(3)
>>> assert SensorChanSpec.coerce(data).normalize().spec == '*:u0|u1|u2'
>>> data = SensorChanSpec.coerce(3)
>>> assert data.spec == 'u0|u1|u2'
>>> assert SensorChanSpec.coerce(data).spec == 'u0|u1|u2'
>>> data = SensorChanSpec.coerce('u:3')
>>> assert data.normalize().spec == '*:u.0|u.1|u.2'
normalize()[source]
concise()[source]
streams()[source]
class kwcoco.sensorchan_spec.SensorChanNode(sensor, chan)[source]

Bases: object

property spec
class kwcoco.sensorchan_spec.FusedChanNode(chan)[source]

Bases: object

Example

s = FusedChanNode(‘a|b|c.0|c.1|c.2’) c = s.concise() print(s) print(c)

property spec
concise()[source]
class kwcoco.sensorchan_spec.SensorChanTransformer(concise_channels=1, concise_sensors=1)[source]

Bases: Transformer

Given a parsed tree for a sensor-chan spec, can transform it into useful forms.

Todo

Make the classes that hold the underlying data more robust such that they either use the existing channel spec or entirely replace it. (probably the former). Also need to add either a FusedSensorChan node that is restircted to only a single sensor and group of fused channels.

chan_id(items)[source]
chan_single(items)[source]
chan_getitem(items)[source]
chan_getslice_0b(items)[source]
chan_getslice_ab(items)[source]
chan_code(items)[source]
sensor_seq(items)[source]
fused_seq(items)[source]
fused(items)[source]
channel_rhs(items)[source]
sensor_lhs(items)[source]
nosensor_chan(items)[source]
sensor_chan(items)[source]
stream_item(items)[source]
stream(items)[source]
kwcoco.sensorchan_spec.normalize_sensor_chan(spec)[source]

Example

>>> # xdoctest: +REQUIRES(module:lark)
>>> from kwcoco.sensorchan_spec import *  # NOQA
>>> spec = 'L8:mat:4,L8:red,S2:red,S2:forest|brush,S2:mat.0|mat.1|mat.2|mat.3'
>>> r1 = normalize_sensor_chan(spec)
>>> spec = 'L8:r|g|b,L8:r|g|b'
>>> r2 = normalize_sensor_chan(spec)
>>> print(f'r1={r1}')
>>> print(f'r2={r2}')
r1=L8:mat.0|mat.1|mat.2|mat.3,L8:red,S2:red,S2:forest|brush,S2:mat.0|mat.1|mat.2|mat.3
r2=L8:r|g|b,L8:r|g|b
kwcoco.sensorchan_spec.concise_sensor_chan(spec)[source]

Example

>>> # xdoctest: +REQUIRES(module:lark)
>>> from kwcoco.sensorchan_spec import *  # NOQA
>>> spec = 'L8:mat.0|mat.1|mat.2|mat.3,L8:red,S2:red,S2:forest|brush,S2:mat.0|mat.1|mat.2|mat.3'
>>> concise_spec = concise_sensor_chan(spec)
>>> normed_spec = normalize_sensor_chan(concise_spec)
>>> concise_spec2 = concise_sensor_chan(normed_spec)
>>> assert concise_spec2 == concise_spec
>>> print(concise_spec)
(L8,S2):(mat:4,red),S2:forest|brush
kwcoco.sensorchan_spec.sensorchan_concise_parts(spec)[source]
kwcoco.sensorchan_spec.sensorchan_normalized_parts(spec)[source]