Example #1
0
def test_invalid_days():

    # File contains 24 hours of 1s, then 15 hours of 0s, then 24 hours of 1s

    nonwear_bouts, wear_bouts = channel_inference.infer_nonwear_actigraph(counts)

    # Get invalid/valid days where valid criterion is default (10 hours)
    invalid_windows, valid_windows = channel_inference.infer_valid_days(counts, wear_bouts)

    # One of the days should be invalid
    assert(len(invalid_windows) == 1)

    # The invalid bout should be exactly 1 day long
    assert(invalid_windows[0].length == timedelta(days=1))

    # Two valid days
    assert(len(valid_windows) == 2)

    # Now get invalid/valid windows where need only 9 hours
    invalid_windows, valid_windows = channel_inference.infer_valid_days(counts, wear_bouts, valid_criterion=timedelta(hours=9))

    # None of the days should be invalid
    assert(len(invalid_windows) == 0)

    # Three valid days
    assert(len(valid_windows) == 3)
Example #2
0
def test_invalid_days():

    # File contains 24 hours of 1s, then 15 hours of 0s, then 24 hours of 1s

    nonwear_bouts, wear_bouts = channel_inference.infer_nonwear_actigraph(counts)

    # Get invalid/valid days where valid criterion is default (10 hours)
    invalid_windows, valid_windows = channel_inference.infer_valid_days(counts, wear_bouts)

    # One of the days should be invalid
    assert(len(invalid_windows) == 1)

    # The invalid bout should be exactly 1 day long
    assert(invalid_windows[0].length == timedelta(days=1))

    # Two valid days
    assert(len(valid_windows) == 2)

    # Now get invalid/valid windows where need only 9 hours
    invalid_windows, valid_windows = channel_inference.infer_valid_days(counts, wear_bouts, valid_criterion=timedelta(hours=9))

    # None of the days should be invalid
    assert(len(invalid_windows) == 0)

    # Three valid days
    assert(len(valid_windows) == 3)
# Request some interesting statistics - mean, min and max of the counts signal
# ...plus basic cutpoints for Sedentary, Light, and Moderate to Vigorous

stats = {"AG_Counts": [("generic", ["mean", "min", "max"]), ("cutpoints", [[0,99],[100,2999],[3000,99999]])]}

# Load Actigraph data
counts, header = Channel.load_channels("/pa/data/Tom/pampro/data/example_actigraph.DAT", "Actigraph", datetime_format="%m/%d/%Y")

ts = Time_Series.Time_Series("Actigraph")
ts.add_channel(counts)

# Get a list of bouts where the monitor was & wasn't worn
nonwear_bouts = channel_inference.infer_nonwear_actigraph(counts, zero_minutes=timedelta(minutes=90))

# Use that list to get a list of days of valid & invalid time
invalid_bouts = channel_inference.infer_valid_days(counts, wear_bouts)

# Since the cutpoints defined above only count positive data, negative values will be ignored
# Where the monitor wasn't worn, set the count value to -1
# Where the monitor wasn't valid, set the count value to -2
counts.fill_windows(nonwear_bouts, fill_value=-1)
counts.fill_windows(nonwear_bouts, fill_value=-2)

# Get the summary level results
summary_results = ts.summary_statistics(statistics=stats)

# Create a time series object, put the summary level results in it, write them to a file
ts_output = Time_Series.Time_Series("Output")
ts_output.add_channels(summary_results)
ts_output.write_channels_to_file("/pa/data/ICAD/example_output.csv")
# Load Actigraph data
counts, header = Channel.load_channels(
    "/pa/data/Tom/pampro/data/example_actigraph.DAT",
    "Actigraph",
    datetime_format="%m/%d/%Y")

ts = Time_Series.Time_Series("Actigraph")
ts.add_channel(counts)

# Get a list of bouts where the monitor was & wasn't worn
nonwear_bouts = channel_inference.infer_nonwear_actigraph(
    counts, zero_minutes=timedelta(minutes=90))

# Use that list to get a list of days of valid & invalid time
invalid_bouts = channel_inference.infer_valid_days(counts, wear_bouts)

# Since the cutpoints defined above only count positive data, negative values will be ignored
# Where the monitor wasn't worn, set the count value to -1
# Where the monitor wasn't valid, set the count value to -2
counts.fill_windows(nonwear_bouts, fill_value=-1)
counts.fill_windows(nonwear_bouts, fill_value=-2)

# Get the summary level results
summary_results = ts.summary_statistics(statistics=stats)

# Create a time series object, put the summary level results in it, write them to a file
ts_output = Time_Series.Time_Series("Output")
ts_output.add_channels(summary_results)
ts_output.write_channels_to_file("/pa/data/ICAD/example_output.csv")