def plot_inflections(study, record, sensor, segment):
    """

    """

    searchRange = retrieve_ref('searchRange')
    searchRange = [int(x) for x in searchRange]
    searchRange.append('unique')

    row_num, col_num, plot_num = len(searchRange) + 2, 2, 0
    row_width_mulp, col_width_mulp = 12, 5
    plot_width, plot_height = col_num * row_width_mulp, row_num * col_width_mulp
    plt.figure(figsize=(plot_width, plot_height))

    for range in searchRange:

        plot_num += 1
        plt.subplot(row_num, col_num, plot_num)

        path = [
            study, 'analyzed', 'inflections', 'all_times',
            str(range), record, segment
        ]
        file = os.path.join(*path, sensor + ".csv")

        if not os.path.isfile(file):
            return

        df = pd.read_csv(file)

        for colName in df.columns:

            if 'Minutes' in colName:
                timeMinutes = list(df[colName])

            if 'measurement' in colName:

                measList = list(df[colName])
                measMin = min(measList)
                measMax = max(measList)
                plt.scatter(timeMinutes, measList, label=str(colName))

            if 'inflectionDecision' in colName or 'unique' in colName:

                if 'inflectionDecision' in colName:
                    dfInflections = df.drop(df[(df[colName] != 'Yes')].index)
                    timeInflections = list(dfInflections['timeMinutes'])

                if 'unique' in colName:
                    plt.scatter(timeMinutes, measList)
                    timeInflections = list(df[colName])

                for time in timeInflections:

                    # multp = searchRange.index(range)/len(searchRange)
                    # colorScatter = [multp*x for x in [0,1,.5]]
                    colorScatter = [0, .9, .6]

                    xx = np.linspace(time, time, 100)
                    yy = np.linspace(measMin, measMax, 100)
                    plt.plot(xx, yy, color=colorScatter, linestyle='--')

                    plt.title('Record = ' + str(record) + ' Range = ' +
                              str(range) + ' seconds ' +
                              ' Inflections Found = ' +
                              str(len(timeInflections)))
                    plt.xlabel('Time (Minutes)')
                    sensor_unit = retrieve_sensor_unit(sensor)
                    plt.ylabel(sensor + ' ' + sensor_unit)
                    # plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')

            if 'polyfitEquation' in colName:

                polyfitCoeff = list(dfInflections[colName])

                coeffPolyList = []
                for coeff in polyfitCoeff:

                    # print('coeff = ' + str(coeff))
                    coeff = str(coeff)
                    coeff = coeff.replace("x", ",")
                    coeff = coeff.replace("*", "")
                    coeff = coeff.replace("**2", "")
                    coeff = coeff.replace("**", "")
                    coeff = coeff.replace("  ", "")
                    coeff = coeff.replace(" ", "")
                    coeff = coeff.replace("+", "")
                    # print('coeff = ' + str(coeff))
                    coeffList = coeff.split(',')
                    coeffPoly = float(coeffList[0])
                    # print('coeffPoly = ' + str(coeffPoly))
                    coeffPolyList.append(coeffPoly)

                plot_num += 1
                plt.subplot(row_num, col_num, plot_num)

                plt.scatter(timeInflections, coeffPolyList)

                plt.title('Time Infletions vs Coefficients')
                plt.xlabel('Time (Minutes)')
                sensor_unit = retrieve_sensor_unit(sensor)
                plt.ylabel(sensor + ' ' + sensor_unit)
                # plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')

    path = [study, 'plotted', 'inflection', 'each_record', record]
    path = build_path(path)
    file = os.path.join(path, sensor + ".png")
    plt.savefig(file, bbox_inches='tight')
    print('inflection plot saved ' + file)
