Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting more than 1 column of PTDF matrix #1

Open
AbrahamAlvarezB opened this issue Mar 16, 2021 · 3 comments
Open

Selecting more than 1 column of PTDF matrix #1

AbrahamAlvarezB opened this issue Mar 16, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@AbrahamAlvarezB
Copy link

AbrahamAlvarezB commented Mar 16, 2021

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?

@raphaelsaavedra
Copy link

raphaelsaavedra commented Mar 16, 2021

@AbrahamAlvarezB
Copy link
Author

AbrahamAlvarezB commented Mar 16, 2021

I agree that if we use the struct call as below we get the data,

julia> b = PTDF_matrix.data[:,[2,4]]
5×2 Array{Float64,2}:
 -0.625  -0.5
 -0.375  -0.5
  0.25    1.38778e-17
  0.125  -0.5
 -0.125  -0.5

but we loose the parent format. I would expect something like this, which may be useful:

b = PTDF_matrix[:,[2,4]]
PowerNetworkMatrix
   Dimension 1, ["Line1", "Line2", "Line3", "Line4", "Line5"]
   Dimension 2, [2, 4]
And data, a (5, 2):
-0.625    -0.5
-0.375    -0.5
 0.25      1.38778e-17
 0.125    -0.5
-0.125    -0.5

@jd-lara jd-lara added the enhancement New feature or request label Mar 18, 2021
@jd-lara
Copy link
Member

jd-lara commented Mar 18, 2021

@AbrahamAlvarezB we don't have a great way to do slicing at the moment. Since we implemented the code to optimize a single value or single column fetching we never implemented additional methods to do the slicing.

@jd-lara jd-lara changed the title Selecting specific columns of PTDF matrix Selecting more than 1 column of PTDF matrix Mar 18, 2021
@jd-lara jd-lara transferred this issue from NREL-Sienna/PowerSystems.jl Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants