• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GenXProject / GenX / #371

14 Sep 2023 02:22AM UTC coverage: 0.271%. First build
#371

Pull #546

travis-ci

Pull Request #546: Thermal+storage (fusion, maintenance)

630 of 630 new or added lines in 9 files covered. (100.0%)

12 of 4424 relevant lines covered (0.27%)

0.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/write_outputs/write_emissions.jl
1
@doc raw"""
2
        write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
3

4
Function for reporting time-dependent CO$_2$ emissions by zone.
5

6
"""
7
function write_emissions(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
×
8
    T = inputs["T"]     # Number of time steps (hours)
×
9
    Z = inputs["Z"]     # Number of zones
×
10

×
11
    scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1
×
12

13
    if (setup["WriteShadowPrices"] == 1 || setup["UCommit"] == 0 ||
×
14
        (setup["UCommit"] == 2 && (setup["OperationalReserves"] == 0 ||
15
          (setup["OperationalReserves"] > 0 && inputs["pDynamic_Contingency"] == 0)))) # fully linear model
16
        # CO2 emissions by zone
×
17

18
        if setup["CO2Cap"] >= 1
19
            # Dual variable of CO2 constraint = shadow price of CO2
×
20
            tempCO2Price = zeros(Z, inputs["NCO2Cap"])
21
            if has_duals(EP) == 1
×
22
                for cap in 1:inputs["NCO2Cap"]
×
23
                    for z in findall(x -> x == 1, inputs["dfCO2CapZones"][:, cap])
×
24
                        tempCO2Price[z, cap] = (-1) *
×
25
                                               dual.(EP[:cCO2Emissions_systemwide])[cap]
×
26
                        # when scaled, The objective function is in unit of Million US$/kton, thus k$/ton, to get $/ton, multiply 1000
27
                        tempCO2Price[z, cap] *= scale_factor
×
28
                    end
29
                end
30
            end
31
            dfEmissions = hcat(DataFrame(Zone = 1:Z),
×
32
                DataFrame(tempCO2Price, :auto),
×
33
                DataFrame(AnnualSum = Array{Float64}(undef, Z)))
×
34
            auxNew_Names = [Symbol("Zone");
35
                            [Symbol("CO2_Price_$cap") for cap in 1:inputs["NCO2Cap"]];
×
36
                            Symbol("AnnualSum")]
37
            rename!(dfEmissions, auxNew_Names)
38
        else
×
39
            dfEmissions = DataFrame(Zone = 1:Z, AnnualSum = Array{Float64}(undef, Z))
×
40
        end
41

42
        emissions_by_zone = value.(EP[:eEmissionsByZone])
×
43
        for i in 1:Z
44
            dfEmissions[i, :AnnualSum] = sum(inputs["omega"] .* emissions_by_zone[i, :]) *
45
                                         scale_factor
×
46
        end
×
47

×
48
        if setup["WriteOutputs"] == "annual"
×
49
            total = DataFrame(["Total" sum(dfEmissions.AnnualSum)], [:Zone; :AnnualSum])
×
50
            if setup["CO2Cap"] >= 1
×
51
                total = DataFrame(
52
                    ["Total" zeros(1, inputs["NCO2Cap"]) sum(dfEmissions.AnnualSum)],
53
                    [:Zone;
×
54
                     [Symbol("CO2_Price_$cap") for cap in 1:inputs["NCO2Cap"]];
×
55
                     :AnnualSum])
×
56
            end
×
57
            dfEmissions = vcat(dfEmissions, total)
×
58
            CSV.write(joinpath(path, "emissions.csv"), dfEmissions)
59
        else# setup["WriteOutputs"] == "full"
60
            dfEmissions = hcat(dfEmissions,
×
61
                DataFrame(emissions_by_zone * scale_factor, :auto))
×
62
            if setup["CO2Cap"] >= 1
63
                auxNew_Names = [Symbol("Zone");
64
                                [Symbol("CO2_Price_$cap") for cap in 1:inputs["NCO2Cap"]];
65
                                Symbol("AnnualSum");
66
                                [Symbol("t$t") for t in 1:T]]
67
                rename!(dfEmissions, auxNew_Names)
×
68
                total = DataFrame(
×
69
                    ["Total" zeros(1, inputs["NCO2Cap"]) sum(dfEmissions[!,
×
70
                        :AnnualSum]) fill(0.0, (1, T))],
71
                    :auto)
×
72
                for t in 1:T
×
73
                    total[:, t + inputs["NCO2Cap"] + 2] .= sum(dfEmissions[:,
×
74
                        Symbol("t$t")][1:Z])
×
75
                end
×
76
            else
×
77
                auxNew_Names = [Symbol("Zone");
78
                                Symbol("AnnualSum");
×
79
                                [Symbol("t$t") for t in 1:T]]
×
80
                rename!(dfEmissions, auxNew_Names)
81
                total = DataFrame(
×
82
                    ["Total" sum(dfEmissions[!, :AnnualSum]) fill(0.0,
83
                        (1, T))],
84
                    :auto)
85
                for t in 1:T
86
                    total[:, t + 2] .= sum(dfEmissions[:, Symbol("t$t")][1:Z])
87
                end
88
            end
89
            rename!(total, auxNew_Names)
90
            dfEmissions = vcat(dfEmissions, total)
91
            CSV.write(joinpath(path, "emissions.csv"),
92
                dftranspose(dfEmissions, false),
93
                writeheader = false)
94
        end
95
        ## Aaron - Combined elseif setup["Dual_MIP"]==1 block with the first block since they were identical. Why do we have this third case? What is different about it?
96
    else
97
        # CO2 emissions by zone
98
        emissions_by_zone = value.(EP[:eEmissionsByZone])
99
        dfEmissions = hcat(DataFrame(Zone = 1:Z),
100
            DataFrame(AnnualSum = Array{Float64}(undef, Z)))
101
        for i in 1:Z
102
            dfEmissions[i, :AnnualSum] = sum(inputs["omega"] .* emissions_by_zone[i, :]) *
103
                                         scale_factor
104
        end
105

106
        if setup["WriteOutputs"] == "annual"
107
            total = DataFrame(["Total" sum(dfEmissions.AnnualSum)], [:Zone; :AnnualSum])
108
            dfEmissions = vcat(dfEmissions, total)
109
            CSV.write(joinpath(path, "emissions.csv"), dfEmissions)
110
        else# setup["WriteOutputs"] == "full"
111
            dfEmissions = hcat(dfEmissions,
112
                DataFrame(emissions_by_zone * scale_factor, :auto))
113
            auxNew_Names = [Symbol("Zone");
114
                            Symbol("AnnualSum");
115
                            [Symbol("t$t") for t in 1:T]]
116
            rename!(dfEmissions, auxNew_Names)
117
            total = DataFrame(["Total" sum(dfEmissions[!, :AnnualSum]) fill(0.0, (1, T))],
118
                :auto)
119
            for t in 1:T
120
                total[:, t + 2] .= sum(dfEmissions[:, Symbol("t$t")][1:Z])
121
            end
122
            rename!(total, auxNew_Names)
123
            dfEmissions = vcat(dfEmissions, total)
124
            CSV.write(joinpath(path, "emissions.csv"),
125
                dftranspose(dfEmissions, false),
126
                writeheader = false)
127

128
            if setup["OutputFullTimeSeries"] == 1 && setup["TimeDomainReduction"] == 1
129
                write_full_time_series_reconstruction(path, setup, dfEmissions, "emissions")
130
                @info("Writing Full Time Series for Emissions")
131
            end
132
        end
133
    end
134
    return nothing
135
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc