Is there a way to modify algorhytmically the geometry.yaml file used by weis?

Hi, I trying to write a script that can algorhytmically change the geometry.yaml file used by weis for its analysis.
Basically, I am using the yaml package, soing something like this, but the output yaml has some differences in formatting.

Has anyone successfully done this?
I thought there must be a package within weis to read/write/modify yaml, maybe based on windio, but I failed to find it.

with open(output_yaml_path, 'r') as f:
        data = yaml.safe_load(f)

    # Update the tower components
    data['components']['tower']['outer_shape_bem']['reference_axis']['x']['grid'] = [0.0, 0.1, 0.2, 1.0]

    # Write modified YAML back
    with open(output_yaml_path, 'w') as f:
        yaml.safe_dump(data, f, sort_keys=False, default_flow_style=None)

Yes, reading and writing the yaml files is a core activity for WISDEM and WEIS. We use the ruamel.yaml package as that seems to be more robust and current with yaml specifications. An easy way for users to read and write yaml files casually is to just use the reader and writer functions that the models use:

from weis.inputs.validation import load_geometry_yaml, write_geometry_yaml

data = load_geometry_yaml(input_file)
data['components']['tower']['outer_shape_bem']['reference_axis']['x']['grid'] = [0.0, 0.1, 0.2, 1.0]
write_geometry_yaml(data, output_yaml_path)

When using WISDEM you could use import wisdem... instead of import weis...

You can see the source code of the functions in WISDEM here and WEIS here.

Thanks a lot, @Garrett.Barter - very appreciated.
The more I use weis, the more I like it - great work!

Thank you for the kind words!

1 Like