Datasets
datasets
¶
Attributes¶
DatasetInput
module-attribute
¶
DatasetInput = Annotated[
IODataset, BeforeValidator(_coerce_to_dataset)
]
A dataset field accepting a mapping, a DataFrame or a Dataset.
Use this instead of Dataset or IODataset when declaring the field of a tool, so
that users can pass the data they already have. The conversion is carried by the
annotation rather than by the tool, so that it also applies when the inputs model is
built directly, as done by the workflow engine.
Classes¶
DatasetAddFromModel
¶
Methods:¶
add_group
classmethod
¶
add_group(
dataset,
input_group_name: str,
input_variable_names: Iterable[str],
model: IntegratedModel,
output_group_name: str,
output_variable_name: str,
bias: float = 0.0,
) -> None
Add group based on the outputs of a model, its inputs being contained in the dataset.
Source code in src\vimseo\utilities\datasets.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
DatasetAddFromStatistics
¶
DatasetAddFromStatistics()
Source code in src\vimseo\utilities\datasets.py
124 125 | |
Methods:¶
add_group
¶
add_group(
dataset,
group_name: str,
variable_names: str,
distributions: Mapping[str, DistributionParameters],
nb_samples: int,
) -> None
Add group based on statistical parameters using OpenTurns distributions.
Source code in src\vimseo\utilities\datasets.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
Variable
¶
Bases: NamedTuple
A convenient data class to define a variable to be placed in a Dataset.
Functions:¶
assert_frame_equal_unordered
¶
assert_frame_equal_unordered(
df1: DataFrame, df2: DataFrame, **kwargs
)
Compare two DataFrames regardliess of column and row order.
Source code in src\vimseo\utilities\datasets.py
783 784 785 786 787 788 | |
dataframe_to_dataset
¶
dataframe_to_dataset(df: DataFrame) -> Dataset
Compute the GEMSEO Dataset from a DataFrame with a_name{a_group}[a_component] convention.
For vectors, naming convention is a_name{a_group}[0], a_name{a_group}[1], ...
This naming convention is obtained with dataset_to_dataframe() with argument
suffix_by_group=True.
This is the advanced, lossless counterpart of :func:dataset_to_dataframe, meant for
round-tripping a dataset through a mono-indexed DataFrame. To build a dataset from
data that does not already follow this convention, use :func:to_dataset instead.
Source code in src\vimseo\utilities\datasets.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
dataset_to_dataframe
¶
dataset_to_dataframe(
dataset: Dataset,
variable_names: list[str] = (),
group_names: list[str] = (),
suffix_by_group: bool = False,
) -> DataFrame
Extracts variables from a GEMSEO dataset, and store them in a mono-indexed DataFrame with variable naming convention a_name[a_group][a_component] .
Source code in src\vimseo\utilities\datasets.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
decode_vector
¶
decode_vector(vector_as_str: str, separator='_') -> ndarray
Decode a stringified vector.
Parameters:
-
vector_as_str(str) –A vector as a
string, under the form of numerical values -
separator–The separator between ply angles.
Returns:
-
ndarray–A vector_as_str as an array of
floats, compatible as a model input.
Source code in src\vimseo\utilities\datasets.py
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 | |
encode_vector
¶
encode_vector(
vector_numerical: ndarray | list[float | int],
)
Encode a vector_as_str.
Example
encode_vector(array([0,90,0])
Args: vector_numerical: [ndarray] A 1D array containing numerical values of plies angles. Returns: vector_as_str_str: [ndarray] An array containing a single string of encoded angle values.
Source code in src\vimseo\utilities\datasets.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 | |
get_nb_input_variables
¶
get_nb_input_variables(dataset: IODataset)
Compute the number of input variables.
Source code in src\vimseo\utilities\datasets.py
234 235 236 | |
plot_dataset_element
¶
plot_dataset_element(
dataset,
sample_id,
variables,
abscissa_variable,
file_name: str = "",
group_name: str = "",
) -> PlotResult
Visualize row number sample_id of a dataset as a line plot.
Useful if the dataset contains vector elements (1D outputs).
Parameters:
-
dataset–A dataset containing 1D outputs to visualize.
-
sample_id–The id of the row to visualize.
-
variables–The variables to be plotted as ordinate.
-
abscissa_variable–The abscissa variable.
-
file_name(str, default:'') –The name of the saved file.
-
group_name(str, default:'') –The name of the group to which
variablesandabscissa_namebelong.
Returns: The plot result.
Source code in src\vimseo\utilities\datasets.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
resolve_io_groups
¶
resolve_io_groups(
dataset: Dataset,
model: IntegratedModel | None = None,
input_names: Iterable[str] = (),
output_names: Iterable[str] = (),
) -> IODataset
Split the default group of a dataset into an input group and an output group.
A dataset that already declares an input or an output group is returned unchanged,
so that this function can be called unconditionally by a tool. Otherwise the roles
are taken from input_names and output_names when given, and from the grammars
of model otherwise. Variables matching neither role are left in the default
group, so that data carried along for reference, such as a batch number, is
preserved.
Parameters:
-
dataset(Dataset) –The dataset whose groups are to be resolved.
-
model(IntegratedModel | None, default:None) –The model providing the variable roles. If
None, the roles must be given explicitly. -
input_names(Iterable[str], default:()) –The names of the variables to place in the input group. If empty, use the input variables of
model. -
output_names(Iterable[str], default:()) –The names of the variables to place in the output group. If empty, use the output variables of
model.
Returns:
-
IODataset–The dataset with an input group and an output group.
Raises:
-
ValueError–If the roles of the variables cannot be resolved.
Source code in src\vimseo\utilities\datasets.py
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | |
to_dataset
¶
to_dataset(
data: Dataset | DataFrame | Mapping[str, Any],
input_names: Iterable[str] = (),
output_names: Iterable[str] = (),
) -> IODataset
Convert user data to a GEMSEO dataset.
This is the entry point used by the tools to accept plain Python data, so that the
GEMSEO :class:~gemseo.datasets.dataset.Dataset API does not have to be learnt.
The accepted forms are:
- a mapping of variable names to values, e.g.
{"dx": [1.0, 0.5], "sigma": [3, 4]}. A value can be a scalar, a vector, an array shaped as(n_entries, n_components)for a vector variable, or a sequence of vectors of different lengths, which are then padded withNaN; - a mapping of group names to such mappings, e.g.
{"inputs": {"dx": ...}, "outputs": {"sigma": ...}}, to state the groups explicitly; - a mono-indexed :class:
~pandas.DataFrame, typically read from a csv file; - a :class:
~pandas.DataFramefollowing thea_name{a_group}[a_component]column convention, see :func:dataframe_to_dataset; - a :class:
~gemseo.datasets.dataset.Dataset, returned unchanged.
Parameters:
-
data(Dataset | DataFrame | Mapping[str, Any]) –The data to convert.
-
input_names(Iterable[str], default:()) –The names of the variables to place in the input group. If empty, no variable is placed in the input group.
-
output_names(Iterable[str], default:()) –The names of the variables to place in the output group. If empty, no variable is placed in the output group.
Returns:
-
IODataset–The data as an :class:
~gemseo.datasets.io_dataset.IODataset.
Raises:
-
TypeError–If the type of
datais not supported.
Source code in src\vimseo\utilities\datasets.py
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |