Skip to content

Commit

Permalink
Merge pull request #28 from dnv-opensource/add_case_parameters
Browse files Browse the repository at this point in the history
Add case parameters
  • Loading branch information
ClaasRostock authored May 22, 2024
2 parents c2d55fe + c431c09 commit a6ef431
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 19 deletions.
27 changes: 16 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e

## [Unreleased]

* -/-


## [0.3.7] - 2024-05-22

### Dependencies
* updated to ruff==0.4.2 (from ruff==0.3.0)
* updated to pyright==1.1.360 (from pyright==1.1.352)
* updated to ruff==0.4.2 (from ruff==0.2.1)
* updated to pyright==1.1.360 (from pyright==1.1.350)
* updated to sourcery==1.16 (from sourcery==1.15)
* updated to lxml>=5.2 (from lxml>=5.1)
* updated to types-lxml>=2024.4 (from types-lxml>=5.1)
Expand All @@ -19,22 +24,21 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e
* updated to sphinx-argparse-cli>=1.15 (from sphinx-argparse-cli>=1.11)
* updated to myst-parser>=3.0 (from myst-parser>=2.0)
* updated to furo>=2024.4 (from furo>=2023.9.10)

### Changed
* replaced black formatter with ruff formatter

### Dependencies
* updated to ruff==0.3.0 (from ruff==0.2.1)
* updated to pyright==1.1.352 (from pyright==1.1.350)
* updated to dictIO>=0.3.4 (from dictIO>=0.3.3)
* updated to ospx>=0.2.14 (from ospx>=0.2.13)
* updated to numpy>=1.26,<2.0 (from numpy>=1.26)
* removed black
* updated to matplotlib>=3.9 (from matplotlib>=3.8)
* removed black

### Changed
* replaced black formatter with ruff formatter
* Changed publishing workflow to use OpenID Connect (Trusted Publisher Management) when publishing to PyPI
* Updated copyright statement
* VS Code settings: Turned off automatic venv activation

### Added
* `farn.core.case.Case`: Added method `add_parameters()`, which allows to manually add user-defined parameters to a Case.


## [0.3.6] - 2024-02-21

Expand Down Expand Up @@ -336,7 +340,8 @@ Users are encouraged to update to this version.
* Added support for Python 3.10

<!-- Markdown link & img dfn's -->
[unreleased]: https://github.com/dnv-opensource/farn/compare/v0.3.6...HEAD
[unreleased]: https://github.com/dnv-opensource/farn/compare/v0.3.7...HEAD
[0.3.7]: https://github.com/dnv-opensource/farn/compare/v0.3.6...v0.3.7
[0.3.6]: https://github.com/dnv-opensource/farn/compare/v0.3.5...v0.3.6
[0.3.5]: https://github.com/dnv-opensource/farn/compare/v0.3.4...v0.3.5
[0.3.4]: https://github.com/dnv-opensource/farn/compare/v0.3.3...v0.3.4
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = "Frank Lumpitzsch, Claas Rostock, Seung Hyeon Yoo"

# The full version, including alpha/beta/rc tags
release = "0.3.6"
release = "0.3.7"

# -- General configuration ---------------------------------------------------

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "farn"
version = "0.3.6"
version = "0.3.7"
description = "Python package to generate an n-dimensional case folder structure applying linear and spatial sampling strategies."
readme = "README.md"
requires-python = ">= 3.9"
Expand Down Expand Up @@ -43,8 +43,8 @@ dependencies = [
"pyDOE3>=1.0",
"psutil>=5.9",
"hilbertcurve>=2.0.5",
"dictIO>=0.3.3",
"ospx>=0.2.13",
"dictIO>=0.3.4",
"ospx>=0.2.14",
]

[project.urls]
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pyDOE3>=1.0
psutil>=5.9
hilbertcurve>=2.0.5

dictIO>=0.3.3
ospx>=0.2.13
dictIO>=0.3.4
ospx>=0.2.14

# ../dictIO
# ../ospx
44 changes: 43 additions & 1 deletion src/farn/core/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
from copy import deepcopy
from enum import IntEnum
from pathlib import Path
from typing import Any, Dict, List, MutableMapping, MutableSequence, Sequence, Set, Union
from typing import (
Any,
Dict,
List,
MutableMapping,
MutableSequence,
Sequence,
Set,
Union,
)

import numpy as np
from dictIO.utils.path import relative_path
Expand Down Expand Up @@ -208,6 +217,28 @@ def is_valid(self) -> bool:

return True

def add_parameters(
self,
parameters: Union[MutableSequence[Parameter], MutableMapping[str, str], None] = None,
):
"""Manually add extra parameters."""
if isinstance(parameters, MutableSequence):
self.parameters.extend(parameters)

elif isinstance(parameters, MutableMapping):
self.parameters.extend(
Parameter(parameter_name, parameter_value) for parameter_name, parameter_value in parameters.items()
)

else:
logger.error(
f"Layer {self.layer}, case {self.case} add_parameters failed:\n"
f"\tWrong input data format for additional parameters.\n"
)
exit(1)

return True

def to_dict(self) -> Dict[str, Any]:
"""Return a dict with all case attributes.
Expand Down Expand Up @@ -246,6 +277,17 @@ class Cases(List[Case]):
into a pandas DataFrame or numpy ndarray, respectively.
"""

def add_parameters(
self,
parameters: Union[MutableSequence[Parameter], MutableMapping[str, str], None] = None,
):
"""Manually add extra parameters."""
_cases: List[Case] = deepcopy(self)
for case in _cases:
_ = case.add_parameters(parameters)

return False

def to_pandas(
self,
use_path_as_index: bool = True,
Expand Down
11 changes: 10 additions & 1 deletion src/farn/farn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
import re
from copy import deepcopy
from pathlib import Path
from typing import Any, Dict, List, MutableMapping, MutableSequence, MutableSet, Sequence, Union
from typing import (
Any,
Dict,
List,
MutableMapping,
MutableSequence,
MutableSet,
Sequence,
Union,
)

from dictIO import CppDict, DictReader, DictWriter, create_target_file_name
from dictIO.utils.strings import remove_quotes
Expand Down

0 comments on commit a6ef431

Please sign in to comment.