From 460b81a235240f8a104baa59479e286460752ffe Mon Sep 17 00:00:00 2001 From: Joseph McKinsey Date: Thu, 23 Mar 2023 15:56:03 -0600 Subject: [PATCH 1/5] Fix some leftover filter function rearrangements --- src/get_data.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/get_data.jl b/src/get_data.jl index 31bf10d..2de0acb 100644 --- a/src/get_data.jl +++ b/src/get_data.jl @@ -273,7 +273,7 @@ function filter_results!( component_type = PSI.get_component_type(k)#getfield(PSY, Symbol(last(split(String(k), "__")))) component_names = PSY.get_name.( - PSY.get_components(filter_func, component_type, PSI.get_system(results)), + PSY.get_components(filter_funct, component_type, PSI.get_system(results)) ) DataFrames.select!(v, vcat(["DateTime"], component_names)) end @@ -415,7 +415,7 @@ function _get_loads(system::PSY.System, load::PSY.StaticLoad) return [load] end function _get_loads(system::PSY.System, sys::PSY.System) - return PSY.get_components(PSY.StaticLoad, system, PSY.get_available) + return PSY.get_components(PSY.get_available, PSY.StaticLoad, system) end get_base_power(system::PSY.System) = PSY.get_base_power(system) From b32bd70a116d85c8a974824dc2994afad4407d05 Mon Sep 17 00:00:00 2001 From: Joseph McKinsey Date: Thu, 23 Mar 2023 16:42:08 -0600 Subject: [PATCH 2/5] Add some more tests, fix docs.yml (hopefully), and run formatter --- .github/workflows/docs.yml | 2 +- src/get_data.jl | 6 +++--- test/test_result_sorting.jl | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 7ea011e..e53ea5d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - uses: julia-actions/setup-julia@v1 with: - version: '1.6' + version: '1' - name: Install dependencies run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' - name: Build and deploy diff --git a/src/get_data.jl b/src/get_data.jl index 2de0acb..2f4cf51 100644 --- a/src/get_data.jl +++ b/src/get_data.jl @@ -273,7 +273,7 @@ function filter_results!( component_type = PSI.get_component_type(k)#getfield(PSY, Symbol(last(split(String(k), "__")))) component_names = PSY.get_name.( - PSY.get_components(filter_funct, component_type, PSI.get_system(results)) + PSY.get_components(filter_funct, component_type, PSI.get_system(results)), ) DataFrames.select!(v, vcat(["DateTime"], component_names)) end @@ -415,7 +415,7 @@ function _get_loads(system::PSY.System, load::PSY.StaticLoad) return [load] end function _get_loads(system::PSY.System, sys::PSY.System) - return PSY.get_components(PSY.get_available, PSY.StaticLoad, system) + return PSY.get_components(PSY.get_available, PSY.StaticLoad, system) end get_base_power(system::PSY.System) = PSY.get_base_power(system) @@ -425,7 +425,7 @@ get_base_power(results::PSI.ProblemResults) = results.base_power function get_load_data( system::PSY.System; aggregation::Union{ - Type{PSY.StandardLoad}, + Type{PSY.StaticLoad}, Type{PSY.Bus}, Type{PSY.System}, Type{<:PSY.AggregationTopology}, diff --git a/test/test_result_sorting.jl b/test/test_result_sorting.jl index fee07e1..ede3a0a 100644 --- a/test/test_result_sorting.jl +++ b/test/test_result_sorting.jl @@ -98,3 +98,18 @@ end fuel_agg = PA.combine_categories(fuel) @test size(fuel_agg) == (48, 8) end + +@testset "Test system data getters" begin + sys = PSI.get_system(results_uc) + load_data1 = PA.get_load_data(sys; aggregation = Bus) + @test length(load_data1.data) == 3 + @test length(load_data1.time) == 24 + + load_data2 = PA.get_load_data(sys, aggregation = StaticLoad) + @test length(load_data2.data) == 3 + @test length(load_data2.time) == 24 + + load_data3 = PA.get_load_data(sys, aggregation = System) + @test length(load_data2.data) == 3 + @test length(load_data2.time) == 24 +end From f433d99280914c296d539b84a5457ca7f17ee54b Mon Sep 17 00:00:00 2001 From: Joseph McKinsey Date: Thu, 23 Mar 2023 17:18:04 -0600 Subject: [PATCH 3/5] Fix filtering and add filter test --- src/get_data.jl | 2 +- test/test_result_sorting.jl | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/get_data.jl b/src/get_data.jl index 2f4cf51..db14f47 100644 --- a/src/get_data.jl +++ b/src/get_data.jl @@ -273,7 +273,7 @@ function filter_results!( component_type = PSI.get_component_type(k)#getfield(PSY, Symbol(last(split(String(k), "__")))) component_names = PSY.get_name.( - PSY.get_components(filter_funct, component_type, PSI.get_system(results)), + PSY.get_components(filter_func, component_type, PSI.get_system(results)), ) DataFrames.select!(v, vcat(["DateTime"], component_names)) end diff --git a/test/test_result_sorting.jl b/test/test_result_sorting.jl index ede3a0a..45f3eb1 100644 --- a/test/test_result_sorting.jl +++ b/test/test_result_sorting.jl @@ -63,8 +63,9 @@ problem_results = run_test_prob() @test length(srv.time) == 5 # TODO: make tests for subsetting data - #sub_gen = get_generation_data(results_uc, filter_func = x->get_name(get_bus(x)) == "bus2") - #@test length(sub_gen.data) == 1 + sub_gen = + get_generation_data(results_uc, filter_func = x -> get_name(get_bus(x)) == "bus1") + @test length(sub_gen.data) == 8 end @testset "test curtailment calculations" begin From 1650b1fd67bc8052c91ea0a667ecf6573c22239d Mon Sep 17 00:00:00 2001 From: Joseph McKinsey Date: Thu, 23 Mar 2023 21:32:26 -0600 Subject: [PATCH 4/5] Add filter func to match other filter func --- src/fuel_results.jl | 11 ++++++++--- src/get_data.jl | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/fuel_results.jl b/src/fuel_results.jl index 8732429..3fcf87b 100644 --- a/src/fuel_results.jl +++ b/src/fuel_results.jl @@ -80,8 +80,13 @@ results = solve_op_model!(OpModel) generators = make_fuel_dictionary(sys) """ -function make_fuel_dictionary(sys::PSY.System, mapping::Dict{NamedTuple, String}) - generators = PSY.get_components(PSY.get_available, PSY.StaticInjection, sys) +function make_fuel_dictionary( + sys::PSY.System, + mapping::Dict{NamedTuple, String}; + filter_func = x -> true, +) + filter_func2 = x -> PSY.get_available(x) && filter_func(x) + generators = PSY.get_components(filter_func2, PSY.StaticInjection, sys) gen_categories = Dict() for category in unique(values(mapping)) gen_categories["$category"] = [] @@ -107,5 +112,5 @@ end function make_fuel_dictionary(sys::PSY.System; kwargs...) mapping = get_generator_mapping(get(kwargs, :generator_mapping_file, nothing)) - return make_fuel_dictionary(sys, mapping) + return make_fuel_dictionary(sys, mapping; kwargs...) end diff --git a/src/get_data.jl b/src/get_data.jl index db14f47..2124d36 100644 --- a/src/get_data.jl +++ b/src/get_data.jl @@ -534,7 +534,7 @@ Re-categorizes data according to an aggregation dictionary # Example ```julia -aggregation = PG.make_fuel_dictionary(results_uc.system) +aggregation = PA.make_fuel_dictionary(results_uc.system) categorize_data(gen_uc.data, aggregation) ``` From 07f509a7c943807d1dfb2cde3516c3905d69f5dc Mon Sep 17 00:00:00 2001 From: Joseph McKinsey Date: Thu, 23 Mar 2023 22:10:10 -0600 Subject: [PATCH 5/5] Fix filter func kwarg parsing --- src/fuel_results.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fuel_results.jl b/src/fuel_results.jl index 3fcf87b..e6437e1 100644 --- a/src/fuel_results.jl +++ b/src/fuel_results.jl @@ -84,6 +84,7 @@ function make_fuel_dictionary( sys::PSY.System, mapping::Dict{NamedTuple, String}; filter_func = x -> true, + kwargs..., ) filter_func2 = x -> PSY.get_available(x) && filter_func(x) generators = PSY.get_components(filter_func2, PSY.StaticInjection, sys)