power-grid-model icon indicating copy to clipboard operation
power-grid-model copied to clipboard

[FEATURE] Expose numpy dtypes of PGM arrays

Open Thijss opened this issue 2 years ago • 2 comments

It would be nice if the numpy dtypes of the of the PGM input and output arrays are directly accessible.

This would make it easier to extend PGM arrays (e.g. as done in APG project)

example of exposed dtypes:


class Base:
    """Base dtype"""

    id: np.int8 = np.iinfo(np.int8).min

class Node(Base):
    """Node data type"""

    u_rated: np.float64 = np.nan
    node_type: np.int8 = np.iinfo(np.int8).min

Thijss avatar Jun 01 '22 10:06 Thijss

I've discussed this before with @bramstoeller

Thijss avatar Jun 01 '22 10:06 Thijss

Is it still desirable to only expose the numpy dtypes? or do we want to make this actual wrappers using overloaded __setattr__ and __getattr__ methods?

e.g.

nodes = NodeInput(3)   # creates new object with nodes.data = initialize_array("input", "node", 3)
nodes.data             # raw data

# attribute wrappers
nodes.id = [1, 2, 3]  # exposes nodes.data["id"]

# element access
node_0 = nodes[0]     # exposes an InputNode wrapper around nodes.data[0]
node_0.data           # exposes nodes.data[0]
node_0.id = 1         # exposes nodes.data[0]["id"]

mgovers avatar Mar 11 '24 12:03 mgovers