def main(subArea, runName, chartTitlePre, ownership):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    varList = [' Stand Replacing FirePMG3', ' Stand Replacing FirePMG4', ' Stand Replacing FirePMG5']
    yLabelText = 'Percent of PMG 3, 4, and 5 in Stand Replacing Fire (top 10%)'
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)

    # list of ownerships to graphs
    if ownership == 'All':
        ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Tribal','Homeowner']
        pdfFile = PdfPages(outDir + 'report3_PMG345_in_HS_Fire_top10pct_All.pdf')
    else:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + 'report3_PMG345_in_HS_Fire_top10pct_' + ownersToGraph[0] + '.pdf')

    # setup plot for all scenarios
    fig = pl.figure(1, figsize=(11,8.5))
    ax = fig.add_subplot(1,1,1)

    for scenario in ['CurrentPolicy','NoFedTreat','Restoration']:
        inDir = outDir + runName + "_" + scenario + "\\"

        yearList = list(set(pd.io.parsers.read_csv(inDir + r'FireOccurance_by_OWNER_pivot.csv')[' Year']))
        repList = list(set(pd.io.parsers.read_csv(inDir + r'FireOccurance_by_OWNER_pivot.csv')[' Run']))
        totalArea = pd.io.parsers.read_csv(inDir + r'FireOccurance_by_OWNER_pivot.csv')
        dataTable = pd.DataFrame(totalArea[totalArea[' Year'] > 0])
        dataTable['key'] = dataTable[' OWNER_label'] + '_' + dataTable[' Run'].astype(str) + '_' + dataTable[' Year'].astype(str)

        if scenario == 'CurrentPolicy':
            scenarioTable = dataTable
        else:
            scenarioTable = pd.merge(scenarioTable, dataTable, how='left', on='key')

    # sum over owners
    scenarioTable.index = scenarioTable['key']
    fireProneArea = PMG345Ha[ownersToGraph[0]]
    if ownership == 'All':
        for rep in range(len(repList)):
            for year in range(1, len(yearList)):
                for owner in ownersToGraph:
                    key = owner + '_' + str(rep) + '_' + str(year)
                    print(key)
                    if owner != ownersToGraph[0]:
                        for varName in varList:
                            scenarioTable.loc[ownersToGraph[0] + '_' + str(rep) + '_' + str(year),varName] += scenarioTable.loc[key,varName]
                            scenarioTable.loc[ownersToGraph[0] + '_' + str(rep) + '_' + str(year),varName + '_x'] += scenarioTable.loc[key,varName + '_x']
                            scenarioTable.loc[ownersToGraph[0] + '_' + str(rep) + '_' + str(year),varName + '_y'] += scenarioTable.loc[key,varName + '_y']

        for owner in ownersToGraph:
            fireProneArea += PMG345Ha[owner]

    ownerArea = pd.DataFrame(scenarioTable[scenarioTable[' OWNER_label'] == ownersToGraph[0]])

    # calculate percent of PMG345 area for each row
    ownerArea['CP_HS_pct'] = (ownerArea[varList[0] + '_x'] + ownerArea[varList[1] + '_x'] + ownerArea[varList[2] + '_x']) / fireProneArea * 100
    ownerArea['NFT_HS_pct'] = (ownerArea[varList[0] + '_y'] + ownerArea[varList[1] + '_y'] + ownerArea[varList[2] + '_y']) / fireProneArea * 100
    ownerArea['Res_HS_pct'] = (ownerArea[varList[0]] + ownerArea[varList[1]] + ownerArea[varList[2]]) / fireProneArea * 100

    #Sort dataTable on percent PMG345 in HS fire
    dataTable = ownerArea.sort('NFT_HS_pct', ascending=False)

    statsList1 = []
    statsList2 = []
    statsList3 = []

    valueSet = []
    maxValueSet = []

    for i in range(int(round(len(dataTable) * 0.1))):
        statsList1.append(dataTable['CP_HS_pct'].iloc[i])
        statsList2.append(dataTable['NFT_HS_pct'].iloc[i])
        statsList3.append(dataTable['Res_HS_pct'].iloc[i])

    valueSet.append(statsList1)
    valueSet.append(statsList2)
    valueSet.append(statsList3)

    maxValueSet.append(max(statsList1))
    maxValueSet.append(max(statsList2))
    maxValueSet.append(max(statsList3))

    labelList = ['Current Policy','No Fed Treatment','Restoration']
    reporterFunc.plotReporter3(fig, ax, ownership + ' - ' + str(len(repList)) + ' reps', pdfFile, valueSet, labelList, subArea, chartTitle, yLabelText, scenario, maxValueSet)


    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
def main(outDir, subArea, runList, chartTitlePre, ownership):
    varList = [
        ' Stand Replacing FirePMG3', ' Stand Replacing FirePMG4',
        ' Stand Replacing FirePMG5'
    ]
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)

    # list of ownerships to graphs
    if ownership == 'All':
        ownersToGraph = [
            'Federal', 'State', 'Private Non-Industrial', 'Private Industrial',
            'Tribal', 'Homeowner'
        ]
        pdfFile = PdfPages(outDir + 'report6bw_PMG345_in_HS_Fire_All.pdf')
    else:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + 'report6bw_PMG345_in_HS_Fire_' +
                           ownersToGraph[0] + '.pdf')

    # Current Policy run required!
    for scenario in ['Restoration', 'CurrentPolicy']:
        inDir = outDir + scenario + "\\"

        if scenario == 'Restoration':
            yearList = list(
                set(
                    pd.io.parsers.read_csv(
                        inDir + r'FireOccurance_by_OWNER_pivot.csv')[' Year']))
            repList = list(
                set(
                    pd.io.parsers.read_csv(
                        inDir + r'FireOccurance_by_OWNER_pivot.csv')[' Run']))

        totalArea = pd.io.parsers.read_csv(inDir +
                                           r'FireOccurance_by_OWNER_pivot.csv')
        dataTable = pd.DataFrame(totalArea[totalArea[' Year'] > 0])
        dataTable['key'] = dataTable[' OWNER_label'] + '_' + dataTable[
            ' Run'].astype(str) + '_' + dataTable[' Year'].astype(str)

        if scenario == 'Restoration':
            scenarioTable = dataTable
        else:
            scenarioTable = pd.merge(scenarioTable,
                                     dataTable,
                                     how='left',
                                     on='key')

    # sum over owners
    scenarioTable.index = scenarioTable['key']
    fireProneArea = PMG345Ha[ownersToGraph[0]]
    if ownership == 'All':
        for rep in range(len(repList)):
            for year in range(1, len(yearList)):
                for owner in ownersToGraph:
                    key = owner + '_' + str(rep) + '_' + str(year)
                    print(key)
                    if owner != ownersToGraph[0]:
                        for varName in varList:
                            scenarioTable.loc[
                                ownersToGraph[0] + '_' + str(rep) + '_' +
                                str(year), varName +
                                '_x'] += scenarioTable.loc[key, varName + '_x']
                            scenarioTable.loc[
                                ownersToGraph[0] + '_' + str(rep) + '_' +
                                str(year), varName +
                                '_y'] += scenarioTable.loc[key, varName + '_y']

        for owner in ownersToGraph:
            fireProneArea += PMG345Ha[owner]

    ownerArea = pd.DataFrame(
        scenarioTable[scenarioTable[' OWNER_label_y'] == ownersToGraph[0]])

    # calculate percent of PMG345 area for each row
    ownerArea['CP_HS_pct'] = (
        ownerArea[varList[0] + '_y'] + ownerArea[varList[1] + '_y'] +
        ownerArea[varList[2] + '_y']) / fireProneArea * 100
    ownerArea['Res_HS_pct'] = (
        ownerArea[varList[0] + '_x'] + ownerArea[varList[1] + '_x'] +
        ownerArea[varList[2] + '_x']) / fireProneArea * 100

    #Sort dataTable on percent PMG345 in HS fire
    dataTable = ownerArea.sort('CP_HS_pct', ascending=False)

    for splot in [1, 2]:
        # setup plot for all scenarios
        fig = pl.figure(1, figsize=(4, 4))
        ax = fig.add_subplot(1, 1, 1)

        # label plots and set percent of top values
        if splot == 1:
            yLabelText = 'Area of high severity fire in fire-frequent landscape (%)'
            labelXaxis = True
            figText = 'a'
            topPercent = 1.0
        elif splot == 2:
            yLabelText = 'Area of top 10% stand-replacing fires in fire-frequent landscape (%)'
            labelXaxis = True
            figText = 'b'
            topPercent = 0.1

        statsList1 = []
        statsList3 = []

        valueSet = []
        maxValueSet = []

        for i in range(int(round(len(dataTable) * topPercent))):
            statsList1.append(dataTable['CP_HS_pct'].iloc[i])
            statsList3.append(dataTable['Res_HS_pct'].iloc[i])

        valueSet.append(statsList1)
        valueSet.append(statsList3)

        maxValueSet.append(max(statsList1))
        maxValueSet.append(max(statsList3))

        labelList = ['Current\nManagement', 'Accelerated\nRestoration']
        print yLabelText
        print 'median for Current Management ' + str(np.median(valueSet[0]))
        print 'median for Restoration ' + str(np.median(valueSet[1]))
        print

        reporterFunc.plotReporter4bw(fig, ax, ownership, pdfFile, valueSet,
                                     labelList, subArea, chartTitle,
                                     yLabelText, maxValueSet, labelXaxis,
                                     figText)

        ##    yLabelText = 'Area of high-severity fire (%)'
        ##    reporterFunc.plotFigureText(fig, '', yLabelText)
        ##
        ## pl.savefig(outDir + 'report4bw_PMG345_in_HS_Fire_All.png', bbox_inches='tight', dpi=300)
        pdfFile.savefig()
        pl.close()
    pdfFile.close()
    print "Done."
