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

Style: Fix formatting of examples #3

Merged
merged 1 commit into from
May 3, 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
8 changes: 4 additions & 4 deletions examples/python/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@
print("State after initialization")
pprint.pprint(z.state)

print("\nPhase 1:\n" + "*"*8)
print("\nPhase 1:\n" + "*" * 8)

results = z.step_phase_1(300.0)
print("Transports:")
pprint.pprint(results)
print("State:")
pprint.pprint(z.state)

print("\nPhase 2:\n" + "*"*8)
print("\nPhase 2:\n" + "*" * 8)
results = z.step_phase_2(840.0)
print("Transports:")
pprint.pprint(results)
print("State:")
pprint.pprint(z.state)

print("\nPhase 3:\n" + "*"*8)
print("\nPhase 3:\n" + "*" * 8)
results = z.step_phase_3(300.0)
print("Transports:")
pprint.pprint(results)
print("State:")
pprint.pprint(z.state)

print("\nPhase 4:\n" + "*"*8)
print("\nPhase 4:\n" + "*" * 8)
results = z.step_phase_4(840.0, ship_volume_sea_to_lake=800.0)
print("Transports:")
pprint.pprint(results)
Expand Down
50 changes: 26 additions & 24 deletions examples/python/phase_multiple_lockages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,42 @@
}

constant_boundary_conditions = {
'head_lake': 0.0,
'temperature_lake': 15.0,
'temperature_sea': 15.0,
"head_lake": 0.0,
"temperature_lake": 15.0,
"temperature_sea": 15.0,
}

mitigation_parameters = {
'density_current_factor_lake': 0.25,
'density_current_factor_sea': 0.25,
'distance_door_bubble_screen_lake': 10.0,
'distance_door_bubble_screen_sea': 10.0,
'flushing_discharge_high_tide': 0.0,
'flushing_discharge_low_tide': 0.0,
'sill_height_lake': 0.5,
"density_current_factor_lake": 0.25,
"density_current_factor_sea": 0.25,
"distance_door_bubble_screen_lake": 10.0,
"distance_door_bubble_screen_sea": 10.0,
"flushing_discharge_high_tide": 0.0,
"flushing_discharge_low_tide": 0.0,
"sill_height_lake": 0.5,
}

# Initialize the lock
z = pyzsf.ZSFUnsteady(15.0, 0.0, **lock_parameters, **constant_boundary_conditions, **mitigation_parameters)
z = pyzsf.ZSFUnsteady(
15.0, 0.0, **lock_parameters, **constant_boundary_conditions, **mitigation_parameters
)

# Read the lockages from a file
df_lockages = pd.read_csv('lockages.csv', index_col=0)
lockages = list(df_lockages.to_dict('records'))
df_lockages = pd.read_csv("lockages.csv", index_col=0)
lockages = list(df_lockages.to_dict("records"))

# Go through all lockages
all_results = []

for parameters in lockages:
routine = int(parameters.pop('routine'))
t_open_lake = parameters.pop('t_open_lake')
t_open_sea = parameters.pop('t_open_sea')
t_level = parameters.pop('t_level')
t_flushing = parameters.pop('t_flushing')
routine = int(parameters.pop("routine"))
t_open_lake = parameters.pop("t_open_lake")
t_open_sea = parameters.pop("t_open_sea")
t_level = parameters.pop("t_level")
t_flushing = parameters.pop("t_flushing")

parameters['ship_volume_sea_to_lake'] = 0.0
parameters['ship_volume_lake_to_sea'] = 0.0
parameters["ship_volume_sea_to_lake"] = 0.0
parameters["ship_volume_lake_to_sea"] = 0.0

if routine == 1:
assert t_level > 0
Expand Down Expand Up @@ -76,11 +78,11 @@
if k.startswith(("volume_", "mass_")):
overall_results[k] = overall_results.get(k, 0.0) + v

overall_mass_to_sea += results['volume_to_sea'] * results['salinity_to_sea']
overall_mass_to_lake += results['volume_to_lake'] * results['salinity_to_lake']
overall_mass_to_sea += results["volume_to_sea"] * results["salinity_to_sea"]
overall_mass_to_lake += results["volume_to_lake"] * results["salinity_to_lake"]

overall_results['salinity_to_sea'] = overall_mass_to_sea / overall_results['volume_to_sea']
overall_results['salinity_to_lake'] = overall_mass_to_lake / overall_results['volume_to_lake']
overall_results["salinity_to_sea"] = overall_mass_to_sea / overall_results["volume_to_sea"]
overall_results["salinity_to_lake"] = overall_mass_to_lake / overall_results["volume_to_lake"]

overall_discharges = {}
for k, v in overall_results.items():
Expand Down
5 changes: 3 additions & 2 deletions wrappers/python/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ deps =
flake8-comprehensions
flake8-import-order
pep8-naming
commands = flake8 src tests setup.py
commands = flake8 src tests setup.py ../../examples/python


[testenv:black]
skip_install = True
deps =
click==8.0.4
black==19.10b
commands =
black --line-length 100 --target-version py36 --check --diff src tests setup.py
black --line-length 100 --target-version py36 --check --diff src tests setup.py ../../examples/python