Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Kallekleiv committed Mar 21, 2019
1 parent 6fb6a98 commit 828ea4d
Show file tree
Hide file tree
Showing 13 changed files with 830 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.eggs
*.egg-info
__pycache__
node_modules
venv
.vscode
.pytest_cache
*.pyc
.DS_Store
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Webviz Subsurface configuration


### Introduction

This repository contains subsurface specific standard webviz containers, which are used as
plugins in [webviz-config](https://github.com/equinor/webviz-config).


### Installation

As Dash is using Python3-only functionality, you should create a Python3
virtual environment before installation. One way of doing this in Equinor is
```bash
export PYTHON_VERSION=3.7.1
source /prog/sdpsoft/env.sh

PATH_TO_VENV='./my_new_venv'
python3 -m virtualenv $PATH_TO_VENV
source $PATH_TO_VENV/bin/activate
```

In order to install the utility, run
```bash
git clone [email protected]:Equinor/webviz-subsurface.git
cd webviz-subsurface
pip install .
```

### Usage

For general usage, see the documentation on
[webviz-config](https://github.com/equinor/webviz-config).

Take a look at this configuration example for something subsurface specific.


### Creating new elements

If you are interested in creating new elements which can be configured through
the configuration file, take a look at the
[webviz-config contribution guide](https://github.com/equinor/webviz-config).


### Disclaimer

This is a tool under heavy development. The current configuration file layout,
also for subsurface pages, will therefore see large changes.
46 changes: 46 additions & 0 deletions examples/basic_example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file demonstrates the most basic usage of webviz in a FMU setting
# The configuration files uses YAML (https://en.wikipedia.org/wiki/YAML).

title: Reek Webviz Demonstration
username: some_username
password: some_password

container_settings:
scratch_ensembles:
iter-0: /scratch/myfield/realization-*/iter-0
iter-1: /scratch/myfield/realization-*/iter-1

pages:

- title: Front page
content:
- Webviz created from configuration file
- title: Summary vectors
content:
- Some text...
- container: SummaryStats
ensemble: iter-0
- ...some other text
- title: Parameter distribution
content:
- Some text...
- container: ParameterDistribution
ensemble: iter-0
- ...some other text
- title: Subsurface map
content:
- container: SubsurfaceMap
ensemble: iter-0
map_value: PERMX
flow_value: FLOWAT
time_step: 26
- title: History match
content:
- container: HistoryMatch
ensembles:
- iter-0
- iter-1
observation_file: some_observation_file.yaml
- title: Another page
content:
- Some basic text with special characters... Åre, Smørbukk Sør.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scipy>=1.2.1
20 changes: 20 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from setuptools import setup, find_packages

setup(
name='webviz-subsurface',
version='0.1',
description='Webviz config containers for subsurface data',
url='https://github.com/equinor/webviz-subsurface',
author='R&T Equinor',
packages=find_packages(exclude=['tests']),
entry_points={
'webviz_config_containers': [
'SummaryStats = webviz_subsurface.containers:SummaryStats',
'ParameterDistribution = webviz_subsurface.containers:ParameterDistribution',
'DiskUsage = webviz_subsurface.containers:DiskUsage',
'SubsurfaceMap = webviz_subsurface.containers:SubsurfaceMap',
'HistoryMatch = webviz_subsurface.containers:HistoryMatch'
]
},
zip_safe=False
)
Empty file added webviz_subsurface/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions webviz_subsurface/containers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'''### _Subsurface specific containers_
These are containers relevant within subsurface workflows. Most of them
rely on the setting `scratch_ensemble` configuration within the `container_settings`.
I.e. you could have
```yaml
title: Reek Webviz Demonstration
username: some_username
password: some_password
container_settings:
scratch_ensembles:
iter-0: /scratch/my_ensemble/realization-*/iter-0
iter-1: /scratch/my_ensemble/realization-*/iter-1
pages:
- title: Front page
content:
- container: SummaryStats
ensemble: iter-0
```
'''

from ._summary_stats import SummaryStats
from ._parameter_distribution import ParameterDistribution
from ._disk_usage import DiskUsage
from ._subsurface_map import SubsurfaceMap
from ._history_match import HistoryMatch


__all__ = ['SummaryStats',
'ParameterDistribution',
'DiskUsage',
'SubsurfaceMap',
'HistoryMatch']
114 changes: 114 additions & 0 deletions webviz_subsurface/containers/_disk_usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import os
from uuid import uuid4
import pandas as pd
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
from webviz_config.webviz_store import webvizstore
from webviz_config.common_cache import cache


class DiskUsage:
'''### Disk usage
This container adds functionality for standard visualization of disk usage in
FMU projects. It adds a dashboard element where the user can choose between
showing disk usage, per user, either as a pie chart or as a bar chart.
* `scratch_dir`: Path to the directory you want to show disk usage for, e.g.
`/scratch/fmu`.
* `title`: Optional title for the container.
'''

def __init__(self, app, scratch_dir: str,
title: str = 'Disk usage'):

self.title = title
self.scratch_dir = scratch_dir
self.chart_id = 'chart-id-{}'.format(uuid4())
self.plot_type_id = 'plot-type-id-{}'.format(uuid4())
self.disk_usage = get_disk_usage(self.scratch_dir)
self.date = str(self.disk_usage['date'].unique()[0])
self.users = self.disk_usage['userid']
self.usage = self.disk_usage['usageKB']/(1024**2)
self.set_callbacks(app)

@property
def layout(self):
return html.Div([
html.H2(self.title),
html.P(
f'This is the disk usage on \
{self.scratch_dir} per user, \
as of {self.date}.'),
dcc.RadioItems(
id=self.plot_type_id,
options=[
{'label': i, 'value': i}
for i in ['Pie chart', 'Bar chart']],
value='Pie chart'),
dcc.Graph(
id=self.chart_id,
config={
'displaylogo': False,
'modeBarButtonsToRemove': ['sendDataToCloud']
}
)
])

def set_callbacks(self, app):
@app.callback(Output(self.chart_id, 'figure'),
[Input(self.plot_type_id, 'value')])
def update_plot(plot_type):
if plot_type == 'Pie chart':
data = [{
'values': self.usage,
'labels': self.users,
'text': (self.usage).map('{:.2f} GB'.format),
'textinfo': 'label',
'textposition': 'inside',
'hoverinfo': 'label+text',
'type': 'pie'
}]
layout = {}

elif plot_type == 'Bar chart':
data = [{
'y': self.usage,
'x': self.users,
'text': (self.usage).map('{:.2f} GB'.format),
'hoverinfo': 'x+text',
'type': 'bar'
}]
layout = {
'yaxis': {
'title': 'Usage in Gigabytes',
'family': 'Equinor'
},
'xaxis': {
'title': 'User name',
'family': 'Equinor'
},
}

layout['height'] = 800
layout['width'] = 1000
layout['font'] = {'family': 'Equinor'}
layout['hoverlabel'] = {'font': {'family': 'Equinor'}}

return {'data': data, 'layout': layout}

def add_webvizstore(self):
return [(get_disk_usage, [{'scratch_dir': self.scratch_dir}])]


@cache.memoize(timeout=cache.TIMEOUT)
@webvizstore
def get_disk_usage(scratch_dir) -> pd.DataFrame:
try:
df = pd.read_csv(os.path.join(scratch_dir, 'disk_usage.csv'))
except FileNotFoundError:
raise FileNotFoundError(f'No disk usage file found at {scratch_dir}')

last_date = sorted(list(df['date'].unique()))[-1]
return df.loc[df['date'] == last_date]
Loading

0 comments on commit 828ea4d

Please sign in to comment.