Skip to content

Improve handling of spcforc output #84

@marcodesiderio

Description

@marcodesiderio

🐛 Describe the bug
spcforce output columns in pandas dataframe are not loaded when using as_df method.

🔢 To Reproduce
binout = Binout(file_path)
binout.read('spcforc')

['time', 'x_resultant', 'y_resultant', 'z_resultant', 'spc_mids', 'date', 'x_force', 'build_id', 'moment_ids', 'x_moment', 'spc_ids', 'revision', 'y_force', 'y_moment', 'force_ids', 'z_force', 'misc', 'z_moment', 'title', 'version']

in binout.py, as_df method:

    if data.ndim > 1:
        df = pd.DataFrame(index=time_pdi)

        if args[0] == "rcforc":
            ids = [
                (str(i) + "m") if j else (str(i) + "s")
                for i, j in zip(self.read("rcforc", "ids"), self.read("rcforc", "side"))
            ]
        else:
            ids = self.read(*args[:-1], "ids")

spcforc does not have 'ids' output (rather, force_ids and moment_ids; or - might not always have, not sure about it)

Suggested solution is to add the following condition (similar to as already present for rcforc)
elif args[0] == "spcforc":
if args[-1].endswith("force"):
ids = self.read(*args[:-1], "force_ids")
elif args[-1].endswith("moment"):
ids = self.read(*args[:-1], "moment_ids")
else:
ids = self.read(*args[:-1], "ids")

To have the following snippet:

    # create dataframe
    if data.ndim > 1:
        df = pd.DataFrame(index=time_pdi)

        if args[0] == "rcforc":
            ids = [
                (str(i) + "m") if j else (str(i) + "s")
                for i, j in zip(self.read("rcforc", "ids"), self.read("rcforc", "side"))
            ]
        elif args[0] == "spcforc":
            if args[-1].endswith("force"):
                ids = self.read(*args[:-1], "force_ids")
            elif args[-1].endswith("moment"):
                ids = self.read(*args[:-1], "moment_ids")
            else:
                ids = self.read(*args[:-1], "ids")
        
        else:
            ids = self.read(*args[:-1], "ids")

🖥️ Setup

  • OS: Windows 11
  • LS-Dyna R14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions