Skip to content
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

Hack for aggregate maps and YAML support for zone file #5

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/xtgeoapp_grd3dmaps/aggregate/_grid_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,9 @@ def _property_to_map(
assert weights is None or weights.shape == prop.shape
if weights is not None:
assert method in [AggregationMethod.MEAN, AggregationMethod.SUM]
if True:
data = prop[0][cols] # Necessary change for the code to work
else:
data = prop[cols]
data = prop[0][cols] if len(prop) == 1 else prop[cols]
# Small hack due to a slight difference between calculating mass and other properties
# TODO: Implement a better solution
weights = np.ones_like(data) if weights is None else weights[cols]
if data.mask.any():
invalid = data.mask
Expand Down
13 changes: 13 additions & 0 deletions src/xtgeoapp_grd3dmaps/aggregate/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ def _zonation_from_zproperty(
grid: xtgeo.Grid,
zproperty: ZProperty
) -> List[Tuple[str, np.ndarray]]:
if zproperty.source.split(".")[-1] in ["yml", "yaml"]:
with open(zproperty.source, "r", encoding="utf8") as stream:
try:
zfile = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
exit()
if 'zranges' not in zfile:
error_text = ("The yaml zone file must be in the format:\nzranges:\
\n - Zone1: [1, 5]\n - Zone2: [6, 10]\n - Zone3: [11, 14])")
raise InputError(error_text)
zranges = zfile['zranges']
return _zonation_from_zranges(grid, zranges)
actnum = grid.actnum_indices
prop = xtgeo.gridproperty_from_file(
zproperty.source, grid=grid, name=zproperty.name
Expand Down