Пример #2
0
def plot_source(study):
    """

    """

    study_list = retrieve_ref('study_list')
    sensor_list = retrieve_ref('sensor_list')
    segment_list = retrieve_ref('segment_list')

    format_type = 'source'
    source_path = os.path.join('studies', study, 'formatted', format_type)
    format_folders = os.listdir(source_path)

    for record in format_folders:

        row_num, col_num, plot_num = len(sensor_list), 1, 0
        row_width_mulp, col_width_mulp = 14, 5
        plot_width, plot_height = col_num * row_width_mulp, row_num * col_width_mulp
        plt.figure(figsize=(plot_width, plot_height))

        for sensor in sensor_list:

            plot_num += 1
            plt.subplot(row_num, col_num, plot_num)

            for segment in segment_list:

                format_types = ['source', 'truncate']

                for format_type in format_types:

                    source = os.path.join('studies', study, 'formatted',
                                          format_type, record, segment,
                                          sensor + '.csv')

                    if os.path.isfile(source):

                        print('source = ' + source)

                        df = pd.read_csv(source)

                        colNames = list(df.head())
                        print('colNames = ')
                        print(colNames)

                        for colName in colNames:

                            if str('measurement') in str(colName):

                                colNameSplit = colName.split('_')
                                labelName = format_type
                                print('labelName = ' + labelName)
                                valueColor = retrieve_ref_color(labelName)

                                plt.scatter(df['timeUnix'],
                                            df[colName],
                                            color=valueColor,
                                            label=labelName)
                                plt.xlabel('time Unix')

                                sensor_unit = retrieve_sensor_unit(sensor)
                                plt.ylabel(sensor + ' ' + sensor_unit)
                                plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2),
                                           loc='upper left')

        path = ['studies', study, 'plotted', format_type, record]
        path = build_path(path)
        file = os.path.join(path, sensor + ".png")
        plt.savefig(file, bbox_inches='tight')
Пример #3
0
def plot_regression_segment(study, record, segment, sensor, degree):
    """

    """

    df_coef = retrieve_regression(study, segment, sensor, degree)
    colNamesCoef = list(df_coef.head())

    format_type = 'clean'
    source = os.path.join('studies', study, 'formatted', format_type, record,
                          segment, sensor + '.csv')
    print('source = ' + source)
    df = pd.read_csv(source)

    colNames = list(df.head())
    print('colNames = ')
    print(colNames)
    xx = list(df['timeMinutes'])

    if len(xx) == 0:
        return (0)

    yyReal = list(df[colNames[-1]])
    i = df_coef[df_coef['recordName'] == record].index.values[0]

    coeff = df_coef.loc[i, colNamesCoef[-1]]

    print('coeff = ')
    print(coeff)

    try:
        float(coeff)
        coeff = [coeff]

    except:
        coeff = coeff.split(' ')

    print('coeff = ')
    print(coeff)

    # print('coeff =')
    # print(coeff)

    yy = []
    for x in xx:
        # print('x = ' + str(x))
        # print('len(coeff) = ' + str(len(coeff)))
        y = 0
        coef_equation = []
        for i in range(len(coeff)):
            y = y + float(coeff[i]) * math.pow(x, len(coeff) - i - 1)
            # y = y + float(coeff[i])*math.pow(x, i)
            coef_equation.append(
                str(
                    str(round(float(coeff[i]), 4)) + '*x^' +
                    str(len(coeff) - i - 1)))
        yy.append(y)
        # explain polyval https://numpy.org/devdocs/reference/generated/numpy.polyval.html

    wearable_num = 1
    colorWearableSegment = retrieve_ref_color_wearable_segment(
        wearable_num, segment)
    plt.scatter(xx, yyReal, color=colorWearableSegment, label='measured')

    wearable_num = 2
    colorWearableSegment = retrieve_ref_color_wearable_segment(
        wearable_num, segment)
    labelPolyfit = str('polyfit degree = ' + str(degree))
    plt.plot(xx, yy, '--', color=colorWearableSegment, label=labelPolyfit)

    plt.xlabel('Time (Minutes)')
    sensor_unit = retrieve_sensor_unit(sensor)
    plt.ylabel(sensor + ' ' + sensor_unit)
    plt.title(segment + ' polyfit for degree ' + str(degree))

    coef_str = [str(x) for x in coef_equation]
    coef_str = ' '.join(coef_str)
    print('coef_str = ')
    print(coef_str)
    plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')
    plt.title(segment + ' polyfit for degree ' + str(degree) + ' ' +
              str(coef_str))

    return (0)
