grat.model.sites
¶
Base class used for all recharge types.
BaseSite
¶
BaseSite(
grat_id,
acres=0,
recharge_type=None,
bottleneck_ids=None,
wafr_sources_primary=None,
wafr_sources_secondary=None,
precip_grid=0,
district=None,
subbasin=None,
watershed=None,
agency=None,
nondistrict=None,
inbasinret=None,
dac=None,
gsc=None,
streamretu=None,
subsidence=None,
shorebird=None,
rsi=None,
groundwater_change=None,
rma=None,
region_number=None,
mlrp_score=None,
projects=None,
sustainability_zone=None,
depth_to_groundwater=None,
**kwargs,
)
Foundation for every recharge site (basins, canals and farms).
A site holds the static attributes that describe a parcel (area, location, which WAFR sources can reach it) plus the per-day arrays that the model fills in as it allocates water across the water year. All volumes are in acre-feet unless stated otherwise, and all day indexes are zero-indexed days of the water year.
Attributes:
| Name | Type | Description |
|---|---|---|
wafr_sources |
combined primary and secondary WAFR source names, built at
construction time from |
|
used_volume |
daily volume applied to the site (acre-feet), one entry per day.
Populated for basins and canals only — |
|
daily_recharge_volumes |
daily volume that reached groundwater (acre-feet).
Populated for basins and canals only — |
|
precip |
daily volume received as precipitation (acre-feet), populated by
|
|
wafr_log |
running total of volume supplied (acre-feet), keyed by WAFR source name. |
|
sort_index |
position of the site in the processing order, assigned by
|
Build a site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grat_id
|
internal unique identifier for the site. |
required | |
acres
|
polygon area in acres. |
0
|
|
recharge_type
|
type of recharge at the site, e.g. "Canal", "Basin" or "OFR".
Determines which sublist the site is grouped into by
|
None
|
|
bottleneck_ids
|
identifiers of the bottlenecks that restrict flow to this site. A single identifier is accepted and wrapped in a list. |
None
|
|
wafr_sources_primary
|
names of the sources that can supply water to this site from within its own district. |
None
|
|
wafr_sources_secondary
|
names of the sources that can supply water to this site from other districts. Used only after the primary sources are spent. |
None
|
|
precip_grid
|
identifier of the precipitation grid cell covering this site.
Used as the lookup key into the precipitation dictionary passed to
|
0
|
|
district
|
district the site belongs to. Transfer limits are tracked per district, so this is the key used to charge a transfer against a budget. |
None
|
|
agency
|
agency the site belongs to, referred to as the GSA elsewhere in
the model. Used by |
None
|
|
rsi
|
RSI score. Higher scores are processed first by the default sort rule. |
None
|
|
rma
|
RMA rank. Lower ranks are processed first by the "RMA" sort rule. |
None
|
|
groundwater_change
|
change in groundwater level. Lower (more negative) values are prioritised when ordering in-lieu sites. |
None
|
|
region_number
|
climate region number. Used as the crop calendar lookup key for in-lieu recharge, where accepted rates vary by region. |
None
|
|
mlrp_score
|
MLRP rank. Lower ranks are converted to the "MLRP" crop first
by |
None
|
|
sustainability_zone
|
sustainability zone name. Coerced to a string when set. |
None
|
|
subbasin
|
groundwater subbasin containing the site. |
None
|
|
watershed
|
watershed containing the site. |
None
|
|
depth_to_groundwater
|
depth to groundwater at the site. |
None
|
|
projects
|
projects associated with the site. |
None
|
|
nondistrict
|
site attribute carried through the model. Meaning not documented in this codebase. |
None
|
|
inbasinret
|
site attribute carried through the model. Meaning not documented in this codebase. |
None
|
|
dac
|
site attribute carried through the model. Meaning not documented in this codebase. |
None
|
|
gsc
|
site attribute carried through the model. Meaning not documented in this codebase. |
None
|
|
streamretu
|
site attribute carried through the model. Meaning not documented in this codebase. |
None
|
|
subsidence
|
site attribute carried through the model. Meaning not documented in this codebase. |
None
|
|
shorebird
|
site attribute carried through the model. Meaning not documented in this codebase. |
None
|
|
**kwargs
|
additional site attributes. |
{}
|
Note
subbasin, watershed, depth_to_groundwater, projects, nondistrict,
inbasinret, dac, gsc, streamretu, subsidence, shorebird and
sustainability_zone are stored on the site but are not read by any model
calculation. They are carried through so the reporting layer can group and
filter results.
Source code in src/grat/model/sites.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 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 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 173 174 175 176 | |
calc_precip
¶
Populate the site's daily precipitation volumes.
Multiplies the site area (acres) by the depth received at the site's
precipitation grid cell (decimal-feet) to give a volume in acre-feet, and
writes the result into self.precip.
Does nothing if the site has no precipitation grid or no dictionary is
supplied. Logs a warning and leaves self.precip untouched if the site's
grid is missing from the dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precip_dictionary
|
dict
|
daily precipitation depth (decimal-feet) for the water year, keyed by precipitation grid identifier. |
required |
Source code in src/grat/model/sites.py
set_daily_recharge
¶
Add volume to the site's groundwater recharge for a day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
new_volume
|
float
|
volume to add (acre-feet). |
required |
Source code in src/grat/model/sites.py
set_wafr_log
¶
Record volume supplied to this site by a WAFR source.
Accumulates across the whole water year rather than per day: repeated calls for the same source add to its running total.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wafr_source
|
str
|
name of the WAFR source that supplied water to this site. |
required |
volume
|
float
|
volume supplied by that source (acre-feet). |
required |
Source code in src/grat/model/sites.py
Basin
¶
Bases: BaseSite
A dedicated managed recharge facility.
Basin recharge is the practice of applying WAFR to dedicated managed facilities, and is reported as groundwater recharge. Basins are filled until WAFR is used up or every basin is full.
Water enters a basin as standing volume (current_capacity) and drains to
groundwater at perc_rate each day, so a basin recharges over several days
rather than instantly.
Attributes:
| Name | Type | Description |
|---|---|---|
current_capacity |
float
|
volume currently standing in the basin (acre-feet). |
Build a percolation basin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_capacity
|
basin capacity (acre-feet). |
0
|
|
perc_rate
|
percolation rate (acre-feet per day). |
0
|
|
**kwargs
|
all other |
{}
|
Source code in src/grat/model/sites.py
update_daily_values
¶
Drain a day's percolation from the basin into groundwater recharge.
The volume recharged is the percolation rate, or the standing volume if that is smaller. The percolation rate is then subtracted from the standing volume, which never goes below zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
Source code in src/grat/model/sites.py
get_basin_volume_available
¶
Return how much water the basin could accept on a day.
Headroom is the basin capacity less the standing volume, plus the volume that will percolate away that day, less the precipitation the basin receives. Never negative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
Returns:
| Type | Description |
|---|---|
|
Volume the basin could accept (acre-feet). |
Source code in src/grat/model/sites.py
set_used_volume
¶
Record water applied to the basin on a day.
Adds the volume to both the day's used volume and the standing volume in the basin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
new_volume
|
float
|
volume applied (acre-feet). |
required |
Source code in src/grat/model/sites.py
use_basin
¶
use_basin(
dowy: int,
wafr: dict,
bottleneck_list: list,
secondary_wafr: bool = False,
transfer_limits: dict | None = None,
)
Apply water to this basin from every source that can reach it.
Works through the site's WAFR sources in order, taking from each the smallest of: the basin's remaining headroom, the volume the source still has that day, and the throughput its bottlenecks still allow. Stops early once the basin has no headroom left.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dowy
|
int
|
zero-indexed day of the water year. |
required |
wafr
|
dict
|
volume still available (acre-feet) per day, keyed by WAFR source name. Mutated: water applied here is subtracted from it. |
required |
bottleneck_list
|
list
|
every bottleneck in the system. The ones relevant to
this site are selected by its |
required |
secondary_wafr
|
bool
|
draw from the site's secondary (out-of-district) sources instead of its primary (in-district) ones. |
False
|
transfer_limits
|
dict | None
|
remaining yearly transfer budget (acre-feet) per
district. Mutated: volume applied is charged against the
site's district. When a district's budget is spent, the sources
subject to that budget are skipped for this site. |
None
|
Source code in src/grat/model/sites.py
312 313 314 315 316 317 318 319 320 321 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 349 350 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 | |
Canal
¶
Bases: Basin
A conveyance structure that recharges groundwater through its bed.
Conveyance refers to the built structures (canals, sloughs) and natural ones (rivers, streams) that transport WAFR from its source to fields within each district. They are modelled as recharge sites in their own right, percolating to groundwater the same way a basin does.
A canal extends Basin with two differences:
max_capacityis a daily array rather than a single number, so capacity can vary across the year with operations.- During the irrigation season the canal is assumed already full for delivery, so its capacity is set to zero and it accepts no WAFR. That season's percolation is accounted for in a separate model.
Note
get_canal_volume_available is deliberately separate from the inherited
Basin.get_basin_volume_available rather than overriding it: the two use
different capacity calculations, and Basin.use_basin must keep calling
the basin one.
Build a canal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
irrigation_days
|
zero-indexed days of the water year in the irrigation season, during which the canal accepts no WAFR. |
None
|
|
**kwargs
|
all other |
{}
|
Source code in src/grat/model/sites.py
get_canal_volume_available
¶
Return how much water the canal could accept on a day.
Headroom is the day's capacity less the standing volume, plus the volume that will percolate away that day. Never negative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
Returns:
| Type | Description |
|---|---|
|
Volume the canal could accept (acre-feet). Zero during the irrigation |
|
|
season, when the canal is assumed already full for delivery. |
Source code in src/grat/model/sites.py
use_canal
¶
Apply an already-allocated volume from one WAFR source to this canal.
The allocation is decided by proportionally_fill; this method applies the
smaller of that allocation and the canal's own headroom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
wafr
|
dict
|
volume still available (acre-feet) per day, keyed by WAFR source name. Mutated: water applied here is subtracted from it. |
required |
source
|
str
|
name of the source supplying the water. |
required |
usable_volume_from_source
|
float
|
volume this canal has been allocated from that source (acre-feet). |
required |
Source code in src/grat/model/sites.py
Farm
¶
Bases: BaseSite
A field in agricultural production, used for on-farm or in-lieu recharge.
A farm supports two distinct recharge methods, tracked in separate sets of arrays so they can be reported independently:
On-farm recharge (OFR), or direct recharge, reduces groundwater level decline by applying surface water in excess of crop demand (ETc), at levels that do not interfere with crop development. The crop compatibility calendar (CCC) determines how much WAFR a field under a given crop can take. Only crops present in the calendar are included in on-farm calculations.
In-lieu recharge is surface water used in lieu of pumping groundwater. It reduces pumping by meeting crop demand (ETc) with surface water instead of groundwater. Accepted rates vary by climate region rather than by soil.
How much a field can take on a day is capped by the crop calendar, by the turnout's flow limit, and by any bottlenecks between it and the source. Precipitation counts against the field's capacity, since rain has already met part of the demand.
Attributes:
| Name | Type | Description |
|---|---|---|
flow_limit |
volume the turnout can still deliver (acre-feet), one entry per day. Drawn down as water is applied. |
|
ofr_used_volume |
daily volume applied as on-farm recharge (acre-feet). |
|
ofr_unused_volume |
daily volume the field could have taken but did not receive (acre-feet), whether limited by available water, a bottleneck or the turnout. |
|
ofr_daily_recharge_volumes |
daily volume reaching groundwater via on-farm recharge (acre-feet). |
|
in_lieu_used_volume |
daily volume applied as in-lieu recharge (acre-feet). |
|
in_lieu_unused_volume |
daily in-lieu volume the field could have taken but did not receive (acre-feet). |
|
in_lieu_daily_recharge_volumes |
daily volume attributed to in-lieu recharge (acre-feet). |
|
used_precip |
precipitation already counted against the field's capacity (acre-feet), tracked to avoid deducting the same rain twice. |
Build a farm site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
soil_type
|
soil classification from SAGBI, used with |
required | |
cfs_limit
|
rate at which water can be applied to the site
(cubic-feet per second). Defaults to 15 when |
required | |
crop
|
crop grown on the field, used for on-farm recharge. A field with no crop is excluded from on-farm calculations. |
None
|
|
in_lieu_crop
|
crop used for in-lieu recharge lookups. A field with no in-lieu crop is excluded from in-lieu calculations. |
None
|
|
**kwargs
|
all other |
{}
|
Source code in src/grat/model/sites.py
get_site_volume
¶
Return how much water the field could still take on a day.
Starts from the rate the crop calendar allows for this field, scaled by its area, less whatever has already been applied that day. Precipitation is then deducted, since rain has already met part of the demand — net of any rain already accounted for on a previous pass.
The result may be negative when precipitation exceeds what the crop can take; callers clamp it at zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
crop_calendar
|
dict
|
accepted application rate (feet per day) by crop. Indexed
as |
required |
in_lieu
|
bool
|
read the in-lieu calendar and in-lieu volumes rather than the on-farm ones. |
False
|
Returns:
| Type | Description |
|---|---|
|
Volume the field could accept (acre-feet). For in-lieu recharge on a |
|
|
field with no climate region number the crop's accepted rate is taken |
|
|
as zero, so the result is the precipitation adjustment alone. |
Source code in src/grat/model/sites.py
set_unused
¶
Record the volume the field could have taken but did not receive.
Replaces the day's value rather than accumulating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
volume
|
float
|
unmet capacity (acre-feet). |
required |
in_lieu
|
bool
|
record against in-lieu recharge rather than on-farm. |
False
|
Source code in src/grat/model/sites.py
set_used_volume
¶
Record water applied to the field on a day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
new_volume
|
float
|
volume applied (acre-feet). |
required |
in_lieu
|
bool
|
record against in-lieu recharge rather than on-farm. |
False
|
Source code in src/grat/model/sites.py
set_daily_recharge
¶
Add volume to the field's groundwater recharge for a day.
Overrides BaseSite.set_daily_recharge to keep on-farm and in-lieu
recharge in separate arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
zero-indexed day of the water year. |
required |
new_volume
|
float
|
volume to add (acre-feet). |
required |
in_lieu
|
bool
|
record against in-lieu recharge rather than on-farm. |
False
|
Source code in src/grat/model/sites.py
use_site
¶
use_site(
dowy: int,
wafr: dict,
bottleneck_list: list,
crop_calendar: dict,
in_lieu: bool = False,
secondary_wafr: bool = False,
transfer_limits: dict | None = None,
)
Apply water to this field as on-farm or in-lieu recharge.
Works through the site's WAFR sources in order, taking from each the smallest of: what the crop can still accept, what the source has left that day, what the bottlenecks still allow, and what the turnout can deliver. Stops early once the crop can take no more.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dowy
|
int
|
zero-indexed day of the water year. |
required |
wafr
|
dict
|
volume still available (acre-feet) per day, keyed by WAFR source name. Mutated: water applied here is subtracted from it. A source the site names but the dictionary does not hold is treated as having no water. |
required |
bottleneck_list
|
list
|
every bottleneck in the system. Mutated: the throughput used is subtracted from the bottlenecks crossed. |
required |
crop_calendar
|
dict
|
accepted application rate (feet per day) by crop. See
|
required |
in_lieu
|
bool
|
apply as in-lieu recharge rather than on-farm. |
False
|
secondary_wafr
|
bool
|
draw from the site's secondary (out-of-district) sources instead of its primary (in-district) ones. |
False
|
transfer_limits
|
dict | None
|
remaining yearly transfer budget (acre-feet) per
district. Mutated. |
None
|
Source code in src/grat/model/sites.py
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 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 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | |
turnout_limit_conversion
¶
Convert a turnout's flow rate into the volume it can deliver in a day.
See constants.CFS_TO_ACRE_FEET_PER_DAY for the conversion factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfs_rate
|
flow rate (cubic-feet per second). |
required |
Returns:
| Type | Description |
|---|---|
|
Volume deliverable in one day (acre-feet per day). |