def main(subArea, runName, chartTitlePre):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    varList = [
        ' Stand Replacing FirePMG3', ' Stand Replacing FirePMG4',
        ' Stand Replacing FirePMG5'
    ]
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)
    #    PMG12345Ha = reporterFunc.getPMG12345Ha(subArea)

    # list of ownerships to graphs
    reporterName = r'FireOccurance_by_OWNER_DETL_pivot.csv'
    ownerLabelField = ' OWNER_DETL_label'

    pdfFile = PdfPages(outDir + 'report5_HS_Fire_byOwner.pdf')

    #    for plotPage in [1,2]:
    # setup plot for all scenarios
    fig = pl.figure(1, figsize=(6.5, 6.5))

    for splot in [1, 2, 3, 4]:
        ax = fig.add_subplot(2, 2, splot)
        inDir = outDir + runName + "_CurrentPolicy\\"

        #        if plotPage == 1:
        if splot == 1:
            ownersToGraph = ['USFS', 'State', 'Corporate Forest']
        elif splot == 2:
            ownersToGraph = [
                'Chemult Ranger District (Fremont-Winema NF)',
                'Chiloquin Ranger District (Fremont-Winema NF)',
                'Klamath Ranger District (Fremont-Winema NF)'
            ]


#        elif plotPage == 2:
        elif splot == 3:
            ownersToGraph = ['ODF Sun Pass', 'ODF Gilchrist']
        elif splot == 4:
            ownersToGraph = [
                'JWTR Timber Holdings', 'Cascade Timberlands (Mazama Forest)',
                'Jeld-Wen Inc', 'J-Spear Ranch'
            ]

        if os.path.isdir(inDir):
            yearList = list(
                set(pd.io.parsers.read_csv(inDir + reporterName)[' Year']))
            repList = list(
                set(pd.io.parsers.read_csv(inDir + reporterName)[' Run']))
            totalArea = pd.io.parsers.read_csv(inDir + reporterName)

            # sum output over selected ownerships
            for ownership in ownersToGraph:
                print ownership

                # get stats from multiple reps
                statsList = []
                for year in range(1, max(yearList) + 1):
                    yearArea = totalArea[totalArea[' Year'] == year]

                    dataList = []
                    for rep in repList:
                        repArea = yearArea[yearArea[' Run'] == rep]

                        if ownership == 'USFS':
                            ownerArea = pd.DataFrame(repArea[
                                repArea[ownerLabelField] ==
                                'Chemult Ranger District (Fremont-Winema NF)'])
                            fireProneArea = PMG345Ha[
                                'Chemult Ranger District (Fremont-Winema NF)']

                            for subOwner in [
                                    'Chiloquin Ranger District (Fremont-Winema NF)',
                                    'Klamath Ranger District (Fremont-Winema NF)'
                            ]:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   subOwner]
                                fireProneArea += PMG345Ha[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                        elif ownership == 'State':
                            ownerArea = pd.DataFrame(repArea[
                                repArea[ownerLabelField] == 'ODF Sun Pass'])
                            fireProneArea = PMG345Ha['ODF Sun Pass']

                            for subOwner in [
                                    'ODF Gilchrist',
                                    'ODF Gilchrist (The Conservation Fund)'
                            ]:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   subOwner]
                                fireProneArea += PMG345Ha[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                        elif ownership == 'ODF Gilchrist':
                            ownerArea = pd.DataFrame(repArea[
                                repArea[ownerLabelField] == 'ODF Gilchrist'])
                            fireProneArea = PMG345Ha['ODF Gilchrist']

                            for subOwner in [
                                    'ODF Gilchrist (The Conservation Fund)'
                            ]:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   subOwner]
                                fireProneArea += PMG345Ha[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                        elif ownership == 'Corporate Forest':
                            ownerArea = pd.DataFrame(
                                repArea[repArea[ownerLabelField] ==
                                        'JWTR Timber Holdings'])
                            fireProneArea = PMG345Ha['JWTR Timber Holdings']

                            for subOwner in [
                                    'Cascade Timberlands (Mazama Forest)',
                                    'Jeld-Wen Inc', 'J-Spear Ranch'
                            ]:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   subOwner]
                                fireProneArea += PMG345Ha[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                        else:
                            ownerArea = pd.DataFrame(
                                repArea[repArea[ownerLabelField] == ownership])
                            fireProneArea = PMG345Ha[ownership]

                        if fireProneArea > 0:
                            dataList.append(
                                (ownerArea[' Stand Replacing FirePMG3'].iloc[0]
                                 +
                                 ownerArea[' Stand Replacing FirePMG4'].iloc[0]
                                 +
                                 ownerArea[' Stand Replacing FirePMG5'].iloc[0]
                                 ) / fireProneArea * 100)
                        else:
                            dataList.append(0.0)

                    # convert to numpy array
                    numpyList = np.array(dataList)
                    lower95th = np.mean(numpyList, axis=0) - (
                        (1.96 * np.std(numpyList, axis=0)) /
                        np.sqrt(len(repList)))
                    upper95th = np.mean(numpyList, axis=0) + (
                        (1.96 * np.std(numpyList, axis=0)) /
                        np.sqrt(len(repList)))

                    if lower95th < 0:
                        lower95th = 0.0

                    # add year data to dictionary
                    dataDict = {
                        'timeStep': year,
                        'mean': np.mean(numpyList, axis=0),
                        'std': np.std(numpyList, axis=0),
                        'lower': lower95th,
                        'upper': upper95th
                    }

                    # convert to list for DataFrame
                    statsList.append(dataDict)

                # convert to DataFrame
                dataTable = pd.DataFrame(statsList)

                plotLegend = (0.99, 0.99)
                labelYtick = True
                if splot == 1:
                    labelXtick = False
                    figText = 'a'
                elif splot == 2:
                    labelXtick = False
                    figText = 'b'
                elif splot == 3:
                    labelXtick = True
                    figText = 'c'
                elif splot == 4:
                    labelXtick = True
                    figText = 'd'

                xLabelText = yLabelText = ''
                reporterFunc.plotReporter5(fig, ax, '', pdfFile, dataTable,
                                           ['mean', 'lower', 'upper'],
                                           xLabelText, yLabelText, ownership,
                                           labelXtick, labelYtick, plotLegend,
                                           figText)

    reporterFunc.plotFigureText(
        fig, 'Simulation year',
        'Fire prone landscape in high severity fire (%)')

    pl.savefig(outDir + 'report5_HS_Fire_byOwner.png',
               bbox_inches='tight',
               dpi=300)
    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
Esempio n. 4
0
def main(subArea, runName, chartTitlePre):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    varList = [' Stand Replacing FirePMG1',' Stand Replacing FirePMG2',' Stand Replacing FirePMG3',' Stand Replacing FirePMG4',' Stand Replacing FirePMG5']
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)
    forestedHa = reporterFunc.getPMG12345Ha(subArea)

    # list of ownerships to graphs
    reporterName = r'FireOccurance_by_OWNER_DETL_pivot.csv'
    ownerLabelField = ' OWNER_DETL_label'

    pdfFile = PdfPages(outDir + 'report5bw_HS_Fire_byOwner.pdf')

#    for plotPage in [1,2,3,4,5,6,7,8]:
    # setup plot for all scenarios
    fig = pl.figure(1, figsize=(6.5,6.5))

    for splot in [1,2,3,4]:
        ax = fig.add_subplot(2,2,splot)
        inDir = outDir + runName + "_CurrentPolicy\\"

