Skip to content

Commit b442dcc

Browse files
authored
Merge pull request #17 from OpenGeoscience/new-initial-conditions
New initial conditions - 002 and 003
2 parents 9032af5 + 0c5704f commit b442dcc

10 files changed

Lines changed: 54 additions & 16 deletions

uvdat_flood_sim/__main__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def _ensure_dir_exists(ctx, param, value):
1818

1919

2020
@click.command(name='Dynamic Flood Simulation')
21+
@click.option(
22+
'--initial-conditions-id', '-i',
23+
type=click.Choice(['001', '002', '003']),
24+
default='001',
25+
help='Initialization for real-world emissions scenarios to represent future climate conditions',
26+
)
2127
@click.option(
2228
'--time-period', '-t',
2329
type=click.Choice(['2031-2050', '2041-2060']),
@@ -83,6 +89,7 @@ def _ensure_dir_exists(ctx, param, value):
8389
help='Library to use for writing result tiff'
8490
)
8591
def main(
92+
initial_conditions_id: Literal['001', '002', '003'],
8693
time_period: Literal['2031-2050', '2041-2060'],
8794
annual_probability: float,
8895
hydrograph_name: Literal['short_charles', 'long_charles'],
@@ -97,13 +104,14 @@ def main(
97104
logging.basicConfig(level=logging.INFO)
98105

99106
logger.info((
100-
f'Inputs: {time_period=}, {annual_probability=}, {hydrograph=}, '
107+
f'Inputs: {initial_conditions_id=}, {time_period=}, {annual_probability=}, {hydrograph=}, '
101108
f'{pet_percentile=}, {sm_percentile=}, {gw_percentile=}, '
102109
f'{output_path=}, {animation=}'
103110
))
104111
start = time.perf_counter()
105112

106113
flood = run_sim(
114+
initial_conditions_id=initial_conditions_id,
107115
time_period=time_period,
108116
annual_probability=annual_probability,
109117
hydrograph_name=hydrograph_name,
@@ -113,11 +121,18 @@ def main(
113121
gw_percentile=gw_percentile,
114122
)
115123

116-
write_multiframe_geotiff(flood, output_path, writer=tiff_writer)
124+
write_multiframe_geotiff(
125+
flood_results=flood,
126+
output_path=output_path / 'flood_simulation.tif',
127+
writer=tiff_writer,
128+
)
117129
logger.info(f'Done in {time.perf_counter() - start} seconds.')
118130

119131
if animation:
120-
animate_results(flood, output_path)
132+
animate_results(
133+
flood_results=flood,
134+
output_path=output_path / 'animation.gif',
135+
)
121136

122137

123138
if __name__ == '__main__':

uvdat_flood_sim/animate_results.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
import matplotlib.animation as ani
55

66

7-
def animate(results, output_folder):
8-
n_frames = results.shape[0]
9-
vmin, vmax = numpy.min(results), numpy.max(results)
7+
def animate(*, flood_results, output_path):
8+
n_frames = flood_results.shape[0]
9+
vmin, vmax = numpy.min(flood_results), numpy.max(flood_results)
1010

1111
fig, ax = plt.subplots()
1212
im = ax.imshow(
13-
results[0],
13+
flood_results[0],
1414
cmap='viridis',
1515
vmin=vmin,
1616
vmax=vmax,
1717
)
1818

1919
def update(i):
2020
ax.set_title(f'Hour={i + 1}')
21-
im.set_data(results[i])
21+
im.set_data(flood_results[i])
2222
return im
2323

2424
animation = ani.FuncAnimation(fig, update, n_frames, interval=1000)
2525
animation.save(
26-
output_folder / 'animation.gif',
26+
output_path,
2727
writer=ani.PillowWriter(fps=2)
2828
)
2929

uvdat_flood_sim/constants.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@
1212
PERCENTILES_PATH = DATA_FOLDER / 'flood_param_percentiles.json'
1313

1414
CESM_DATA = {
15-
'2031-2050': DATA_FOLDER / 'boston_cesm2-001_2031_2050.npy',
16-
'2041-2060': DATA_FOLDER / 'boston_cesm2-001_2041_2060.npy',
15+
'001': {
16+
'2031-2050': DATA_FOLDER / 'boston_cesm2-001_2031_2050.npy',
17+
'2041-2060': DATA_FOLDER / 'boston_cesm2-001_2041_2060.npy',
18+
},
19+
'002': {
20+
'2031-2050': DATA_FOLDER / 'boston_cesm2-002_2031_2050.npy',
21+
'2041-2060': DATA_FOLDER / 'boston_cesm2-002_2041_2060.npy',
22+
},
23+
'003': {
24+
'2031-2050': DATA_FOLDER / 'boston_cesm2-003_2031_2050.npy',
25+
'2041-2060': DATA_FOLDER / 'boston_cesm2-003_2041_2060.npy',
26+
},
1727
}
1828

1929
HYDROGRAPHS = dict(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:cdcf3d6bdd1353142437d4846b2c353334ced817be2e79c9d928f0b3cb287d99
3+
size 700928
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:2717b313bbab31da14c7b686a1f9e58999ae06f79e0a533a9e5738c204cf1a47
3+
size 700928
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:c951f8d0203642a5e73994fe70a4a8e7c42bab8bbd81941e3fec5b2001987ea8
3+
size 700928
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:3c84df4f798552160b4f3fd6700685d3a8152a8918b04e9942e355f998b1dbf9
3+
size 700928

uvdat_flood_sim/downscaling_prediction.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ def annual_precipitation_maxima(daily):
1616
return apm
1717

1818

19-
def downscale_boston_cesm(cesm_id, annual_probability):
20-
cesm_file = CESM_DATA[cesm_id] # CESM data is a projection of 20 years of daily weather conditions, spatially coarse over a large region
19+
def downscale_boston_cesm(initial_conditions_id, time_period, annual_probability):
20+
# CESM data is a projection of 20 years of daily weather conditions, spatially coarse over a large region
21+
cesm_file = CESM_DATA[initial_conditions_id][time_period]
2122
cesm_data = numpy.load(cesm_file, allow_pickle=True)
2223
with DOWNSCALING_MODEL_PATH.open('rb') as m:
2324
model = pickle.load(m)

uvdat_flood_sim/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
def run_sim(
1717
*,
18+
initial_conditions_id: Literal['001', '002', '003'],
1819
time_period: Literal['2031-2050', '2041-2060'],
1920
annual_probability: float,
2021
hydrograph_name: Literal['short_charles', 'long_charles'] | None = None,
@@ -49,7 +50,7 @@ def run_sim(
4950
ground_water = percentiles['gw'][gw_percentile]
5051

5152
# Extreme precipitation level in millimeters
52-
level = downscale_boston_cesm(time_period, annual_probability)
53+
level = downscale_boston_cesm(initial_conditions_id, time_period, annual_probability)
5354
logger.info(f'Downscaling prediction: precipitation level = {level}')
5455

5556
# Obtain discharge

uvdat_flood_sim/save_results.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ def large_image_write(results, output_path):
7878
def write_multiframe_geotiff(
7979
*,
8080
flood_results: NDArray[numpy.float32],
81-
output_folder: Path,
81+
output_path: Path,
8282
writer: Literal['rasterio', 'large_image'] = 'rasterio',
8383
) -> None:
84-
output_path = output_folder / 'flood_simulation.tif'
8584
if writer == 'rasterio':
8685
rasterio_write(flood_results, output_path)
8786
elif writer == 'large_image':

0 commit comments

Comments
 (0)