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, 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, 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(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."
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(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 + 'report5_ForestStructre2_byOwner.pdf') for varStruct in varList: 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 + "_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: 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)'] ) 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']: 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]) / 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) if splot == 1: labelXaxis = False plotLegend = True yLabelText = 'Area (%) in' + varStruct elif splot == 2: labelXaxis = True plotLegend = True yLabelText = 'Area (%) in' + varStruct reporterFunc.plotReporter5(fig, ax, '', pdfFile, dataTable, ['mean', 'lower', 'upper'], yLabelText, ownership, labelXaxis, plotLegend) 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(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."
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."