예제 #1
0
def saveStatsLite(saveDir, plmCount, plmHeights, plmModHeights, modifier=''):
    ''' Generate statistics, Lite version. Used for stats after the overall plume dictionary has been thrown away. '''

    statsList = [
        'Plumes Processed', 'Number of Valid Pairs', 'Number of Dropped Pairs',
        'MINX Plume Max', 'Model Plume Max', 'MINX Plume Min',
        'Model Plume Min', 'MINX Plume Mean', 'Model Plume Mean', 'RMSD',
        'Pearson Correlation Coefficient, pValue', 'R Squared, pValue',
        'Mean Absolute Percent Error', 'Mean Percentage Error'
    ]
    plmClean, modClean = clean_inv(plmHeights, plmModHeights)
    plmMax, plmMin, plmMean = np.nanmax(plmClean), np.nanmin(
        plmClean), np.nanmean(plmClean)
    modMax, modMin, modMean = np.nanmax(modClean), np.nanmin(
        modClean), np.nanmean(modClean)
    rmsdVal = RMSD(plmClean, modClean)
    corrVal = corr_coeff(plmClean, modClean)
    rSquareVal = linRegress(plmClean, modClean)
    mapeVal = mape(plmClean, modClean)
    mpeVal = mpe(plmClean, modClean)
    mbVal = mean_bias(plmClean, modClean)
    numPlms = plmCount
    pairVal = len(plmClean)
    unPairVal = len(plmHeights) - len(plmClean)
    statsVals = [
        numPlms, pairVal, unPairVal, plmMax, modMax, plmMin, modMin, plmMean,
        modMean, rmsdVal, corrVal, rSquareVal, mapeVal, mpeVal
    ]
    f = open(os.path.join(saveDir, 'PlumesStats{}.txt'.format(modifier)), 'w')
    for statInd, stat in enumerate(statsList):
        f.write('{}, {} \n'.format(stat, str(statsVals[statInd])))
    f.close()
예제 #2
0
def plotFuels(fuelDir, plmFuels, threshVal, pt, modifier=''):
    ''' Get results by fuel type. '''

    nu.makeDir(fuelDir)
    distRanges = [[0, 10], [10, 30], [30, 60], [60, 500]]
    distDir = os.path.join(fuelDir, 'distances')
    for fuel in plmFuels:
        try:
            plmHeights = plmFuels[fuel]['plmHeights']
            plmModHeights = plmFuels[fuel]['plmModHeights']
            plmDists = plmFuels[fuel]['plmDists']
            plmCount = plmFuels[fuel]['plmCount']
            cleanPlm, cleanMod, cleanDist = clean_inv(plmHeights,
                                                      plmModHeights, plmDists)
            overallImages(plmDists,
                          plmHeights,
                          plmModHeights,
                          saveDir=fuelDir,
                          modifier=modifier + '_fuel{}'.format(fuel))
            saveStatsLite(fuelDir,
                          plmCount,
                          plmHeights,
                          plmModHeights,
                          modifier=modifier + '_fuel{}'.format(fuel))
            for dRange in distRanges:
                try:
                    dPlmHeights, dPlmModHeights, dPlmDists = filterPlmRange(
                        dRange, plmHeights, plmModHeights, plmDists)
                    overallImages(
                        dPlmDists,
                        dPlmHeights,
                        dPlmModHeights,
                        distDir,
                        modifier=modifier +
                        '_{}_dist{}-{}'.format(fuel, dRange[0], dRange[1]))
                    saveStatsLite(
                        distDir,
                        'N/A',
                        dPlmHeights,
                        dPlmModHeights,
                        modifier=modifier +
                        '{}_dist{}-{}'.format(fuel, dRange[0], dRange[1]))
                except:
                    pass
            cleanModPlmRatio = []
            for pInd, (plm, modPlm) in enumerate(zip(cleanPlm, cleanMod)):
                modPlmRatio = modPlm / plm
                cleanModPlmRatio += [modPlmRatio]
            pltDistRatio(cleanDist,
                         cleanModPlmRatio,
                         fuelDir,
                         modifier=modifier + '_fuel{}'.format(fuel))
            pltPlmHeightComp('fuel', fuel, cleanPlm, cleanMod, fuelDir,
                             modifier)
            nu.plotFuelMap(fuelDir,
                           plmOrigins=plmFuels[fuel]['plmXYOrigins'],
                           modifier=modifier + '_{}'.format(fuel))
            print('Fuel {} map plotted'.format(fuel))
        except:
            pass
