Skip to content

access

Isolation status, nearest-facility times, 2SFCA and Hansen accessibility.

quakecascade.access

Place-based accessibility and post-event isolation.

Decay functions, Hansen potential and the two-step floating catchment area (2SFCA) are ported from the PlanX engine (engine/accessibility.py, same author); the cost-matrix layout of the public wrappers follows quakecascade.network.RoadNetwork.travel_time_matrix: rows are demand units (origins), columns are facilities.

  • Cumulative opportunities (Wachs & Kumagai 1973).
  • Gravity potential (Hansen 1959): \(A_i = \sum_j S_j f(c_{ij})\).
  • 2SFCA (Radke & Mu 2000; Luo & Wang 2003) with a decayed catchment (Luo & Qi 2009): \(R_j = S_j / \sum_k P_k f(c_{kj})\), \(A_i = \sum_j R_j f(c_{ij})\).

The isolation status compares access before and after an event (closed roads) for each unit: newly cut off, worse, same, improved or always cut off.

Decay kinds (c cost, T threshold/cutoff, p the kind's parameter):

============== ===================================== ============================= cumulative 1 if c <= T Wachs & Kumagai 1973 linear max(0, 1 - c/T) cone (Luo & Qi 2009) exponential exp(-p c) p = beta per cost unit gaussian (exp(-c^2/(2T^2)) - e^-1/2)/(1-e^-1/2) Dai 2010, Eq. 2; no p gaussian_sigma exp(-c^2 / (2 p^2)) p = sigma (Kwan 1998) power min(1, c^-p) p = beta; c < 1 reads as 1 logistic 1 / (1 + exp((c - p) 4/p)) p = half-weight cost ============== ===================================== =============================

Every kind is exactly zero beyond T and for non-finite costs.

DECAY_KINDS module-attribute

DECAY_KINDS = (
    "cumulative",
    "linear",
    "exponential",
    "gaussian",
    "gaussian_sigma",
    "power",
    "logistic",
)

Distance-decay functions accepted by the 2SFCA and Hansen measures.

NEWLY_CUT_OFF module-attribute

NEWLY_CUT_OFF = 'newly_cut_off'

Reachable before the event, not after.

WORSE module-attribute

WORSE = 'worse'

Reachable before and after, slower by more than the tolerance.

SAME module-attribute

SAME = 'same'

Reachable before and after, with a change within the tolerance.

IMPROVED module-attribute

IMPROVED = 'improved'

Reachable only after the event, or faster by more than the tolerance.

ALWAYS_CUT_OFF module-attribute

ALWAYS_CUT_OFF = 'always_cut_off'

Reachable neither before nor after the event: not a loss caused by the event.

ISOLATION_CATEGORIES module-attribute

ISOLATION_CATEGORIES = (
    NEWLY_CUT_OFF,
    WORSE,
    SAME,
    IMPROVED,
    ALWAYS_CUT_OFF,
)

The categories of isolation_status. A unit with an unknown travel time gets no_pre_time or no_post_time instead.

NO_TRAVEL_TIME module-attribute

NO_TRAVEL_TIME = contract.missing('travel_time')

Status of a value that needs a travel time that is not known.

AccessAccumulator

AccessAccumulator(
    n_origins, population, kind, param, cutoff
)

Chunk-wise Hansen and 2SFCA sums over destination-by-origin blocks.

The caller feeds blocks of destinations (add_block), each with its costs to every origin; the sums are complete when the last block is in. 2SFCA can be built this way because each facility's ratio R_j needs only its own column. Costs must be finite or inf; NaN handling is done by two_step_fca.

add_block

add_block(cost_dest_by_origin, supply)

Costs shaped (block, n_origins) and the block's supply weights.

gaussian_decay

gaussian_decay(cost, threshold)

Threshold-normalised Gaussian weight of Dai (2010).

\[G(c, T) = \frac{e^{-\frac12 (c/T)^2} - e^{-\frac12}}{1 - e^{-\frac12}}, \quad c \le T\]

and 0 beyond T; 1 at c = 0 and 0 at c = T.

Source: Dai, D. (2010). Black residential segregation, disparities in spatial access to health care facilities, and late-stage breast cancer diagnosis in metropolitan Detroit. Health & Place 16(5), 1038-1052, Eq. 2. doi:10.1016/j.healthplace.2010.06.012

decay

decay(cost, kind, param, cutoff)

Weight in [0, 1] for travel costs cost.

Parameters:

Name Type Description Default
cost array_like

Travel costs (any unit consistent with cutoff and param). inf/NaN and costs above cutoff weigh zero.

required
kind str

One of DECAY_KINDS (see the module table for sources).

required
param float or None

The kind's own parameter; required (positive) for exponential, gaussian_sigma, power and logistic, ignored otherwise.

required
cutoff float

Threshold T beyond which every weight is zero.

required

half_weight_time

half_weight_time(kind, param, cutoff)

Cost at which the decay first reaches 0.5 (None if it never does).

two_step_fca

two_step_fca(
    cost,
    supply,
    demand,
    threshold,
    decay="cumulative",
    param=None,
    return_ratio=False,
)

Two-step floating catchment area accessibility.

\[R_j = \frac{S_j}{\sum_k P_k\, f(c_{kj})}, \qquad A_i = \sum_j R_j\, f(c_{ij})\]

(Radke & Mu 2000; Luo & Wang 2003; decayed catchment: Luo & Qi 2009; Gaussian: Dai 2010). Population-weighted access sums to the supply of every facility that someone can reach: \(\sum_i P_i A_i = \sum_{j:\,D_j>0} S_j\).

Parameters:

Name Type Description Default
cost (n_demand, n_facility) array

Travel cost from each demand unit to each facility; inf = unreachable, NaN = unknown (for example an unsnapped unit).

required
supply (n_facility,) array

Facility capacity (beds, places). NaN = unknown; the facility is left out and every unit that reaches it is marked partial.

required
demand (n_demand,) array

Population per unit. NaN = unknown; the unit adds nobody to any catchment, so the ratios it touches are upper bounds (partial).

required
threshold float

Catchment size T in cost units.

required
decay str

A DECAY_KINDS entry; "gaussian" is Dai (2010).

'cumulative'
param float

Parameter of the decay kind when it needs one.

None
return_ratio bool

Also return the facility table.

False

Returns:

Type Description
DataFrame (and facility DataFrame when ``return_ratio``)

Per demand unit: access, n_reachable (facilities within T), access_status (computed, partial, or no_travel_time when its whole cost row is unknown). Per facility: ratio, catchment_demand, ratio_status (no_supply; no_travel_time when every cost to the facility is unknown; empty with NaN ratio when nobody lives within the catchment, so the ratio is undefined, and the units that still reach it read partial; no_demand when the only residents within it have unknown numbers; partial; computed).

hansen

hansen(
    cost, supply, threshold, decay="cumulative", param=None
)

Hansen (1959) potential \(A_i = \sum_j S_j f(c_{ij})\) per demand unit.

cost is (n_demand, n_facility). A unit whose whole cost row is NaN gets NaN; NaN entries elsewhere count as unreachable (the value is then a lower bound). Facilities with NaN supply are skipped, which also makes the value a lower bound; a unit that reaches only facilities of unknown supply gets NaN, not 0.

nearest_time

nearest_time(matrix)

Cost to the nearest facility per row of a cost matrix.

Returns nearest_time (inf when no facility is reachable), nearest_index (column, -1 when none) and nearest_status: computed; partial when some entries were unknown (the value is an upper bound); no_travel_time when the known entries reach nothing and some are unknown, or the whole row is unknown (value NaN).

isolation_status

isolation_status(pre, post, limit_s=None, worse_tol_s=None)

Compare access before and after an event, unit by unit.

A unit is reachable when its time is finite (and not above limit_s when a limit is given). With d = post - pre:

================ ============================================ newly_cut_off reachable before, not after always_cut_off reachable neither before nor after improved not reachable before, reachable after; or d < -tol worse d > tol same |d| <= tol ================ ============================================

A NaN (unknown) time gives no_pre_time / no_post_time and no category. The categories follow the pre/post comparison of network accessibility-loss studies (e.g. Sohn 2006, doi:10.1016/j.tra.2005.08.006); the tolerance is the caller's.

Parameters:

Name Type Description Default
pre array_like

Times per unit (inf = unreachable, NaN = unknown), e.g. the nearest_time column of nearest_time.

required
post array_like

Times per unit (inf = unreachable, NaN = unknown), e.g. the nearest_time column of nearest_time.

required
limit_s float

Times above it count as unreachable.

None
worse_tol_s float

Change smaller than or equal to this is same. Required: no published default exists (use 0 for an exact comparison).

None

Returns:

Type Description
DataFrame

pre_time, post_time, delta_time (NaN unless both are reachable) and isolation_status.

population_by_status

population_by_status(status, population)

People and units per isolation category.

Returns one row per category (the five of ISOLATION_CATEGORIES always, plus any missing-data code present) with n_units, population (sum; NaN when every unit in the category lacks a population) and n_population_missing.