# fig-EETscaleup-A.py
# Calculates efficiency of EET based rewired carbon fixation
#
# Farshid Salimijazi and Buz Barstow
# Last updated by Buz Barstow on 2019-10-28
# ------------------------------------------------------------------------------------------------ #


from rewiredcarbon.scenario import ImportScenarioTable, CalculateScenarioEfficiencies, \
Plot_Efficiency_Scattergraphs, Export_Efficiency_Scattergraphs

from rewiredcarbon.utils import ensure_dir

scenarioTableFileName = 'input/fig-EETscaleup-A.csv'

outputFileDirname = 'output/fig-EETscaleup/fig-EETscaleup-A/'
ensure_dir(outputFileDirname)

outputFilePrefix = 'VariableResistivity'

scenarioDict = ImportScenarioTable(scenarioTableFileName)

efficienciesDict = CalculateScenarioEfficiencies(scenarioDict,
                                                 mode='scattergraph')

Plot_Efficiency_Scattergraphs(efficienciesDict, 'effTotalElectricalToFuel')



Export_Efficiency_Scattergraphs(outputFileDirname, outputFilePrefix, efficienciesDict, \
'effTotalElectricalToFuel', keysToPlot=None)
# Farshid Salimijazi and Buz Barstow
# Last updated by Buz Barstow on 2019-10-25
# ------------------------------------------------------------------------------------------------ #


from rewiredcarbon.scenario import ImportScenarioTable, CalculateScenarioEfficiencies, \
Plot_Efficiency_Bargraph, Generate_EfficienciesDict_Keys_Sorted_by_Efficiency, \
Export_Efficiency_Bargraph

from rewiredcarbon.utils import ensure_dir

scenarioTableFileName = 'input/fig-cbb_n2_to_amino_acids.csv'
outputFilenameEff = 'output/fig-cbb-n2_to_amino_acids/fig-cbb_n2_to_amino_acids_eff.csv'
outputFilenameFuelMassEff = 'output/fig-cbb-n2_to_amino_acids/fig-cbb_n2_to_amino_acids_fuel_mass.csv'

ensure_dir(outputFilenameEff)
ensure_dir(outputFilenameFuelMassEff)

scenarioDict = ImportScenarioTable(scenarioTableFileName)

efficienciesDict = CalculateScenarioEfficiencies(scenarioDict)

# keysArray = \
# Generate_EfficienciesDict_Keys_Sorted_by_Efficiency(efficienciesDict, 'effTotalElectricalToFuel')

keysArray = list(efficienciesDict.keys())

Plot_Efficiency_Bargraph(efficienciesDict, 'effTotalElectricalToFuel', \
'effTotalElectricalToFuel_lowerError', 'effTotalElectricalToFuel_upperError', keysToPlot=keysArray)

# Last updated by Buz Barstow on 2019-10-25
# ------------------------------------------------------------------------------------------------ #


from rewiredcarbon.scenario import ImportScenarioTable, CalculateScenarioEfficiencies, \
Plot_Efficiency_Bargraph, Generate_EfficienciesDict_Keys_Sorted_by_Efficiency, \
Export_Efficiency_Bargraph

from rewiredcarbon.utils import ensure_dir




scenarioTableFileName = 'input/fig-co2fixation.csv'
outputFilename = 'output/fig-co2fixation/fig-co2fixation.csv'
ensure_dir(outputFilename)


scenarioDict = ImportScenarioTable(scenarioTableFileName)

efficienciesDict = CalculateScenarioEfficiencies(scenarioDict)


# keysArray = \
# Generate_EfficienciesDict_Keys_Sorted_by_Efficiency(efficienciesDict, 'effTotalElectricalToFuel')


keysArray = list(efficienciesDict.keys())

Plot_Efficiency_Bargraph(efficienciesDict, 'effTotalElectricalToFuel', \
'effTotalElectricalToFuel_lowerError', 'effTotalElectricalToFuel_upperError', keysToPlot=keysArray)
for targetEfficiencyRatio in targetEfficiencyRatios:

    outputDict = \
    Calculate_Density_and_Area_for_Target_to_Peak_Efficiency_Ratio_for_Array_of_Input_Powers(\
    scenarioDict, efficienciesDict, efficienciesDictKeysForCalc, targetEfficiencyRatio, \
    peakElectricalToFuelEfficiency, solarConstant=solarConstant)

    collectedOutputDict[str(targetEfficiencyRatio)] = deepcopy(outputDict)

# Plot out the system footprint calculations and export them to a CSV file
keys = collectedOutputDict.keys()
vectorList_tankAreaRelativeToSolarPVArea = []
headerList_tankAreaRelativeToSolarPVArea = []
outputFilename_tankAreaRelativeToSolarPVArea \
= outputFileDirname + '/' + 'fig-h2scaleup-E-area_relative_to_PV_area.csv'
ensure_dir(outputFilename_tankAreaRelativeToSolarPVArea)

figure()
for key in keys:
    outputDict = collectedOutputDict[key]

    totalElectricalPowerArray = outputDict['totalElectricalPowerArray']
    tankAreaRelativeToSolarPVAreaArray = outputDict[
        'tankAreaRelativeToSolarPVAreaArray']

    loglog(totalElectricalPowerArray,
           tankAreaRelativeToSolarPVAreaArray,
           label=key)

    headerList_tankAreaRelativeToSolarPVArea.append('totalElectricalPower_' +
                                                    key)