Пример #4
0
def plot_inflections(study, record, sensor, segment):
    """
    plot inflections
    """

    if segment != 'All':
        return

    searchRange = retrieve_ref('searchRange')
    searchRange = [int(x) for x in searchRange]

    format_type, segment, range = 'trunate', 'All', searchRange[0]
    path = [study, 'analyzed', 'inflections', 'all_times', str(range), record, segment]
    file = os.path.join(*path, sensor + ".csv")

    if not os.path.isfile(file):
        return


    row_num, col_num, plot_num = len(searchRange)+2, 1, 0
    row_width_mulp, col_width_mulp = 12, 5
    plot_width, plot_height = col_num*row_width_mulp, row_num*col_width_mulp
    plt.figure(figsize=(plot_width, plot_height))

    for range in searchRange:

        plot_num += 1
        plt.subplot(row_num, col_num, plot_num)

        path = [study, 'analyzed', 'inflections', 'all_times', str(range), record, segment]
        file = os.path.join(*path, sensor + ".csv")

        if not os.path.isfile(file):
            continue

        # source = os.path.join(study, 'formatted', format_type, record, segment, sensor + '.csv')
        # print('source = ' + source)
        df = pd.read_csv(file)

        for colName in df.columns:

            if 'Unnamed' in colName:
                del df[colName]

            elif 'Minutes' in colName:
                timeMinutes = list(df[colName])

            elif 'measurement' in colName and '_' not in colName:
                measList = list(df[colName])
                measMin = min(measList)
                measMax = max(measList)
                plt.scatter(timeMinutes, measList, label = str(colName))

            elif 'inflectionDecision' in colName:
                dfInflections = df.drop(df[(df[colName] != 'Yes')].index)
                timeInflections = list(dfInflections['timeMinutes'])

            print('timeInflections = ')
            print(timeInflections)

            for time in timeInflections:

                xx = np.linspace( time, time, 100)
                yy = np.linspace( measMin, measMax, 100)
                plt.plot(xx, yy, color=[0,.9,.6])

            plt.xlabel('time Unix')
            sensor_unit = retrieve_sensor_unit(sensor)
            plt.ylabel(sensor + ' ' + sensor_unit )
            # plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')
            plt.title('Record = ' + str(record) + ' Range = ' + str(range) + ' seconds ' + ' Inflections Found = ' + str(len(timeInflections)) )

        path = [study, 'plotted', 'inflection', 'each_record', record]
        path = build_path(path)
        file = os.path.join(path, sensor + ".png")
        plt.savefig(file, bbox_inches='tight')
        print('inflection plot saved ' + file)
Пример #5
0
def plot_coregister(study):
    """

    """

    segment = 'All'

    study_list = retrieve_ref('study_list')
    sensor_list = retrieve_ref('sensor_list')
    segment_list = retrieve_ref('segment_list')
    segment_list.reverse()

    format_type = 'clean'
    source_path = os.path.join('studies', study, 'formatted', format_type)
    format_folders = os.listdir(source_path)

    format_types = ['clean']

    for record in format_folders:

        row_num, col_num, plot_num = len(sensor_list), 1, 0
        row_width_mulp, col_width_mulp = 14, 5
        plot_width, plot_height = col_num * row_width_mulp, row_num * col_width_mulp
        plt.figure(figsize=(plot_width, plot_height))

        for sensor in sensor_list:

            plot_num += 1
            plt.subplot(row_num, col_num, plot_num)

            for format_type in format_types:

                for segment in segment_list:

                    source = os.path.join('studies', study, 'formatted',
                                          format_type, record, segment,
                                          sensor + '.csv')

                    if os.path.isfile(source):

                        print('source = ' + source)

                        df = pd.read_csv(source)

                        colNames = list(df.head())
                        print('colNames = ')
                        print(colNames)

                        for colName in colNames:

                            if str('measurement') in str(colName):

                                colNameSplit = colName.split('_')
                                labelName = str(format_type + ' ' +
                                                colNameSplit[0])
                                print('labelName = ' + labelName)
                                index_col = df.columns.get_loc(colName)
                                wearable_num = len(colNames) - index_col
                                print('wearable_num = ' + str(wearable_num))
                                colorWearableSegment = retrieve_ref_color_wearable_segment(
                                    wearable_num, segment)

                                plt.scatter(df['timeMinutes'],
                                            df[colName],
                                            color=colorWearableSegment,
                                            label=labelName)

            plt.xlabel('Record Time (minutes)')
            sensor_unit = retrieve_sensor_unit(sensor)
            plt.ylabel(sensor + ' ' + sensor_unit)
            plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')

        path = ['studies', study, 'plotted', 'clean', record]
        path = build_path(path)
        file = os.path.join(path, sensor + ".png")
        plt.savefig(file, bbox_inches='tight')
