GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TimeResponseData.to_pandas() fails if there are no states in a NonlinearIOSystem · Issue #957 · python-control/python-control

TimeResponseData.to_pandas() fails if there are no states in a NonlinearIOSystem #957

New issue
Copy link
New issue
Copy link
Closed
#958
Closed
TimeResponseData.to_pandas() fails if there are no states in a NonlinearIOSystem#957
#958
Copy link
Assignees
murrayrm
Labels
bug

Description

@joaoantoniocardoso
joaoantoniocardoso
opened on Jan 3, 2024
Issue body actions

TimeResponseData.to_pandas() fails if there are no states in a NonlinearIOSystem:

import control as ct

class System:
    @classmethod
    def _outputs(cls, t, x, u, params: dict):
        v = u[0]
        i = u[1]
        k = u[2]

        return k*v**2 + i

    @classmethod
    def build(cls):
        return ct.NonlinearIOSystem(
            None,
            cls._outputs,
            name="system",
            states=None,
            inputs=('v', 'i', 'V'),
            outputs=('I',),
            params=params,
        )

T = np.arange(100)   # simulation time in seconds
U = np.ones(shape=(3, len(T)))

sys = System.build()
ydata = ct.input_output_response(sys, T=T, U=U, solve_ivp_method="Radau").to_pandas()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[106], [line 28](vscode-notebook-cell:?execution_count=106&line=28)
     [25](vscode-notebook-cell:?execution_count=106&line=25) U = np.ones(shape=(3, len(T)))
     [27](vscode-notebook-cell:?execution_count=106&line=27) sys = System.build()
---> [28](vscode-notebook-cell:?execution_count=106&line=28) ydata = ct.input_output_response(sys, T=T, U=U, solve_ivp_method="Radau").to_pandas()
     [29](vscode-notebook-cell:?execution_count=106&line=29) ydata

File [~/workspace_TCC/repo_2022_2/.env/lib/python3.10/site-packages/control/timeresp.py:655](https://file+.vscode-resource.vscode-cdn.net/home/joaoantoniocardoso/workspace_TCC/repo_2022_2/models/2020/panel/~/workspace_TCC/repo_2022_2/.env/lib/python3.10/site-packages/control/timeresp.py:655), in TimeResponseData.to_pandas(self)
    [650](https://file+.vscode-resource.vscode-cdn.net/home/joaoantoniocardoso/workspace_TCC/repo_2022_2/models/2020/panel/~/workspace_TCC/repo_2022_2/.env/lib/python3.10/site-packages/control/timeresp.py:650) data.update(
    [651](https://file+.vscode-resource.vscode-cdn.net/home/joaoantoniocardoso/workspace_TCC/repo_2022_2/models/2020/panel/~/workspace_TCC/repo_2022_2/.env/lib/python3.10/site-packages/control/timeresp.py:651)     {name: self.u[i] for i, name in enumerate(self.input_labels)})
    [652](https://file+.vscode-resource.vscode-cdn.net/home/joaoantoniocardoso/workspace_TCC/repo_2022_2/models/2020/panel/~/workspace_TCC/repo_2022_2/.env/lib/python3.10/site-packages/control/timeresp.py:652) data.update(
    [653](https://file+.vscode-resource.vscode-cdn.net/home/joaoantoniocardoso/workspace_TCC/repo_2022_2/models/2020/panel/~/workspace_TCC/repo_2022_2/.env/lib/python3.10/site-packages/control/timeresp.py:653)     {name: self.y[i] for i, name in enumerate(self.output_labels)})
    [654](https://file+.vscode-resource.vscode-cdn.net/home/joaoantoniocardoso/workspace_TCC/repo_2022_2/models/2020/panel/~/workspace_TCC/repo_2022_2/.env/lib/python3.10/site-packages/control/timeresp.py:654) data.update(
--> [655](https://file+.vscode-resource.vscode-cdn.net/home/joaoantoniocardoso/workspace_TCC/repo_2022_2/models/2020/panel/~/workspace_TCC/repo_2022_2/.env/lib/python3.10/site-packages/control/timeresp.py:655)     {name: self.x[i] for i, name in enumerate(self.state_labels)})
    [657](https://file+.vscode-resource.vscode-cdn.net/home/joaoantoniocardoso/workspace_TCC/repo_2022_2/models/2020/panel/~/workspace_TCC/repo_2022_2/.env/lib/python3.10/site-packages/control/timeresp.py:657) return pandas.DataFrame(data)

TypeError: 'NoneType' object is not iterable

Not optimal, but as a workaround, I'm introducing a state:

class System:
    @classmethod
    def _updates(cls, t, x, u, params: dict):
        return 0

    @classmethod
    def _outputs(cls, t, x, u, params: dict):
        v = u[0]
        i = u[1]
        k = u[2]

        return k*v**2 + i

    @classmethod
    def build(cls):
        return ct.NonlinearIOSystem(
            cls._updates,
            cls._outputs,
            name="system",
            states=1,
            inputs=('v', 'i', 'V'),
            outputs=('I',),
            params=params,
        )

Activity

  1. murrayrm
    added
    bug
    on Jan 4, 2024
  2. murrayrm
    self-assigned this
    on Jan 4, 2024
  3. murrayrm commented on Jan 4, 2024

    @murrayrm
    murrayrm
    on Jan 4, 2024
    Member
    More actions

    Thanks for reporting this. Should be a quick fix. Will get to it as soon as I can (probably in the next day or two).

    Reacted by João Antônio Cardoso
  4. murrayrm
    added a commit that references this issue on Jan 4, 2024

    fix TimeResponseData.to_pandas() to handle zero state case (python-co…

    6a8779c
  5. murrayrm
    linked a pull request that will close this issueFix TimeResponseData.to_pandas() to handle zero state case #958on Jan 4, 2024
  6. bnavigator
    closed this as completedin #958on Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @murrayrm
    murrayrm

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.