-
Notifications
You must be signed in to change notification settings - Fork 7
fix(io): extending and testing ascii writes #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| from collections.abc import MutableMapping | ||
| from collections.abc import Iterable, MutableMapping | ||
| from datetime import datetime | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
@@ -47,6 +47,8 @@ def _get_binding_type(component: Component) -> str: | |
| cls_name = component.__class__.__name__ | ||
| if isinstance(component, Exchange): | ||
| return f"{'-'.join([cls_name[:2], cls_name[3:]]).upper()}6" | ||
| elif isinstance(component, Solution): | ||
| return f"{component.slntype}6" | ||
| else: | ||
| return f"{cls_name.upper()}6" | ||
|
|
||
|
|
@@ -107,7 +109,7 @@ def unstructure_component(value: Component) -> dict[str, Any]: | |
| for comp in field_value.values() | ||
| if comp is not None | ||
| ] | ||
| elif isinstance(field_value, (list, tuple)): | ||
| elif isinstance(field_value, Iterable): | ||
| components = [ | ||
| _Binding.from_component(comp).to_tuple() | ||
| for comp in field_value | ||
|
|
@@ -170,16 +172,16 @@ def unstructure_component(value: Component) -> dict[str, Any]: | |
| ( | ||
| field_value.sizes["nper"], | ||
| parent.dims["nlay"], | ||
| parent.dims["ncol"], | ||
| parent.dims["nrow"], | ||
| parent.dims["ncol"], | ||
| ) | ||
| ), | ||
| dims=("nper", "nlay", "ncol", "nrow"), | ||
| dims=("nper", "nlay", "nrow", "ncol"), | ||
| coords={ | ||
| "nper": field_value.coords["nper"], | ||
| "nlay": range(parent.dims["nlay"]), | ||
| "ncol": range(parent.dims["ncol"]), | ||
| "nrow": range(parent.dims["nrow"]), | ||
| "ncol": range(parent.dims["ncol"]), | ||
| }, | ||
| name=field_value.name, | ||
| ) | ||
|
|
@@ -189,12 +191,28 @@ def unstructure_component(value: Component) -> dict[str, Any]: | |
| for kper in range(field_value.sizes["nper"]) | ||
| } | ||
| else: | ||
| if block_name not in period_data: | ||
| period_data[block_name] = {} | ||
| period_data[block_name][field_name] = field_value # type: ignore | ||
| if ( | ||
| # TODO: refactor | ||
| # field_name == "save_budget" | ||
| # or field_name == "save_head" | ||
| # or field_name == "print_budget" | ||
| # or field_name == "print_head" | ||
| np.issubdtype(field_value.dtype, np.str_) | ||
| ): | ||
| period_data[field_name] = { | ||
| kper: field_value[kper] for kper in range(field_value.sizes["nper"]) | ||
| } | ||
| else: | ||
| if block_name not in period_data: | ||
| period_data[block_name] = {} | ||
| period_data[block_name][field_name] = field_value # type: ignore | ||
| else: | ||
| if field_value is not None: | ||
| blocks[block_name][field_name] = field_value | ||
| if isinstance(field_value, bool): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this prevents false keywords from being written |
||
| if field_value: | ||
| blocks[block_name][field_name] = field_value | ||
| else: | ||
| blocks[block_name][field_name] = field_value | ||
|
|
||
| if block_name in period_data and isinstance(period_data[block_name], dict): | ||
| dataset = xr.Dataset(period_data[block_name]) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,19 @@ | ||
| from abc import ABC | ||
| from pathlib import Path | ||
| from typing import ClassVar, Optional | ||
|
|
||
| import attrs | ||
| from xattree import xattree | ||
| from xattree import field, xattree | ||
|
|
||
| from flopy4.mf6.package import Package | ||
|
|
||
|
|
||
| @xattree | ||
| class Solution(Package, ABC): | ||
| slntype: ClassVar[str] = "sln" | ||
|
|
||
| slnfname: Optional[Path] = field(default=None) # type: ignore | ||
| models: list[str] = attrs.field(default=attrs.Factory(list)) | ||
|
|
||
| def default_filename(self) -> str: | ||
| return str(self.slnfname) if self.slnfname else f"solution.{self.slntype.lower()}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't know about the tilde for string concatenation before. TIL.