예제 #3
0
def pltHistModValues(plmModValues, saveDir, threshVal, modifier=''):
    fig3 = plt.figure()
    plt.hist(clean_inv(plmModValues))
    plt.title('Model Plume Values (Local Max of PM2.5)')
    fig3.savefig(
        os.path.join(
            saveDir,
            '{}PlumeModValuesHist_thresh{}.png'.format(modifier, threshVal)))
    plt.close('all')
예제 #4
0
def pltHistFRP(plmFRPs, saveDir, threshVal, modifier=''):
    # Also not likely to be used, since FRP is not representative of plume size/height given that it takes a cluster of fire pixels within the digitized plume
    fig2 = plt.figure()
    plt.hist(clean_inv(plmFRPs))
    plt.title('Plume FRPs')
    fig2.savefig(
        os.path.join(saveDir,
                     '{}PlumeFRPs_thresh{}.png'.format(modifier, threshVal)))
    plt.close('all')
예제 #5
0
def mpe(x, y):
    # mean percent error
    err = 0
    arg1, arg2 = clean_inv(x, y)
    for ind, (xVal, yVal) in enumerate(zip(arg1, arg2)):
        try:
            err += (xVal - yVal) / xVal
        except:
            continue
    return err * 100 / len(arg1)
예제 #6
0
def mean_bias(optVal, modVal, error=False, normalized=True):
    bias = []
    optval, modelval = clean_inv(optVal, modVal)
    if not error:
        numer = sum([(oval - modelval[i])**2 for i, oval in enumerate(optval)])
    else:
        numer = sum(
            [abs(oval - modelval[i])**2 for i, oval in enumerate(optval)])
    denom = len(optVal) if not normalized else sum(modelval)
    bias.append(numer / denom)
    return bias[0] if len(bias) == 1 else bias
예제 #7
0
def mape(x, y):
    # mean absolute percent error,
    # forecast value is model, true value is MINX plume
    arg1, arg2 = clean_inv(x, y)
    errors = []
    for ind, (xVal, yVal) in enumerate(zip(arg1, arg2)):
        try:
            err = np.abs((xVal - yVal) / xVal)
            errors.append(err)
        except:
            continue
    return np.mean(errors) * 100
예제 #8
0
def pltHistHeight(plmHeights, plmModHeights, saveDir, modifier=''):
    ''' Plot a histogram of the plume MINX and Model heights. '''

    figHist = plt.figure()
    clnPlmHeights, clnPlmModHeights = clean_inv(plmHeights, plmModHeights)
    plt.hist(clnPlmHeights, alpha=0.5)
    plt.hist(clnPlmModHeights, alpha=0.5)
    plt.legend(['MINX Plume Heights', 'Model Plume Heights'])
    plt.xlabel('Plume Heights')
    plt.title('Plume Height Histogram')
    figHist.savefig(
        os.path.join(saveDir, 'DistanceHist{}.png'.format(modifier)))
    plt.close('all')
예제 #9
0
def pltResids(plmHeights, plmModHeights, saveDir, modifier=''):
    ''' Plot a residual plot. This is used to see if there is a linear trend in the data. '''

    cleanPlm, cleanMod = clean_inv(plmHeights, plmModHeights)
    residuals = []
    for point, (pl, md) in enumerate(zip(cleanPlm, cleanMod)):
        residuals.append(pl - md)
    figResid = plt.figure()
    plt.scatter(cleanPlm, residuals)
    plt.xlabel('MINX Plume Height')
    plt.ylabel('Plume Height (MINX - Model)')
    plt.title('Plume Comparison Residual Plot')
    figResid.savefig(
        os.path.join(saveDir, 'ResidualPlot{}.png'.format(modifier)))
    plt.close('all')
