data_creation
data_creation
¶
This package encapsulates Anne Hulsey's data processing pipeline.
Modules:
Name | Description |
---|---|
constants |
defined constants for this module |
query_NSHM |
get hazard data from the NSHM hazard API. |
NSHM_to_hdf5 |
helper functions for saving hazard data as an HDF5 file. |
extract_data |
helper functions to read the the NSHM hdf5. |
sa_parameter_generation |
derives the PGA, Sa,s, and Tc parameters from the NSHM hazard curves. |
dm_parameter_generation |
produces the magnitude and distances values for the parameter table. |
mean_magnitudes |
retrieves magnitude data from the NSHM hazard API |
gis_data |
geospatial analysis for the distance to faults |
util |
helper function for formatting the latitude and longitude labels |
constants
¶
This module contains constants.
AGG_LIST = ['mean', '0.9']
module-attribute
¶
ALL_SITES: Dict[str, Dict[str, Any]] = {location_by_id(_id)['name']: location_by_id(_id)for _id in LOCATION_LISTS[location_list]['locations']}
module-attribute
¶
CFM_URL = 'https://www.gns.cri.nz/assets/Data-and-Resources/Download-files/Community-Hazard-Model/NZ_CFM_v1_0_shapefile.zip'
module-attribute
¶
DEFAULT_RPS = [25, 50, 100, 250, 500, 1000, 2500]
module-attribute
¶
IMTL_LIST = [0.0001, 0.0002, 0.0004, 0.0006, 0.0008, 0.001, 0.002, 0.004, 0.006, 0.008, 0.01, 0.02, 0.04, 0.06, 0.08, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.5, 4.0, 4.5, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
module-attribute
¶
IMT_LIST = ['PGA', 'SA(0.1)', 'SA(0.15)', 'SA(0.2)', 'SA(0.25)', 'SA(0.3)', 'SA(0.35)', 'SA(0.4)', 'SA(0.5)', 'SA(0.6)', 'SA(0.7)', 'SA(0.8)', 'SA(0.9)', 'SA(1.0)', 'SA(1.25)', 'SA(1.5)', 'SA(1.75)', 'SA(2.0)', 'SA(2.5)', 'SA(3.0)', 'SA(3.5)', 'SA(4.0)', 'SA(4.5)', 'SA(5.0)', 'SA(6.0)', 'SA(7.5)', 'SA(10.0)']
module-attribute
¶
LOCATION_REPLACEMENTS: dict[str, LocationReplacement] = {'Auckland': LocationReplacement('Auckland', ['Manukau City']), 'Tauranga': LocationReplacement('Tauranga', ['Mount Maunganui']), 'Wellington': LocationReplacement('Wellington', ['Wellington CBD']), 'Lower Hutt': LocationReplacement('Lower Hutt', ['Wainuiomata', 'Eastbourne'])}
module-attribute
¶
LOWER_BOUND_PARAMETERS: dict[str, Any] = {'controlling_site': 'Auckland', 'controlling_percentile': 0.9}
module-attribute
¶
PGA_N_DP = 2
module-attribute
¶
PGA_REDUCTIONS: dict[str, PGA_reductions] = {'IV': PGA_reductions('IV', 0.076, 0.123, 0.198), 'V': PGA_reductions('V', 0.114, 0.227, 0.137), 'VI': PGA_reductions('VI', 0.085, 0.171, 0.133)}
module-attribute
¶
POE_TO_RP = {poe: rpfor (rp, poe) in RP_TO_POE.items()}
module-attribute
¶
POLYGON_PATH = Path(RESOURCES_FOLDER) / 'pipeline/v1/input_data' / 'polygons_locations.geojson'
module-attribute
¶
PSV_N_DP = 2
module-attribute
¶
RP_TO_POE = {10000: ProbabilityEnum._05_PCT_IN_50YRS, 5000: ProbabilityEnum._1_PCT_IN_50YRS, 2500: ProbabilityEnum._2_PCT_IN_50YRS, 1000: ProbabilityEnum._5_PCT_IN_50YRS, 500: ProbabilityEnum._10_PCT_IN_50YRS, 250: ProbabilityEnum._18_PCT_IN_50YRS, 100: ProbabilityEnum._39_PCT_IN_50YRS, 50: ProbabilityEnum._63_PCT_IN_50YRS, 25: ProbabilityEnum._86_PCT_IN_50YRS}
module-attribute
¶
SAS_N_DP = 2
module-attribute
¶
SITE_CLASSES: dict[str, SiteClass] = {'I': SiteClass('I', 750, 'Site Class I', 750, np.nan), 'II': SiteClass('II', 525, 'Site Class II', 450, 750), 'III': SiteClass('III', 375, 'Site Class III', 300, 450), 'IV': SiteClass('IV', 275, 'Site Class IV', 250, 300), 'V': SiteClass('V', 225, 'Site Class V', 200, 250), 'VI': SiteClass('VI', 175, 'Site Class VI', 150, 200)}
module-attribute
¶
TC_N_SF = 2
module-attribute
¶
VS30_LIST = [SITE_CLASSES[sc].representative_vs30 for sc in SITE_CLASSES.keys()]
module-attribute
¶
akl_location_id = 'srg_29'
module-attribute
¶
location_grid = 'NZ_0_1_NB_1_1'
module-attribute
¶
location_list = 'SRWG214'
module-attribute
¶
LocationReplacement
¶
PGA_reductions
¶
Bases: NamedTuple
Source code in nzssdt_2023/data_creation/constants.py
28 29 30 31 32 |
|
SiteClass
¶
Bases: NamedTuple
Source code in nzssdt_2023/data_creation/constants.py
15 16 17 18 19 20 |
|
lat_lon_from_id(id)
¶
Source code in nzssdt_2023/data_creation/constants.py
35 36 |
|
query_NSHM
¶
Functions to get hazard data from the NSHM hazard API.
log = logging.getLogger(__name__)
module-attribute
¶
create_sites_df(named_sites: bool = True, site_list: Optional[List[str]] = None, cropped_grid: bool = False, grid_limits: Tuple[float, float, float, float] = (-np.inf, np.inf, -np.inf, np.inf), site_limit: int = 0) -> pdt.DataFrame
¶
creates a pd dataframe of the sites of interest
Parameters:
Name | Type | Description | Default |
---|---|---|---|
named_sites
|
bool
|
if True returns SRG sites, False returns lat/lon sites |
True
|
site_list
|
Optional[List[str]]
|
specifies a subset of SRG sites |
None
|
cropped_grid
|
bool
|
True returns all lat/lon sites, False crops to grid_limits |
False
|
grid_limits
|
Tuple[float, float, float, float]
|
set outer bound coordinates of the grid [min_lat, max_lat, min_lon, max_lon] |
(-np.inf, np.inf, -np.inf, np.inf)
|
site_limit
|
int
|
for creating test fixtures |
0
|
Returns: a dataframe idx: sites, cols: ['latlon', 'lat', 'lon']
Source code in nzssdt_2023/data_creation/query_NSHM.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
retrieve_hazard_curves(sites: pdt.DataFrame, vs30_list: List[int], imt_list: List[str], agg_list: List[str], hazard_id: str) -> Tuple[npt.NDArray, List[float]]
¶
retrieves the hazard curves for the sites, vs30s, imts, and aggs of interest
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sites
|
pdt.DataFrame
|
idx: sites, cols: ['latlon', 'lat', 'lon'] |
required |
vs30_list
|
List[int]
|
vs30s of interest |
required |
imt_list
|
List[str]
|
imts of interest |
required |
agg_list
|
List[str]
|
agg types of interest (e.g., mean or "0.f" where f is a fractile |
required |
hazard_id
|
str
|
query the NSHM |
required |
Returns:
Type | Description |
---|---|
Tuple[npt.NDArray, List[float]]
|
np.array hazard curves indexed by [n_vs30s, n_sites, n_imts, n_imtls, n_aggs] list intensities included |
Source code in nzssdt_2023/data_creation/query_NSHM.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
NSHM_to_hdf5
¶
helper functions for producing an HDF5 file for the NZSSDT tables
g = 9.80665
module-attribute
¶
acc_to_disp(acc, t)
¶
:param acc: float intensity in acceleration [g] :param t: float time in seconds
:return: float intensity in displacement [m]
Source code in nzssdt_2023/data_creation/NSHM_to_hdf5.py
45 46 47 48 49 50 51 52 53 54 |
|
acc_to_vel(acc, t)
¶
:param acc: float intensity in acceleration [g] :param t: float time in seconds
:return: float intensity in velocity [m/s]
Source code in nzssdt_2023/data_creation/NSHM_to_hdf5.py
57 58 59 60 61 62 63 64 65 66 |
|
add_uniform_hazard_spectra(data: Dict[str, Any], hazard_rps: Optional[List[int]] = None) -> Dict[str, Any]
¶
Adds uniform hazard spectra to the data dictionary, based on the input hazard_rps
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Dict[str, Any]
|
dictionary containing hazard curves and metadata for vs30, sites, intensity measures |
required |
hazard_rps
|
Optional[List[int]]
|
list of return periods of interest (inverse of annual probability of exceedance, apoe) |
None
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
updated dictionary includes design intensities |
If hazard_rps is None (default) or empty, the default return periods, constants.DEFAULT_RPS
, will be used.
Source code in nzssdt_2023/data_creation/NSHM_to_hdf5.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
calculate_hazard_design_intensities(data: Dict[str, Any], hazard_rps: Union[List[int], npt.NDArray], intensity_type='acc')
¶
calculate design intensities based on an annual probability of exceedance (APoE)
Todo
The hazard curve is interpolated linearly in logspace. However, this function does that in natural log and converts back with the exponent It should be done in log base10 and converted back through 10**x
:param data: dictionary containing hazard curves and metadata for vs30, sites, intensity measures :param hazard_rps: list containing the desired return periods (1 / APoE)
:return: np arrays for all intensities from the hazard curve realizations and stats (mean and quantiles)
Source code in nzssdt_2023/data_creation/NSHM_to_hdf5.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
convert_imtls_to_disp(acc_imtls)
¶
converts the acceleration intensity measure types and levels to spectral displacements
:param acc_imtls: dictionary keys: acc intensity measure names, values: intensity levels
:return: dictionary keys: disp intensity measure names, values: intensity levels
Source code in nzssdt_2023/data_creation/NSHM_to_hdf5.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
create_hcurve_dictionary(sites, vs30_list, imt_list, imtl_list, agg_list, hcurves)
¶
compile hazard data into a dictionary
:param sites: pd dataframe idx: sites, cols: ['latlon', 'lat', 'lon'] :param vs30_list: list vs30s of interest :param imt_list: list imts of interest :param imtl_list: list intensity levels :param agg_list: list agg types of interest (e.g., mean or "0.f" where f is a fractile :param hcurves:
:return: dictionary hazard curves including metadata
Source code in nzssdt_2023/data_creation/NSHM_to_hdf5.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
period_from_imt(imt)
¶
retrieves period in seconds from the intensity measure type
:param imt: string intensity measure type
:return: float period
Source code in nzssdt_2023/data_creation/NSHM_to_hdf5.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
query_NSHM_to_hdf5(hf_name: Path, hazard_id: str, site_list: pd.DataFrame, site_limit: int = 0)
¶
Query the NSHM and save the results to an hdf5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hf_name
|
Path
|
name of hdf5 file with hazard curve data |
required |
hazard_id
|
str
|
NSHM model id |
required |
site_list
|
pd.DataFrame
|
sites to include in the sa parameter table |
required |
site_limit
|
int
|
for building test fixtures |
0
|
Todo
- Chris BC, the default hazard_id should actually be part of your version control
Source code in nzssdt_2023/data_creation/NSHM_to_hdf5.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
save_hdf(hf_name, data)
¶
Saves the data dictionary as an hdf5 file for later use.
:param hf_name: name of the hdf5 file :param data: dictionary containing hazard curves and metadata for vs30, sites, intensity measures, and design intensities
Source code in nzssdt_2023/data_creation/NSHM_to_hdf5.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
extract_data
¶
This module extracts the data and metadata in the hdf5 containing the NSHM data.
extract_APoEs(data_file: str | Path) -> Tuple[List[str], List[int]]
¶
Extract uniform hazard spectra annual probabilities of exceedance from the hdf5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_file
|
str | Path
|
name of hazard hdf5 file |
required |
Returns:
Name | Type | Description |
---|---|---|
APoEs |
List[str]
|
list of APoE strings |
hazard_rp_list |
List[int]
|
list of return periods |
Source code in nzssdt_2023/data_creation/extract_data.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
extract_quantiles(data_file: str | Path) -> List[float]
¶
Extract hazard quantiles from the hdf5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_file
|
str | Path
|
name of hazard hdf5 file |
required |
Returns:
Name | Type | Description |
---|---|---|
quantiles |
List[float]
|
list of quantiles |
Source code in nzssdt_2023/data_creation/extract_data.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
extract_sites(data_file: str | Path) -> pdt.DataFrame
¶
Extract sites from the hdf5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_file
|
str | Path
|
name of hazard hdf5 file |
required |
Returns:
Name | Type | Description |
---|---|---|
sites |
pdt.DataFrame
|
dataframe of sites with lat/lons |
Source code in nzssdt_2023/data_creation/extract_data.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
extract_spectra(data_file: str | Path) -> Tuple[npt.NDArray, dict]
¶
Extract the uniform hazard spectra from the hdf5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_file
|
str | Path
|
name of hazard hdf5 file |
required |
Returns:
Name | Type | Description |
---|---|---|
acc_spectra |
npt.NDArray
|
acceleration spectra (dimensions: vs30, site, return period, statistic) |
imtls |
dict
|
keys: intensity measures e.g., SA(1.0), values: list of intensity levels |
Source code in nzssdt_2023/data_creation/extract_data.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
extract_vs30s(data_file: str | Path) -> List[int]
¶
Extract the vs30 values from the hdf5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_file
|
str | Path
|
name of hazard hdf5 file |
required |
Returns:
Name | Type | Description |
---|---|---|
vs30_list |
List[int]
|
list of vs30s included in hdf5 |
Source code in nzssdt_2023/data_creation/extract_data.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
sa_parameter_generation
¶
This module derives the PGA, Sa,s, Tc, and Td parameters from the NSHM hazard curves.
PGA_REDUCTION_ENABLED = True
module-attribute
¶
PGA_ROUNDING_ENABLED = True
module-attribute
¶
log = logging.getLogger(__name__)
module-attribute
¶
Td_fit_error(td: float, relevant_periods: npt.NDArray, relevant_spectrum: npt.NDArray, pga=float, sas=float, tc=float) -> float
¶
Calculate the spectral fit error term for the selected td value. The error is evaluated as the sum of the square root of the absolute difference between the fit spectrum and the original spectrum, at relevant periods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
td
|
float
|
spectral-velocity-plateau corner period [seconds] |
required |
relevant_periods
|
npt.NDArray
|
periods included in the relevant domain [seconds] |
required |
relevant_spectrum
|
npt.NDArray
|
spectrum over the relevant periods [g] |
required |
pga
|
peak ground acceleration [g] |
float
|
|
sas
|
short-period spectral acceleration [g] |
float
|
|
tc
|
spectral-acceleration-plateau corner period [seconds] |
float
|
Returns:
Name | Type | Description |
---|---|---|
error |
float
|
error term |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
acc_spectra_to_vel(acc_spectra: npt.NDArray, imtls: dict) -> npt.NDArray
¶
Convert uniform hazard spectra from acceleration to velocity
Parameters:
Name | Type | Description | Default |
---|---|---|---|
acc_spectra
|
npt.NDArray
|
acceleration spectra |
required |
imtls
|
dict
|
keys: intensity measures e.g., SA(1.0), values: list of intensity levels |
required |
Returns:
Name | Type | Description |
---|---|---|
vel_spectra |
npt.NDArray
|
velocity spectra |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
calc_R_PGA(pga: float, site_class: str) -> float
¶
Calculate the reduction factor for the peak ground acceleration (Eq. C3.15)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pga
|
float
|
peak ground acceleration [g] |
required |
site_class
|
str
|
roman numeral |
required |
Returns:
Name | Type | Description |
---|---|---|
r_pga |
float
|
reduction factor for peak ground acceleration |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
calc_reduced_PGA(pga: float, site_class: str) -> float
¶
Calculate the adjusted peak ground acceleration (Eq. C3.14)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pga
|
float
|
peak ground acceleration [g] |
required |
site_class
|
str
|
roman numeral |
required |
Returns:
Name | Type | Description |
---|---|---|
reduced_pga |
float
|
adjusted peak ground acceleration |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
calculate_parameter_arrays(data_file: str | Path) -> Tuple[npt.NDArray, npt.NDArray, npt.NDArray, npt.NDArray]
¶
Calculate PGA, Sa,s, and Tc values for uniform hazard spectra in hdf5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_file
|
str | Path
|
name of hazard hdf5 file |
required |
Returns:
Name | Type | Description |
---|---|---|
PGA |
npt.NDArray
|
adjusted peak ground acceleration [g] (Eqn C3.14) |
Sas |
npt.NDArray
|
short-period spectral acceleration [g] (90% of maximum spectral acceleration) |
PSV |
npt.NDArray
|
95% of maximum spectral velocity [m/s] |
Tc |
npt.NDArray
|
spectral-acceleration-plateau corner period [seconds] |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
choose_site_class(vs30: Union[int, float], lower_bound: bool = False) -> str
¶
Returns the site class for the selected vs30 value Site class definitions can be found in TS Table 3.1
Note that the site class returned here is based on vs30 alone, i.e. the a) clauses in Table 3.1
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vs30
|
Union[int, float]
|
vs30 of interest [m/s] |
required |
lower_bound
|
bool
|
False returns the site class as defined in TS Table 3.1 True returns the alternate site class at the vs30 discontinuity |
False
|
Returns:
Name | Type | Description |
---|---|---|
sc |
str
|
site class |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
create_mean_sa_table(PGA, Sas, PSV, Tc, mean_Td, site_list, vs30_list, hazard_rp_list)
¶
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
|
create_sa_table(hf_path: Path, lower_bound_flags: bool = True) -> pdt.DataFrame
¶
Creates a pandas dataframe with the sa parameters
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hf_path
|
Path
|
hdf5 filename, containing the hazard data |
required |
lower_bound_flags
|
bool
|
True includes the metadata for updating the lower bound hazard |
True
|
Returns:
Name | Type | Description |
---|---|---|
df |
pdt.DataFrame
|
dataframe of sa parameters |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 |
|
fit_Td(spectrum: npt.NDArray, periods: npt.NDArray, pga: float, sas: float, tc: float) -> float
¶
Fit the Td value to obtain the best fit over the response spectrum
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
npt.NDArray
|
acceleration spectrum [g] |
required |
periods
|
npt.NDArray
|
periods over which spectrum is defined [seconds] |
required |
pga
|
float
|
peak ground acceleration [g] |
required |
sas
|
float
|
short-period spectral acceleration [g] |
required |
tc
|
float
|
spectral-acceleration-plateau corner period [seconds] |
required |
Returns:
Name | Type | Description |
---|---|---|
td |
float
|
spectral-velocity-plateau corner period [seconds] |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
fit_Td_array(PGA: npt.NDArray, Sas: npt.NDArray, Tc: npt.NDArray, acc_spectra: npt.NDArray, imtls: dict, site_list: List[str], vs30_list: List[int], hazard_rp_list: List[int], i_stat: int = 0, sites_of_interest: Optional[List[str]] = None) -> npt.NDArray
¶
Fit the Td values for all sites, site classes and APoE of interest
Parameters:
Name | Type | Description | Default |
---|---|---|---|
PGA
|
npt.NDArray
|
adjusted peak ground acceleration [g] (Eqn C3.14) |
required |
Sas
|
npt.NDArray
|
short-period spectral acceleration [g] (90% of maximum spectral acceleration) |
required |
Tc
|
spectral-acceleration-plateau corner period [seconds] |
required | |
acc_spectra
|
npt.NDArray
|
acceleration spectra [g] |
required |
imtls
|
dict
|
keys: intensity measures e.g., SA(1.0), values: list of intensity levels |
required |
site_list
|
List[str]
|
sites included in acc_spectra |
required |
vs30_list
|
List[int]
|
vs30s included in acc_spectra |
required |
hazard_rp_list
|
List[int]
|
return periods included in acc_spectra |
required |
i_stat
|
int
|
spectra index for stats in ['mean'] + quantiles |
0
|
sites_of_interest
|
Optional[List[str]]
|
subset of sites |
None
|
Returns:
Name | Type | Description |
---|---|---|
Td |
npt.NDArray
|
spectral-velocity-plateau corner period [seconds] |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
interpolate_spectra(spectra: npt.NDArray, imtls: dict, dt: float = 0.1) -> Tuple[npt.NDArray, npt.NDArray]
¶
Linearly interpolate spectra over the original domain, in increments of dt
Inputs
spectra: acceleration spectra imtls: keys: intensity measures e.g., SA(1.0), values: list of intensity levels dt: period increments at which to interpolate
Returns:
Name | Type | Description |
---|---|---|
new_spectra |
npt.NDArray
|
interpolated spectra |
new_period_list |
npt.NDArray
|
periods at which the spectra are defined |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
reduce_PGAs(PGA: npt.NDArray) -> npt.NDArray
¶
Apply peak ground acceleration adjustments to all PGA values (Eq. C3.14)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
PGA
|
npt.NDArray
|
peak ground acceleration |
required |
Returns:
Name | Type | Description |
---|---|---|
reduced_PGA |
npt.NDArray
|
adjusted peak ground acceleration |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
relevant_spectrum_domain(spectrum: npt.NDArray, periods: npt.NDArray, tc: float, inclusive: bool = False) -> Tuple[npt.NDArray, npt.NDArray]
¶
Return the spectrum over the relevant domain for potential values of Td
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spectrum
|
npt.NDArray
|
acceleration spectrum [g] |
required |
periods
|
npt.NDArray
|
periods as which spectrum is defined [seconds] |
required |
tc
|
float
|
spectral-acceleration-plateau corner period [seconds] |
required |
inclusive
|
bool
|
if true, the range includes the tc+0.5 value (e.g. for Tc+0.5 = 0.75, 0.7 <= Td rather than 0.8 <= Td) |
False
|
Returns:
Name | Type | Description |
---|---|---|
relevant_spectrum |
npt.NDArray
|
spectrum over the relevant periods |
relevant_periods |
npt.NDArray
|
periods included in the relevant domain |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
remove_irrelevant_location_replacements(site_list: List[str], location_replacements: dict[str, LocationReplacement]) -> dict[str, LocationReplacement]
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site_list
|
List[str]
|
list of sites included in the sa tables |
required |
location_replacements
|
dict[str, LocationReplacement]
|
list of the location replacements |
required |
Returns:
Name | Type | Description |
---|---|---|
location_replacements |
dict[str, LocationReplacement]
|
a new dictionary of replacements |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
|
replace_relevant_locations(df: pdt.DataFrame, print_locations: bool = False) -> pdt.DataFrame
¶
replace parameters for locations that are tied to other locations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
pdt.DataFrame
|
mutli-index dataframe including all sites, annual probabilities of exceedance, and site classes |
required |
print_locations
|
bool
|
if True, print relevant locations before and after replacements |
False
|
Returns:
Name | Type | Description |
---|---|---|
df |
pdt.DataFrame
|
mutli-index dataframe with replaced locations |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
|
sig_figs(x: Union[float, List[float], npt.NDArray], n: int) -> npt.NDArray
¶
Rounds all values of x to n significant figures
Inputs
x: float value(s) n: number of significant digits
Returns:
Name | Type | Description |
---|---|---|
x_rounded |
npt.NDArray
|
x rounded to n digits |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
uhs_value(period: Union[float, npt.NDArray], PGA: float, Sas: float, Tc: float, Td: float) -> float
¶
Derive the spectral acceleration Sa(T) at a given period (T), based on the seismic demand parameters. Sa(T) equations come from TS Eq. 3.2-3.5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
period
|
Union[float, npt.NDArray]
|
period, T, a which the spectral acceleration is calculated [seconds] |
required |
PGA
|
float
|
peak ground acceleration [g] |
required |
Sas
|
float
|
short-period spectral acceleration [g] |
required |
Tc
|
float
|
spectral-acceleration-plateau corner period [seconds] |
required |
Td
|
float
|
spectral-velocity-plateau corner period [seconds] |
required |
Todo
this works (i.e. it handles the code as it's called now) - but I think there's a better way to do this sort of thing whe your data is in numpy arrays see: https://stackoverflow.com/questions/42594695/ how-to-apply-a-function-map-values-of-each-element-in-a-2d-numpy-array-matrix
Returns:
Name | Type | Description |
---|---|---|
SaT |
float
|
spectral acceleration [g] |
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
update_lower_bound_sa(mean_df, PGA, Sas, Tc, PSV, acc_spectra, imtls, vs30_list, hazard_rp_list, quantile_list)
¶
Source code in nzssdt_2023/data_creation/sa_parameter_generation.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
|
dm_parameter_generation
¶
This module compiles the magnitude and distances values for the parameter table.
TODO
extract_m_values
uses/builds entire mean mag tables independent of what locations and PoEs are requested in function args.- Consolidate the mean mag csv files into one cache rather than 3 separate files. Any locations/poes not available can be looked up and added to the cache.
create_D_and_M_df(site_list: List[str], rp_list: List[int] = DEFAULT_RPS, no_cache: bool = False, legacy: bool = False) -> pdt.DataFrame
¶
Compiles the D and M parameter tables
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site_list
|
List[str]
|
list of sites of interest |
required |
rp_list
|
|
list of return periods of interest |
DEFAULT_RPS
|
no_cache
|
bool
|
if True, ignore the cache file |
False
|
legacy
|
bool
|
if True double rounds magnitudes to match original mean mags from v1 of the workflow. |
False
|
Returns:
Name | Type | Description |
---|---|---|
D_and_M |
pdt.DataFrame
|
dataframe of the d and m tables |
Source code in nzssdt_2023/data_creation/dm_parameter_generation.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
extract_m_values(site_names: List[str], freqs: List[str], agg: AggregationEnum, no_cache: bool = False, legacy: bool = False) -> pdt.DataFrame
¶
Extracts the magnitudes from the input .csv folder into a manageable dataframe
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site_names
|
List[str]
|
names of sites of interest |
required |
frequencies
|
list of the frequencys (1/return period) of interest |
required | |
agg
|
AggregationEnum
|
the aggregate hazard curve at which to calculate mean magnitude (e.g., "mean", "0.9", ...) |
required |
no_cache
|
bool
|
if True, ignore the cache file |
False
|
legacy
|
bool
|
if True double rounds magnitudes to match origional mean mags from v1 of the workflow. |
False
|
Returns:
Name | Type | Description |
---|---|---|
mags |
pdt.DataFrame
|
mean magnitudes |
The format of the frequencies entries is e.g. "APoE: 1/25"
If no_cache is False then the mean magnitudes will be looked up in a cache file. If not found there, they will be calculated and added to the cache. The cache file is in the WORKING_FOLDER named mags_{agg}.csv where {agg} is the hazard curve aggregate.
site names are location names or lat~lon codes e.g. "Pukekohe" or "-45.500~166.600"
Source code in nzssdt_2023/data_creation/dm_parameter_generation.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
mean_magnitudes
¶
This module contains functions for extracting mean magnitudes from disaggregations and packaging into DataFrame objects.
DTYPE = float
module-attribute
¶
IMT = 'PGA'
module-attribute
¶
INV_TIME = 1.0
module-attribute
¶
VS30 = 275
module-attribute
¶
coded_locations_with_id = [CodedLocation(*lat_lon_from_id(_id), 0.001) for _id in LOCATION_LISTS['ALL']['locations']]
module-attribute
¶
df = get_mean_mag_df(hazard_id, locations, poes, hazard_agg)
module-attribute
¶
hazard_agg = model.AggregationEnum.MEAN
module-attribute
¶
hazard_id = 'NSHM_v1.0.4_mag'
module-attribute
¶
imts = ['PGA']
module-attribute
¶
location_codes_with_id = [loc.code for loc in coded_locations_with_id]
module-attribute
¶
locations = [CodedLocation(*lat_lon_from_id(_id), 0.001) for _id in LOCATION_LISTS['SRWG214']['locations']]
module-attribute
¶
mean_mag_filepath = 'mean_mag.csv'
module-attribute
¶
poes = [model.ProbabilityEnum._2_PCT_IN_50YRS, model.ProbabilityEnum._5_PCT_IN_50YRS, model.ProbabilityEnum._10_PCT_IN_50YRS, model.ProbabilityEnum._18_PCT_IN_50YRS, model.ProbabilityEnum._39_PCT_IN_50YRS, model.ProbabilityEnum._63_PCT_IN_50YRS, model.ProbabilityEnum._86_PCT_IN_50YRS]
module-attribute
¶
vs30s = [275]
module-attribute
¶
calculate_mean_magnitude(disagg: npt.NDArray, bins: npt.NDArray)
¶
Calculate the mean magnitude for a single site using the magnitude disaggregation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
disaggregation
|
The probability contribution to hazard of the magnitude bins (in apoe). |
required | |
bins
|
npt.NDArray
|
The bin centers of the magnitude disaggregation. |
required |
Returns:
Type | Description |
---|---|
the mean magnitude |
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
empty_mean_mag_df(poes: List[model.ProbabilityEnum]) -> pd.DataFrame
¶
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
213 214 215 216 217 |
|
frequency_to_poe(frequency: str) -> model.ProbabilityEnum
¶
converts a frequency string (e.g., "APoE: 1/25") to a annual probability of exceedance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
frequency
|
str
|
the frequency string |
required |
Returns:
Type | Description |
---|---|
model.ProbabilityEnum
|
the annual probability of exceedance |
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
get_loc_id_and_name(location_code)
¶
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
32 33 34 35 36 37 38 39 40 41 42 43 |
|
get_mean_mag(hazard_id: str, location: CodedLocation, poe: model.ProbabilityEnum, hazard_agg: model.AggregationEnum, legacy: bool = False) -> float
¶
Get a mean mantitudefor a single location and poe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hazard_id
|
str
|
the toshi-hazard-post ID of the hazard model from which to get disaggregations. |
required |
location
|
CodedLocation
|
the location at which to calculate mean magnitude. |
required |
poe
|
model.ProbabilityEnum
|
the annual probability of exceedence at which to calculate mean magnitude. |
required |
hazard_agg
|
model.AggregationEnum
|
the hazard aggregate (e.g. mean or a fractile) at which to calculate mean magnitude. |
required |
legacy
|
bool
|
if True double rounds magnitude to match origional mean mag from v1 of the workflow. |
False
|
Returns:
Type | Description |
---|---|
float
|
the mean magnitue |
The legacy calculation is necessary to match the origional mean magnitude dataframe becuase the orignal csv file had magnitudes rounded to 2 decimal places. When the final ouput is rounded to one decimal place, this results in rounding errors. For example:
>>> round(5.948071422587211, 1)
5.9
>>> round(round(5.948071422587211, 2), 1)
6.0
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
get_mean_mag_df(hazard_id: str, locations: List[CodedLocation], poes: List[model.ProbabilityEnum], hazard_agg: model.AggregationEnum, legacy: bool = False) -> pd.DataFrame
¶
Get the mean magnitude table for the requested locations and annual probabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hazard_id
|
str
|
the toshi-hazard-post ID of the hazard model from which to get disaggregations. |
required |
locations
|
List[CodedLocation]
|
the locations at which to calculate mean magnitudes. |
required |
poes
|
List[model.ProbabilityEnum]
|
the annual probabilities of exceedences at which to calculate mean magnitudes. |
required |
hazard_agg
|
model.AggregationEnum
|
the hazard aggregate (e.g. mean or a fractile) at which to calculate mean magnitudes. |
required |
legacy
|
bool
|
if True double rounds magnitudes to match origional mean mags from v1 of the workflow. |
False
|
Returns:
Type | Description |
---|---|
pd.DataFrame
|
the mean magnitudes. The DataFrame index is the location name and the columns are frequencies. |
The legacy calculation is necessary to match the original mean magnitude dataframe because the original csv file had magnitudes rounded to 2 decimal places. When the final output is rounded to one decimal place, this results in rounding errors. For example:
>>> round(5.948071422587211, 1)
5.9
>>> round(round(5.948071422587211, 2), 1)
6.0
NB: "APoE in the column name is a misnomer as they are approximate return frequencies not probabilities. Magnitudes are rounded to the nearest decimal. The rounding error introduced in the original workflow (incurred by rounding to the nearest 2 decimal places and then nearest 1) have been reproduced here to ensure output is stable.
The format of the output DataFrame is:
APoE: 1/25 APoE: 1/50 APoE: 1/100 APoE: 1/250 APoE: 1/500 APoE: 1/1000 APoE: 1/2500
Kaitaia 5.7 5.8 5.8 5.9 6.0 6.0 6.1
Kerikeri 5.7 5.8 5.9 5.9 6.0 6.0 6.1
... ... ... ... ... ... ... ...
Bluff 6.7 6.8 6.9 7.0 7.0 7.1 7.1
Oban 6.7 6.8 6.9 7.0 7.1 7.2 7.3
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|
get_mean_mags(hazard_id: str, locations: Iterable[CodedLocation], vs30s: Iterable[int], imts: Iterable[str], poes: Iterable[model.ProbabilityEnum], hazard_agg: model.AggregationEnum) -> Generator[Dict[str, Any], None, None]
¶
The mean magnitudes for a collection of sites.
This function uses toshi-hazard-store
to retrieve disaggregations from the database and therefore requires read
access. It assumes all disaggregations are done for magnitude only (i.e., not distance, epsilon, etc.)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hazard_id
|
str
|
the hazard id of the model in the database. |
required |
locations
|
Iterable[CodedLocation]
|
the site locations for which to obtain the mean magnitude. |
required |
vs30s
|
Iterable[int]
|
the site vs30 values for which to obtain the mean magnitude. |
required |
imts
|
Iterable[str]
|
the intensity measure types for which to obtain the mean magnitude. |
required |
poes
|
Iterable[model.ProbabilityEnum]
|
the probability of exeedances for which to obtain the mean magnitude. |
required |
aggregate
|
the hazard curve aggregation at which to obtain the mean magnitude (e.g. mean, 20th percentile, etc.) |
required |
Yields:
Type | Description |
---|---|
Dict[str, Any]
|
A dict for each location, vs30, imt, poe, aggregate with keys:
location_id: str, the locaiton id from |
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
get_sorted_rp_strs(poes: List[model.ProbabilityEnum]) -> List[str]
¶
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
207 208 209 210 |
|
poe_to_rp(apoe: model.ProbabilityEnum) -> int
¶
Converts annual probability to a rounded return period. The return periods are "conventional" return periods used by the hazard and risk community that are roughly equivalent to the (more exact) annual probabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
apoe
|
model.ProbabilityEnum
|
annual probability of exceedance |
required |
Returns:
Type | Description |
---|---|
int
|
the approximate return period rounded to the nearest "conventional" number. |
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
prob_to_rate(prob: npt.NDArray) -> npt.NDArray
¶
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
71 72 |
|
read_mean_mag_df(filepath: Union[Path, str]) -> pd.DataFrame
¶
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
198 199 200 |
|
rp_to_freqstr(rp: int)
¶
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
203 204 |
|
site_name_to_coded_location(site_name: str) -> CodedLocation
¶
get the coded location from the site name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
site_name
|
str
|
the site name |
required |
Returns:
Type | Description |
---|---|
CodedLocation
|
the coded location |
site names are e.g. "Pukekohe", "Tairua", "-45.600~166.600", or "-45.500~166.600"
Source code in nzssdt_2023/data_creation/mean_magnitudes.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
gis_data
¶
This module creates .geojson version of all gis data and calculates D (distance) values between polygons and faults
log = logging.getLogger(__name__)
module-attribute
¶
build_d_value_dataframe() -> pdt.DataFrame
¶
Calculates the distance from faults to each named location and grid point
The number of sites considered is always the full amount, regardless of whether the site_list has been reduced for the rest of the table generation
Returns:
Source code in nzssdt_2023/data_creation/gis_data.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
calc_distance_to_faults(gdf: gpdt.DataFrame, faults: gpdt.DataFrame) -> pdt.DataFrame
¶
Calculates the closest distance of polygons or points to a set of fault lines
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf
|
gpdt.DataFrame
|
geodataframe of locations (polygons or points) |
required |
faults
|
gpdt.DataFrame
|
geodataframe of fault lines |
required |
Returns:
Name | Type | Description |
---|---|---|
df |
pdt.DataFrame
|
dataframe of distance from each location to the closest fault |
Source code in nzssdt_2023/data_creation/gis_data.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
cleanup_polygon_gpd(polygon_path) -> gpdt.DataFrame
¶
Removes extra columns from input polygon file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon_path
|
path to the original polygon file |
required |
Returns:
Name | Type | Description |
---|---|---|
gdf |
gpdt.DataFrame
|
geodataframe with only relevant columns |
Source code in nzssdt_2023/data_creation/gis_data.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
create_fault_and_polygon_gpds() -> Tuple[gpdt.DataFrame, gpdt.DataFrame]
¶
Creates the two geodataframes for resource output
Returns:
Name | Type | Description |
---|---|---|
faults |
gpdt.DataFrame
|
geodataframe of major faults |
polygons |
gpdt.DataFrame
|
geodataframe of urban area polygons |
Source code in nzssdt_2023/data_creation/gis_data.py
160 161 162 163 164 165 166 167 168 169 170 171 |
|
create_geojson_files(polygons_path: Union[str | Path], faults_path: Union[str | Path], grid_path: Union[str | Path], override: bool = False)
¶
Create the .geojsons for the version resources
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygons_path
|
Union[str | Path]
|
path to polygon .geojson |
required |
faults_path
|
Union[str | Path]
|
path to faults .geojson |
required |
grid_path
|
Union[str | Path]
|
path to grid points .geojson |
required |
override
|
bool
|
if True, rewrite all files |
False
|
Source code in nzssdt_2023/data_creation/gis_data.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
create_grid_gpd() -> gpdt.DataFrame
¶
Creates one geodataframe for resource output
Returns:
Name | Type | Description |
---|---|---|
grid |
gpdt.DataFrame
|
geodataframe of lat/lon grid points |
Source code in nzssdt_2023/data_creation/gis_data.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
filter_cfm_by_sliprate(cfm_url, slip_rate: float = 5.0) -> gpdt.DataFrame
¶
Filters the original Community Fault Model (CFM) .shp file
The faults are filtered by the (Slip Rate Preferred >=5 mmyr) criterion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slip_rate
|
float
|
slip rate for filter criterion, >= slip_rate |
5.0
|
Returns:
Name | Type | Description |
---|---|---|
gdf |
gpdt.DataFrame
|
geodataframe of filtered faults |
Source code in nzssdt_2023/data_creation/gis_data.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
polygon_location_list() -> List[str]
¶
Returns the urban and rural settlement names, excluding those that do not have their own polygon
Returns:
Name | Type | Description |
---|---|---|
polygon_list |
List[str]
|
ordered list of polygon names |
Source code in nzssdt_2023/data_creation/gis_data.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
save_gdf_to_geojson(gdf: gpdt.DataFrame, path, include_idx=False)
¶
Saves a geodataframe to a .geojson file
TODO: set up typing for the path input
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf
|
gpdt.DataFrame
|
geodataframe to save as .geosjon |
required |
path
|
path of new geojson |
required | |
include_idx
|
False drops the index from the gpd (e.g. if index is just a range, 0 -> n) |
False
|
Source code in nzssdt_2023/data_creation/gis_data.py
30 31 32 33 34 35 36 37 38 39 40 41 |
|
util
¶
utility functions
set_coded_location_resolution(dataframe_with_location: pd.DataFrame)
¶
Sets the dataframe index to coded_locations with res 0.1
Source code in nzssdt_2023/data_creation/util.py
8 9 10 11 12 13 14 15 16 17 18 19 20 |
|