Пример #6
0
def plot_acc(study):
    """

    """

    print('compare ACC sensors')

    format_type, sensor, segment = 'truncate', 'ACC', 'All'
    source_path = os.path.join('studies', study, 'formatted', format_type)
    format_folders = os.listdir(source_path)

    for record in format_folders:

        row_num, col_num, plot_num = 5, 1, 0
        row_width_mulp, col_width_mulp = 14, 5
        plot_width, plot_height = col_num * row_width_mulp, row_num * col_width_mulp
        plt.figure(figsize=(plot_width, plot_height))

        source = os.path.join('studies', study, 'formatted', format_type,
                              record, segment, sensor + '.csv')

        if os.path.isfile(source):

            print('source = ' + source)

            df = pd.read_csv(source)

            colNames = list(df.head())
            print('colNames = ')
            print(colNames)

            for colName in colNames:

                if str('eas') in str(colName):

                    plot_num += 1
                    plt.subplot(row_num, col_num, plot_num)

                    labelName = colName
                    print('labelName = ' + labelName)

                    valueColor = retrieve_ref_color(
                        str('color_' + str(sensor) + '_' + str(colName)))
                    plt.scatter(df['timeUnix'],
                                df[colName],
                                color=valueColor,
                                label=labelName)

                    plt.xlabel('time Unix')
                    sensor_unit = retrieve_sensor_unit(sensor)
                    plt.ylabel(sensor + ' ' + sensor_unit)
                    plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2),
                               loc='upper left')

            plot_num += 1
            plt.subplot(row_num, col_num, plot_num)

            for colName in colNames:

                if str('eas') in str(colName):

                    labelName = colName
                    print('labelName = ' + labelName)

                    valueColor = retrieve_ref_color(
                        str('color_' + str(sensor) + '_' + str(colName)))
                    plt.scatter(df['timeUnix'],
                                df[colName],
                                color=valueColor,
                                label=labelName)

            plt.xlabel('time (Unix)')
            sensor_unit = retrieve_sensor_unit(sensor)
            plt.ylabel(sensor + ' ' + sensor_unit)
            plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')

        path = ['studies', study, 'plotted', format_type, record]
        path = build_path(path)
        file = os.path.join(path, sensor + ".png")
        plt.savefig(file, bbox_inches='tight')
        print('acc saved: ' + file)
