1- """This module contains functions related to creating a storm surge lookup table used
1+ """Functions to create a storm surge lookup table.
2+
3+ This module contains functions related to creating a storm surge lookup table used
24when running pyCIAM in "probabilistic" mode (i.e. running on many thousands of Monte
35Carlo samples of sea level rise trajectories). In this mode, calculating storm surge
46damages for each elevation slice, each year, each segment, each socioeconomic
@@ -61,8 +63,7 @@ def _get_lslr_rhdiff_range(
6163 mc_dim = "mc_sample_id" ,
6264 storage_options = {},
6365):
64- """Get the range of lslr and rhdiff that we need to model to cover the full range
65- across scenario/mcs.
66+ """Get range of lslr and rhdiff that we need to model to cover the full range.
6667
6768 The minimum LSLR value we'll need to model for the purposes of
6869 assessing storm damage is the minimum across sites of: the site-level maximum of "0
@@ -71,7 +72,6 @@ def _get_lslr_rhdiff_range(
7172 maximum experienced at any site in any year for all of the sceanrio/mcs we use in
7273 the binned LSL dataset.
7374 """
74-
7575 if isinstance (slr_0_years , int ):
7676 slr_0_years = [slr_0_years ] * len (slr_stores )
7777 assert len (slr_0_years ) == len (slr_stores )
@@ -149,18 +149,25 @@ def _get_lslr_rhdiff_range(
149149 # occasionally, the gumbel fit was negative, so we set the 1-year return to 0
150150 assert (rh_diff_max > 0 ).all ()
151151
152+ seg_vals = pc_in [seg_var ].values
152153 return xr .Dataset (
153154 {
154155 "lslr_by_seg" : (
155156 ("lslr" , seg_var ),
156- np .linspace (min_lslr , max_lslr , n_interp_pts_lslr ),
157+ np .repeat (
158+ np .linspace (min_lslr , max_lslr , n_interp_pts_lslr )[:, np .newaxis ],
159+ len (seg_vals ),
160+ axis = 1 ,
161+ ),
157162 ),
158163 "rh_diff_by_seg" : (
159164 ("rh_diff" , seg_var ),
160- np .linspace (0 , rh_diff_max , n_interp_pts_rhdiff ),
165+ np .repeat (
166+ np .linspace (0 , rh_diff_max , n_interp_pts_rhdiff )[:, np .newaxis ],
167+ len (seg_vals ),
168+ axis = 1 ,
169+ ),
161170 ),
162- },
163- coords = {
164171 "lslr" : np .arange (n_interp_pts_lslr ),
165172 "rh_diff" : np .arange (n_interp_pts_lslr ),
166173 seg_var : pc_in [seg_var ].values ,
@@ -245,7 +252,7 @@ def _save_storm_dam(
245252 slr_0_years = 2005 ,
246253 storage_options = {},
247254):
248- """Function to map over each chunk to run through damage calcs."""
255+ """Map over each chunk to run through damage calcs."""
249256 diff_ranges = _get_lslr_rhdiff_range (
250257 sliiders_store ,
251258 slr_stores ,
@@ -381,7 +388,9 @@ def create_surge_lookup(
381388 client_kwargs = {},
382389 storage_options = {},
383390):
384- """Create a storm surge lookup table which is used to define a linear spline
391+ """Create storm surge lookup table.
392+
393+ Create a storm surge lookup table which is used to define a linear spline
385394 function for each region modeled in pyCIAM. This output is not strictly necessary to
386395 run pyCIAM but substantially reduces computational expense when running pyCIAM on a
387396 large probabilistic ensemble of SLR trajectories.
@@ -460,7 +469,6 @@ def create_surge_lookup(
460469 -------
461470 Returns None, but saves storm surge lookup table to `surge_lookup_store`.
462471 """
463-
464472 to_save = _create_surge_lookup_skeleton_store (
465473 sliiders_store ,
466474 n_interp_pts_lslr ,
0 commit comments