#        if plotPage % 2 == 1:
        if splot == 1:
            ownersToGraph = ['USFS','State','Corporate Forest']
            ownerLabel = ['USFS','State','Corporate']
        elif splot == 2:
            ownersToGraph = ['Chemult Ranger District (Fremont-Winema NF)','Chiloquin Ranger District (Fremont-Winema NF)','Klamath Ranger District (Fremont-Winema NF)']
            ownerLabel = ['Chemult RD','Chiloquin RD','Klamath RD']
#        else:
        elif splot == 3:
            ownersToGraph = ['ODF Sun Pass','ODF Gilchrist']
            ownerLabel = ownersToGraph
        elif splot == 4:
            ownersToGraph = ['JWTR Timber Holdings','Cascade Timberlands (Mazama Forest)','Jeld-Wen Inc','J-Spear Ranch']
            ownerLabel = ['PC1','PC2','PC3','PC4']

        if os.path.isdir(inDir):
            yearList = list(set(pd.io.parsers.read_csv(inDir + reporterName)[' Year']))
            repList = list(set(pd.io.parsers.read_csv(inDir + reporterName)[' Run']))
            totalArea = pd.io.parsers.read_csv(inDir + reporterName)

            # sum output over selected ownerships
            valueSet = []
            maxValueSet = []
            for ownership in ownersToGraph:
                print ownership

                # get stats from multiple reps
                dataList = []
                for year in range(1,max(yearList) + 1):
                    yearArea = totalArea[totalArea[' Year'] == year]

                    for rep in repList:
                        repArea = yearArea[yearArea[' Run'] == rep]

                        if ownership == 'USFS':
                            ownerArea = pd.DataFrame(repArea[repArea[ownerLabelField] == 'Chemult Ranger District (Fremont-Winema NF)'])
                            fireProneArea345 = PMG345Ha['Chemult Ranger District (Fremont-Winema NF)']
                            fireProneArea = forestedHa['Chemult Ranger District (Fremont-Winema NF)']

                            for subOwner in ['Chiloquin Ranger District (Fremont-Winema NF)','Klamath Ranger District (Fremont-Winema NF)']:
                                tempArea = repArea[repArea[ownerLabelField] == subOwner]
                                fireProneArea345 += PMG345Ha[subOwner]
                                fireProneArea += forestedHa[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[varName].iloc[0]

                        elif ownership == 'State':
                            ownerArea = pd.DataFrame(repArea[repArea[ownerLabelField] == 'ODF Sun Pass'])
                            fireProneArea345 = PMG345Ha['ODF Sun Pass']
                            fireProneArea = forestedHa['ODF Sun Pass']

                            for subOwner in ['ODF Gilchrist','ODF Gilchrist (The Conservation Fund)']:
                                tempArea = repArea[repArea[ownerLabelField] == subOwner]
                                fireProneArea345 += PMG345Ha[subOwner]
                                fireProneArea += forestedHa[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[varName].iloc[0]

                        elif ownership == 'ODF Gilchrist':
                            ownerArea = pd.DataFrame(repArea[repArea[ownerLabelField] == 'ODF Gilchrist'])
                            fireProneArea = forestedHa['ODF Gilchrist']

                            for subOwner in ['ODF Gilchrist (The Conservation Fund)']:
                                tempArea = repArea[repArea[ownerLabelField] == subOwner]
                                fireProneArea += forestedHa[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[varName].iloc[0]

                        elif ownership == 'Corporate Forest':
                            ownerArea = pd.DataFrame(repArea[repArea[ownerLabelField] == 'JWTR Timber Holdings'])
                            fireProneArea345 = PMG345Ha['JWTR Timber Holdings']
                            fireProneArea = forestedHa['JWTR Timber Holdings']

                            for subOwner in ['Cascade Timberlands (Mazama Forest)','Jeld-Wen Inc','J-Spear Ranch']:
                                tempArea = repArea[repArea[ownerLabelField] == subOwner]
                                fireProneArea345 += PMG345Ha[subOwner]
                                fireProneArea += forestedHa[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[varName].iloc[0]

                        else:
                            ownerArea = pd.DataFrame(repArea[repArea[ownerLabelField] == ownership])
                            fireProneArea345 = PMG345Ha[ownership]
                            fireProneArea = forestedHa[ownership]

##                        if plotPage in [1,2,5,6]:
##                            if fireProneArea345 > 0:
##                                dataList.append((ownerArea[' Stand Replacing FirePMG3'].iloc[0] + ownerArea[' Stand Replacing FirePMG4'].iloc[0] + ownerArea[' Stand Replacing FirePMG5'].iloc[0]) / fireProneArea345 * 100)
##                            else:
##                                dataList.append(0.0)
##                        else:
                        if fireProneArea > 0:
                            dataList.append((ownerArea[' Stand Replacing FirePMG1'].iloc[0] + ownerArea[' Stand Replacing FirePMG2'].iloc[0] + ownerArea[' Stand Replacing FirePMG3'].iloc[0] + ownerArea[' Stand Replacing FirePMG4'].iloc[0] + ownerArea[' Stand Replacing FirePMG5'].iloc[0]) / fireProneArea * 100)
                        else:
                            dataList.append(0.0)

##                    if plotPage < 5:
##                        topPercent = 1.0
##                    else:
                topPercent = 0.1

                dataList.sort(reverse=True)
                subDataList = []
                for i in range(int(round(len(dataList) * topPercent))):
                    subDataList.append(dataList[i])

                valueSet.append(subDataList)
                maxValueSet.append(max(subDataList))

            if splot == 1:
                labelXaxis = True
                figText = 'a'
            elif splot == 2:
                labelXaxis = True
                figText = 'b'
            elif splot == 3:
                labelXaxis = True
                figText = 'c'
            elif splot == 4:
                labelXaxis = True
                figText = 'd'

##                if plotPage in [1,2]:
##                    yLabelText = 'Fire frequent area (%)'
##                elif plotPage in [3,4]:
##                    yLabelText = 'Forested area (%)'
##                elif plotPage in [5,6]:
##                    yLabelText = 'Top 10% Fire frequent area (%)'
##                elif plotPage in [7,8]:
##                    yLabelText = 'Top 10% Forested area (%)'

            #reporterFunc.plotReporter5bw(fig, ax, '', pdfFile, valueSet, ownersToGraph, subArea, chartTitle, yLabelText, maxValueSet)

            yLabelText = ''
            reporterFunc.plotReporter5bw(fig, ax, '', pdfFile, valueSet, ownerLabel, subArea, chartTitle, yLabelText, maxValueSet, labelXaxis, figText)


    yLabelText = 'Forested area burned (%)'
    reporterFunc.plotFigureText(fig, '', yLabelText)

    pl.savefig(outDir + 'report5bw_HS_Fire_byOwner.png', bbox_inches='tight', dpi=300)
    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
Esempio n. 5
0
def main(subArea, runName, chartTitlePre, ownership):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    #    varList = [' Resilient (ha) PMG345', ' Semi-Resilient (ha) PMG345', ' Low Resilience (ha) PMG345']
    varList = [' Resilient (ha) PMG345', ' Low Resilience (ha) PMG345']
    yLabelText = 'Area (%)'
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)
    forestedHa = reporterFunc.getOwnerForestedHa(subArea)
    #    figTextList = ['High resilience','Moderate resilience','Low resilience']
    figTextList = ['High resilience', 'Low resilience']

    # list of ownerships to graphs
    ownersToGraph = [
        'Federal', 'State', 'Private Non-Industrial', 'Private Industrial',
        'Tribal', 'Homeowner'
    ]
    reporterName = r'ForestStructure2_by_OWNER_pivot.csv'
    ownerLabelField = ' OWNER_label'

    if ownership == 'All':
        pdfFile = PdfPages(outDir + 'report4_Resilience_landscape.pdf')
    elif ownership in ownersToGraph:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + 'report4_Resilience_' + ownersToGraph[0] +
                           '.pdf')
    else:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + 'report4_Resilience_' + ownersToGraph[0] +
                           '.pdf')
        ownerLabelField = ' OWNER_DETL_label'
        reporterName = r'ForestStructure2_by_OWNER_DETL_pivot.csv'

    fig = pl.figure(1, figsize=(6.5, 4))
    for varStruct in varList:
        # setup plot for all scenarios
        ax = fig.add_subplot(1, 2, varList.index(varStruct) + 1)

        for scenario in [
                'CurrentPolicy', 'No_Treatment_Fed', 'Restoration',
                'noFireNoTreatFed'
        ]:
            inDir = outDir + runName + "_" + scenario + "\\"

            if os.path.isdir(inDir):
                yearList = list(
                    set(pd.io.parsers.read_csv(inDir + reporterName)[' Year']))
                repList = list(
                    set(pd.io.parsers.read_csv(inDir + reporterName)[' Run']))
                totalArea = pd.io.parsers.read_csv(inDir + reporterName)

                # get stats from multiple reps
                statsList = []
                for year in range(1, max(yearList) + 1):
                    yearArea = totalArea[totalArea[' Year'] == year]

                    dataList = []
                    for rep in repList:
                        repArea = yearArea[yearArea[' Run'] == rep]

                        # sum output over selected ownerships
                        for ownerToGraph in ownersToGraph:
                            if ownerToGraph == ownersToGraph[0]:
                                ownerArea = pd.DataFrame(repArea[
                                    repArea[ownerLabelField] == ownerToGraph])
                                fireProneArea345 = PMG345Ha[ownerToGraph]
                                fireProneArea = forestedHa[ownerToGraph]
                            else:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   ownerToGraph]
                                for varName in varList:
                                    #                            totalArea.loc[list(ownerArea.index)[0],varName] += tempArea[varName].iloc[0]
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                                fireProneArea345 += PMG345Ha[ownerToGraph]
                                fireProneArea += forestedHa[ownerToGraph]
                                ownerToGraph = 'All'

                        if varStruct in [
                                ' Resilient (ha) PMG345',
                                ' Semi-Resilient (ha) PMG345',
                                ' Low Resilience (ha) PMG345'
                        ]:
                            if fireProneArea345 > 0:
                                dataList.append(ownerArea[varStruct].iloc[0] /
                                                fireProneArea345 * 100)
                            else:
                                dataList.append(0.0)
                        else:
                            if fireProneArea > 0:
                                dataList.append(ownerArea[varStruct].iloc[0] /
                                                fireProneArea * 100)
                            else:
                                dataList.append(0.0)

                    # convert to numpy array
                    numpyList = np.array(dataList)
                    lower95th = np.mean(numpyList, axis=0) - (
                        (1.96 * np.std(numpyList, axis=0)) /
                        np.sqrt(len(repList)))
                    upper95th = np.mean(numpyList, axis=0) + (
                        (1.96 * np.std(numpyList, axis=0)) /
                        np.sqrt(len(repList)))

                    if lower95th < 0:
                        lower95th = 0.0

                    # add year data to dictionary
                    dataDict = {
                        'timeStep': year,
                        'mean': np.mean(numpyList, axis=0),
                        'std': np.std(numpyList, axis=0),
                        'lower': lower95th,
                        'upper': upper95th
                    }

                    # convert to list for DataFrame
                    statsList.append(dataDict)

                # convert to DataFrame
                dataTable = pd.DataFrame(statsList)

                plotLegend = (-99, -99)
                if varStruct == ' Pole and Small (ha) Forest' or varStruct == ' Low Resilience (ha) PMG345':
                    plotLegend = (0.99, 0.25)

                if varList.index(varStruct) >= (len(varList) - 3):
                    labelXtick = True
                else:
                    labelXtick = False

                if varList.index(varStruct) == 0:
                    labelYtick = True
                else:
                    labelYtick = False

                xLabelText = yLabelText = ''
                reporterFunc.plotReporter4(
                    fig, ax, '', pdfFile, dataTable,
                    ['mean', 'lower', 'upper'], xLabelText, yLabelText,
                    scenario, labelXtick, labelYtick, plotLegend,
                    figTextList[varList.index(varStruct)])

    reporterFunc.plotFigureText(fig, 'Simulation Year', 'Area (%)')

    pl.savefig(outDir + 'report4_Resilience_landscape.png',
               bbox_inches='tight',
               dpi=300)
    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