def plot_inflections():
    """

    """

    study_list = retrieve_ref('study_list')
    sensor_list = retrieve_ref('sensor_list')
    segment_list = retrieve_ref('segment_list')
    searchRange = retrieve_ref('searchRange')

    for study in study_list:

        for sensor in sensor_list:

            format_type = 'clean'
            clean_path = os.path.join(study, 'formatted', format_type)
            recordNames = os.listdir(clean_path)

            for sensor in sensor_list:

                for record in recordNames:

                    row_num, col_num, plot_num = len(searchRange), 2, 0
                    row_width_mulp, col_width_mulp = 7, 5
                    plot_width, plot_height = col_num * row_width_mulp, row_num * col_width_mulp
                    plt.figure(figsize=(plot_width, plot_height))

                    for range in searchRange:

                        plot_num += 1
                        plt.subplot(row_num, col_num, plot_num)

                        format_type = 'clean'
                        segment = 'All'

                        path = [
                            study, 'analyzed', 'inflections', 'all_times',
                            str(range), record, segment
                        ]
                        path = build_path(path)
                        file = os.path.join(path, sensor + ".csv")

                        if os.path.isfile(file):

                            source = os.path.join(study, 'formatted',
                                                  format_type, record, segment,
                                                  sensor + '.csv')
                            print('source = ' + source)
                            df = pd.read_csv(source)

                            for colName in df.columns:
                                if 'timeMinutes' in colName:
                                    timeMinutes = list(df[colName])

                                if 'meas' in colName:
                                    measList = list(df[colName])
                                    measMin = min(measList)
                                    measMax = max(measList)
                                    plt.scatter(timeMinutes,
                                                measList,
                                                label=str(colName))

                            df = pd.read_csv(file)
                            for colName in df.columns:

                                if 'inflection' in colName:

                                    df = df.drop(
                                        df[(df[colName] != 'Yes')].index)

                            timeInflections = list(df['timeMinutes'])

                            for time in timeInflections:

                                xx = np.linspace(time, time, 100)
                                yy = np.linspace(measMin, measMax, 100)
                                plt.plot(xx, yy, color=[0, .9, .6])

                            plt.xlabel('time Unix')
                            sensor_unit = retrieve_sensor_unit(sensor)
                            plt.ylabel(sensor + ' ' + sensor_unit)
                            # plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')
                            plt.title('Record = ' + str(record) + ' Range = ' +
                                      str(range) + ' seconds')

                    path = [
                        study, 'plotted', 'inflection', 'each_record', record
                    ]
                    path = build_path(path)
                    file = os.path.join(path, sensor + ".png")
                    plt.savefig(file, bbox_inches='tight')
                    print('inflection plot saved ' + file)
