WindSpeedDetection - scottcarr/wind GitHub Wiki

This task consists of:

  • the WindVxi data source
  • the ramp_detected source
  • the wind_speed_alaram sink

##WindVxi source

The WindVxi data source is defined in fast_data.py. It reads in the FAST simulation output data file a line at a time.

labels = ["Time","WindVxi","WindVyi","WindVzi","HorWndDir","VerWndDir", \
    "BldPitch2","IPDefl1","IPDefl2","TwstDefl1","TwstDefl2","TwstDefl3", "RootMxb2"\
    , "RootMyb2", "RootMzb2", "LSShftFys", "LSShftFzs", "LSSTipMys", "LSSTipMzs",\
    "YawBrTDxp", "YawBrTDyp", "YawBrMxn", "YawBrMyn", "YawBrMzn"]

def line_to_dict(labels, line):
    values = map(float, (line.split()))
    return {label: value for (label, value) in zip(labels, values)}

def fast_read():
    while 1: # loop forever
        f = open("Test13.out")
        i = 0
        for line in f.readlines():
        # there are 8 lines of header
            if i < 8:
                i += 1
            else:
                yield line_to_dict(labels, line)
        f.close()

def init_fast():
    for l in labels:
        create_source(l)
    cond = lambda: True # this generator should always fire
    add_generator(fast_read(), cond)

##ramp_detected source

The ramp_detected source consumes 100 WindVxi data points, takes the average and yields a ramp_detected if it exceeds a threshold.

label = "ramp_detected"
WINDVAR = "WindVxi"

def cond():
    if count_available_elements(WINDVAR) >= N:
        x = remove_elements(WINDVAR, N)
        a = np.average(x)
        if a > THRESHOLD:
            return True
        else:
            print "[INFO] wind speed normal."
    return False

def speed_detection():
    while 1:
        yield {label: True} 

def init_wind_monitor():
    create_source(label)
    add_generator(speed_detection(), cond)

##wind_speed_alarm sink

The wind_speed_alaram just prints a warning whenever ramp_detected is put on the queue.

label = "ramp_detected"

def cond():
    return count_available_elements(label)

def action():
    remove_elements(label, 1) # consume a warning
    print("[WARNING] wind speed too high!")

def init_wind_speed_alarm():
    add_sink(action, cond)