'F:\\Users\\Gittis\\Dropbox\\Manuscripts\\Isett_Gittis_2021\\')
    basepath = Path(
        'F:\\Users\\Gittis\\Dropbox\\Gittis Lab Data\\OptoBehavior\\')
else:
    savepath = Path('/home/brian/Dropbox/Manuscripts/Isett_Gittis_2021/')
    basepath = Path('/home/brian/Dropbox/Gittis Lab Data/OptoBehavior/')

fig_name = 'Figure 1_a2a_chr2_str'

newbase = savepath.joinpath(fig_name).joinpath('data').joinpath('raw')

# %%
# inc = [x + ['AG3233_5'] for x in inc]
ethovision_tools.raw_csv_to_preprocessed_csv(newbase,
                                             inc,
                                             exc,
                                             force_replace=True,
                                             win=10)

# %%

pns = dataloc.raw_csv(newbase, inc[0], exc[0])
if not isinstance(pns, list):
    pns = [pns]
saveit = True
closeit = True
for pn in pns:
    df, meta = ethovision_tools.csv_load(pn, columns='All', method='preproc')
    plots.plot_openloop_day(df,
                            meta,
                            save=saveit,
"""
import pandas as pd
import json
import numpy as np
from pathlib import Path
from gittislab import dataloc, ethovision_tools, signals, plots
import matplotlib.pyplot as plt

basepath = '/home/brian/Dropbox/Gittis Lab Data/OptoBehavior/Str/Naive/A2A/Ai32/Bilateral/10x10/'
inc = [['AG5477_4']]
# basepath = '/home/brian/Dropbox/Gittis Lab Data/OptoBehavior/GPe/Naive/CAG/Arch/Right/5x30/'
# inc=[['AG4486_1']]
exc = [['exclude']]
ethovision_tools.unify_raw_to_csv(basepath, inc, exc)
ethovision_tools.raw_csv_to_preprocessed_csv(basepath,
                                             inc,
                                             exc,
                                             force_replace=True)
pns = dataloc.raw_csv(basepath, inc[0], exc[0])
raw, meta = ethovision_tools.csv_load(pns, method='preproc')
ethovision_tools.boris_prep(basepath,
                            inc,
                            exc,
                            plot_cols=['time', 'mouse_height', 'vel'],
                            event_col='rear',
                            event_thresh=0.5,
                            method='preproc')

dlc = ethovision_tools.add_dlc_helper(raw,
                                      meta,
                                      pns.parent,
                                      force_replace=True)
    'Exclude',
]
# inc=[['AG','GPe','CAG','Arch','10x']]
exc = [ex0]
inc = [
    ['AG', 'GPe', 'FoxP2', 'ChR2', '10x10_20mW'],
]
basepath = '/home/brian/Dropbox/Gittis Lab Data/OptoBehavior/'
ethovision_tools.unify_raw_to_csv(basepath,
                                  inc,
                                  exc,
                                  force_replace=False,
                                  win=10)
ethovision_tools.raw_csv_to_preprocessed_csv(basepath,
                                             inc,
                                             exc,
                                             force_replace=False,
                                             win=10)
for ii, ee in zip(inc, exc):
    pns = dataloc.raw_csv(basepath, ii, ee)
    for pn in pns:
        temp = {}
        raw, meta = ethovision_tools.csv_load(pn, method='preproc')
        plots.plot_openloop_day(raw, meta)
# %%

# def test_batch_analyze(inc,exc):

data = pd.DataFrame([],
                    columns=[
                        'anid', 'proto', 'cell_area_opsin', 'amb_vel',
Beispiel #4
0
def combine_raw_csv_for_modeling(raw_pns,
                                 boris_obs_names,
                                 use_cols,
                                 uniform_boris_fn='Rearing Observations.boris',
                                 rescale=False,
                                 avg_model_detrend=False,
                                 z_score_x_y=False,
                                 flip_y=False,
                                 meta_to_raw=[]):

    combined = pd.DataFrame([], columns=use_cols)

    for pn, obs in zip(raw_pns, boris_obs_names):
        p = Path(pn)
        inc = [['AG']]
        exc = [['exclude']]
        ethovision_tools.unify_raw_to_csv(p, inc, exc)
        ethovision_tools.raw_csv_to_preprocessed_csv(p,
                                                     inc,
                                                     exc,
                                                     force_replace=False)
        pns = dataloc.raw_csv(p, inc[0], exc[0])
        raw, meta = ethovision_tools.csv_load(pns, method='raw')

        fn_ka = p.joinpath(uniform_boris_fn)
        f = open(fn_ka, 'r')
        boris = json.loads(f.read())
        # Get human scored rearing events and add as vector!
        human_scored_rearing = behavior.boris_to_logical_vector(
            raw, boris, obs, 'a', 'd')

        dlc = ethovision_tools.add_dlc_helper(raw, meta, p, force_replace=True)
        dlc = dlc[0]
        # pdb.set_trace()
        if meta['exp_room_number'][0] == 228:
            x_scale = 512 / 480
            y_scale = 1.455  #Scale pixels #Video takes up only half of screen in these recordings
            vid_res = np.ones((dlc.shape[0], 1)) * 704  #Video width 704 x 480
            # pdb.set_trace()
        else:
            x_scale = 1
            y_scale = 1
            vid_res = np.ones(
                (dlc.shape[0], 1)) * 1280  #Video width   height = 512

        if rescale == True:
            for col in dlc.columns:
                if ('dlc' in col) and ('x' in col):
                    dlc[col] = dlc[col].values * x_scale

                if ('dlc' in col) and ('y' in col):
                    dlc[col] = dlc[col].values * y_scale

        dlc['video_resolution'] = vid_res
        dlc['human_scored_rear'] = human_scored_rearing
        # dlc['head_hind_px_height']= dlc ['dlc_rear_centroid_y'] - dlc['dlc_side_head_y']

        dlc['front_hind_px_height'] = dlc['dlc_rear_centroid_y'] - dlc[
            'dlc_front_centroid_y']
        dlc['head_hind_5hz_pw'] = signals.get_spectral_band_power(
            dlc['front_hind_px_height'], meta['fs'][0], 4.5, 6.5)
        dlc['snout_hind_px_height'] = dlc['dlc_rear_centroid_y'] - dlc[
            'dlc_snout_y']
        dlc['side_length_px'] = signals.calculateDistance(
            dlc['dlc_front_centroid_x'].values,
            dlc['dlc_front_centroid_y'].values,
            dlc['dlc_rear_centroid_x'].values,
            dlc['dlc_rear_centroid_y'].values)
        # dlc['top_length_px']=signals.calculateDistance(dlc['dlc_top_head_x'].values,
        #                                                dlc['dlc_top_head_y'].values,
        #                                                dlc ['dlc_top_tail_base_x'].values,
        #                                                dlc ['dlc_top_tail_base_y'].values)
        #Detrend effect of mouse distance from camera using an average pre-fitted
        #z-score approach:
        if avg_model_detrend == True:
            detrend_cols = [
                'snout_hind_px_height', 'front_hind_px_height',
                'side_length_px'
            ]
            for col in detrend_cols:
                y = dlc[col]
                x = dlc['x']
                dlc[col + '_detrend'] = average_z_score(x, y)

        if z_score_x_y == True:
            for col in dlc.columns:
                if ('dlc' in col) and (('x' in col) or ('y' in col)):
                    temp = dlc[col].values
                    temp = temp - np.nanmean(temp)
                    temp = temp / np.nanstd(temp)
                    dlc[col] = temp

        if flip_y == True:
            for col in dlc.columns:
                if ('dlc' in col) and ('y' in col):
                    dlc[col] = -1 * dlc[col]
                    # dlc[col] = dlc[col] - np.nanmin(dlc[col])

        for col in meta_to_raw:
            dlc[col] = meta[col][0]

        temp = dlc[use_cols]
        combined = pd.concat([combined, temp])

    #Add time lags (?)
    combined.reset_index(drop=True, inplace=True)
    return combined