Esempio n. 1
0
def plot_cumulative_from_stage_df(data,
                                  scored=True,
                                  stages=None,
                                  base_freq=None,
                                  target_freq=None,
                                  end_of_title=3,
                                  set_file_title=True,
                                  set_name_title=False,
                                  *args,
                                  **kwargs):
    """
    Function to take in raw dataframe that has been read in and
        plot the cumulative sum of all the columns on the same axis
    :param scored_df:
    :param base_freq:
    :param target_freq:
    :param args:
    :param kwargs:
    :return:
    """
    if scored:
        scored_df = score_whole_df(data, stages)
    else:
        scored_df = data

    cumsum_df = scored_df.cumsum()
    converted_data = convert_to_units(cumsum_df, base_freq, target_freq)
    if set_file_title:
        kwargs["title"] = kwargs["fname"].stem[:end_of_title]
    if set_name_title:
        kwargs["title"] = kwargs["fname"].stem[:end_of_title] + data.name

    _plot_cumulative_stage(converted_data, *args, **kwargs)
Esempio n. 2
0
# Define the variables that will change
stage_list = ["NR", "N1", "R", "R1"]
label = "total sleep time, (hours)"
title = "Total sleep per day"
save_name = "01_total_sleep.png"

# Step two: Count the sleep
sleep_count_df = prep.lightdark_df(df_list=df_list, stage_list=stage_list)

### HACK AS HAVEN'T FINISHED SCORING
# sleep_count_df.iloc[4, -1] = 12000

# Step three: convert to hours
sleep_hours = prep.convert_to_units(sleep_count_df,
                                    base_freq="4S",
                                    target_freq="1H")
# convert to long form data
data = sleep_hours.stack().reset_index()
x = "Experimental_day"
y = label
hue = "Light"
cols = [hue, "Animal", x, label]
data.columns = cols

# Step four: Plot as a scatter/box plot
fig, ax = plot.dark_light_plot(data,
                               x=x,
                               y=y,
                               hue=hue,
                               figsize=(10, 10),
Esempio n. 3
0
df = prep.read_file_to_df(file_list[1], **kwargs)

sleep_stages = ["NR", "R", "NR1", "R1"]

sleep_df = prep.score_whole_df(df, sleep_stages)

wake_stage = ["W", "W1", "M"]

wake_df = prep.score_whole_df(df, wake_stage)

sleep_cumsum = sleep_df.cumsum()
data = sleep_cumsum.copy()
base_freq = "4S"
target_freq = "1H"

data = prep.convert_to_units(data, base_freq, target_freq)

fig, ax = plt.subplots()

for col in data:
    data_to_plot = data.loc[:, col]
    ax.plot(data_to_plot, label=col)
fig.legend()

# tidy up with kwargs and labels
fig.autofmt_xdate()
xfmt = mdates.DateFormatter("%H:%M:%S")
ax.xaxis.set_major_formatter(xfmt)
ax.xaxis.set_major_locator(mdates.HourLocator(interval=interval))

xlabel = "ZT/CT"
Esempio n. 4
0
df = prep.read_file_to_df(file_list[1], **kwargs)

sleep_stages = ["NR", "R", "NR1", "R1"]

sleep_df = prep.score_whole_df(df, sleep_stages)

wake_stage = ["W", "W1", "M"]

wake_df = prep.score_whole_df(df, wake_stage)

sleep_cumsum = sleep_df.cumsum()
df_0 = sleep_cumsum.copy()
base_freq = "4S"
target_freq = "1H"

df_1 = prep.convert_to_units(df_0, base_freq, target_freq)


def my_decorator(func):
    def wrapper():
        print("Something before")
        fig, ax = func()
        ax.set_xlabel("a label")
        print("Something after")

    return wrapper


def second_decorator(func):
    def second_wrap():
        print("Another before")