Exemplo n.º 1
0
def picarroMetCombo(filename):

    met = metTrim()
    sheet = pd.read_csv(filename,
                        encoding='utf8',
                        header=None,
                        delim_whitespace=True)
    sheet.columns = ['date', 'value']
    sheet['datetime'] = decToDatetime(sheet['date'].values)
    sheet.drop('date', axis=1, inplace=True)
    earlyVals = ~(met['datetime'] <= sheet['datetime'][0])
    met.drop(earlyVals, axis=0, inplace=True)
    met.reset_index(drop=True, inplace=True)
    met.drop(['steady'], axis=1, inplace=True)

    # merge the met data onto the concentration data by finding the nearest datetime within an hour\
    sheet.dropna(axis=0, how='any', inplace=True)
    picarro = pd.merge_asof(sheet.sort_values('datetime'),
                            met,
                            on='datetime',
                            direction='nearest',
                            tolerance=pd.Timedelta('1 hour'))
    picarro.dropna(axis=0, how='any', inplace=True)

    return picarro
Exemplo n.º 2
0
def metRemove(sheet, tolerance, dropMet=True):
    """
    metRemove is a function that removes values from a Summit dataset if the linked meteorlogical data is identified
    as being from a polluted zone. It takes a specific dataframe as an input, and returns the same exact dataframe.

    :param sheet: the dataframe can have any values but it must have a column labeled 'datetime'
    :param tolerance: the integer number of hours set to link met data with
    :param dropMet: default True, drops the columns of met data from the returned product. If false, met columns
    remain intact
    :return combo: returns the same dataframe, reindexed, polluted values removed
    """

    # identify and set the tolerence
    hours = f'{tolerance} hours'
    timedelt = pd.Timedelta(hours)

    # combine the input data with met data, dropping NaN's before and after
    met = metTrim()
    met.dropna(axis=0, how='any', inplace=True)
    sheet.dropna(axis=0, how='any', inplace=True)
    combo = pd.merge_asof(sheet.sort_values('datetime'),
                          met,
                          on='datetime',
                          direction='nearest',
                          tolerance=timedelt)
    combo.dropna(axis=0, how='any', inplace=True)

    # remove polluted values
    speedCutoff = 1.02889  # meters/second, too slow
    dirCutoff = (342, 72)  # polution directions, above 342, below 72

    lenOrig = len(combo)

    combo = combo[combo['spd'] > speedCutoff]
    combo.reset_index(drop=True, inplace=True)

    valuesInRange = np.logical_or(combo['dir'] >= dirCutoff[0],
                                  combo['dir'] <= dirCutoff[1])

    combo.drop(combo[valuesInRange].index, axis=0, inplace=True)

    combo.reset_index(drop=True, inplace=True)

    percentChange = (1 - (len(combo) / lenOrig)) * 100
    print(
        f'{percentChange} percent of the data was trimmed from pollution identification'
    )

    # remove unnecesary steady column
    badcol = ['steady']
    combo.drop(badcol, axis=1, inplace=True)

    if dropMet:
        combo.drop(['dir', 'spd'], axis=1, inplace=True)

    return combo
Exemplo n.º 3
0
def metPlotQC():

    register_matplotlib_converters()

    # import data
    met = metTrim()
    timelim = (met['datetime'].iloc[0] - dt.timedelta(days=20),
               met['datetime'].iloc[-1] + dt.timedelta(days=20))

    speedCutoff = 1.02889  # meters/second, too slow
    dirCutoff = (342, 72)  # polution directions, above 342, below 72

    sns.set()
    f, ax = plt.subplots(ncols=2, figsize=(12, 8))
    sns.despine(f)
    plt.subplots_adjust(left=None,
                        bottom=None,
                        right=None,
                        top=None,
                        wspace=None,
                        hspace=0.5)

    ax1 = sns.distplot(met['dir'], ax=ax[0])
    ax1.set_title('Summit Wind Direction Histogram')
    ax1.set_xlabel('Direction Clockwise from True North')
    ax1.set_ylabel('Value Distribution')
    # ax1.set(xlim=(timelim[0], timelim[1]))

    ax2 = sns.distplot(met['spd'], ax=ax[1])
    ax2.set_title('Summit Wind Speed Histogram')
    ax2.set_xlabel('Wind Speed [m/s]')
    ax2.set_ylabel('Value Distribution')
    # ax2.set(xlim=(timelim[0], timelim[1]))

    plt.show()

    sns.set(style="white", font_scale=1.5)
    sns.despine()
    g = sns.jointplot(met['dir'],
                      met['spd'],
                      kind='hex',
                      cmap=cm.magma_r,
                      color='#e65c00')
    g.set_axis_labels('Wind Direction Measured CW from True North',
                      'Wind Speed [m/s]',
                      fontsize=20)
    g.fig.suptitle('Met Data from Summit, Greenland', fontsize=28)
    plt.tick_params(axis='both', labelsize=18)
    plt.legend()

    plt.show()