def main(subArea, runName, chartTitlePre):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    varList = [
        ' Potential HighSev Fire (ha) PMG3',
        ' Potential HighSev Fire (ha) PMG4',
        ' Potential HighSev Fire (ha) PMG5'
    ]
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)
    #    PMG12345Ha = reporterFunc.getPMG12345Ha(subArea)

    # list of ownerships to graphs
    reporterName = r'PotentialDisturbance_by_OWNER_DETL_pivot.csv'
    ownerLabelField = ' OWNER_DETL_label'

    pdfFile = PdfPages(outDir +
                       'report5_PMG345_HS_Hazard_byOwner_NoTreatment.pdf')

    for plotPage in [1, 2]:
        # setup plot for all scenarios
        fig = pl.figure(1, figsize=(8.5, 11))

        for splot in [1, 2]:
            ax = fig.add_subplot(2, 1, splot)
            inDir = outDir + runName + "_NoTreatment\\"

            if plotPage == 1:
                if splot == 1:
                    ownersToGraph = ['USFS', 'State', 'Corporate Forest']
                elif splot == 2:
                    ownersToGraph = [
                        'Chemult Ranger District (Fremont-Winema NF)',
                        'Chiloquin Ranger District (Fremont-Winema NF)',
                        'Klamath Ranger District (Fremont-Winema NF)'
                    ]
            elif plotPage == 2:
                if splot == 1:
                    ownersToGraph = ['ODF Sun Pass', 'ODF Gilchrist']
                elif splot == 2:
                    ownersToGraph = [
                        'JWTR Timber Holdings',
                        'Cascade Timberlands (Mazama Forest)', 'Jeld-Wen Inc',
                        'J-Spear Ranch'
                    ]

            if os.path.isdir(inDir):
                yearList = list(
                    set(pd.io.parsers.read_csv(inDir + reporterName)[' Year']))
                repList = list(
                    set(pd.io.parsers.read_csv(inDir + reporterName)[' Run']))
                totalArea = pd.io.parsers.read_csv(inDir + reporterName)

                # sum output over selected ownerships
                for ownership in ownersToGraph:
                    print ownership

                    # get stats from multiple reps
                    statsList = []
                    for year in range(1, max(yearList) + 1):
                        yearArea = totalArea[totalArea[' Year'] == year]

                        dataList = []
                        for rep in repList:
                            repArea = yearArea[yearArea[' Run'] == rep]

                            if ownership == 'USFS':
                                ownerArea = pd.DataFrame(repArea[
                                    repArea[ownerLabelField] ==
                                    'Chemult Ranger District (Fremont-Winema NF)']
                                                         )
                                fireProneArea = PMG345Ha[
                                    'Chemult Ranger District (Fremont-Winema NF)']

                                for subOwner in [
                                        'Chiloquin Ranger District (Fremont-Winema NF)',
                                        'Klamath Ranger District (Fremont-Winema NF)'
                                ]:
                                    tempArea = repArea[repArea[ownerLabelField]
                                                       == subOwner]
                                    fireProneArea += PMG345Ha[subOwner]
                                    for varName in varList:
                                        ownerArea[varName].iloc[0] += tempArea[
                                            varName].iloc[0]

                            elif ownership == 'State':
                                ownerArea = pd.DataFrame(
                                    repArea[repArea[ownerLabelField] ==
                                            'ODF Sun Pass'])
                                fireProneArea = PMG345Ha['ODF Sun Pass']

                                for subOwner in ['ODF Gilchrist']:
                                    tempArea = repArea[repArea[ownerLabelField]
                                                       == subOwner]
                                    fireProneArea += PMG345Ha[subOwner]
                                    for varName in varList:
                                        ownerArea[varName].iloc[0] += tempArea[
                                            varName].iloc[0]

                            elif ownership == 'Corporate Forest':
                                ownerArea = pd.DataFrame(
                                    repArea[repArea[ownerLabelField] ==
                                            'JWTR Timber Holdings'])
                                fireProneArea = PMG345Ha[
                                    'JWTR Timber Holdings']

                                for subOwner in [
                                        'Cascade Timberlands (Mazama Forest)',
                                        'Jeld-Wen Inc', 'J-Spear Ranch'
                                ]:
                                    tempArea = repArea[repArea[ownerLabelField]
                                                       == subOwner]
                                    fireProneArea += PMG345Ha[subOwner]
                                    for varName in varList:
                                        ownerArea[varName].iloc[0] += tempArea[
                                            varName].iloc[0]

                            else:
                                ownerArea = pd.DataFrame(repArea[
                                    repArea[ownerLabelField] == ownership])
                                fireProneArea = PMG345Ha[ownership]

                            if fireProneArea > 0:
                                dataList.append(
                                    (ownerArea[
                                        ' Potential HighSev Fire (ha) PMG3'].
                                     iloc[0] + ownerArea[
                                         ' Potential HighSev Fire (ha) PMG4'].
                                     iloc[0] + ownerArea[
                                         ' Potential HighSev Fire (ha) PMG5'].
                                     iloc[0]) / fireProneArea * 100)
                            else:
                                dataList.append(0.0)

                        # convert to numpy array
                        numpyList = np.array(dataList)
                        lower95th = np.mean(numpyList, axis=0) - (
                            (1.96 * np.std(numpyList, axis=0)) /
                            np.sqrt(len(repList)))
                        upper95th = np.mean(numpyList, axis=0) + (
                            (1.96 * np.std(numpyList, axis=0)) /
                            np.sqrt(len(repList)))

                        if lower95th < 0:
                            lower95th = 0.0

                        # add year data to dictionary
                        dataDict = {
                            'timeStep': year,
                            'mean': np.mean(numpyList, axis=0),
                            'std': np.std(numpyList, axis=0),
                            'lower': lower95th,
                            'upper': upper95th
                        }

                        # convert to list for DataFrame
                        statsList.append(dataDict)

                    # convert to DataFrame
                    dataTable = pd.DataFrame(statsList)

                    if splot == 1:
                        labelXaxis = False
                        plotLegend = True
                        yLabelText = 'Percent of Fire Prone Landscape in High Severity Fire Hazard'
                    elif splot == 2:
                        labelXaxis = True
                        plotLegend = True
                        yLabelText = 'Percent of Fire Prone Landscape in High Severity Fire Hazard'

                    reporterFunc.plotReporter5(fig, ax, '', pdfFile, dataTable,
                                               ['mean', 'lower', 'upper'],
                                               yLabelText, ownership,
                                               labelXaxis, plotLegend)

        pdfFile.savefig()
        pl.close()
    pdfFile.close()
    print "Done."
