Dusk and dawn bitmap

Generates a boolean ping with every sample value assigned to True when the ping time occurs between dusk or dawn (±1hr); all other pings have samples assigned to False.

List of operands

Operand 1 - Any acoustic variable


Echoview Code Operator source file

Created by Echoview(R) 10.0.218 on Monday, 29 April 2019

See the Echoview help file for Code operator documentation and

NumPy User Guide: https://docs.scipy.org/doc/numpy/user/
NumPy Reference: https://docs.scipy.org/doc/numpy/Reference/
SciPy Reference Guide: https://docs.scipy.org/doc/scipy/Reference/

Echoview(R) is a registered trademark of Echoview Software Pty Ltd.

# Authorship information
__author__ = "Echoview Software Pty Ltd. 2019."
__disclaimer__ = (
    "This example code is provided AS IS, without warranty of any "
    "kind, express or implied, including but not limited to the "
    "warranties of merchantability, fitness for a particular purpose "
    "and noninfringement. In no event shall Echoview Software Pty Ltd "
    "be liable for any claim, damages or other liability, arising "
    "from, out of or in connection with the use of this example code."
__version__ = "1.0"

# System Imports
from typing import List

# Libraries
from echoview import OperatorBase, MeasurementType, OperandInput, Error
from datetime import datetime, date, time, timedelta
import numpy as np

class Operator(OperatorBase):
    Dusk and Dawn bitmap generator
    Generates a bitmap where all samples in pings from Operand 1 around
    dawn and dusk (+-1 hour) are True.


    * Operand 1 - Any acoustic variable

    def result_type(self, input_types: List[MeasurementType]):
        Instructs Echoview to create a single beam or multi-beam
        boolean variable based on the input type.

        if(input_types and input_types[0].is_acoustic):
            if input_types[0].is_single_beam:
                return MeasurementType.SINGLE_BEAM_BOOLEAN
            elif input_types[0].is_multibeam:
                return MeasurementType.MULTIBEAM_BOOLEAN

        # If no input type or input isn't a single beam or multi-beam
        # acoustic variable
        return MeasurementType.UNDEFINED

    def eval(self, inputs: List[OperandInput]):
        Generates a boolean ping with every sample true that falls
        between dusk or dawn (+- 1hr); all other pings will have false

        ping = inputs[0].measurement
        ping_date = ping.datetime.date()

        # Calculate the dusk and dawn times,these are currently hard
        # coded to 7 and 19 hours respectively.
        # Note: These must be adapted depending on your data's lat/longs
        # and time of year
        dawn = datetime.combine(ping_date, time(7, 0, 0))
        dusk = datetime.combine(ping_date, time(19, 0, 0))
        threshold = timedelta(hours=1)

        if (((ping.datetime >= (dawn - threshold)) and (ping.datetime <= (dawn + threshold))) or
            ((ping.datetime >= (dusk - threshold)) and (ping.datetime <= (dusk + threshold)))):
            return np.full(ping.data.shape, True)
            return np.full(ping.data.shape, False)

See also

Code operator
About the Code operator
Using the Code operator