Beispiel #1
0
def device_to_sensor(device: dict, slot: str) -> assets.Sensor:
    # Append slot code to device identifier
    sensor_id = str(device['zNumber']) + slot
    return assets.Sensor(
        sensor_id=sensor_id,
        family='Zephyr',
        detectors=list(
            dict(name=new, unit=settings.UNITS[old])
            for old, new in settings.FIELD_MAP.items() if new not in {'timestamp', 'sensor'}
        ),
        first_date=device['location']['since'][:10],
    )
Beispiel #2
0
def station_to_sensor(station: dict) -> assets.Sensor:
    """Map station data to Urban Flows station metadata"""

    return assets.Sensor(
        sensor_id=station['stationReference'],
        family='Environment Agency Flood',
        detectors=[
            dict(name=measure['parameter'], unit=measure['unitName'], id=measure['@id'])
            for measure in station['measures']
        ],
        desc_url=station['@id'],
        first_date=station.get('dateOpened'),
    )
Beispiel #3
0
def instrument_to_sensor(instrument: Mapping) -> assets.Sensor:
    """
    Map an Aeroqual instrument to an Urban Flows sensor asset.
    """

    detectors = list()
    for s in instrument['sensors']:
        detectors.append(sensor_to_detector(s))

    return assets.Sensor(
        sensor_id=instrument['serial'],
        serial_number=instrument['serial'],
        family=settings.FAMILY,
        detectors=detectors,
    )
Beispiel #4
0
def build_sensor(station: parsers.Station, sampling_points: iter,
                 unit_map: dict) -> assets.Sensor:
    detectors = [build_detector(sp, unit_map) for sp in sampling_points]

    # Remove unknown detectors
    detectors = [det for det in detectors if det['name'] != mappings.MISSING]

    return assets.Sensor(
        sensor_id=clean_station_id(station.id),
        family=settings.FAMILY,
        detectors=detectors,
        first_date=station.start_time,
        desc_url=station.info,
        provider=dict(
            name='Department for Environment, Food and Rural Affairs'),
    )
Beispiel #5
0
def instrument_to_sensor(instrument: Mapping) -> assets.Sensor:
    """
    Map an Aeroqual instrument to an Urban Flows sensor asset.
    """

    detectors = list()
    for s in instrument['sensors']:
        try:
            detectors.append(sensor_to_detector(s))
        except KeyError:
            if s['name'] in settings.IGNORE_METRICS:
                continue
            else:
                raise

    return assets.Sensor(
        sensor_id=instrument['serial'],
        family=settings.FAMILY,
        detectors=detectors,
    )
Beispiel #6
0
def build_sensor(station: parsers.inspire.Station, sampling_point: parsers.inspire.SamplingPoint) -> assets.Sensor:
    """
    Map a Station and its Sampling Points to an Urban Flows Sensor (pod)

    Sampling point: An instrument or other device configured to measure an air quality
    https://uk-air.defra.gov.uk/data/so/sampling-points/
    """

    observed_property_url = sampling_point.observed_property
    unit_of_measurement_url = sampling_point.unit_of_measurement

    try:
        measure = settings.UNIT_MAP[unit_of_measurement_url][observed_property_url]
    except KeyError:
        LOGGER.error("%s: No unit metadata", sampling_point.id)
        return

    unit_of_measurement = measure['unit']
    label = measure['label']

    sensor = assets.Sensor(
        sensor_id=sampling_point.id,
        family='DEFRA_UK-AIR',
        provider=dict(
            id=sampling_point.belongs_to,
        ),
        detectors=[
            dict(
                name=label,
                unit=unit_of_measurement,
            ),
        ],
        desc_url=sampling_point.url,
        first_date=sampling_point.start_time.date().isoformat(),
    )

    return sensor