Esempio n. 7
0
def main(outDir, subArea, runList, chartTitle, ownership):
    varList = [' Potential HighSev Fire (ha) PMG1', ' Potential HighSev Fire (ha) PMG2', ' Potential HighSev Fire (ha) PMG3', ' Potential HighSev Fire (ha) PMG4', ' Potential HighSev Fire (ha) PMG5']
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)
    PMG12345Ha = reporterFunc.getPMG12345Ha(subArea)

    # list of ownerships to graphs
    if ownership == 'All':
        ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Tribal','Homeowner']
        pdfFile = PdfPages(outDir + chartTitle + '_Potential_HS_Fire_Landscape_PMG345.pdf')
    else:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + chartTitle + '_Potential_HS_Fire_' + ownersToGraph[0] + '.pdf')

    # setup plot for all scenarios
    fig = pl.figure(1, figsize=(4,4))

    for splot in [2]:
        ax = fig.add_subplot(1,1,1)
        for scenario in runList:
            inDir = outDir + scenario + "\\"

            if os.path.isdir(inDir):
                yearList = list(set(pd.io.parsers.read_csv(inDir + r'PotentialDisturbance_by_OWNER_pivot.csv')[' Year']))
                repList = list(set(pd.io.parsers.read_csv(inDir + r'PotentialDisturbance_by_OWNER_pivot.csv')[' Run']))
                totalArea = pd.io.parsers.read_csv(inDir + r'PotentialDisturbance_by_OWNER_pivot.csv')

                # get stats from multiple reps
                statsList = []
                for year in range(1,max(yearList) + 1):
                    yearArea = totalArea[totalArea[' Year'] == year]

                    dataList = []
                    for rep in repList:
                        repArea = yearArea[yearArea[' Run'] == rep]

                        # sum output over selected ownerships
                        for ownerToGraph in ownersToGraph:
                            if ownerToGraph == ownersToGraph[0]:
                                ownerArea = pd.DataFrame(repArea[repArea[' OWNER_label'] == ownerToGraph])
                                fireProneArea = PMG345Ha[ownerToGraph]
                                forestedArea = PMG12345Ha[ownerToGraph]
                            else:
                                tempArea = repArea[repArea[' OWNER_label'] == ownerToGraph]
                                for varName in varList:
        #                            totalArea.loc[list(ownerArea.index)[0],varName] += tempArea[varName].iloc[0]
                                    ownerArea[varName].iloc[0] += tempArea[varName].iloc[0]


                                fireProneArea += PMG345Ha[ownerToGraph]
                                forestedArea += PMG12345Ha[ownerToGraph]
                                ownerToGraph = 'All'

                        if splot == 1:
                            if forestedArea > 0:
                                dataList.append((ownerArea[' Potential HighSev Fire (ha) PMG1'].iloc[0] + ownerArea[' Potential HighSev Fire (ha) PMG2'].iloc[0] + ownerArea[' Potential HighSev Fire (ha) PMG3'].iloc[0] + ownerArea[' Potential HighSev Fire (ha) PMG4'].iloc[0] + ownerArea[' Potential HighSev Fire (ha) PMG5'].iloc[0]) / forestedArea * 100)
                            else:
                                dataList.append(0.0)
                        elif splot == 2:
                            if fireProneArea > 0:
                                dataList.append((ownerArea[' Potential HighSev Fire (ha) PMG3'].iloc[0] + ownerArea[' Potential HighSev Fire (ha) PMG4'].iloc[0] + ownerArea[' Potential HighSev Fire (ha) PMG5'].iloc[0]) / fireProneArea * 100)
                            else:
                                dataList.append(0.0)

                    # convert to numpy array
                    numpyList = np.array(dataList)
                    lower95th = np.mean(numpyList, axis=0) - ((1.96 * np.std(numpyList, axis=0)) / np.sqrt(len(repList)))
                    upper95th = np.mean(numpyList, axis=0) + ((1.96 * np.std(numpyList, axis=0)) / np.sqrt(len(repList)))

                    if lower95th < 0:
                        lower95th = 0.0

                    # add year data to dictionary
                    dataDict = {'timeStep': year, 'mean': np.mean(numpyList, axis=0), 'std': np.std(numpyList, axis=0), 'lower': lower95th, 'upper': upper95th}

                    # convert to list for DataFrame
                    statsList.append(dataDict)

                # convert to DataFrame
                dataTable = pd.DataFrame(statsList)

                labelXtick = True
                labelYtick = True
                plotLegend = (0.6,0.99)
                xLabelText = 'Simulation Year'

                if splot == 1:
                    yLabelText = 'Area of high-severity fire hazard (%)'
                elif splot == 2:
                    yLabelText = 'Area of fire prone landscape in high-severity hazard (%)'

                reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['mean','lower','upper'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, '')


    pl.savefig(outDir + 'report4_Potential_HS_Fire_Landscape.png', bbox_inches='tight', dpi=300)
    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
Esempio n. 8
0
def main(outDir, subArea, runName, chartTitlePre, ownership):
    varList = [' NumberDwellings1kmFromStandRep']
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)

    # list of ownerships to graphs
#    if ownership == 'All':
#        ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Tribal','Homeowner']
    pdfFile = PdfPages(outDir + 'report4bw_Homes_Exposed_to_HS_Fire_All.pdf')
#    else:
#        ownersToGraph = [ownership]
#        pdfFile = PdfPages(outDir + 'report4bw_Homes_Exposed_to_HS_Fire_' + ownersToGraph[0] + '.pdf')

    # setup plot for all scenarios
    fig = pl.figure(1, figsize=(4,6.5))

    # Current Policy run required!
    for scenario in ['No_Treatment_Fed','Restoration','CurrentPolicy']:
        inDir = outDir + runName + "_" + scenario + "\\"

        if scenario == 'No_Treatment_Fed':
            yearList = list(set(pd.io.parsers.read_csv(inDir + r'FireExperience_pivot.csv')[' Year']))
            repList = list(set(pd.io.parsers.read_csv(inDir + r'FireExperience_pivot.csv')[' Run']))

        totalArea = pd.io.parsers.read_csv(inDir + r'FireExperience_pivot.csv')
        dataTable = pd.DataFrame(totalArea[totalArea[' Year'] > 0])
        dataTable['key'] = 'run' + dataTable[' Run'].astype(str) + '_' + dataTable[' Year'].astype(str)

        if scenario == 'No_Treatment_Fed':
            scenarioTable = dataTable
        else:
            scenarioTable = pd.merge(scenarioTable, dataTable, how='left', on='key')

    # sum over owners
    scenarioTable.index = scenarioTable['key']

    #Sort dataTable on number of homes exposed to fire
    scenarioTable = scenarioTable.rename(columns={' NumberDwellings1kmFromStandRep': 'CP_Dwellings1kmHSFire',' NumberDwellings1kmFromStandRep_x': 'NFT_Dwellings1kmHSFire',' NumberDwellings1kmFromStandRep_y': 'Res_Dwellings1kmHSFire'})
    dataTable = scenarioTable.sort('NFT_Dwellings1kmHSFire', ascending=False)

    for splot in [1, 2]:
        ax = fig.add_subplot(2,1,splot)

        # label plots and set percent of top values
        if splot == 1:
            yLabelText = 'Number of dwellings 1km from stand-replacing fire'
            labelXaxis = False
            figText = 'A'
            topPercent = 1.0
        elif splot == 2:
            yLabelText = 'Number of dwellings 1km from top 10% of stand-replacing fires'
            labelXaxis = True
            figText = 'B'
            topPercent = 0.1

        statsList1 = []
        statsList2 = []
        statsList3 = []

        valueSet = []
        maxValueSet = []

        for i in range(int(round(len(dataTable) * topPercent))):
            statsList1.append(dataTable['CP_Dwellings1kmHSFire'].iloc[i])
            statsList2.append(dataTable['NFT_Dwellings1kmHSFire'].iloc[i])
            statsList3.append(dataTable['Res_Dwellings1kmHSFire'].iloc[i])

        valueSet.append(statsList1)
        valueSet.append(statsList2)
        valueSet.append(statsList3)

        maxValueSet.append(max(statsList1))
        maxValueSet.append(max(statsList2))
        maxValueSet.append(max(statsList3))

        yLabelText = ''
        labelList = ['Current\nManagement','No Federal\nTreatment','Accelerated\nRestoration']
        reporterFunc.plotReporter4bw(fig, ax, ownership, pdfFile, valueSet, labelList, subArea, chartTitle, yLabelText, maxValueSet, labelXaxis, figText)


    yLabelText = 'Number of dwellings 1km from high-severity fire'
    reporterFunc.plotFigureText(fig, '', yLabelText)

    pl.savefig(outDir + 'report4bw_Homes_Exposed_to_HS_Fire_All.png', bbox_inches='tight', dpi=300)
    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
