Skip to content

Conversation

@dafeda
Copy link
Contributor

@dafeda dafeda commented Sep 18, 2025

Issue
Resolves #10909

Example of usage via API

from ert.storage import open_storage

storage_path = "/Users/FCUR/git/ert/test-data/ert/heat_equation/storage"
experiment_name = "ensemble_experiment"
with open_storage(storage_path, "r") as storage:
    experiment = storage.get_experiment_by_name(experiment_name)

experiment.parameter_configuration["COND"]

Field(type='field', name='COND', forward_init=True, update=True, nx=10, ny=10, nz=1, xlength=10.0, ylength=10.0, xinc=1.0, yinc=1.0, rotation_angle=0.0, origin=(6.123233998228043e-16, 10.0), file_format=<FieldFileFormat.BGRDECL: 'bgrdecl'>, output_transformation=None, input_transformation=None, truncation_min=None, truncation_max=None, forward_init_file='cond.bgrdecl', output_file=PosixPath('cond.bgrdecl'), grid_file='/Users/FCUR/git/ert/test-data/ert/heat_equation/CASE.EGRID', mask_file=PosixPath('/Users/FCUR/git/ert/test-data/ert/heat_equation/storage/experiments/f094b1d1-de8d-4dff-aaa3-2503bd2626d1/grid_mask.npy'))

Performance (ran locally on my mac)

Drogon (approx 900k parameters):

Time to load grid and calculate ertbox params: 0.0660250186920166s
ErtboxParameters(nx=92, ny=146, nz=66, xlength=92.0, ylength=146.0, xinc=1.0, yinc=1.0, rotation_angle=0.0, origin=(0.0, 146.0))

10mill parameters:
Time to load grid and calculate ertbox params: 1.0769238471984863s
ErtboxParameters(nx=1000, ny=100, nz=100, xlength=1000.0, ylength=100.0, xinc=1.0, yinc=1.0, rotation_angle=0.0, origin=(0.0, 100.0))

  • PR title captures the intent of the changes, and is fitting for release notes.
  • Added appropriate release note label
  • Commit history is consistent and clean, in line with the contribution guidelines.
  • Make sure unit tests pass locally after every commit (git rebase -i main --exec 'just rapid-tests')

When applicable

  • When there are user facing changes: Updated documentation
  • New behavior or changes to existing untested code: Ensured that unit tests are added (See Ground Rules).
  • Large PR: Prepare changes in small commits for more convenient review
  • Bug fix: Add regression test for the bug
  • Bug fix: Add backport label to latest release (format: 'backport release-branch-name')

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 18, 2025

CodSpeed Performance Report

Merging #11851 will not alter performance

Comparing dafeda:add-grid-properties (f6b566e) with main (f7c488d)1

Summary

✅ 22 untouched

Footnotes

  1. No successful run was found on main (c2a7edc) during the generation of this report, so f7c488d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@dafeda dafeda force-pushed the add-grid-properties branch 14 times, most recently from 1cbb8a3 to 9c898c7 Compare September 24, 2025 08:27
@dafeda dafeda marked this pull request as ready for review September 24, 2025 09:48
@dafeda dafeda self-assigned this Sep 24, 2025
@dafeda dafeda added this to SCOUT Sep 24, 2025
if global_grid_file_path is not None:
global_grid_file_path = Path(global_grid_file_path)

grid_extension = global_grid_file_path.suffix.lower()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could maybe all this grid relates parsing and loading be in the field config as classmethods?

@dafeda dafeda force-pushed the add-grid-properties branch from 4944055 to c281bc8 Compare September 26, 2025 11:47
f"Grid file {grid_file_path} did not contain dimensions",
grid_file_path,
)
assert grid_file_path is not None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can move this assert before line == 128 and just do assert global_grid_file_path is not None


if errors:
raise ConfigValidationError.from_collected(errors)
assert file_format is not None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these 2 asserts be removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I still need both asserts.

corner_indices = []

if left_handed:
origin_cell = (1, 1, 1)
Copy link
Contributor

@xjules xjules Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a very naive question :) The cells start with (1,1,1) and not (0,0,0) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best if @oddvarlia answers this I think.

# Returns 24 values: [x0,y0,z0, x1,y1,z1, ..., x7,y7,z7]
coord = grid.get_xyz_cell_corners(ijk=corner_index, activeonly=False)
coord_cell.append(coord)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion with vectorize approach:

coords = [np.array(grid.get_xyz_cell_corners(ijk=idx, activeonly=False)).reshape(8, 3)
          for idx in corner_indices]
if left_handed:
    origin = coords[0][0, :2] 
    xdir   = coords[1][1, :2] 
    ydir   = coords[2][2, :2] 
else:
    origin = coords[0][2, :2]
    xdir   = coords[1][3, :2]
    ydir   = coords[2][0, :2]

xlength = np.linalg.norm(xdir - origin)
ylength = np.linalg.norm(ydir - origin)
xinc = xlength / nx
yinc = ylength / ny

@dafeda dafeda force-pushed the add-grid-properties branch 3 times, most recently from 692c065 to bf27eac Compare October 3, 2025 10:14
@dafeda dafeda force-pushed the add-grid-properties branch from bf27eac to f6b566e Compare October 3, 2025 11:41
Copy link
Contributor

@xjules xjules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR @dafeda !
As discussed about the commit message content:

  • localization params introduction via xtgeo (more verbose) and it's called ertbox
  • maybe something on ertbox?
  • storage migration to14 with some test modification

@github-project-automation github-project-automation bot moved this to Reviewed in SCOUT Oct 3, 2025
@dafeda dafeda merged commit 5ee130c into equinor:main Oct 3, 2025
34 checks passed
@dafeda dafeda deleted the add-grid-properties branch October 3, 2025 12:50
@github-project-automation github-project-automation bot moved this from Reviewed to Done in SCOUT Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Save grid location when loading grid

2 participants