Skip to content

Commit

Permalink
Ui compatibility (#8)
Browse files Browse the repository at this point in the history
* bump version

* initial

* move projection down into mesh, add property accessor instead, made the mesh a param class for param.depends functionality

* minor formatting

* add link to adhui [skip ci]

* bump version

* change param.DataFrame default to empty df

* change param.DataFrame default to empty df

* add methods to get a path from a string dataframe

* doc strings

* bump gdal and rasterio

* bump earthsim

* bump versions
  • Loading branch information
kcpevey authored Aug 16, 2019
1 parent ed3237a commit 2c5d49d
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 36 deletions.
74 changes: 74 additions & 0 deletions adhmodel/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,77 @@ def get_path_by_loc(g, locs, verts):
previous_node = current_node

return path


def get_string_by_card(all_strings, card=None, string_number=None):
"""Reduce the boundary_strings dataframe to a single card type or
a single string number
Args:
all_strings: dataframe
AdhSimulation.BoundaryCondition.boundary_strings dataframe
card: string
String card to extract from the dataframe (e.g. 'EGS', 'NDS', 'MTS')
string_number: integer
Number of the string to extract
Returns:
subset - dataframe
subset dataframe containing only the requested cards and/or string
"""
if card:
card_condition = all_strings['CARD'] == card
else:
card_condition = all_strings['CARD'].notnull()

if string_number:
string_number_condition = all_strings['ID_1'] == string_number
else:
string_number_condition = all_strings['ID_1'].notnull()

subset = all_strings.loc[card_condition & string_number_condition]

return subset


def string_to_list(string_df, column_1='ID', column_2='ID_0'):
"""Convert AdH Boundary String dataframe into a list of properly ordered nodes
AdH Boundary Strings are 2 column format, each row consists of two nodes that make
up one edge. The second node is repeated as the first node on the next row
Args:
string_df: dataframe
Boundary string dataframe (already reduced to a single string)
column_1: string
Dataframe column label of the first vertex of the edge
column_2: string
Dataframe column label for the second vertex of the edge
Returns:
Boundary string nodes as a list
"""
# get the string series as a list
lst = string_df[column_1].to_list()
# add the last node in the string
lst.append(string_df[column_2].iloc[-1])
# return the list
return lst


def get_boundary_string_path(mesh, node_list):
"""Convert a node list into path object
Args:
mesh: AdhMesh object
node_list: List of nodes numbers with which to generate the path
Nodes should be one-based since AdhMesh.verts index is one-based.
Returns:
Geoviews path object
"""

path = gv.Path(mesh.verts.loc[node_list], crs=mesh.projection.get_crs())
return path

16 changes: 8 additions & 8 deletions adhmodel/simulation/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def write_fr_cards(bc_file, bc_class):
bc_class: The ADH simulation class that holds all simulation information
"""
fr = bc_class.friction_controls
if fr is not None:
if not fr.empty:
bc_file.write('! Friction Controls\n')
bc_file.write(fr.to_csv(sep=' ', na_rep='', index=False, header=False,).replace('\r\n', '\n'))
bc_file.write('\n') # blank line after Friction Controls
Expand All @@ -967,7 +967,7 @@ def write_pc_cards(bc_file, bc_class):
if oc.output_control_option == objects[0]:
bc_file.write('OC {}\n'.format(oc.oc_time_series_id))
ofs = oc.output_flow_strings
if ofs is not None:
if not ofs.empty:
bc_file.write(ofs.to_csv(sep=' ', na_rep='', index=False, header=False,).replace('\r\n', '\n'))

if oc.print_adaptive_mesh:
Expand Down Expand Up @@ -1010,11 +1010,11 @@ def write_solution_control_cards(bc_file, bc_class):
"""
bc_file.write('! Solution Controls\n')
sc = bc_class.solution_controls
if sc is not None:
if not sc.empty:
bc_file.write(sc.to_csv(sep=' ', na_rep='', index=False, header=False,).replace('\r\n', '\n'))

nb_sdr = bc_class.stage_discharge_boundary
if nb_sdr is not None:
if not nb_sdr.empty:
bc_file.write(nb_sdr.to_csv(sep=' ', na_rep='', index=False, header=False, ).replace('\r\n', '\n'))

if bc_class.constituent_properties.temperature:
Expand All @@ -1024,17 +1024,17 @@ def write_solution_control_cards(bc_file, bc_class):
write_breach_control_cards(bc_file, bc_class)

wer = bc_class.weirs
if wer is not None:
if not wer.empty:
bc_file.write('WER {}\n'.format(len(wer.index)))
bc_file.write(wer.to_csv(sep=' ', na_rep='', index=False, header=False,).replace('\r\n', '\n'))

flp = bc_class.flap_gates
if flp is not None:
if not flp.empty:
bc_file.write('FLP {}\n'.format(len(flp.index)))
bc_file.write(flp.to_csv(sep=' ', na_rep='', index=False, header=False,).replace('\r\n', '\n'))

sls = bc_class.sluice_gates
if sls is not None:
if not sls.empty:
bc_file.write('SLUICE {}\n'.format(len(sls.index)))
bc_file.write(sls.to_csv(sep=' ', na_rep='', index=False, header=False,).replace('\r\n', '\n'))

Expand All @@ -1050,7 +1050,7 @@ def write_breach_control_cards(bc_file, bc_class):
bc_class: The ADH simulation class that holds all simulation information
"""
br = bc_class.breach_controls
if br is None:
if br.empty:
return
format_dict = {'JAI': [str, str, int, int, float, float, float, float, int, int],
'SAS': [str, str, int, int, float, float, float, float, int, int],
Expand Down
3 changes: 2 additions & 1 deletion adhmodel/simulation/output_control.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import param
import pandas as pd
import panel as pn


Expand All @@ -17,7 +18,7 @@ class OutputControl(param.Parameterized):
precedence=2,
)
output_flow_strings = param.DataFrame(
default=None,
default=pd.DataFrame(data=[], columns=['CARD', 'S_ID']),
doc='FLX: CARD S_ID, '
'CARD - FLX, '
'S_ID - String ID for mid string or edge string for which flow is to be output.',
Expand Down
17 changes: 11 additions & 6 deletions adhmodel/simulation/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ class BoundaryConditions(param.Parameterized):
'FGT, SLUICE, SLS.',
)
stage_discharge_boundary = param.DataFrame(
default=None,
default=pd.DataFrame(data=[], columns=['CARD', 'S_ID', 'COEF_A', 'COEF_B', 'COEF_C', 'COEF_D', 'COEF_E']),
doc='Columns [CARD, S_ID, COEF_A, COEF_B, COEF_C, COEF_D, COEF_E], '
'NB SDR: Stage discharge boundary. S_ID: String id, COEF_A: coeficient A, COEF_B: coeficient B, '
'COEF_C: coeficient C, COEF_D: coeficient D, COEF_E: coeficient E.',
)
friction_controls = param.DataFrame(
default=None,
default=pd.DataFrame(data=[], columns=["CARD", "CARD_2", "STRING_ID", "REAL_01", "REAL_02",
"REAL_03", "REAL_04", "REAL_05"]),
doc='Columns for this DataFrame ["CARD", "CARD_2", "STRING_ID", "REAL_01", "REAL_02", '
'"REAL_03", "REAL_04", REAL_05"]. '
'This holds information for the following: '
Expand All @@ -96,7 +97,8 @@ class BoundaryConditions(param.Parameterized):
"thickness of bridge deck",
)
breach_controls = param.DataFrame(
default=None,
default=pd.DataFrame(data=[], columns=['CARD', 'CARD_1', 'C_00', 'C_01', 'C_02', 'C_03', 'C_04',
'C_05', 'C_06', 'C_07', 'C_08', 'C_09']),
doc='[CARD][CARD_1][C_00][C_01]...[C_09]'
'BR JAI S_ID BREACH_SEC WIDTH MIN_ELEV CREST_ELEV FAIL_TIME FURTHEST CLOSEST - Breach johnson and illes, '
'S_ID: string id, BREACH_SEC: breach section, WIDTH: width of main breach, MIN_ELEV: min breach elev, '
Expand Down Expand Up @@ -130,14 +132,16 @@ class BoundaryConditions(param.Parameterized):
'slope node closest to breach, ',
)
weirs = param.DataFrame(
default=None,
default=pd.DataFrame(data=[], columns=['WRS NUMBER', 'S_UPSTREAM', 'S_DOWNSTREAM', 'WS_UPSTREAM',
'WS_DOWNSTREAM', 'LENGTH', 'CREST_ELEV', 'HEIGHT']),
doc='WRS NUMBER S_UPSTREAM S_DOWNSTREAM WS_UPSTREAM WS_DOWNSTREAM LENGTH CREST_ELEV HEIGHT - Weir Parameters, '
'NUMBER: Weir number, S_UPSTREAM: string upstream of weir, S_DOWNSTREAM: string downstream of weir, '
'NUMBER: weir number, WS_UPSTREAM: weir string on upstream, WS_DOWNSTREAM: weir string on downstream, '
'LENGTH: length of weir, CREST_ELEV: crest elevation, HEIGHT: weir height',
)
flap_gates = param.DataFrame(
default=None,
default=pd.DataFrame(data=[], columns=['FGT NUMBER', 'USER', 'S_UPSTREAM', 'S_DOWNSTREAM', 'FS_UPSTREAM',
'FS_DOWNSTREAM', 'COEF_A', 'COEF_B', 'COEF_C', 'COEF_D', 'COEF_E']),
doc='FGT NUMBER USER S_UPSTREAM S_DOWNSTREAM FS_UPSTREAM FS_DOWNSTREAM COEF_A COEF_B COEF_C COEF_D COEF_E '
'COEF_F LENGTH - Flap gate parameters, NUMBER: flap gate number, USER: user defined parameters, '
'S_UPSTREAM: string upstream of flap, S_DOWNSTREAM: string downstream of flap, FS_UPSTREAM: flap '
Expand All @@ -146,7 +150,8 @@ class BoundaryConditions(param.Parameterized):
'COEF_F: coeficient F, LENGTH: length of flap gate',
)
sluice_gates = param.DataFrame(
default=None,
default=pd.DataFrame(data=[], columns=['SLS NUMBER', 'S_UPSTREAM', 'S_DOWNSTREAM', 'SS_UPSTREAM',
'SS_DOWNSTREAM', 'LENGTH', 'TS_OPENING']),
doc='SLS NUMBER S_UPSTREAM S_DOWNSTREAM SS_UPSTREAM SS_DOWNSTREAM LENGTH TS_OPENING - Sluice gate parameters, '
'NUMBER: sluice gate number, S_UPSTREAM: string upstream of sluice gate, S_DOWNSTREAM: string '
'downstream of sluice gate, SS_UPSTREAM: sluice string on upstream, SS_DOWNSTREAM: sluice string on '
Expand Down
18 changes: 8 additions & 10 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: adhmodel
channels:
- pyviz/label/earthsim
- pyviz/label/dev
- bokeh
- erdc/label/dev
- erdc
- conda-forge
- aquaveo
Expand All @@ -20,32 +20,30 @@ dependencies:
- holoviews>=1.12.3
- datashader>=0.7.0
- geoviews>=1.6.2
- panel>=0.5.0
- panel>=0.6.0
- bokeh>=1.1.0
- cartopy>=0.17.0
- xarray>=0.11.0
- colorcet>=1.0.0
- notebook>=5.5.0
- fiona
- gdal>=2.3.3
- rasterio==1.0.13
- gdal>=2.4.1
- rasterio>=1.0.24
- xmscore
- xmsinterp
- xmsgrid
- xmsmesh
- opencv
- quest==3.1.1
- ulmo==0.8.5
- quest>=3.1.1
- ulmo>=0.8.5
- lancet>=0.9.0
- param >=1.7.0
- pyct >=0.4.4
- setuptools >=30.3.0
- bokeh >=1.1.0
- pyviz_comms >=0.6.0
- nodejs >=9.11.1
- earthsim
- earthsim >=1.1.1a2
- jupyterlab
- genesis
- genesis>=0.0.5
# for testing
- pytest
- pyflakes
Expand Down
19 changes: 8 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='AdhModel',
version='0.3.0',
version='0.4.0',
packages=find_packages(),
include_package_data=True,
install_requires=[
Expand All @@ -15,36 +15,33 @@
'holoviews>=1.12.3',
'datashader>=0.7.0',
'geoviews>=1.6.2',
'panel>=0.5.0',
'panel>=0.6.0',
'bokeh>=1.1.0',
'cartopy>=0.17.0',
'xarray>=0.11.0',
'colorcet>=1.0.0',
'notebook>=5.5.0',
'fiona',
'gdal>=2.3.3',
'rasterio==1.0.13',
'gdal>=2.4.1',
'rasterio>=1.0.24',
'xmscore',
'xmsinterp',
'xmsgrid',
'xmsmesh',
'opencv',
'quest==3.1.1',
'ulmo==0.8.5',
'quest>=3.1.1',
'ulmo>=0.8.5',
'lancet>=0.9.0',
'param >=1.7.0',
'pyct >=0.4.4',
'setuptools >=30.3.0',
'bokeh >=1.1.0',
'pyviz_comms >=0.6.0',
'nodejs >=9.11.1',
'earthsim',
'earthsim>=1.1.1a2',
'jupyterlab',
'pyuit',
'pytest',
'pyflakes',
'nbsmoke',
'genesis'
'genesis>=0.0.5'
],
description="Parameterized class for reading/write/specifying all aspects of an Adaptive Hydraulics Model",
url="https://github.com/erdc/AdhModel",
Expand Down

0 comments on commit 2c5d49d

Please sign in to comment.