def main(subArea, runName, chartTitlePre):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    varList = [
        ' Resilient (ha) PMG345', ' Early Successional (ha) Forest',
        ' Pole and Small (ha) Forest', ' Medium (ha) Forest',
        ' Large and Giant (ha) Forest', ' Open Canopy (ha) Forest',
        ' Moderate Canopy (ha) Forest', ' Closed Canopy (ha) Forest'
    ]
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)
    forestedHa = reporterFunc.getOwnerForestedHa(subArea)

    # list of ownerships to graphs
    reporterName = r'ForestStructure2_by_OWNER_DETL_pivot.csv'
    ownerLabelField = ' OWNER_DETL_label'

    pdfFile = PdfPages(outDir + 'report5bar_ForestStructre2_byOwner.pdf')

    # setup plot for all owners
    fig = pl.figure(1, figsize=(11, 8.5))

    inDir = outDir + runName + "_CurrentPolicy\\"
    ownersToGraph = [
        'USFS', 'State', 'Corporate Forest',
        'Chemult Ranger District (Fremont-Winema NF)',
        'Chiloquin Ranger District (Fremont-Winema NF)',
        'Klamath Ranger District (Fremont-Winema NF)', 'ODF Sun Pass',
        'ODF Gilchrist', 'JWTR Timber Holdings',
        'Cascade Timberlands (Mazama Forest)', 'Jeld-Wen Inc', 'J-Spear Ranch'
    ]

    if os.path.isdir(inDir):
        yearList = list(
            set(pd.io.parsers.read_csv(inDir + reporterName)[' Year']))
        repList = list(
            set(pd.io.parsers.read_csv(inDir + reporterName)[' Run']))
        totalArea = pd.io.parsers.read_csv(inDir + reporterName)

        # sum output over selected ownerships
        for ownership in ownersToGraph:
            ax = fig.add_subplot(2, 6, ownersToGraph.index(ownership) + 1)
            print ownership

            # get stats from multiple reps
            statsList = []
            for varStruct in varList:
                for year in [1, max(yearList)]:
                    yearArea = totalArea[totalArea[' Year'] == year]

                    dataList = []
                    for rep in repList:
                        repArea = yearArea[yearArea[' Run'] == rep]

                        if ownership == 'USFS':
                            ownerArea = pd.DataFrame(repArea[
                                repArea[ownerLabelField] ==
                                'Chemult Ranger District (Fremont-Winema NF)'])
                            fireProneArea345 = PMG345Ha[
                                'Chemult Ranger District (Fremont-Winema NF)']
                            fireProneArea = forestedHa[
                                'Chemult Ranger District (Fremont-Winema NF)']

                            for subOwner in [
                                    'Chiloquin Ranger District (Fremont-Winema NF)',
                                    'Klamath Ranger District (Fremont-Winema NF)'
                            ]:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   subOwner]
                                fireProneArea345 += PMG345Ha[subOwner]
                                fireProneArea += forestedHa[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                        elif ownership == 'State':
                            ownerArea = pd.DataFrame(repArea[
                                repArea[ownerLabelField] == 'ODF Sun Pass'])
                            fireProneArea345 = PMG345Ha['ODF Sun Pass']
                            fireProneArea = forestedHa['ODF Sun Pass']

                            for subOwner in [
                                    'ODF Gilchrist',
                                    'ODF Gilchrist (The Conservation Fund)'
                            ]:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   subOwner]
                                fireProneArea345 += PMG345Ha[subOwner]
                                fireProneArea += forestedHa[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                        elif ownership == 'ODF Gilchrist':
                            ownerArea = pd.DataFrame(repArea[
                                repArea[ownerLabelField] == 'ODF Gilchrist'])
                            fireProneArea345 = PMG345Ha['ODF Gilchrist']
                            fireProneArea = forestedHa['ODF Gilchrist']

                            for subOwner in [
                                    'ODF Gilchrist (The Conservation Fund)'
                            ]:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   subOwner]
                                fireProneArea345 += PMG345Ha[subOwner]
                                fireProneArea += forestedHa[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                        elif ownership == 'Corporate Forest':
                            ownerArea = pd.DataFrame(
                                repArea[repArea[ownerLabelField] ==
                                        'JWTR Timber Holdings'])
                            fireProneArea345 = PMG345Ha['JWTR Timber Holdings']
                            fireProneArea = forestedHa['JWTR Timber Holdings']

                            for subOwner in [
                                    'Cascade Timberlands (Mazama Forest)',
                                    'Jeld-Wen Inc', 'J-Spear Ranch'
                            ]:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   subOwner]
                                fireProneArea345 += PMG345Ha[subOwner]
                                fireProneArea += forestedHa[subOwner]
                                for varName in varList:
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                        else:
                            ownerArea = pd.DataFrame(
                                repArea[repArea[ownerLabelField] == ownership])
                            fireProneArea345 = PMG345Ha[ownership]
                            fireProneArea = forestedHa[ownership]

                        if varStruct in [
                                ' Resilient (ha) PMG345',
                                ' Semi-Resilient (ha) PMG345',
                                ' Low Resilience (ha) PMG345'
                        ]:
                            if fireProneArea345 > 0:
                                dataList.append((ownerArea[varStruct].iloc[0]))
                            else:
                                dataList.append(0.0)
                        else:
                            if fireProneArea > 0:
                                dataList.append((ownerArea[varStruct].iloc[0]))
                            else:
                                dataList.append(0.0)

                    # calculate percent change
                    numpyList = np.array(dataList)
                    if year == 1:
                        startYrMean = np.mean(numpyList, axis=0)
                    else:
                        endYrMean = np.mean(numpyList, axis=0)

                # convert to list for DataFrame
                statsList.append((endYrMean - startYrMean) / startYrMean * 100)

            if 'USFS' in ownership or 'Sun Pass' in ownership:
                labelYaxis = True
            else:
                labelYaxis = False

            yLabelText = 'Percent change'
            varList2 = []
            for varName in varList:
                if '(ha)' in varName:
                    varList2.append(varName[:-12])

            statsList.reverse()
            varList2.reverse()
            statsDF = pd.DataFrame(statsList)
            statsDF['positives'] = statsDF[0] > 0
            reporterFunc.plotReporter5bar(fig, ax, '', pdfFile, statsDF,
                                          varList2, yLabelText, ownership,
                                          labelYaxis)

    reporterFunc.plotFigureText(fig, 'Change in % of ownership', '')

    pl.savefig(outDir + 'report5bar_ForestStructre2_byOwner.png',
               bbox_inches='tight',
               dpi=300)
    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
