Skip to content

Commit

Permalink
Reduce data size Map (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored May 29, 2019
1 parent bb0dbbe commit e0ad6d4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
'scipy>=1.2.1',
'webviz-config>=0.0.4',
'webviz-plotly>=0.0.1',
'webviz-subsurface-components>=0.0.2'
'webviz-subsurface-components>=0.0.3'
],
tests_require=tests_require,
extras_require={'tests': tests_require},
Expand Down
82 changes: 73 additions & 9 deletions webviz_subsurface/containers/_subsurface_map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from uuid import uuid4
import json
import pandas as pd
import dash_html_components as html
from webviz_config.webviz_store import webvizstore
Expand Down Expand Up @@ -39,25 +40,88 @@ def __init__(self, container_settings, ensemble, map_value: str,
def layout(self):
return html.Div([
html.H2(self.title),
Map(id=self.map_id, data=self.map_data.to_json())
Map(id=self.map_id, data=self.map_data)
])

def add_webvizstore(self):
return [(get_map_data, [{'ensemble_path': self.ensemble_path,
'map_value': self.map_value,
'flow_value': self.flow_value,
'time_step': self.time_step}])]
return [(get_uncompressed_data, [{'ensemble_path': self.ensemble_path,
'map_value': self.map_value,
'flow_value': self.flow_value,
'time_step': self.time_step}])]


@cache.memoize(timeout=cache.TIMEOUT)
@webvizstore
def get_map_data(ensemble_path, map_value, flow_value,
time_step) -> pd.DataFrame:
time_step):
'''Returns map data in the format of a JSON string, suitable for the
corresponding subsurface map component in
https://github.com/equinor/webviz-subsurface-components
'''

grid = get_uncompressed_data(ensemble_path, map_value, flow_value,
time_step)

INDICES_COL = ['i', 'j', 'k']
X_COL = ['x0', 'x1', 'x2', 'x3']
Y_COL = ['y0', 'y1', 'y2', 'y3']
FLOW_COL = ['FLOWI+', 'FLOWJ+']

RESOLUTION = 1000

grid = grid[INDICES_COL + X_COL + Y_COL + ['value'] + FLOW_COL]
grid = grid[grid['value'] > 0]

xmin, xmax = grid[X_COL].values.min(), grid[X_COL].values.max()
ymin, ymax = grid[Y_COL].values.min(), grid[Y_COL].values.max()

flowmin, flowmax = grid[FLOW_COL].values.min(), grid[FLOW_COL].values.max()

valmin, valmax = grid['value'].min(), grid['value'].max()

if (xmax - xmin) > (ymax - ymin):
coord_scale = RESOLUTION/(xmax - xmin)
else:
coord_scale = RESOLUTION/(ymax - ymin)

grid[X_COL] = (grid[X_COL] - xmin) * coord_scale
grid[Y_COL] = (grid[Y_COL] - ymin) * coord_scale
grid[X_COL + Y_COL] = grid[X_COL + Y_COL].astype(int)

flow_scale = RESOLUTION/(flowmax - flowmin)
grid[FLOW_COL] = (grid[FLOW_COL] - flowmin) * flow_scale
grid[FLOW_COL] = grid[FLOW_COL].astype(int)

val_scale = RESOLUTION/(valmax - valmin)
grid['value'] = (grid['value'] - valmin) * val_scale
grid['value'] = grid['value'].astype(int)

grid[INDICES_COL] = grid[INDICES_COL].astype(int)

data = {
'values': grid.values.tolist(),
'linearscales': {
'coord': [float(coord_scale), float(xmin), float(ymin)],
'value': [float(val_scale), float(valmin)],
'flow': [float(flow_scale), float(flowmin)]
}
}

return json.dumps(data, separators=(',', ':'))


@webvizstore
def get_uncompressed_data(ensemble_path, map_value, flow_value,
time_step) -> pd.DataFrame:

ens = scratch_ensemble('', ensemble_path)

grid = ens.get_eclgrid([map_value, f'{flow_value}I+', f'{flow_value}J+'],
report=time_step)
properties = [map_value, f'{flow_value}I+', f'{flow_value}J+']
if 'PERMX' not in properties:
properties.append('PERMX')

grid = ens.get_eclgrid(properties, report=time_step)

grid = grid[grid['PERMX'] > 0] # Remove inactive grid cells

grid['value'] = grid[map_value]
grid['FLOWI+'] = grid[f'{flow_value}I+']
Expand Down

0 comments on commit e0ad6d4

Please sign in to comment.