Пример #8
0
def plot_timestamp():
    """
    compare the curves to verify the end of the record was properly found
    plot the source measurements for temperature
    plot the timestamped data for the temperature
    plot the truncated data
    plot the timestamped and truncated on the same plot
    """

    print("begin plotting timestamped data")

    study_list = retrieve_ref('study_list')
    sensor_list = retrieve_ref('sensor_list')
    analysis_list = retrieve_ref('analysis_list')

    for study in study_list:

        metadata_path = os.path.join(study, 'meta')
        metadata_file = os.path.join(metadata_path, 'metadata.csv')
        df_meta = pd.read_csv(metadata_file)
        # print(df_meta)

    # timestamp temp
    sensor = 'TEMP'
    for study in study_list:

        df_meta = retrieve_meta(study)
        source_path = list(df_meta['source_path'])

        for record in source_path:

            row_num, col_num, plot_num = 4, 1, 0
            row_width_mulp, col_width_mulp = 14, 5
            plot_width, plot_height = col_num*row_width_mulp, row_num*col_width_mulp
            plt.figure(figsize=(plot_width, plot_height))

            # plot the timestamp in unix of timestamped record
            plot_num += 1
            plt.subplot(row_num, col_num, plot_num)
            analysis_type = 'source'
            df = retrieve_analyzed(study, analysis_type, record, sensor)
            valueColor = retrieve_ref_color(str('color_' + str(analysis_type)))
            plt.scatter(df['count'], df['measurement'], color = valueColor, label = str(analysis_type))
            plt.title( analysis_type + ' ' + record + ' ' + sensor)
            plt.xlabel('Measurement Count - Before Timestamp')
            sensor_unit = retrieve_sensor_unit(sensor)
            plt.ylabel(str(sensor) + ' ( ' + str(sensor_unit) + ' )')
            plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')

            # plot the timestamp in unix of timestamped record
            plot_num += 1
            plt.subplot(row_num, col_num, plot_num)
            analysis_type = 'timestamp'
            df = retrieve_analyzed(study, analysis_type, record, sensor)
            valueColor = retrieve_ref_color(str('color_' + str(analysis_type)))
            plt.scatter(df['timeMinutes'], df['measurement'], color = valueColor, label = str(analysis_type))
            plt.title( analysis_type + ' ' + record + ' ' + sensor)
            plt.xlabel('Time (Unix)')
            sensor_unit = retrieve_sensor_unit(sensor)
            plt.ylabel(str(sensor) + ' ( ' + str(sensor_unit) + ' )')
            plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')
            # plot both the original and the truncated record
            plot_num += 1
            plt.subplot(row_num, col_num, plot_num)
            for analysis_type in analysis_list:
                df = retrieve_analyzed(study, analysis_type, record, sensor)
                valueColor = retrieve_ref_color(str('color_' + str(analysis_type)))
                plt.scatter(df['timeMinutes'], df['measurement'], color = valueColor, label = str(analysis_type))
            plt.title( analysis_type + ' ' + record + ' ' + sensor)
            plt.xlabel('Time (minutes)')
            sensor_unit = retrieve_sensor_unit(sensor)
            plt.ylabel(str(sensor) + ' ( ' + str(sensor_unit) + ' )')
            plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')



            # plot the truncated record
            plot_num += 1
            plt.subplot(row_num, col_num, plot_num)
            analysis_type = 'truncate'
            df = retrieve_analyzed(study, analysis_type, record, sensor)
            valueColor = retrieve_ref_color(str('color_' + str(analysis_type)))
            plt.scatter(df['timeMinutes'], df['measurement'], color = valueColor, label = str(analysis_type))
            plt.title( analysis_type + ' ' + record + ' ' + sensor)
            plt.xlabel('Time (minutes)')
            sensor_unit = retrieve_sensor_unit(sensor)
            plt.ylabel(str(sensor) + ' ( ' + str(sensor_unit) + ' )')
            plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2), loc='upper left')


            # save the plot
            plot_path = os.path.join(study, 'plot')
            if not os.path.isdir(plot_path): os.mkdir(plot_path)
            plot_path = os.path.join(study, 'plot', 'timestamp')
            if not os.path.isdir(plot_path): os.mkdir(plot_path)
            plot_path = os.path.join(study, 'plot', 'timestamp', record)
            if not os.path.isdir(plot_path): os.mkdir(plot_path)
            plot_file = os.path.join(plot_path, sensor + '.png')
            plt.savefig(plot_file, bbox_inches='tight')

    print("completed plotting timestamped data")
Пример #9
0
def plot_segment():
    """
    Clean the data
    """

    print("plot segment data")

    study_list = retrieve_ref('study_list')
    sensor_list = retrieve_ref('sensor_list')
    segment_list = retrieve_ref('segment_list')
    timePreStudy = retrieve_ref('timePreStudy')
    timePostStudy = retrieve_ref('timePostStudy')

    for study in study_list:
        df_meta = retrieve_meta(study)
        source_path = list(df_meta['source_path'])

        for record in source_path:

            row_num, col_num, plot_num = 6, 1, 0
            row_width_mulp, col_width_mulp = 14, 5
            plot_width, plot_height = col_num * row_width_mulp, row_num * col_width_mulp
            plt.figure(figsize=(plot_width, plot_height))

            for sensor in sensor_list:

                # plot the timestamp in unix of timestamped record
                plot_num += 1
                plt.subplot(row_num, col_num, plot_num)

                for segment in segment_list[0:-1]:

                    # print('segment_list')
                    # print(segment_list)

                    analysis_type = segment
                    df = retrieve_analyzed(study, analysis_type, record,
                                           sensor)

                    # print(df)

                    valueColor = retrieve_ref_color(
                        str('color_' + str(segment)))
                    plt.scatter(df['timeMinutes'],
                                df['measurement'],
                                color=valueColor,
                                label=str(segment))
                    plt.title(analysis_type + ' ' + record + ' ' + sensor)
                    plt.xlabel('Measurement Count - Before Timestamp')
                    sensor_unit = retrieve_sensor_unit(sensor)
                    plt.ylabel(str(sensor) + ' ( ' + str(sensor_unit) + ' )')
                    plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2),
                               loc='upper left')

            # save the plot
            plot_path = os.path.join(study, 'plot')
            if not os.path.isdir(plot_path): os.mkdir(plot_path)
            plot_path = os.path.join(study, 'plot', 'segment')
            if not os.path.isdir(plot_path): os.mkdir(plot_path)
            plot_path = os.path.join(study, 'plot', 'segment', record)
            if not os.path.isdir(plot_path): os.mkdir(plot_path)
            plot_file = os.path.join(plot_path, sensor + '.png')
            plt.savefig(plot_file, bbox_inches='tight')