Esempio n. 10
0
def main(subArea, runName, chartTitlePre, ownership):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    varList = [' Black-backed Woodpecker Good (ha)']
    yLabelText = 'Black-backed Woodpecker Good Habitat (ha)'
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)

    # list of ownerships to graphs
    if ownership == 'All':
        ownersToGraph = [
            'Federal', 'State', 'Private Non-Industrial', 'Private Industrial',
            'Tribal', 'Homeowner'
        ]
        pdfFile = PdfPages(outDir + 'report2_BBWO_iLAP_All.pdf')
    else:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + 'report2_BBWO_iLAP_' + ownersToGraph[0] +
                           '.pdf')

    # setup plot for all scenarios
    fig = pl.figure(1, figsize=(11, 8.5))
    ax = fig.add_subplot(1, 1, 1)

    for scenario in [
            'CurrentPolicy', 'NoFedTreat', 'Restoration', 'NoFireNoMgmt'
    ]:
        inDir = outDir + runName + "_" + scenario + "\\"

        if os.path.isdir(inDir):
            yearList = list(
                set(
                    pd.io.parsers.read_csv(
                        inDir + r'ILAP_wildlife_models_pivot.csv')[' Year']))
            repList = list(
                set(
                    pd.io.parsers.read_csv(
                        inDir + r'ILAP_wildlife_models_pivot.csv')[' Run']))
            totalArea = pd.io.parsers.read_csv(
                inDir + r'ILAP_wildlife_models_pivot.csv')

            # get stats from multiple reps
            statsList = []
            for year in range(1, max(yearList) + 1):
                yearArea = totalArea[totalArea[' Year'] == year]

                dataList = []
                for rep in repList:
                    repArea = yearArea[yearArea[' Run'] == rep]

                    ##                # sum output over selected ownerships
                    ##                for ownerToGraph in ownersToGraph:
                    ##                    if ownerToGraph == ownersToGraph[0]:
                    ##                        ownerArea = pd.DataFrame(repArea[repArea[' OWNER_label'] == ownerToGraph])
                    ##                        fireProneArea = PMG345Ha[ownerToGraph]
                    ##                    else:
                    ##                        tempArea = repArea[repArea[' OWNER_label'] == ownerToGraph]
                    ##                        for varName in varList:
                    ###                            totalArea.loc[list(ownerArea.index)[0],varName] += tempArea[varName].iloc[0]
                    ##                            ownerArea[varName].iloc[0] += tempArea[varName].iloc[0]
                    ##
                    ##                        fireProneArea += PMG345Ha[ownerToGraph]
                    ##                        ownerToGraph = 'All'

                    ownerToGraph = 'All'
                    ownerArea = repArea
                    dataList.append(ownerArea[varList[0]].iloc[0])

                # convert to numpy array
                numpyList = np.array(dataList)
                lower95th = np.mean(numpyList, axis=0) - (
                    (1.96 * np.std(numpyList, axis=0)) / np.sqrt(len(repList)))
                upper95th = np.mean(numpyList, axis=0) + (
                    (1.96 * np.std(numpyList, axis=0)) / np.sqrt(len(repList)))

                if lower95th < 0:
                    lower95th = 0.0

                # add year data to dictionary
                dataDict = {
                    'timeStep': year,
                    'mean': np.mean(numpyList, axis=0),
                    'std': np.std(numpyList, axis=0),
                    'lower': lower95th,
                    'upper': upper95th
                }

                # convert to list for DataFrame
                statsList.append(dataDict)

            # convert to DataFrame
            dataTable = pd.DataFrame(statsList)

            reporterFunc.plotReporter2(
                fig, ax, ownerToGraph + ' - ' + str(len(repList)) + ' reps',
                pdfFile, dataTable, ['mean', 'lower', 'upper'], subArea,
                chartTitle, yLabelText, scenario)

    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
def main(subArea, runName, chartTitlePre, ownership):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    varList = [
        ' Stand Replacing FirePMG1', ' Stand Replacing FirePMG2',
        ' Stand Replacing FirePMG3', ' Stand Replacing FirePMG4',
        ' Stand Replacing FirePMG5'
    ]
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)
    PMG12345Ha = reporterFunc.getPMG12345Ha(subArea)

    # list of ownerships to graphs
    ownersToGraph = [
        'Federal', 'State', 'Private Non-Industrial', 'Private Industrial',
        'Tribal', 'Homeowner'
    ]
    reporterName = r'FireOccurance_by_OWNER_pivot.csv'
    ownerLabelField = ' OWNER_label'

    if ownership == 'All':
        pdfFile = PdfPages(outDir + 'report4_HS_Fire_landscape.pdf')
    elif ownership in ownersToGraph:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + 'report4_HS_Fire_' + ownersToGraph[0] +
                           '.pdf')
    else:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + 'report4_HS_Fire_' + ownersToGraph[0] +
                           '.pdf')
        ownerLabelField = ' OWNER_DETL_label'
        reporterName = r'FireOccurance_by_OWNER_DETL_pivot.csv'

    # setup plot for all scenarios
    fig = pl.figure(1, figsize=(4, 4))

    for splot in [1]:
        ax = fig.add_subplot(1, 1, splot)
        for scenario in ['CurrentPolicy', 'No_Treatment_Fed', 'Restoration']:
            inDir = outDir + runName + "_" + scenario + "\\"

            if os.path.isdir(inDir):
                yearList = list(
                    set(pd.io.parsers.read_csv(inDir + reporterName)[' Year']))
                repList = list(
                    set(pd.io.parsers.read_csv(inDir + reporterName)[' Run']))
                totalArea = pd.io.parsers.read_csv(inDir + reporterName)

                # get stats from multiple reps
                statsList = []
                for year in range(1, max(yearList) + 1):
                    yearArea = totalArea[totalArea[' Year'] == year]

                    dataList = []
                    for rep in repList:
                        repArea = yearArea[yearArea[' Run'] == rep]

                        # sum output over selected ownerships
                        for ownerToGraph in ownersToGraph:
                            if ownerToGraph == ownersToGraph[0]:
                                ownerArea = pd.DataFrame(repArea[
                                    repArea[ownerLabelField] == ownerToGraph])
                                fireProneArea = PMG345Ha[ownerToGraph]
                                forestedArea = PMG12345Ha[ownerToGraph]
                            else:
                                tempArea = repArea[repArea[ownerLabelField] ==
                                                   ownerToGraph]
                                for varName in varList:
                                    #                            totalArea.loc[list(ownerArea.index)[0],varName] += tempArea[varName].iloc[0]
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                                fireProneArea += PMG345Ha[ownerToGraph]
                                forestedArea += PMG12345Ha[ownerToGraph]
                                ownerToGraph = 'All'

                        if splot == 1:
                            if forestedArea > 0:
                                dataList.append(
                                    (ownerArea[' Stand Replacing FirePMG1'].
                                     iloc[0] + ownerArea[
                                         ' Stand Replacing FirePMG2'].iloc[0] +
                                     ownerArea[' Stand Replacing FirePMG3'].
                                     iloc[0] + ownerArea[
                                         ' Stand Replacing FirePMG4'].iloc[0] +
                                     ownerArea[' Stand Replacing FirePMG5'].
                                     iloc[0]) / forestedArea * 100)
                            else:
                                dataList.append(0.0)
                        elif splot == 2:
                            if fireProneArea > 0:
                                dataList.append(
                                    (ownerArea[' Stand Replacing FirePMG3'].
                                     iloc[0] + ownerArea[
                                         ' Stand Replacing FirePMG4'].iloc[0] +
                                     ownerArea[' Stand Replacing FirePMG5'].
                                     iloc[0]) / fireProneArea * 100)
                            else:
                                dataList.append(0.0)

                    # convert to numpy array
                    numpyList = np.array(dataList)
                    lower95th = np.mean(numpyList, axis=0) - (
                        (1.96 * np.std(numpyList, axis=0)) /
                        np.sqrt(len(repList)))
                    upper95th = np.mean(numpyList, axis=0) + (
                        (1.96 * np.std(numpyList, axis=0)) /
                        np.sqrt(len(repList)))

                    if lower95th < 0:
                        lower95th = 0.0

                    # add year data to dictionary
                    dataDict = {
                        'timeStep': year,
                        'mean': np.mean(numpyList, axis=0),
                        'std': np.std(numpyList, axis=0),
                        'lower': lower95th,
                        'upper': upper95th
                    }

                    # convert to list for DataFrame
                    statsList.append(dataDict)

                # convert to DataFrame
                dataTable = pd.DataFrame(statsList)

                labelXtick = True
                labelYtick = True
                plotLegend = (0.99, 0.99)
                xLabelText = 'Simulation Year'

                if splot == 1:
                    yLabelText = 'Area of high-severity fire (%)'
                elif splot == 2:
                    yLabelText = 'Percent of Fire Prone Landscape in high-severity Fire'

                reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable,
                                           ['mean', 'lower', 'upper'],
                                           xLabelText, yLabelText, scenario,
                                           labelXtick, labelYtick, plotLegend,
                                           '')

    pl.savefig(outDir + 'report4_HS_Fire_landscape.png',
               bbox_inches='tight',
               dpi=300)
    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