Exemplo n.º 4
0
def metPlot():

    # import data
    met = metTrim()

    # wind rose plotting with just wind speed
    ax = wr.WindroseAxes.from_ax()
    ax.bar(met['dir'].values, met['spd'].values, normed=True, opening=0.9, edgecolor='black',
           nsector=24, bins=14, cmap=cm.viridis_r, blowto=False)
    ax.set_title('Wind Speed and Direction at Summit, Greenland')
    ax.set_xlabel('Wind Speed in Meters per Second')
    ax.set_legend()

    plt.show()

    return ax
Exemplo n.º 5
0
def windRoseMethane():

    # ---- import data
    root = r'C:\Users\ARL\Desktop\J_Summit\analyses\Data'
    met = metTrim()
    arl = metCombo(root + r'\methane2019updated.txt')
    arl.dropna(axis=0, how='any', inplace=True)
    pic = pd.read_csv(root + r'\picarro_ch4.txt',
                      delim_whitespace=True,
                      encoding='utf8',
                      error_bad_lines=False,
                      header=None)
    flask = pd.read_csv(root + r'\flask_ch4.txt',
                        delim_whitespace=True,
                        error_bad_lines=False,
                        header=None)

    # ---- combining datasets (met and picarro)
    pic.columns = ['date', 'value']
    pic['datetime'] = decToDatetime(pic['date'].values)
    pic.drop('date', axis=1, inplace=True)
    met.drop(['steady'], axis=1, inplace=True)

    # merge the met data onto the concentration data by finding the nearest datetime within an hour
    pic.dropna(axis=0, how='any', inplace=True)
    picarro = pd.merge_asof(pic.sort_values('datetime'),
                            met,
                            on='datetime',
                            direction='nearest',
                            tolerance=pd.Timedelta('1 hour'))
    picarro.dropna(axis=0, how='any', inplace=True)

    # ---- combining datasets (flask and met)
    met = metTrim()
    colnames = ['yr', 'mo', 'dy', 'hr', 'val']
    flask.columns = colnames
    flask['datetime'] = createDatetime(flask['yr'], flask['mo'], flask['dy'],
                                       flask['hr'])
    flask.drop(['yr', 'mo', 'dy', 'hr'], axis=1, inplace=True)
    earlyVals = (met['datetime'] <= flask['datetime'][0])
    met.drop(['steady'], axis=1, inplace=True)

    # merge the met data onto the concentration data by finding the nearest datetime within an hour
    flaskMet = pd.merge_asof(flask,
                             met,
                             on='datetime',
                             direction='nearest',
                             tolerance=pd.Timedelta('1 hour'))
    flaskMet.dropna(axis=0, how='any', inplace=True)

    # ---- plotting
    fig, (ax1, ax2, ax3) = plt.subplots(1,
                                        3,
                                        subplot_kw=dict(projection='windrose'))
    fig.suptitle('Methane Conc. at Summit by Wind Direction', fontsize=16)
    plt.subplots_adjust(left=None,
                        bottom=None,
                        right=None,
                        top=None,
                        wspace=0.2,
                        hspace=-0.3)

    # setup GC methane windrose
    ax1.bar(arl['dir'].values,
            arl['val'].values,
            normed=False,
            opening=0.9,
            edgecolor='black',
            nsector=24,
            bins=14,
            cmap=cm.viridis_r,
            blowto=False)
    ax1.set_title('GCFID Methane Conc. [ppb]\n')
    ax1.set_legend(loc=8,
                   fancybox=True,
                   shadow=True,
                   bbox_to_anchor=(0.5, -1.05))

    # setup picarro methane windrose
    ax2.bar(picarro['dir'].values,
            picarro['value'].values,
            normed=False,
            opening=0.9,
            edgecolor='black',
            nsector=24,
            bins=14,
            cmap=cm.viridis_r,
            blowto=False)
    ax2.set_title('Picarro Methane Conc. [ppb]\n', )
    ax2.set_legend(loc=8,
                   fancybox=True,
                   shadow=True,
                   bbox_to_anchor=(0.5, -1.05))

    # setup flask methane windrose
    ax3.bar(flaskMet['dir'].values,
            flaskMet['val'].values,
            normed=False,
            opening=0.9,
            edgecolor='black',
            nsector=24,
            bins=14,
            cmap=cm.viridis_r,
            blowto=False)
    ax3.set_title('Flask Methane Conc. [ppb]\n')
    ax3.set_legend(loc=8,
                   fancybox=True,
                   shadow=True,
                   bbox_to_anchor=(0.5, -1.05))

    plt.show()