예제 #10
0
def saveStats(saveDir,
              plumeDict,
              plmHeights,
              plmModHeights,
              minFRP,
              modifier=''):
    ''' Generate some statistics and save to a txt file. '''

    statsList = [
        'Minimum FRP (MWatts)', 'Plumes Processed', 'Number of Valid Pairs',
        'Number of Dropped Pairs', 'MINX Plume Max', 'Model Plume Max',
        'MINX Plume Min', 'Model Plume Min', 'MINX Plume Mean',
        'Model Plume Mean', 'RMSD', 'Pearson Correlation Coefficient, pValue',
        'R Squared, pValue', 'Mean Absolute Percent Error',
        'Mean Percentage Error'
    ]

    plmClean, modClean = clean_inv(plmHeights, plmModHeights)
    plmMax, plmMin, plmMean = np.nanmax(plmClean), np.nanmin(
        plmClean), np.nanmean(plmClean)
    modMax, modMin, modMean = np.nanmax(modClean), np.nanmin(
        modClean), np.nanmean(modClean)
    rmsdVal = RMSD(plmClean, modClean)
    corrVal = corr_coeff(plmClean, modClean)
    rSquareVal = linRegress(plmClean, modClean)
    mapeVal = mape(plmClean, modClean)
    mpeVal = mpe(plmClean, modClean)
    mbVal = mean_bias(plmClean, modClean)
    numPlms = len(plumeDict.keys())
    pairVal = len(plmClean)
    unPairVal = len(plmHeights) - len(plmClean)
    statsVals = [
        minFRP, numPlms, pairVal, unPairVal, plmMax, modMax, plmMin, modMin,
        plmMean, modMean, rmsdVal, corrVal, rSquareVal, mapeVal, mpeVal
    ]

    f = open(os.path.join(saveDir, 'PlumeStats{}.txt'.format(modifier)), 'w')
    for statInd, stat in enumerate(statsList):
        f.write('{}, {} \n'.format(stat, str(statsVals[statInd])))
    f.close()
예제 #11
0
def plotBiomes(biomeDir, plmBiomes, modifier=''):
    ''' Get results by biome. '''

    nu.makeDir(biomeDir)
    for biome in plmBiomes:
        try:
            cleanPlm, cleanMod, cleanDist = clean_inv(
                plmBiomes[biome]['plmHeights'],
                plmBiomes[biome]['plmModHeights'],
                plmBiomes[biome]['plmDists'])
            cleanModPlmRatio = []
            for pInd, (plm, modPlm) in enumerate(zip(cleanPlm, cleanMod)):
                modPlmRatio = modPlm / plm  # is this proper division?
                cleanModPlmRatio += [modPlmRatio]
            pltDistRatio(cleanDist,
                         cleanModPlmRatio,
                         biomeDir,
                         modifier=modifier + '_biome{}'.format(biome))
            pltPlmHeightComp('biome', biome, cleanPlm, cleanMod, biomeDir,
                             modifier)
        except:
            pass
예제 #12
0
def distanceStats(plumeHeights,
                  modHeights,
                  distances,
                  saveDir,
                  distBins=5,
                  modifier=''):
    ''' This is a misnomer actually.

    Plots a histogram of distances then plots a ratio of model/minc plume points by distance.
    '''

    cleanPlm, cleanMod, cleanDist = clean_inv(plumeHeights, modHeights,
                                              distances)
    pltHistDistances(cleanDist, distBins, saveDir, modifier)
    cleanModPlmRatio = []
    for pInd, (plm, modPlm) in enumerate(zip(cleanPlm, cleanMod)):
        modPlmRatio = modPlm / plm  # is this proper division?
        cleanModPlmRatio += [modPlmRatio]
    pltDistRatio(cleanDist, cleanModPlmRatio, saveDir, modifier)
    #NOTE: should include the savestats method here as well

    pltResid = False
    if pltResid == True:
        pltResids(plmHeights, plmModHeights, saveDir, threshVal, pt)
예제 #13
0
def corr_coeff(optVal, modVal):
    from scipy import stats
    arg1, arg2 = clean_inv(optVal, modVal)
    return stats.pearsonr(arg1, arg2)
예제 #14
0
def linRegress(x, y):
    from scipy import stats
    arg1, arg2 = clean_inv(x, y)
    slope, intercept, rVal, pVal, stndErr = stats.linregress(arg1, arg2)
    return (rVal**2, pVal, 'y = {}x + {}'.format(slope, intercept))
예제 #15
0
def RMSD(optVal, modVal):
    RMS = []
    optval, modelval = clean_inv(optVal, modVal)
    numer = sum([(oval - modelval[i])**2 for i, oval in enumerate(optval)])
    RMS.append((numer / len(optval))**0.5)
    return RMS[0] if len(RMS) == 1 else RMS