Esempio n. 12
0
def main(subArea, runName, chartTitlePre, ownership):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    varList = [
        ' Stand Replacing FirePMG3', ' Stand Replacing FirePMG4',
        ' Stand Replacing FirePMG5'
    ]
    yLabelText = 'Percent of PMG 3, 4, and 5 in Stand Replacing Fire'
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)

    # list of ownerships to graphs
    if ownership == 'All':
        ownersToGraph = [
            'Federal', 'State', 'Private Non-Industrial', 'Private Industrial',
            'Tribal', 'Homeowner'
        ]
        pdfFile = PdfPages(outDir + 'report3_PMG345_in_HS_Fire_All.pdf')
    else:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + 'report3_PMG345_in_HS_Fire_' +
                           ownersToGraph[0] + '.pdf')

    # setup plot for all scenarios
    fig = pl.figure(1, figsize=(11, 8.5))
    ax = fig.add_subplot(1, 1, 1)

    valueSet1 = []
    valueSet2 = []
    maxValueSet1 = []
    maxValueSet2 = []
    for scenario in ['CurrentPolicy', 'NoFedTreat', 'Restoration']:
        inDir = outDir + runName + "_" + scenario + "\\"

        yearList = list(
            set(
                pd.io.parsers.read_csv(
                    inDir + r'FireOccurance_by_OWNER_pivot.csv')[' Year']))
        repList = list(
            set(
                pd.io.parsers.read_csv(
                    inDir + r'FireOccurance_by_OWNER_pivot.csv')[' Run']))
        totalArea = pd.io.parsers.read_csv(inDir +
                                           r'FireOccurance_by_OWNER_pivot.csv')

        # get stats from multiple reps
        statsList1 = []
        statsList2 = []
        for year in range(1, max(yearList) + 1):
            yearArea = totalArea[totalArea[' Year'] == year]

            dataList = []
            for rep in repList:
                repArea = yearArea[yearArea[' Run'] == rep]

                # sum output over selected ownerships
                for ownerToGraph in ownersToGraph:
                    if ownerToGraph == ownersToGraph[0]:
                        ownerArea = pd.DataFrame(
                            repArea[repArea[' OWNER_label'] == ownerToGraph])
                        fireProneArea = PMG345Ha[ownerToGraph]
                    else:
                        tempArea = repArea[repArea[' OWNER_label'] ==
                                           ownerToGraph]
                        for varName in varList:
                            #                            totalArea.loc[list(ownerArea.index)[0],varName] += tempArea[varName].iloc[0]
                            ownerArea[varName].iloc[0] += tempArea[
                                varName].iloc[0]

                        fireProneArea += PMG345Ha[ownerToGraph]
                        ownerToGraph = 'All'

                if fireProneArea > 0:
                    dataList.append(
                        (ownerArea[varList[0]].iloc[0] +
                         ownerArea[varList[1]].iloc[0] +
                         ownerArea[varList[2]].iloc[0]) / fireProneArea * 100)
                else:
                    dataList.append(0.0)

            # add year data to dictionary
            if year < 25:
                statsList1 += dataList
            else:
                statsList2 += dataList

        valueSet1.append(statsList1)
        valueSet2.append(statsList2)
        maxValueSet1.append(max(statsList1))
        maxValueSet2.append(max(statsList2))

    labelList = [
        'CP 0-24', 'NFT 0-24', 'Res 0-24', 'CP 25-50', 'NFT 25-50', 'Res 25-50'
    ]
    reporterFunc.plotReporter3(
        fig, ax, ownerToGraph + ' - ' + str(len(repList)) + ' reps', pdfFile,
        valueSet1 + valueSet2, labelList, subArea, chartTitle, yLabelText,
        scenario, maxValueSet1 + maxValueSet2)

    pdfFile.savefig()
    pl.close()
    pdfFile.close()
    print "Done."
def main(subArea, runName, chartTitlePre, ownership):
    outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\"
    varList = [
        ' Resilient (ha) PMG345', ' Semi-Resilient (ha) PMG345',
        ' Low Resilience (ha) PMG345', ' Early Successional (ha) Forest',
        ' Plantations (ha) Forest', ' Pole and Small (ha) Forest',
        ' Medium (ha) Forest', ' Large and Giant (ha) Forest'
    ]
    yLabelText = 'Percent of Landscape in'
    chartTitle = chartTitlePre
    PMG345Ha = reporterFunc.getPMG345Ha(subArea)
    forestedHa = reporterFunc.getOwnerForestedHa(subArea)

    # list of ownerships to graphs
    if ownership == 'All':
        ownersToGraph = [
            'Federal', 'State', 'Private Non-Industrial', 'Private Industrial',
            'Tribal', 'Homeowner'
        ]
        pdfFile = PdfPages(outDir + 'report2_ForestStructure2_All.pdf')
    else:
        ownersToGraph = [ownership]
        pdfFile = PdfPages(outDir + 'report2_ForestStructure2_' +
                           ownersToGraph[0] + '.pdf')

    for varStruct in varList:
        # setup plot for all scenarios
        fig = pl.figure(1, figsize=(11, 8.5))
        ax = fig.add_subplot(1, 1, 1)

        for scenario in [
                'CurrentPolicy', 'NoFedTreat', 'Restoration', 'NoFireNoMgmt'
        ]:
            inDir = outDir + runName + "_" + scenario + "\\"

            if os.path.isdir(inDir):
                yearList = list(
                    set(
                        pd.io.parsers.read_csv(
                            inDir +
                            r'ForestStructure2_by_OWNER_pivot.csv')[' Year']))
                repList = list(
                    set(
                        pd.io.parsers.read_csv(
                            inDir +
                            r'ForestStructure2_by_OWNER_pivot.csv')[' Run']))
                totalArea = pd.io.parsers.read_csv(
                    inDir + r'ForestStructure2_by_OWNER_pivot.csv')

                # get stats from multiple reps
                statsList = []
                for year in range(1, max(yearList) + 1):
                    yearArea = totalArea[totalArea[' Year'] == year]

                    dataList = []
                    for rep in repList:
                        repArea = yearArea[yearArea[' Run'] == rep]

                        # sum output over selected ownerships
                        for ownerToGraph in ownersToGraph:
                            if ownerToGraph == ownersToGraph[0]:
                                ownerArea = pd.DataFrame(repArea[
                                    repArea[' OWNER_label'] == ownerToGraph])
                                fireProneArea345 = PMG345Ha[ownerToGraph]
                                fireProneArea = forestedHa[ownerToGraph]
                            else:
                                tempArea = repArea[repArea[' OWNER_label'] ==
                                                   ownerToGraph]
                                for varName in varList:
                                    #                            totalArea.loc[list(ownerArea.index)[0],varName] += tempArea[varName].iloc[0]
                                    ownerArea[varName].iloc[0] += tempArea[
                                        varName].iloc[0]

                                fireProneArea345 += PMG345Ha[ownerToGraph]
                                fireProneArea += forestedHa[ownerToGraph]
                                ownerToGraph = 'All'

                        if varStruct in [
                                ' Resilient (ha) PMG345',
                                ' Semi-Resilient (ha) PMG345',
                                ' Low Resilience (ha) PMG345'
                        ]:
                            if fireProneArea345 > 0:
                                dataList.append(ownerArea[varStruct].iloc[0] /
                                                fireProneArea345 * 100)
                            else:
                                dataList.append(0.0)
                        else:
                            if fireProneArea > 0:
                                dataList.append(ownerArea[varStruct].iloc[0] /
                                                fireProneArea * 100)
                            else:
                                dataList.append(0.0)

                    # convert to numpy array
                    numpyList = np.array(dataList)
                    lower95th = np.mean(numpyList, axis=0) - (
                        (1.96 * np.std(numpyList, axis=0)) /
                        np.sqrt(len(repList)))
                    upper95th = np.mean(numpyList, axis=0) + (
                        (1.96 * np.std(numpyList, axis=0)) /
                        np.sqrt(len(repList)))

                    if lower95th < 0:
                        lower95th = 0.0

                    # add year data to dictionary
                    dataDict = {
                        'timeStep': year,
                        'mean': np.mean(numpyList, axis=0),
                        'std': np.std(numpyList, axis=0),
                        'lower': lower95th,
                        'upper': upper95th
                    }

                    # convert to list for DataFrame
                    statsList.append(dataDict)

                # convert to DataFrame
                dataTable = pd.DataFrame(statsList)

                reporterFunc.plotReporter2(
                    fig, ax,
                    ownerToGraph + ' - ' + str(len(repList)) + ' reps',
                    pdfFile, dataTable, ['mean', 'lower', 'upper'], subArea,
                    chartTitle, yLabelText + varStruct, scenario)

        pdfFile.savefig()
        pl.close()
    pdfFile.close()
    print "Done."