def main(outDir, subArea, runList, chartTitle, ownership): varList = [' Early Successional (ha) Forest', ' Pole and Small (ha) Forest', ' Medium (ha) Forest', ' Large and Giant (ha) Forest',' Open Canopy (ha) Sm+ Forest',' Closed Canopy (ha) Sm+ Forest'] yLabelText = 'Area (%)' figTextList = ['Early successional','Pole and small','Medium','Large and giant','Open canopy','Closed canopy'] # list of ownerships to graphs ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Homeowner'] reporterName = r'ForestStructure2_by_OWNER_pivot.csv' reporterNameSYU = r'ForestStructure2_SYU_by_OWNER_pivot.csv' ownerLabelField = ' OWNER_label' if ownership == 'All': pdfFile = PdfPages(outDir + chartTitle + '_syu_ForestStructure2_landscape.pdf') forestedSYUArea = 222072 elif ownership in ownersToGraph: ownersToGraph = [ownership] forestedSYUArea = 172556 pdfFile = PdfPages(outDir + chartTitle + '_syu_ForestStructure2_' + ownersToGraph[0] + '.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_syu_ForestStructure2_' + ownersToGraph[0] + '.pdf') ownerLabelField = ' OWNER_DETL_label' reporterName = r'ForestStructure2_by_OWNER_DETL_pivot.csv' # load area stats by owner areaStats = pd.io.parsers.read_csv(outDir + runList[0] + "\\AreaStats_by_OWNER_pivot.csv") areaStats = areaStats[areaStats[' Year'] == 1] # sum total areas over selected ownerships for ownerToGraph in ownersToGraph: ownerStats = areaStats[areaStats[ownerLabelField] == ownerToGraph] if ownerToGraph == ownersToGraph[0]: forestedArea = ownerStats[' Forested (ha)'].iloc[0] else: forestedArea += ownerStats[' Forested (ha)'].iloc[0] fig = pl.figure(1, figsize=(8,6.5)) for varStruct in varList: # setup plot for all scenarios ax = fig.add_subplot(2,3,varList.index(varStruct) + 1) print ('Running ' + varStruct) for scenario in runList: inDir = outDir + scenario + "\\" if os.path.isdir(inDir): for reporter in [reporterName, reporterNameSYU]: totalArea = pd.io.parsers.read_csv(inDir + reporter) yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # 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]) else: ownerArea[varStruct].iloc[0] += repArea[repArea[ownerLabelField] == ownerToGraph][varStruct].iloc[0] dataList.append(ownerArea[varStruct].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) if '_SYU_' in reporter: scenario += '_SYU_' dataTable['mean'] = dataTable['mean'] / forestedSYUArea * 100 dataTable['lower'] = dataTable['lower'] / forestedSYUArea * 100 dataTable['upper'] = dataTable['upper'] / forestedSYUArea * 100 else: dataTable['mean'] = dataTable['mean'] / forestedArea * 100 dataTable['lower'] = dataTable['lower'] / forestedArea * 100 dataTable['upper'] = dataTable['upper'] / forestedArea * 100 plotLegend = (-99,-99) if varStruct == ' Pole and Small (ha) Forest': plotLegend = (0.8,0.45) if varList.index(varStruct) >= (len(varList) - 3): labelXtick = True else: labelXtick = False # if varList.index(varStruct) == 0 or varList.index(varStruct) == 3: labelYtick = True xLabelText = yLabelText = '' mnAxis, mxAxis = reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, figTextList[varList.index(varStruct)]) reporterFunc.plotFigureText(fig, 'Simulation Year', 'Area (%)') # pl.savefig(outDir + 'report4_ForestStructure2_landscape.png', bbox_inches='tight', dpi=300) pdfFile.savefig() pl.close() pdfFile.close() print "Done with forest structure 2."
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(outDir, subArea, runList, chartTitle, ownership): varList = [' NumberDwellings1kmFromStandRep'] # list of ownerships to graphs reporterName = r'FireExperience_pivot.csv' pdfFile = PdfPages(outDir + chartTitle + '_HS_Fire_Homes_Exposed_cumulative.pdf') for splot in [1]: # setup plot for all scenarios fig = pl.figure(1, figsize=(4,4)) ax = fig.add_subplot(1,1,1) for scenario in runList: inDir = outDir + scenario + "\\" if os.path.isdir(inDir): totalArea = pd.io.parsers.read_csv(inDir + reporterName) yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # 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] dataList.append(repArea[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) labelXtick = True labelYtick = True plotLegend = (0.5,0.99) xLabelText = 'Simulation Year' dataTable['mean'] = dataTable['mean'] / 1000 dataTable['lower'] = dataTable['lower'] / 1000 dataTable['upper'] = dataTable['upper'] / 1000 if splot == 1: yLabelText = 'Cumulative Homes Exposed to HS fire (1000 dwellings)' ## mnAxis, mxAxis = reporterFunc.plotReporter6_cumulative(fig, ax, '', pdfFile, dataTable, ['mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, '') dataTable['cum_mean'] = dataTable['mean'].cumsum() mnAxis, mxAxis = reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['cum_mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, '') pdfFile.savefig() pl.close() pdfFile.close() print "Done with cumulative HS fire Homes Exposed."
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."
def main(outDir, subArea, runList, chartTitle, ownership): varList = [ ' Smoke_surfaceFire (Mg)', ' Smoke_mixSevFire (Mg)', ' Smoke_standRepFire (Mg)', ' Smoke_prescribedFire (Mg)' ] # list of ownerships to graphs ## ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Tribal','Homeowner'] # remove Tribal from owners to graph ownersToGraph = [ 'Federal', 'State', 'Private Non-Industrial', 'Private Industrial', 'Homeowner' ] reporterName = r'Smoke_by_OWNER_pivot.csv' ownerLabelField = ' OWNER_label' # set list of owners to graph if ownership == 'All': pdfFile = PdfPages(outDir + chartTitle + '_smoke_landscape.pdf') elif ownership in ownersToGraph: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_smoke_' + ownersToGraph[0] + '.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_smoke_' + ownersToGraph[0] + '.pdf') ownerLabelField = ' OWNER_DETL_label' reporterName = r'Smoke_by_OWNER_DETL_pivot.csv' for splot in [1, 2, 3, 4]: # setup plot for all scenarios fig = pl.figure(1, figsize=(4, 4)) ax = fig.add_subplot(1, 1, 1) for scenario in runList: inDir = outDir + scenario + "\\" if os.path.isdir(inDir): totalArea = pd.io.parsers.read_csv(inDir + reporterName) yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # 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]) 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] ownerToGraph = 'All' if splot == 1 or splot == 2: dataList.append( ownerArea[' Smoke_surfaceFire (Mg)'].iloc[0] + ownerArea[' Smoke_mixSevFire (Mg)'].iloc[0] + ownerArea[' Smoke_standRepFire (Mg)'].iloc[0]) elif splot == 3 or splot == 4: dataList.append( ownerArea[' Smoke_prescribedFire (Mg)'].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) labelXtick = True labelYtick = True plotLegend = (0.99, 0.99) xLabelText = 'Simulation Year' outVar = 'mean' if splot == 1: yLabelText = 'Smoke from wildfire (Mg)' elif splot == 2: yLabelText = 'Cumulative smoke from wildfire (1000 Mg)' dataTable['cum_mean'] = dataTable['mean'].cumsum() dataTable['cum_mean'] = dataTable['cum_mean'] / 1000 outVar = 'cum_mean' plotLegend = (0.5, 0.99) elif splot == 3: yLabelText = 'Smoke from prescribed fire (Mg)' elif splot == 4: yLabelText = 'Cumulative smoke from prescribed fire (Mg)' dataTable['cum_mean'] = dataTable['mean'].cumsum() outVar = 'cum_mean' plotLegend = (0.5, 0.99) mnAxis, mxAxis = reporterFunc.plotReporter4( fig, ax, '', pdfFile, dataTable, [outVar], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, '') if mxAxis > 1000: pl.subplots_adjust(left=0.14) pdfFile.savefig() pl.close() pdfFile.close() print "Done with smoke."
def main(outDir, subArea, runList, chartTitle, ownership): varList = [' Stand Replacing FirePMG1', ' Stand Replacing FirePMG2', ' Stand Replacing FirePMG3', ' Stand Replacing FirePMG4', ' Stand Replacing FirePMG5'] # list of ownerships to graphs ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Homeowner'] reporterName = r'FireOccurance_by_OWNER_pivot.csv' ownerLabelField = ' OWNER_label' # reset list of owners to graph if ownership == 'All': pdfFile = PdfPages(outDir + chartTitle + '_HS_Fire_landscape_cumulative.pdf') elif ownership in ownersToGraph: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_HS_Fire_' + ownersToGraph[0] + 'cumulative.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_HS_Fire_' + ownersToGraph[0] + 'cumulative.pdf') ownerLabelField = ' OWNER_DETL_label' reporterName = r'FireOccurance_by_OWNER_DETL_pivot.csv' # load area stats by owner areaStats = pd.io.parsers.read_csv(outDir + runList[0] + "\\AreaStats_by_OWNER_pivot.csv") areaStats = areaStats[areaStats[' Year'] == 1] # sum total areas over selected ownerships for ownerToGraph in ownersToGraph: ownerStats = areaStats[areaStats[ownerLabelField] == ownerToGraph] if ownerToGraph == ownersToGraph[0]: PMG345Area = ownerStats[' PVT MNG GR 3 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 4 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 5 (ha)'].iloc[0] PMG12345Area = ownerStats[' PVT MNG GR 1 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 2 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 3 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 4 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 5 (ha)'].iloc[0] PMG1Area = ownerStats[' PVT MNG GR 1 (ha)'].iloc[0] PMG2Area = ownerStats[' PVT MNG GR 2 (ha)'].iloc[0] else: PMG345Area += ownerStats[' PVT MNG GR 3 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 4 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 5 (ha)'].iloc[0] PMG12345Area += ownerStats[' PVT MNG GR 1 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 2 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 3 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 4 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 5 (ha)'].iloc[0] PMG1Area += ownerStats[' PVT MNG GR 1 (ha)'].iloc[0] PMG2Area += ownerStats[' PVT MNG GR 2 (ha)'].iloc[0] for splot in [1,3,5,7]: # setup plot for all scenarios fig = pl.figure(1, figsize=(4,4)) ax = fig.add_subplot(1,1,1) for scenario in runList: print "HS Fire Cumulative Running scenario " + scenario inDir = outDir + scenario + "\\" if os.path.isdir(inDir): totalArea = pd.io.parsers.read_csv(inDir + reporterName) yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # get stats from multiple reps statsList = [] for year in range(1,max(yearList) + 1): yearArea = totalArea[totalArea[' Year'] == year] print 'running year ' + str(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]) else: tempArea = pd.DataFrame(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] if splot == 1 or splot == 2: 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]) elif splot == 3 or splot == 4: dataList.append(ownerArea[' Stand Replacing FirePMG3'].iloc[0] + ownerArea[' Stand Replacing FirePMG4'].iloc[0] + ownerArea[' Stand Replacing FirePMG5'].iloc[0]) elif splot == 5 or splot == 6: dataList.append(ownerArea[' Stand Replacing FirePMG2'].iloc[0]) elif splot == 7 or splot == 8: dataList.append(ownerArea[' Stand Replacing FirePMG1'].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) labelXtick = True labelYtick = True plotLegend = (0.5,0.99) xLabelText = 'Simulation Year' dataTable['mean'] = dataTable['mean'] / 1000 dataTable['lower'] = dataTable['lower'] / 1000 dataTable['upper'] = dataTable['upper'] / 1000 if splot == 1: yLabelText = 'Cumulative area of HS fire (1000 ha)' elif splot == 2: yLabelText = 'Cumulative area of HS fire (1000 ac)' dataTable['mean'] = dataTable['mean'] * 2.471 dataTable['lower'] = dataTable['lower'] * 2.471 dataTable['upper'] = dataTable['upper'] * 2.471 elif splot == 3: yLabelText = 'Cumulative area of fire frequent PMG in HS fire (1000 ha)' elif splot == 4: yLabelText = 'Cumulative area of fire frequent PMG in HS fire (1000 ac)' dataTable['mean'] = dataTable['mean'] * 2.471 dataTable['lower'] = dataTable['lower'] * 2.471 dataTable['upper'] = dataTable['upper'] * 2.471 elif splot == 5: yLabelText = 'Cumulative area of lodgepole PMG in HS fire (1000 ha)' elif splot == 7: yLabelText = 'Cumulative area of high elev PMG in HS fire (1000 ha)' ## mnAxis, mxAxis = reporterFunc.plotReporter6_cumulative(fig, ax, '', pdfFile, dataTable, ['mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, '') dataTable['cum_mean'] = dataTable['mean'].cumsum() mnAxis, mxAxis = reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['cum_mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, '') ## # get max y value ## if runList.index(scenario) == 0: ## mxAxis = dataTable['mean'].cumsum().max() ## else: ## if dataTable['mean'].cumsum().max() > mxAxis: ## mxAxis = dataTable['mean'].cumsum().max() # repeat y axis on right with percent ax.set_ylim(mnAxis,mxAxis) print "Max y axis value found: " + str(mxAxis) + " and min y axis value: " + str(mnAxis) if splot == 1: yLabelText = 'Cumulative area of HS fire (%)' mnAxis = mnAxis / PMG12345Area * 100000 mxAxis = mxAxis / PMG12345Area * 100000 elif splot == 2: yLabelText = 'Cumulative area of HS fire (%)' mnAxis = mnAxis / PMG12345Area * 100000 / 2.471 mxAxis = mxAxis / PMG12345Area * 100000 / 2.471 elif splot == 3: yLabelText = 'Cumulative area of fire frequent PMG in HS fire (%)' mnAxis = mnAxis / PMG345Area * 100000 mxAxis = mxAxis / PMG345Area * 100000 elif splot == 4: yLabelText = 'Cumulative area of fire frequent PMG in HS fire (%)' mnAxis = mnAxis / PMG345Area * 100000 / 2.471 mxAxis = mxAxis / PMG345Area * 100000 / 2.471 elif splot == 5: yLabelText = 'Cumulative area of lodgepole PMG in HS fire (%)' mnAxis = mnAxis / PMG2Area * 100000 mxAxis = mxAxis / PMG2Area * 100000 elif splot == 7: yLabelText = 'Cumulative area of high elev PMG in HS fire (%)' mnAxis = mnAxis / PMG1Area * 100000 mxAxis = mxAxis / PMG1Area * 100000 reporterFunc.plotSecondYAxis(ax.twinx(), yLabelText, mnAxis, mxAxis) pl.subplots_adjust(right=0.89) pdfFile.savefig() pl.close() pdfFile.close() print "Done with cumulative HS fire."
def main(outDir, subArea, runList, chartTitle, ownership): varStruct = ' Total Merch Harvest (m3)' yLabelText = 'Merchantable large tree vol ( $\mathregular{1x10^3}$ $\mathregular{m^3}$)' yLabelText2 = 'Cumulative merchantable large tree vol ( $\mathregular{1x10^6}$ $\mathregular{m^3}$)' figTextList = [ 'Federal', 'Tribal', 'Corporate Forest', 'Family Forest', 'Homeowner' ] # list of ownerships to graphs ownersToGraph = [ 'Federal', 'Tribal', 'Private Non-Industrial', 'Private Industrial', 'Homeowner' ] pdfFile = PdfPages(outDir + chartTitle + '_Vol_LgTree_owners.pdf') pdfFile2 = PdfPages(outDir + chartTitle + '_Vol_LgTree_owners_cumulative.pdf') for owner in ownersToGraph: fig = pl.figure(1, figsize=(4, 4)) fig2 = pl.figure(2, figsize=(4, 4)) # setup plot for all scenarios ax = fig.add_subplot(1, 1, 1) ax2 = fig2.add_subplot(1, 1, 1) for scenario in runList: inDir = outDir + scenario + "\\" if os.path.isdir(inDir): totalArea = pd.io.parsers.read_csv( inDir + r'LgTreeVol_MerchHarvLive_D3_D55_by_OWNER_pivot.csv') totalArea2 = pd.io.parsers.read_csv( inDir + r'LgTreeVol_SalHarvest_by_OWNER_pivot.csv') yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # get stats from multiple reps statsList = [] for year in range(1, max(yearList) + 1): yearArea = totalArea[totalArea[' Year'] == year] yearArea2 = totalArea2[totalArea2[' Year'] == year] dataList = [] for rep in repList: repArea = yearArea[yearArea[' Run'] == rep] repArea2 = yearArea2[yearArea2[' Run'] == rep] ownerArea = pd.DataFrame( repArea[repArea[' OWNER_label'] == owner]) ownerArea2 = pd.DataFrame( repArea2[repArea2[' OWNER_label'] == owner]) dataList.append( ownerArea[' LgTreeVol MerchHarvLive D55_1 (m3)']. iloc[0] + ownerArea[' LgTreeVol MerchHarvLive D55_2 (m3)']. iloc[0] + ownerArea[' LgTreeVol MerchHarvLive D55_3 (m3)']. iloc[0] + ownerArea[' LgTreeVol MerchHarvLive D55_4 (m3)']. iloc[0] + ownerArea[' LgTreeVol MerchHarvLive D55_5 (m3)']. iloc[0] + ownerArea[' LgTreeVol MerchHarvLive D3_1 (m3)']. iloc[0] + ownerArea[' LgTreeVol MerchHarvLive D3_2 (m3)']. iloc[0] + ownerArea[' LgTreeVol MerchHarvLive D3_3 (m3)']. iloc[0] + ownerArea[' LgTreeVol MerchHarvLive D3_4 (m3)']. iloc[0] + ownerArea2[' LgTreeVol SalHarvest Giant (m3)']. iloc[0] + ownerArea2[' LgTreeVol SalHarvest Large (m3)']. iloc[0] + ownerArea2[' LgTreeVol SalHarvest Medium (m3)']. 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) labelXtick = True labelYtick = True plotLegend = (0.99, 0.99) xLabelText = 'Simulation Year' dataTable['mean'] = dataTable['mean'] / 1000 dataTable['lower'] = dataTable['lower'] / 1000 dataTable['upper'] = dataTable['upper'] / 1000 dataTable['cum_mean'] = dataTable['mean'].cumsum() dataTable['cum_mean'] = dataTable['cum_mean'] / 1000 if owner == 'Tribal': plotLegend = (0.84, 0.33) pl.figure(1) mnAxis, mxAxis = reporterFunc.plotReporter4( fig, ax, '', pdfFile, dataTable, ['mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, figTextList[ownersToGraph.index(owner)]) pl.figure(2) mnAxis, mxAxis = reporterFunc.plotReporter4( fig2, ax2, '', pdfFile2, dataTable, ['cum_mean'], xLabelText, yLabelText2, scenario, labelXtick, labelYtick, plotLegend, figTextList[ownersToGraph.index(owner)]) pdfFile.savefig(fig) pdfFile2.savefig(fig2) pl.close(fig) pl.close(fig2) ##reporterFunc.plotFigureText(fig, 'Simulation Year', 'Merchantable volume ( $\mathregular{1x10^3}$ $\mathregular{m^3}$)') ## pl.savefig(outDir + 'report4_Vol_Owners.png', bbox_inches='tight', dpi=300) pdfFile.close() pdfFile2.close() print "Done with harvest vol by owner."
def main(outDir, subArea, runList, chartTitle, ownership): varStruct = ' Total Merch Harvest (m3)' yLabelText = 'Merchantable volume ( $\mathregular{1x10^3}$ $\mathregular{m^3}$)' yLabelText2 = 'Cumulative Merchantable volume ( $\mathregular{1x10^6}$ $\mathregular{m^3}$)' figTextList = ['Federal', 'Tribal', 'Corporate Forest', 'Family Forest'] # list of ownerships to graphs owner = 'Federal' pdfFile = PdfPages(outDir + chartTitle + '_Vol_PP_MC_Fed.pdf') pdfFile2 = PdfPages(outDir + chartTitle + '_Vol_PP_MC_Fed_cumulative.pdf') for scenario in runList: fig = pl.figure(1, figsize=(4, 4)) fig2 = pl.figure(2, figsize=(4, 4)) # setup plot for all scenarios ax = fig.add_subplot(1, 1, 1) ax2 = fig2.add_subplot(1, 1, 1) for volSpp in ['', '_PP', '_MC']: inDir = outDir + scenario + "\\" if os.path.isdir(inDir): totalArea = pd.io.parsers.read_csv(inDir + r'WoodProducts' + volSpp + '_by_OWNER_pivot.csv') yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # 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] ownerArea = pd.DataFrame( repArea[repArea[' OWNER_label'] == owner]) if volSpp == '_PP': dataList.append(ownerArea[' PP' + varStruct].iloc[0]) elif volSpp == '_MC': dataList.append(ownerArea[' MC' + varStruct].iloc[0]) else: dataList.append(ownerArea[varStruct].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) labelXtick = True labelYtick = True plotLegend = (0.99, 0.99) xLabelText = 'Simulation Year' dataTable['mean'] = dataTable['mean'] / 1000 dataTable['lower'] = dataTable['lower'] / 1000 dataTable['upper'] = dataTable['upper'] / 1000 dataTable['cum_mean'] = dataTable['mean'].cumsum() dataTable['cum_mean'] = dataTable['cum_mean'] / 1000 if owner == 'Tribal': plotLegend = (0.84, 0.33) pl.figure(1) mnAxis, mxAxis = reporterFunc.plotReporter4( fig, ax, '', pdfFile, dataTable, ['mean', 'lower', 'upper'], xLabelText, yLabelText, 'HarvVol' + volSpp, labelXtick, labelYtick, plotLegend, scenario) pl.figure(2) mnAxis, mxAxis = reporterFunc.plotReporter4( fig2, ax2, '', pdfFile2, dataTable, ['cum_mean'], xLabelText, yLabelText2, 'HarvVol' + volSpp, labelXtick, labelYtick, plotLegend, scenario) pdfFile.savefig(fig) pdfFile2.savefig(fig2) pl.close(fig) pl.close(fig2) ##reporterFunc.plotFigureText(fig, 'Simulation Year', 'Merchantable volume ( $\mathregular{1x10^3}$ $\mathregular{m^3}$)') ## pl.savefig(outDir + 'report4_Vol_Owners.png', bbox_inches='tight', dpi=300) pdfFile.close() pdfFile2.close() print "Done with harvest vol by owner."
def main(subArea, runName, chartTitlePre, ownership): outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\" varStruct = ' Total Merch Harvest (m3)' # yLabelText = 'Percent of Landscape in' chartTitle = chartTitlePre forestedHa = reporterFunc.getOwnerForestedHa(subArea) ownerAllHa = reporterFunc.getOwnerHa(subArea) # list of ownerships to graphs ownersToGraph = ['BLM Lands','Chemult Ranger District (Fremont-Winema NF)','Chiloquin Ranger District (Fremont-Winema NF)','Klamath Ranger District (Fremont-Winema NF)','ODF Sun Pass','JWTR Timber Holdings','Cascade Timberlands (Mazama Forest)','Jeld-Wen Inc','J-Spear Ranch'] pdfFile = PdfPages(outDir + 'report4_Vol_Owners_Detl.pdf') fig = pl.figure(1, figsize=(8.5,11)) subPlotNum = 0 for owner in ownersToGraph: # setup plot for all scenarios subPlotNum += 1 if subPlotNum == 5: subPlotNum = 1 pdfFile.savefig() pl.close() fig = pl.figure(1, figsize=(8.5,11)) ax = fig.add_subplot(2,2,subPlotNum) for scenario in ['CurrentPolicy','NoTreatment','NoFedTreat','Restoration','NoFireNoMgmt']: inDir = outDir + runName + "_" + scenario + "\\" if os.path.isdir(inDir): yearList = list(set(pd.io.parsers.read_csv(inDir + r'WoodProducts_by_OWNER_DETL_pivot.csv')[' Year'])) repList = list(set(pd.io.parsers.read_csv(inDir + r'WoodProducts_by_OWNER_DETL_pivot.csv')[' Run'])) totalArea = pd.io.parsers.read_csv(inDir + r'WoodProducts_by_OWNER_DETL_pivot.csv') yLabelText = 'Merchantable Volume Harvested (m3)' # 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] ownerArea = pd.DataFrame(repArea[repArea[' OWNER_DETL_label'] == owner]) dataList.append(ownerArea[varStruct].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) plotLegend = False if subPlotNum == 3 or subPlotNum == 4: labelXaxis = True else: labelXaxis = False yLabelTextOwner = owner + ' ' + yLabelText reporterFunc.plotReporter4(fig, ax, owner + ' - ' + str(len(repList)) + ' reps', pdfFile, dataTable, ['mean','lower','upper'], yLabelTextOwner, scenario, labelXaxis, plotLegend) pdfFile.savefig() pl.close() pdfFile.close() print "Done."
def main(outDir, subArea, runList, chartTitle, ownership): varList = [' Seedling-Sapling', ' Pole',' Small tree',' Medium tree',' Large tree',' Giant tree',' Open Canopy',' Moderate Canopy',' Closed Canopy',' Single-story',' Multi-story'] # list of ownerships to graphs ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Homeowner'] reporterNameVol = r'ForestStructure3_by_OWNER_pivot.csv' ownerLabelField = ' OWNER_label' if ownership == 'All': pdfFile = PdfPages(outDir + chartTitle + '_ForestStructure3_landscape.pdf') elif ownership in ownersToGraph: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_ForestStructure3_' + ownersToGraph[0] + '.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_ForestStructure3_' + ownersToGraph[0] + '.pdf') ownerLabelField = ' OWNER_DETL_label' # load area stats by owner areaStats = pd.io.parsers.read_csv(outDir + runList[0] + "\\AreaStats_by_OWNER_pivot.csv") areaStats = areaStats[areaStats[' Year'] == 1] # sum total areas over selected ownerships for ownerToGraph in ownersToGraph: ownerStats = areaStats[areaStats[ownerLabelField] == ownerToGraph] if ownerToGraph == ownersToGraph[0]: PMG345Area = ownerStats[' PVT MNG GR 3 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 4 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 5 (ha)'].iloc[0] analysisModeledArea = ownerStats[' Forested (ha)'].iloc[0] + ownerStats[' Arid (ha)'].iloc[0] analysisForestedArea = ownerStats[' Forested (ha)'].iloc[0] else: PMG345Area += ownerStats[' PVT MNG GR 3 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 4 (ha)'].iloc[0] + ownerStats[' PVT MNG GR 5 (ha)'].iloc[0] analysisModeledArea += ownerStats[' Forested (ha)'].iloc[0] + ownerStats[' Arid (ha)'].iloc[0] analysisForestedArea += ownerStats[' Forested (ha)'].iloc[0] for landscape in [' (ha) PMG345',' (ha) Forest']: for varStruct in varList: print 'Forest structure 3 - ' + varStruct + landscape fig = pl.figure(1, figsize=(4,4)) # setup plot for all scenarios ax = fig.add_subplot(1,1,1) varStruct += landscape if landscape == ' (ha) PMG345': yLabelText = 'Area of FF landscape in ' + varStruct[1:-12] + ' (1000 ha)' analysisArea = PMG345Area elif landscape == ' (ha) Forest': yLabelText = 'Area of ' + varStruct[1:-12] + ' (1000 ha)' analysisArea = analysisForestedArea else: yLabelText = 'Error!! Missing landscape' analysisArea = 1 for scenario in runList: inDir = outDir + scenario + "\\" if os.path.isdir(inDir): totalArea = pd.io.parsers.read_csv(inDir + reporterNameVol) yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # 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]) else: ownerArea[varStruct].iloc[0] += repArea[repArea[ownerLabelField] == ownerToGraph][varStruct].iloc[0] dataList.append(ownerArea[varStruct].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) labelYtick = True # unitText = ' ( $\mathregular{1x10^6}$ $\mathregular{m^3}$ )' dataTable['mean'] = dataTable['mean'] / 1000 dataTable['lower'] = dataTable['lower'] / 1000 dataTable['upper'] = dataTable['upper'] / 1000 labelXtick = True xLabelText = 'Simulation Year' plotLegend = (0.5,0.99) figText = '' mnAxis, mxAxis = reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, figText) # repeat y axis on right with percent ax.set_ylim(mnAxis,mxAxis) print "Max y axis value found: " + str(mxAxis) + " and min y axis value: " + str(mnAxis) yLabelText = yLabelText[:-8] + '%)' mnAxis = mnAxis / analysisArea * 100000 mxAxis = mxAxis / analysisArea * 100000 reporterFunc.plotSecondYAxis(ax.twinx(), yLabelText, mnAxis, mxAxis) if mxAxis - mnAxis <= 4.5: pl.subplots_adjust(right=0.87) elif (mxAxis * analysisArea / 100000) > 1000: pl.subplots_adjust(left=0.14) pdfFile.savefig() pl.close() pdfFile.close() print "Done with ForestStructure3."
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."
def main(subArea, runName, chartTitlePre, ownership): outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\" varList = [' Moderate Suitability', ' American Marten', ' Black-backed Woodpecker', ' White-headed Woodpecker', ' Northern Goshawk', ' Western Bluebird', ' Pileated Woodpecker', 'MD Moderate Suitability', ' DownyBrome0.33-0.66 (ha)'] yLabelText = 'Percent of Landscape in' chartTitle = chartTitlePre forestedHa = reporterFunc.getOwnerForestedHa(subArea) ownerAllHa = reporterFunc.getOwnerHa(subArea) # list of ownerships to graphs if ownership == 'All': ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Tribal','Homeowner'] pdfFile = PdfPages(outDir + 'report4_Wildlife23_landscape.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + 'report4_Wildlife23_' + ownersToGraph[0] + '.pdf') fig = pl.figure(1, figsize=(8.5,11)) for varStruct in varList: # setup plot for all scenarios ax = fig.add_subplot(3,3,varList.index(varStruct) + 1) if varStruct == ' Moderate Suitability': varStructAdd = ' High Suitability' yLabelTextStruct = yLabelText + ' VFO Northern Spotted Owl Mod+High' modelGroup = 'vfoNSO' elif varStruct == 'MD Moderate Suitability': varStructAdd = ' High Suitability' yLabelTextStruct = yLabelText + ' Mule Deer Mod+High' varStruct = ' Moderate Suitability' modelGroup = 'muleDeer' elif varStruct == ' DownyBrome0.33-0.66 (ha)': varStructAdd = ' DownyBrome0.66-1 (ha)' yLabelTextStruct = yLabelText + ' Downy Brome Mod+High' modelGroup = 'downyBrome' else: yLabelTextStruct = yLabelText + varStruct + ' Fair+Good' varStructAdd = varStruct + ' Good (ha)' varStruct = varStruct + ' Fair (ha)' modelGroup = 'iLAP' for scenario in ['CurrentPolicy','NoTreatment','NoFedTreat','Restoration','NoFireNoMgmt']: inDir = outDir + runName + "_" + scenario + "\\" if os.path.isdir(inDir): if modelGroup == 'vfoNSO': yearList = list(set(pd.io.parsers.read_csv(inDir + r'VFO_Spotted_Owl_by_OWNER_pivot.csv')[' Year'])) repList = list(set(pd.io.parsers.read_csv(inDir + r'VFO_Spotted_Owl_by_OWNER_pivot.csv')[' Run'])) totalArea = pd.io.parsers.read_csv(inDir + r'VFO_Spotted_Owl_by_OWNER_pivot.csv') elif modelGroup == 'muleDeer': yearList = list(set(pd.io.parsers.read_csv(inDir + r'Mule_Deer_by_OWNER_pivot.csv')[' Year'])) repList = list(set(pd.io.parsers.read_csv(inDir + r'Mule_Deer_by_OWNER_pivot.csv')[' Run'])) totalArea = pd.io.parsers.read_csv(inDir + r'Mule_Deer_by_OWNER_pivot.csv') elif modelGroup == 'downyBrome': yearList = list(set(pd.io.parsers.read_csv(inDir + r'Downy_Brome_by_OWNER_pivot.csv')[' Year'])) repList = list(set(pd.io.parsers.read_csv(inDir + r'Downy_Brome_by_OWNER_pivot.csv')[' Run'])) totalArea = pd.io.parsers.read_csv(inDir + r'Downy_Brome_by_OWNER_pivot.csv') else: yearList = list(set(pd.io.parsers.read_csv(inDir + r'ILAP_wildlife_models_by_OWNER_pivot.csv')[' Year'])) repList = list(set(pd.io.parsers.read_csv(inDir + r'ILAP_wildlife_models_by_OWNER_pivot.csv')[' Run'])) totalArea = pd.io.parsers.read_csv(inDir + r'ILAP_wildlife_models_by_OWNER_pivot.csv') # sum fair and good habitat into fair column totalArea[varStruct] = totalArea[varStruct] + totalArea[varStructAdd] # 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]) analysisTotalArea = ownerAllHa[ownerToGraph] analysisForestedArea = 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[varStruct].iloc[0] += tempArea[varStruct].iloc[0] analysisTotalArea += ownerAllHa[ownerToGraph] analysisForestedArea += forestedHa[ownerToGraph] ownerToGraph = 'All' if varStruct == ' DownyBrome0.66-1 (ha)' or varStruct == ' DownyBrome0.33-0.66 (ha)': if analysisTotalArea > 0: dataList.append(ownerArea[varStruct].iloc[0] / analysisTotalArea * 100) else: dataList.append(0.0) else: if analysisForestedArea > 0: dataList.append(ownerArea[varStruct].iloc[0] / analysisForestedArea * 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 yLabelTextStruct == (yLabelText + ' Pileated Woodpecker Fair+Good') or yLabelTextStruct == (yLabelText + ' Mule Deer Mod+High') or yLabelTextStruct == (yLabelText + ' Downy Brome Mod+High'): labelXaxis = True else: labelXaxis = False plotLegend = False ## if varList.index(varStruct) + 1 == 8: ## plotLegend = True reporterFunc.plotReporter4(fig, ax, ownerToGraph + ' - ' + str(len(repList)) + ' reps', pdfFile, dataTable, ['mean','lower','upper'], yLabelTextStruct, scenario, labelXaxis, plotLegend) pdfFile.savefig() pl.close() pdfFile.close() print "Done."
def main(outDir, subArea, runList, chartTitle, ownership): varList = [' Stand Replacing FirePMG1',' Stand Replacing FirePMG2',' Stand Replacing FirePMG3',' Stand Replacing FirePMG4',' Stand Replacing FirePMG5',' Surface FirePMG1',' Surface FirePMG2',' Surface FirePMG3',' Surface FirePMG4',' Surface FirePMG5',' Mixed Severity FirePMG1',' Mixed Severity FirePMG2',' Mixed Severity FirePMG3',' Mixed Severity FirePMG4',' Mixed Severity FirePMG5'] # list of ownerships to graphs ## ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Tribal','Homeowner'] # remove Tribal from owners to graph ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Homeowner'] reporterName = r'FireOccurance_by_OWNER_pivot.csv' ownerLabelField = ' OWNER_label' # set list of owners to graph if ownership == 'All': pdfFile = PdfPages(outDir + chartTitle + '_HS_Fire_proportion.pdf') elif ownership in ownersToGraph: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_HS_Fire_prop_' + ownersToGraph[0] + '.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_HS_Fire_prop_' + ownersToGraph[0] + '.pdf') ownerLabelField = ' OWNER_DETL_label' reporterName = r'FireOccurance_by_OWNER_DETL_pivot.csv' for splot in [1,3,5,7]: # setup plot for all scenarios fig = pl.figure(1, figsize=(4,4)) ax = fig.add_subplot(1,1,1) for scenario in runList: inDir = outDir + scenario + "\\" print ('Running scenario ' + scenario) if os.path.isdir(inDir): totalArea = pd.io.parsers.read_csv(inDir + reporterName) yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # 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]) 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] ownerToGraph = 'All' if splot == 1 or splot == 2: HSarea = 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] MSarea = ownerArea[' Mixed Severity FirePMG1'].iloc[0] + ownerArea[' Mixed Severity FirePMG2'].iloc[0] + ownerArea[' Mixed Severity FirePMG3'].iloc[0] + ownerArea[' Mixed Severity FirePMG4'].iloc[0] + ownerArea[' Mixed Severity FirePMG5'].iloc[0] SUarea = ownerArea[' Surface FirePMG1'].iloc[0] + ownerArea[' Surface FirePMG2'].iloc[0] + ownerArea[' Surface FirePMG3'].iloc[0] + ownerArea[' Surface FirePMG4'].iloc[0] + ownerArea[' Surface FirePMG5'].iloc[0] elif splot == 3 or splot == 4: HSarea = ownerArea[' Stand Replacing FirePMG3'].iloc[0] + ownerArea[' Stand Replacing FirePMG4'].iloc[0] + ownerArea[' Stand Replacing FirePMG5'].iloc[0] MSarea = ownerArea[' Mixed Severity FirePMG3'].iloc[0] + ownerArea[' Mixed Severity FirePMG4'].iloc[0] + ownerArea[' Mixed Severity FirePMG5'].iloc[0] SUarea = ownerArea[' Surface FirePMG3'].iloc[0] + ownerArea[' Surface FirePMG4'].iloc[0] + ownerArea[' Surface FirePMG5'].iloc[0] elif splot == 5 or splot == 6: HSarea = ownerArea[' Stand Replacing FirePMG2'].iloc[0] MSarea = ownerArea[' Mixed Severity FirePMG2'].iloc[0] SUarea = ownerArea[' Surface FirePMG2'].iloc[0] elif splot == 7 or splot == 8: HSarea = ownerArea[' Stand Replacing FirePMG1'].iloc[0] MSarea = ownerArea[' Mixed Severity FirePMG1'].iloc[0] SUarea = ownerArea[' Surface FirePMG1'].iloc[0] # if fire occured in that rep then add to dataList if (HSarea + MSarea + SUarea) > 0: dataList.append(HSarea / (HSarea + MSarea + SUarea) * 100) # 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 if len(numpyList) > 0: dataDict = {'timeStep': year, 'mean': np.mean(numpyList, axis=0), 'std': np.std(numpyList, axis=0), 'lower': lower95th, 'upper': upper95th} else: dataDict = {'timeStep': year, 'mean': 0.0, 'std': 0.0, 'lower': 0.0, 'upper': 0.0} # convert to list for DataFrame statsList.append(dataDict) # convert to DataFrame dataTable = pd.DataFrame(statsList) labelXtick = True labelYtick = True plotLegend = (0.5,0.99) xLabelText = 'Simulation Year' if splot == 1: yLabelText = 'Proportion of wildfire in HS (%)' elif splot == 3: yLabelText = 'Proportion of wildfire in HS for FF landscape (%)' if splot == 5: yLabelText = 'Proportion of wildfire in HS for lodgepole landscape (%)' if splot == 7: yLabelText = 'Proportion of wildfire in HS for high elev landscape (%)' mnAxis, mxAxis = reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, '') pdfFile.savefig() pl.close() pdfFile.close() print "Done with PMG in HS fire proportion."
def main(outDir, subArea, runList, chartTitle, ownership): varList = [ ' Small Tree Saw Timber Total', ' Medium Tree Saw Timber Total', ' Large Tree Saw Timber Total', ' Giant Tree Saw Timber Total' ] yLabelText = '' figTextList = ['Small trees', 'Medium trees', 'Large trees', 'Giant trees'] # list of ownerships to graphs ownersToGraph = [ 'Federal', 'State', 'Private Non-Industrial', 'Private Industrial', 'Homeowner' ] reporterName = r'StandingVol_bySize_by_OWNER_pivot.csv' ownerLabelField = ' OWNER_label' if ownership == 'All': pdfFile = PdfPages(outDir + chartTitle + '_syu_StandingVol_bySize_landscape.pdf') elif ownership in ownersToGraph: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_syu_StandingVol_bySize_' + ownersToGraph[0] + '.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_syu_StandingVol_bySize_' + ownersToGraph[0] + '.pdf') ownerLabelField = ' OWNER_DETL_label' reporterName = r'StandingVol_bySize_by_OWNER_DETL_pivot.csv' fig = pl.figure(1, figsize=(11, 8.5)) for varStruct in varList: # setup plot for all scenarios ax = fig.add_subplot(2, 2, varList.index(varStruct) + 1) print('Running ' + varStruct) for scenario in runList: inDir = outDir + scenario + "\\" if os.path.isdir(inDir): totalArea = pd.io.parsers.read_csv(inDir + reporterName) yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # get stats from multiple reps statsList = [] statsList2 = [] for year in range(1, max(yearList) + 1): yearArea = totalArea[totalArea[' Year'] == year] dataList = [] dataList2 = [] 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]) 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] ownerToGraph = 'All' dataList.append(ownerArea[varStruct + ' (m3)'].iloc[0]) dataList2.append(ownerArea[varStruct + ' SYU (m3)'].iloc[0]) # convert to numpy array numpyList = np.array(dataList) numpyList2 = np.array(dataList2) # add year data to dictionary dataDict = { 'timeStep': year, 'mean': np.mean(numpyList, axis=0) } dataDict2 = { 'timeStep': year, 'mean': np.mean(numpyList2, axis=0) } # convert to list for DataFrame statsList.append(dataDict) statsList2.append(dataDict2) # convert to DataFrame dataTable = pd.DataFrame(statsList) dataTable2 = pd.DataFrame(statsList2) if (varList.index(varStruct)) < (len(varList) / 2): labelXtick = False else: labelXtick = True labelYtick = True yLabelText = '' labelYtick = True plotLegend = (0.99, 0.99) xLabelText = '' dataTable['mean'] = dataTable['mean'] / 1000000 dataTable2['mean'] = dataTable2['mean'] / 1000000 mnAxis, mxAxis = reporterFunc.plotReporter4( fig, ax, '', pdfFile, dataTable, ['mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, figTextList[varList.index(varStruct)]) mnAxis, mxAxis = reporterFunc.plotReporter4( fig, ax, '', pdfFile, dataTable2, ['mean'], xLabelText, yLabelText, scenario + '_SYU_', labelXtick, labelYtick, plotLegend, figTextList[varList.index(varStruct)]) reporterFunc.plotFigureText( fig, 'Simulation Year', 'Standing saw timber volume ( $\mathregular{1x10^6}$ $\mathregular{m^3}$)' ) # pl.savefig(outDir + 'report4_ForestStructure2_landscape.png', bbox_inches='tight', dpi=300) pdfFile.savefig() pl.close() pdfFile.close() print "Done with standing volume."
def main(subArea, runName, chartTitlePre, ownership): outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\" varList = [ ' High Suitability', ' American Marten Good (ha)', ' Black-backed Woodpecker Good (ha)', ' White-headed Woodpecker Good (ha)', ' Northern Goshawk Good (ha)', ' Western Bluebird Good (ha)', ' Pileated Woodpecker Good (ha)', 'MD High Suitability', ' DownyBrome0.66-1 (ha)' ] figTextList = [ 'Northern Spotted Owl\n(nest)', 'Pacific Marten', 'Black-backed WP', 'White-headed WP', 'Northern Goshawk\n(nest)', 'Western Bluebird', 'Pileated WP', 'Mule Deer', 'Cheatgrass' ] yLabelText = 'Area (%)' chartTitle = chartTitlePre forestedHa = reporterFunc.getOwnerForestedHa(subArea) ownerAllHa = reporterFunc.getOwnerHa(subArea) # list of ownerships to graphs if ownership == 'All': ownersToGraph = [ 'Federal', 'State', 'Private Non-Industrial', 'Private Industrial', 'Tribal', 'Homeowner' ] pdfFile = PdfPages(outDir + 'report4_Wildlife_landscape.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + 'report4_Wildlife_' + ownersToGraph[0] + '.pdf') fig = pl.figure(1, figsize=(6.5, 8)) for varStruct in varList: # setup plot for all scenarios ax = fig.add_subplot(3, 3, varList.index(varStruct) + 1) if varStruct == ' High Suitability': yLabelTextStruct = yLabelText + ' VFO Northern Spotted Owl High Suitability' modelGroup = 'vfoNSO' elif varStruct == 'MD High Suitability': yLabelTextStruct = yLabelText + ' Mule Deer High Suitability' varStruct = ' High Suitability' modelGroup = 'muleDeer' elif varStruct == ' DownyBrome0.66-1 (ha)': yLabelTextStruct = yLabelText + ' Downy Brome High Suitability' modelGroup = 'downyBrome' else: yLabelTextStruct = yLabelText + varStruct yLabelTextStruct = yLabelTextStruct.replace(" (ha)", "") modelGroup = 'iLAP' for scenario in [ 'CurrentPolicy', 'No_Treatment_Fed', 'Restoration', 'noFireNoTreatFed' ]: inDir = outDir + runName + "_" + scenario + "\\" if os.path.isdir(inDir): if modelGroup == 'vfoNSO': yearList = list( set( pd.io.parsers.read_csv( inDir + r'VFO_Spotted_Owl_by_OWNER_pivot.csv') [' Year'])) repList = list( set( pd.io.parsers.read_csv( inDir + r'VFO_Spotted_Owl_by_OWNER_pivot.csv') [' Run'])) totalArea = pd.io.parsers.read_csv( inDir + r'VFO_Spotted_Owl_by_OWNER_pivot.csv') elif modelGroup == 'muleDeer': yearList = list( set( pd.io.parsers.read_csv( inDir + r'Mule_Deer_by_OWNER_pivot.csv')[' Year'])) repList = list( set( pd.io.parsers.read_csv( inDir + r'Mule_Deer_by_OWNER_pivot.csv')[' Run'])) totalArea = pd.io.parsers.read_csv( inDir + r'Mule_Deer_by_OWNER_pivot.csv') elif modelGroup == 'downyBrome': yearList = list( set( pd.io.parsers.read_csv( inDir + r'Downy_Brome_by_OWNER_pivot.csv')[' Year'])) repList = list( set( pd.io.parsers.read_csv( inDir + r'Downy_Brome_by_OWNER_pivot.csv')[' Run'])) totalArea = pd.io.parsers.read_csv( inDir + r'Downy_Brome_by_OWNER_pivot.csv') else: yearList = list( set( pd.io.parsers.read_csv( inDir + r'ILAP_wildlife_models_by_OWNER_pivot.csv') [' Year'])) repList = list( set( pd.io.parsers.read_csv( inDir + r'ILAP_wildlife_models_by_OWNER_pivot.csv') [' Run'])) totalArea = pd.io.parsers.read_csv( inDir + r'ILAP_wildlife_models_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]) analysisTotalArea = ownerAllHa[ownerToGraph] analysisForestedArea = 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[varStruct].iloc[0] += tempArea[ varStruct].iloc[0] analysisTotalArea += ownerAllHa[ownerToGraph] analysisForestedArea += forestedHa[ ownerToGraph] ownerToGraph = 'All' if varStruct == ' DownyBrome0.66-1 (ha)' or varStruct == ' DownyBrome0.33-0.66 (ha)': if analysisTotalArea > 0: dataList.append(ownerArea[varStruct].iloc[0] / analysisTotalArea * 100) else: dataList.append(0.0) else: if analysisForestedArea > 0: dataList.append(ownerArea[varStruct].iloc[0] / analysisForestedArea * 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) figText = figTextList[varList.index(varStruct)] if modelGroup == 'muleDeer': figText = 'Mule Deer' if varList.index(varStruct) + 1 > 6 or modelGroup == 'muleDeer': labelXtick = True else: labelXtick = False if figText == 'Black-backed WP': plotLegend = (1.01, 0.87) else: plotLegend = (-99, -99) if figText == 'Northern Spotted Owl\n(nest)' or figText == 'White-headed WP' or figText == 'Pileated WP': labelYtick = True else: labelYtick = False labelYtick = True xLabelText = yLabelText = '' reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['mean', 'lower', 'upper'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, figText) reporterFunc.plotFigureText(fig, 'Simulation Year', 'Area (%)') pl.savefig(outDir + 'report4_Wildlife_landscape.png', bbox_inches='tight', dpi=300) pdfFile.savefig() pl.close() pdfFile.close() print "Done."
def main(outDir, subArea, runList, chartTitle, ownership): varList = [' High Suitability', ' American Marten Good (ha)', ' Black-backed Woodpecker Good (ha)', ' White-headed Woodpecker Good (ha)', ' Northern Goshawk Good (ha)', ' Western Bluebird Good (ha)', ' Pileated Woodpecker Good (ha)', 'MD High Suitability', ' DownyBrome0.66-1 (ha)'] figTextList = ['Northern Spotted Owl\n(nest)','Pacific Marten','Black-backed WP','White-headed WP','Northern Goshawk\n(nest)','Western Bluebird','Pileated WP','Mule Deer','Cheatgrass'] yLabelText = 'Area (%)' ownerLabelField = ' OWNER_label' # list of ownerships to graphs if ownership == 'All': ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Homeowner'] pdfFile = PdfPages(outDir + chartTitle + '_Wildlife_landscape_BBWO23.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + chartTitle + '_Wildlife_' + ownersToGraph[0] + '_BBWO23.pdf') # load area stats by owner areaStats = pd.io.parsers.read_csv(outDir + runList[0] + "\\AreaStats_by_OWNER_pivot.csv") areaStats = areaStats[areaStats[' Year'] == 1] # sum total areas over selected ownerships for ownerToGraph in ownersToGraph: ownerStats = areaStats[areaStats[ownerLabelField] == ownerToGraph] if ownerToGraph == ownersToGraph[0]: analysisModeledArea = ownerStats[' Forested (ha)'].iloc[0] + ownerStats[' Arid (ha)'].iloc[0] analysisForestedArea = ownerStats[' Forested (ha)'].iloc[0] else: analysisModeledArea += ownerStats[' Forested (ha)'].iloc[0] + ownerStats[' Arid (ha)'].iloc[0] analysisForestedArea += ownerStats[' Forested (ha)'].iloc[0] for varStruct in varList: # setup plot for all scenarios fig = pl.figure(1, figsize=(4,4)) ax = fig.add_subplot(1,1,1) if varStruct == ' High Suitability': yLabelTextStruct = yLabelText + ' VFO Northern Spotted Owl High Suitability' modelGroup = 'vfoNSO' elif varStruct == 'MD High Suitability': yLabelTextStruct = yLabelText + ' Mule Deer High Suitability' varStruct = ' High Suitability' modelGroup = 'muleDeer' elif varStruct == ' DownyBrome0.66-1 (ha)': yLabelTextStruct = yLabelText + ' Downy Brome High Suitability' modelGroup = 'downyBrome' else: yLabelTextStruct = yLabelText + varStruct yLabelTextStruct = yLabelTextStruct.replace(" (ha)", "") modelGroup = 'iLAP' for scenario in runList: print 'Wildlife Running scenario ' + scenario + ' and variable ' + varStruct inDir = outDir + scenario + "\\" if os.path.isdir(inDir): if modelGroup == 'vfoNSO': totalArea = pd.io.parsers.read_csv(inDir + r'VFO_Spotted_Owl_by_OWNER_pivot.csv') elif modelGroup == 'muleDeer': totalArea = pd.io.parsers.read_csv(inDir + r'Mule_Deer_by_OWNER_pivot.csv') elif modelGroup == 'downyBrome': totalArea = pd.io.parsers.read_csv(inDir + r'Downy_Brome_by_OWNER_pivot.csv') else: totalArea = pd.io.parsers.read_csv(inDir + r'ILAP_wildlife_models_by_OWNER_pivot.csv') # if species is Black-backed wookpecker do fair + good if varStruct == ' Black-backed Woodpecker Good (ha)': totalArea[' Black-backed Woodpecker Good (ha)'] = totalArea[' Black-backed Woodpecker Good (ha)'] + totalArea[' Black-backed Woodpecker Fair (ha)'] yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # 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]) else: tempArea = repArea[repArea[' OWNER_label'] == ownerToGraph] # for varName in varList: # totalArea.loc[list(ownerArea.index)[0],varName] += tempArea[varName].iloc[0] ownerArea[varStruct].iloc[0] += tempArea[varStruct].iloc[0] ownerToGraph = 'All' dataList.append(ownerArea[varStruct].iloc[0]) ## if varStruct == ' DownyBrome0.66-1 (ha)' or varStruct == ' DownyBrome0.33-0.66 (ha)': ## if analysisTotalArea > 0: ## dataList.append(ownerArea[varStruct].iloc[0] / analysisTotalArea * 100) ## else: ## dataList.append(0.0) ## else: ## if analysisForestedArea > 0: ## dataList.append(ownerArea[varStruct].iloc[0] / analysisForestedArea * 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) dataTable['mean'] = dataTable['mean'] / 1000 * 2.471 dataTable['lower'] = dataTable['lower'] / 1000 * 2.471 dataTable['upper'] = dataTable['upper'] / 1000 * 2.471 figText = figTextList[varList.index(varStruct)] if modelGroup == 'muleDeer': figText = 'Mule Deer' labelXtick = True labelYtick = True yLabelText = 'Area (1000 ac)' xLabelText = 'Simulation Year' if figText == 'Western Bluebird': plotLegend = (0.99,0.5) elif figText == 'Northern Goshawk\n(nest)': plotLegend = (0.99,0.6) elif figText == 'Pacific Marten' or figText == 'Black-backed WP' or figText == 'White-headed WP' or figText == 'Mule Deer' or figText == 'Pileated WP': plotLegend = (0.35,0.3) elif figText == 'Northern Spotted Owl\n(nest)': plotLegend = (0.35,0.99) else: plotLegend = (0.99,0.99) mnAxis, mxAxis = reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['mean'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, figText) # repeat y axis on right with percent ax.set_ylim(mnAxis,mxAxis) print "Max y axis value found: " + str(mxAxis) + " and min y axis value: " + str(mnAxis) yLabelText = 'Area (%)' if varStruct == ' DownyBrome0.66-1 (ha)' or varStruct == ' DownyBrome0.33-0.66 (ha)': mnAxis = mnAxis / analysisModeledArea * 100000 / 2.471 mxAxis = mxAxis / analysisModeledArea * 100000 / 2.471 else: mnAxis = mnAxis / analysisForestedArea * 100000 / 2.471 mxAxis = mxAxis / analysisForestedArea * 100000 / 2.471 reporterFunc.plotSecondYAxis(ax.twinx(), yLabelText, mnAxis, mxAxis) if mxAxis - mnAxis <= 4.5: pl.subplots_adjust(right=0.87) elif (mxAxis * analysisForestedArea / 100000 * 2.471) > 1000: pl.subplots_adjust(left=0.14) pdfFile.savefig() pl.close() pdfFile.close() print "Done with wildlife BBWO23."
def main(subArea, runName, chartTitlePre, ownership): outDir = "C:\\Users\\olsenk\\Dropbox\\FPF\\Envision Runs\\keith_production\\" varList = [' NumberDwellingsFirewise', ' NumberDwellings'] yLabelText = 'Firewised dwellings (%)' chartTitle = chartTitlePre # list of ownerships to graphs reporterName = r'FireWiseWUI_pivot.csv' pdfFile = PdfPages(outDir + 'report4_Firewise_landscape.pdf') fig = pl.figure(1, figsize=(8.5, 11)) # setup plot for all scenarios ax = fig.add_subplot(2, 1, 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] if repArea[' NumberDwellings'].iloc[0] > 0: dataList.append( repArea[' NumberDwellingsFirewise'].iloc[0] / repArea[' NumberDwellings'].iloc[0] * 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.3, 0.99) labelXtick = labelYtick = True reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['mean', 'lower', 'upper'], 'Simulation Year', yLabelText, scenario, labelXtick, labelYtick, plotLegend, '') pdfFile.savefig() pl.close() pdfFile.close() print "Done."
def main(outDir, subArea, runName, chartTitlePre, ownership): varList = [' Total Merch Harvest (m3)', ' Total Carbon (live+dead) (Mg)'] # yLabelText = 'Percent of Landscape in' chartTitle = chartTitlePre forestedHa = reporterFunc.getOwnerForestedHa(subArea) ownerAllHa = reporterFunc.getOwnerHa(subArea) # list of ownerships to graphs ownersToGraph = ['Federal','State','Private Non-Industrial','Private Industrial','Tribal','Homeowner'] reporterNameWood = r'WoodProducts_by_OWNER_pivot.csv' reporterNameVol = r'Carbon_by_OWNER_pivot.csv' ownerLabelField = ' OWNER_label' if ownership == 'All': pdfFile = PdfPages(outDir + 'report4_Vol_Carbon_landscape.pdf') elif ownership in ownersToGraph: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + 'report4_Vol_Carbon_' + ownersToGraph[0] + '.pdf') else: ownersToGraph = [ownership] pdfFile = PdfPages(outDir + 'report4_Vol_Carbon_' + ownersToGraph[0] + '.pdf') ownerLabelField = ' OWNER_DETL_label' reporterNameWood = r'WoodProducts_by_OWNER_DETL_pivot.csv' reporterNameVol = r'Carbon_by_OWNER_DETL_pivot.csv' fig = pl.figure(1, figsize=(4,6.5)) for varStruct in varList: # setup plot for all scenarios ax = fig.add_subplot(2,1,varList.index(varStruct) + 1) # for scenario in ['CurrentPolicy','No_Treatment_Fed','Restoration','noFireNoTreatFed','noFireCurrentPolicy']: for scenario in ['CurrentPolicy','No_Treatment_Fed','Restoration','noFireNoTreatFed']: inDir = outDir + runName + "_" + scenario + "\\" if os.path.isdir(inDir): if varStruct == ' Total Merch Harvest (m3)': yearList = list(set(pd.io.parsers.read_csv(inDir + reporterNameWood)[' Year'])) repList = list(set(pd.io.parsers.read_csv(inDir + reporterNameWood)[' Run'])) totalArea = pd.io.parsers.read_csv(inDir + reporterNameWood) figText = 'A' elif varStruct == ' Total Carbon (live+dead) (Mg)': yearList = list(set(pd.io.parsers.read_csv(inDir + reporterNameVol)[' Year'])) repList = list(set(pd.io.parsers.read_csv(inDir + reporterNameVol)[' Run'])) totalArea = pd.io.parsers.read_csv(inDir + reporterNameVol) figText = 'B' # 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]) analysisTotalArea = ownerAllHa[ownerToGraph] analysisForestedArea = forestedHa[ownerToGraph] else: tempArea = repArea[repArea[ownerLabelField] == ownerToGraph] # for varName in varList: # totalArea.loc[list(ownerArea.index)[0],varName] += tempArea[varName].iloc[0] ownerArea[varStruct].iloc[0] += tempArea[varStruct].iloc[0] analysisTotalArea += ownerAllHa[ownerToGraph] analysisForestedArea += forestedHa[ownerToGraph] ownerToGraph = 'All' dataList.append(ownerArea[varStruct].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) labelYtick = True if varStruct == ' Total Merch Harvest (m3)': yLabelText = 'Merchantable volume ( $\mathregular{1x10^3}$ $\mathregular{m^3}$)' dataTable['mean'] = dataTable['mean'] / 1000 dataTable['lower'] = dataTable['lower'] / 1000 dataTable['upper'] = dataTable['upper'] / 1000 labelXtick = False xLabelText = '' plotLegend = (0.99,0.99) elif varStruct == ' Total Carbon (live+dead) (Mg)': yLabelText = 'Aboveground carbon ( $\mathregular{1x10^6}$ Mg )' dataTable['mean'] = dataTable['mean'] / 1000000 dataTable['lower'] = dataTable['lower'] / 1000000 dataTable['upper'] = dataTable['upper'] / 1000000 labelXtick = True xLabelText = 'Simulation Year' plotLegend = (-99,-99) reporterFunc.plotReporter4(fig, ax, '', pdfFile, dataTable, ['mean','lower','upper'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, figText) pl.savefig(outDir + 'report4_Vol_Carbon_landscape.png', bbox_inches='tight', dpi=300) pdfFile.savefig() pl.close() pdfFile.close() print "Done."
def main(outDir, subArea, runList, chartTitle, ownership): varList = [ ' Harvest (ha)', ' Prescribed Fire (ha)', ' Mowing and Grinding (ha)', ' Salvage Logging (ha)', ' Thinning (ha)', ' Partial Harvest (ha)', ' Partial Harvest - Light (ha)', ' Partial Harvest - Heavy (ha)', ' Clear-cut (ha)' ] ## forestedHa = reporterFunc.getOwnerForestedHa(subArea) ## ownerAllHa = reporterFunc.getOwnerHa(subArea) figTextList = ['Federal', 'Tribal', 'Corporate Forest', 'Family Forest'] # list of ownerships to graphs # ownersToGraph = ['Federal','Tribal','Private Industrial','Private Non-Industrial'] ownersToGraph = ['Federal'] if ownership == 'SYU': pdfFile = PdfPages(outDir + chartTitle + '_syu_Management_area.pdf') varList = [ ' Harvest (ha) SYU', ' Prescribed Fire (ha) SYU', ' Mowing and Grinding (ha) SYU', ' Salvage Logging (ha) SYU', ' Thinning (ha) SYU', ' Partial Harvest (ha) SYU', ' Partial Harvest - Light (ha) SYU', ' Partial Harvest - Heavy (ha) SYU', ' Clear-cut (ha) SYU' ] else: pdfFile = PdfPages(outDir + chartTitle + '_Management_area.pdf') for varStruct in varList: for owner in ownersToGraph: fig = pl.figure(1, figsize=(4, 4)) # setup plot for all scenarios ax = fig.add_subplot(1, 1, 1) yLabelText = 'Area of' + varStruct[:-3] + "1000 ha)" for scenario in runList: inDir = outDir + scenario + "\\" if os.path.isdir(inDir): # load area stats by owner areaStats = pd.io.parsers.read_csv( inDir + "AreaStats_by_OWNER_pivot.csv") areaStats = areaStats[areaStats[' Year'] == 1] totalArea = pd.io.parsers.read_csv( inDir + r'ManagementDisturb_by_OWNER_pivot.csv') if ownership == 'SYU': totalArea[' Harvest (ha) SYU'] = totalArea[ ' Thinning (ha) SYU'] + totalArea[ ' Partial Harvest (ha) SYU'] + totalArea[ ' Partial Harvest - Light (ha) SYU'] + totalArea[ ' Partial Harvest - Heavy (ha) SYU'] + totalArea[ ' Clear-cut (ha) SYU'] else: totalArea[' Harvest (ha)'] = totalArea[ ' Thinning (ha)'] + totalArea[ ' Partial Harvest (ha)'] + totalArea[ ' Partial Harvest - Light (ha)'] + totalArea[ ' Partial Harvest - Heavy (ha)'] + totalArea[ ' Clear-cut (ha)'] yearList = list(set(totalArea[' Year'])) repList = list(set(totalArea[' Run'])) # 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] ownerArea = pd.DataFrame( repArea[repArea[' OWNER_label'] == owner]) dataList.append(ownerArea[varStruct].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) labelXtick = True labelYtick = True plotLegend = (0.99, 0.99) xLabelText = 'Simulation Year' dataTable['mean'] = dataTable['mean'] / 1000 dataTable['lower'] = dataTable['lower'] / 1000 dataTable['upper'] = dataTable['upper'] / 1000 if owner == 'Tribal': plotLegend = (0.84, 0.33) mnAxis, mxAxis = reporterFunc.plotReporter4( fig, ax, '', pdfFile, dataTable, ['mean', 'lower', 'upper'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, figTextList[ownersToGraph.index(owner)]) if mxAxis > 7: mxAxis += 1 ax.set_ylim(mnAxis, mxAxis) pdfFile.savefig() pl.close() ##reporterFunc.plotFigureText(fig, 'Simulation Year', 'Merchantable volume ( $\mathregular{1x10^3}$ $\mathregular{m^3}$)') ## pl.savefig(outDir + 'report4_Vol_Owners.png', bbox_inches='tight', dpi=300) pdfFile.close() print "Done with Management area."
def main(outDir, subArea, runName, chartTitlePre, ownership): varStruct = ' Total Merch Harvest (m3)' # yLabelText = 'Percent of Landscape in' chartTitle = chartTitlePre forestedHa = reporterFunc.getOwnerForestedHa(subArea) ownerAllHa = reporterFunc.getOwnerHa(subArea) figTextList = ['A', 'B', 'C', 'D'] # list of ownerships to graphs ownersToGraph = [ 'Federal', 'Tribal', 'Private Industrial', 'Private Non-Industrial' ] pdfFile = PdfPages(outDir + 'report4_Vol_Owners.pdf') fig = pl.figure(1, figsize=(6.5, 6.5)) for owner in ownersToGraph: # setup plot for all scenarios ax = fig.add_subplot(2, 2, ownersToGraph.index(owner) + 1) # for scenario in ['CurrentPolicy','No_Treatment_Fed','Restoration','noFireNoTreatFed','noFireCurrentPolicy']: 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 + r'WoodProducts_by_OWNER_pivot.csv')[' Year'])) repList = list( set( pd.io.parsers.read_csv( inDir + r'WoodProducts_by_OWNER_pivot.csv')[' Run'])) totalArea = pd.io.parsers.read_csv( inDir + r'WoodProducts_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] ownerArea = pd.DataFrame( repArea[repArea[' OWNER_label'] == owner]) dataList.append(ownerArea[varStruct].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) labelXtick = True labelYtick = True plotLegend = (-99, -99) xLabelText = 'Simulation Year' dataTable['mean'] = dataTable['mean'] / 1000 dataTable['lower'] = dataTable['lower'] / 1000 dataTable['upper'] = dataTable['upper'] / 1000 if ownersToGraph.index(owner) < 2: labelXtick = False xLabelText = '' if ownersToGraph.index(owner) % 2 == 1: yLabelText = '' if owner == 'Tribal': plotLegend = (0.84, 0.33) xLabelText = yLabelText = '' reporterFunc.plotReporter4( fig, ax, '', pdfFile, dataTable, ['mean', 'lower', 'upper'], xLabelText, yLabelText, scenario, labelXtick, labelYtick, plotLegend, figTextList[ownersToGraph.index(owner)]) reporterFunc.plotFigureText( fig, 'Simulation Year', 'Merchantable volume ( $\mathregular{1x10^3}$ $\mathregular{m^3}$)') pl.savefig(outDir + 'report4_Vol_Owners.png', bbox_inches='tight', dpi=300) pdfFile.savefig() pl.close() pdfFile.close() print "Done."