Пример #10
0
def plot_acc():
    """
    compare the curves to verify the end of the record was properly found
    plot the source measurements for temperature
    plot the timestamped data for the temperature
    plot the truncated data
    plot the timestamped and truncated on the same plot
    """

    print("begin plotting acc data")

    study_list = retrieve_ref('study_list')
    sensor_list = retrieve_ref('sensor_list')
    analysis_list = retrieve_ref('analysis_list')

    for study in study_list:

        metadata_path = os.path.join(study, 'meta')
        metadata_file = os.path.join(metadata_path, 'metadata.csv')
        df_meta = pd.read_csv(metadata_file)
        # print(df_meta)

    # timestamp ACC
    sensor = 'ACC'
    for study in study_list:

        df_meta = retrieve_meta(study)
        source_path = list(df_meta['source_path'])

        for record in source_path:

            row_num, col_num, plot_num = 5, 1, 0
            row_width_mulp, col_width_mulp = 20, 5
            plot_width, plot_height = col_num * row_width_mulp, row_num * col_width_mulp
            plt.figure(figsize=(plot_width, plot_height))

            analysis_type = 'truncate'
            df = retrieve_analyzed(study, analysis_type, record, sensor)

            for name in list(df.columns):

                if 'time' not in name:

                    plot_num += 1
                    plt.subplot(row_num, col_num, plot_num)
                    colorScatter = valueColor = retrieve_ref_color(
                        str('color_' + str(sensor) + '_' + str(name)))
                    plt.scatter(df['timeMinutes'],
                                df[name],
                                color=colorScatter,
                                label=str(name))
                    # plt.scatter(df['timeMinutes'], df['measurement'], label = str('vector'))
                    plt.title(analysis_type + ' ' + record + ' ' + sensor)
                    plt.xlabel('Time (Minutes)')
                    plt.ylabel(str(sensor + ' ' + name))
                    plt.xlim([0, 1.02 * max(list(df['timeMinutes']))])
                    plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2),
                               loc='upper left')

            plot_num += 1
            plt.subplot(row_num, col_num, plot_num)

            for name in list(df.columns):

                if 'time' not in name:
                    colorScatter = valueColor = retrieve_ref_color(
                        str('color_' + str(sensor) + '_' + str(name)))
                    plt.scatter(df['timeMinutes'],
                                df[name],
                                color=colorScatter,
                                label=str(name))
                    plt.title(analysis_type + ' ' + record + ' ' + sensor +
                              ' ' + name)
                    plt.xlabel('Time (Minutes)')
                    sensor_unit = retrieve_sensor_unit(sensor)
                    plt.ylabel(
                        str(sensor + ' ' + name + ' ( ' + str(sensor_unit) +
                            ' )'))
                    plt.xlim([0, 1.02 * max(list(df['timeMinutes']))])
                    plt.legend(bbox_to_anchor=(1, 0.5, 0.3, 0.2),
                               loc='upper left')

            # save the plot
            plot_path = os.path.join(study, 'plot')
            if not os.path.isdir(plot_path): os.mkdir(plot_path)
            plot_path = os.path.join(study, 'plot', 'timestamp')
            if not os.path.isdir(plot_path): os.mkdir(plot_path)
            plot_path = os.path.join(study, 'plot', 'timestamp', record)
            if not os.path.isdir(plot_path): os.mkdir(plot_path)
            plot_file = os.path.join(plot_path, sensor + '.png')
            plt.savefig(plot_file, bbox_inches='tight')
            print('saved plotted acc figure - ' + str(plot_file))

    print("completed plotting acc data")