Sienna-Platform / Sienna-Platform/PowerNetworkMatrices.jl
Selecting more than 1 column of PTDF matrix
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Julia
- Stars
- 31
- Forks
- 22
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 18
Description
Error when selecting specific columns of the PTDF matrix I would expect that the following commands work:
julia> a = rand(4,5)
4×5 Array{Float64,2}:
0.0246739 0.483415 0.0234004 0.378329 0.965849
0.665427 0.575655 0.843898 0.457372 0.492012
0.441002 0.719667 0.619103 0.252873 0.80892
0.647832 0.472036 0.784917 0.577866 0.25087
julia> b = a[:,[2,4]]
4×2 Array{Float64,2}:
0.483415 0.378329
0.575655 0.457372
0.719667 0.252873
0.472036 0.577866
However for a system sys the PTDF matrix
julia> PTDF_matrix = PTDF(sys)
PowerNetworkMatrix
Dimension 1, ["Line1", "Line2", "Line3", "Line4", "Line5"]
Dimension 2, [1, 2, 3, 4]
And data, a (5, 4):
0.0 -0.625 -0.375 -0.5
0.0 -0.375 -0.625 -0.5
0.0 0.25 -0.25 1.38778e-17
0.0 0.125 -0.125 -0.5
0.0 -0.125 0.125 -0.5
julia> b = PTDF_matrix[:,[2,4]]
ERROR: KeyError: key [2, 4] not found
Stacktrace:
[1] getindex at ./dict.jl:467 [inlined]
[2] lookup_index at /Users/abrahamalvarezb/.julia/packages/PowerSystems/r86iN/src/utils/network_calculations/common.jl:38 [inlined]
[3] _to_index_tuple at /Users/abrahamalvarezb/.julia/packages/PowerSystems/r86iN/src/utils/network_calculations/common.jl:52 [inlined] (repeats 2 times)
[4] to_index at /Users/abrahamalvarezb/.julia/packages/PowerSystems/r86iN/src/utils/network_calculations/common.jl:71 [inlined]
[5] getindex(::PTDF{Tuple{Array{String,1},Array{Int64,1}},Tuple{Dict{String,Int64},Dict{Int64,Int64}}}, ::Function, ::Array{Int64,1}) at /Users/abrahamalvarezb/.julia/packages/PowerSystems/r86iN/src/utils/network_calculations/common.jl:89
[6] top-level scope at REPL[107]:1
Is this an issue or can it be improved?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the PTDF(sys) example and the failing PTDF_matrix[:, [2,4]] selection. Start with utils/network_calculations/common.jl, focusing on lookup_index, _to_index_tuple, to_index, and getindex from the stack trace. Done means selecting multiple column indices returns the corresponding 5×2 matrix without a KeyError, with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100