Core Module¶
core ¶
Core module for effective precipitation calculations using Google Earth Engine.
This module provides the main :class:EffectivePrecipitation class for calculating
effective precipitation from various climate datasets available on Google Earth Engine.
The module supports multiple effective precipitation methods:
- Ensemble: Mean of 6 methods (default)
- CROPWAT: FAO CROPWAT method
- FAO/AGLW: FAO Dependable Rainfall (80% exceedance)
- Fixed Percentage: Simple fixed percentage method
- Dependable Rainfall: FAO Dependable Rainfall method
- FarmWest: FarmWest method
- USDA-SCS: Soil moisture depletion method (requires AWC and ETo)
- TAGEM-SuET: Turkish irrigation method (requires ETo)
- PCML: Physics-Constrained ML for Western U.S. (pre-computed GEE asset)
Example
from pycropwat import EffectivePrecipitation
ep = EffectivePrecipitation(
asset_id='ECMWF/ERA5_LAND/MONTHLY_AGGR',
precip_band='total_precipitation_sum',
geometry_path='study_area.geojson',
start_year=2015,
end_year=2020,
precip_scale_factor=1000,
method='ensemble'
)
results = ep.process(output_dir='./output', n_workers=4)
See Also
pycropwat.methods : Individual effective precipitation calculation functions. pycropwat.analysis : Post-processing and analysis tools. pycropwat.utils : Utility functions for GEE and file operations.
EffectivePrecipitation ¶
EffectivePrecipitation(asset_id: str, precip_band: str, geometry_path: Optional[Union[str, Path]] = None, start_year: int = None, end_year: int = None, scale: Optional[float] = None, precip_scale_factor: float = 1.0, gee_project: Optional[str] = None, gee_geometry_asset: Optional[str] = None, method: PeffMethod = 'ensemble', method_params: Optional[dict] = None)
Calculate effective precipitation from GEE climate data.
Supports multiple effective precipitation calculation methods including CROPWAT, FAO/AGLW, Fixed Percentage, Dependable Rainfall, FarmWest, and USDA-SCS (which requires AWC and ETo data).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_id
|
str
|
GEE ImageCollection asset ID for precipitation data. Common options:
|
required |
precip_band
|
str
|
Name of the precipitation band in the asset. Examples:
|
required |
geometry_path
|
str, Path, or None
|
Path to shapefile or GeoJSON file defining the region of interest. Can also be a GEE FeatureCollection asset ID. Set to None if using gee_geometry_asset instead. |
None
|
start_year
|
int
|
Start year for processing (inclusive). |
None
|
end_year
|
int
|
End year for processing (inclusive). |
None
|
scale
|
float
|
Output resolution in meters. If None (default), uses native resolution of the dataset. |
None
|
precip_scale_factor
|
float
|
Factor to convert precipitation to mm. Default is 1.0. Common values: ERA5-Land (m to mm) = 1000, TerraClimate = 1.0, GridMET = 1.0. |
1.0
|
gee_project
|
str
|
GEE project ID for authentication. Required for cloud-based GEE access. |
None
|
gee_geometry_asset
|
str
|
GEE FeatureCollection asset ID for the region of interest. Takes precedence over geometry_path if both are provided. |
None
|
method
|
str
|
Effective precipitation calculation method. Default is 'ensemble'. Options:
|
'ensemble'
|
method_params
|
dict
|
Additional parameters for the selected method: For For For |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
geometry |
Geometry
|
The loaded geometry for the region of interest. |
collection |
ImageCollection
|
The filtered and scaled precipitation image collection. |
bounds |
list
|
Bounding box coordinates of the geometry. |
Examples:
Basic usage with Ensemble method (default):
from pycropwat import EffectivePrecipitation
ep = EffectivePrecipitation(
asset_id='ECMWF/ERA5_LAND/MONTHLY_AGGR',
precip_band='total_precipitation_sum',
geometry_path='roi.geojson',
start_year=2015,
end_year=2020,
precip_scale_factor=1000
)
ep.process(output_dir='./output', n_workers=4)
Using GEE FeatureCollection asset:
ep = EffectivePrecipitation(
asset_id='ECMWF/ERA5_LAND/MONTHLY_AGGR',
precip_band='total_precipitation_sum',
gee_geometry_asset='projects/my-project/assets/study_area',
start_year=2015,
end_year=2020,
precip_scale_factor=1000,
gee_project='my-gee-project'
)
Using FAO/AGLW method:
ep = EffectivePrecipitation(
asset_id='IDAHO_EPSCOR/TERRACLIMATE',
precip_band='pr',
geometry_path='study_area.geojson',
start_year=2000,
end_year=2020,
method='fao_aglw'
)
Using fixed percentage method (80%):
ep = EffectivePrecipitation(
asset_id='IDAHO_EPSCOR/GRIDMET',
precip_band='pr',
geometry_path='farm.geojson',
start_year=2010,
end_year=2020,
method='fixed_percentage',
method_params={'percentage': 0.8}
)
Using USDA-SCS method with AWC and ETo data:
ep = EffectivePrecipitation(
asset_id='ECMWF/ERA5_LAND/MONTHLY_AGGR',
precip_band='total_precipitation_sum',
geometry_path='arizona.geojson',
start_year=2015,
end_year=2020,
precip_scale_factor=1000,
method='usda_scs',
method_params={
'awc_asset': 'projects/my-project/assets/soil_awc',
'awc_band': 'AWC',
'eto_asset': 'IDAHO_EPSCOR/GRIDMET',
'eto_band': 'eto',
'eto_is_daily': True,
'rooting_depth': 1.0
}
)
See Also
pycropwat.methods : Individual effective precipitation calculation functions. pycropwat.analysis : Post-processing and analysis tools.
Source code in pycropwat/core.py
cropwat_effective_precip
staticmethod
¶
Calculate CROPWAT effective precipitation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pr
|
ndarray
|
Precipitation in mm. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Effective precipitation in mm. |
Source code in pycropwat/core.py
process ¶
process(output_dir: Union[str, Path], n_workers: int = 4, months: Optional[List[int]] = None, input_dir: Optional[Union[str, Path]] = None, save_inputs: bool = False) -> List[Tuple[Optional[Path], Optional[Path]]]
Process all months and save effective precipitation rasters.
Downloads precipitation data from Google Earth Engine, calculates effective precipitation using the configured method, and saves results as GeoTIFF files. Uses Dask for parallel processing of multiple months.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str or Path
|
Directory to save output rasters. Will be created if it doesn't exist. |
required |
n_workers
|
int
|
Number of parallel workers for Dask. Default is 4. Set to 1 for sequential processing. |
4
|
months
|
list of int
|
List of months to process (1-12). If None, processes all months in the date range. Useful for seasonal analyses. |
None
|
input_dir
|
str or Path
|
Directory to save downloaded input data (precipitation, AWC, ETo).
If None and save_inputs is True, uses |
None
|
save_inputs
|
bool
|
Whether to save downloaded input data as GeoTIFF files. Default is False. Useful for debugging or further analysis. |
False
|
Returns:
| Type | Description |
|---|---|
list of tuple
|
List of tuples containing paths to saved files:
|
Notes
Output files are named:
effective_precip_YYYY_MM.tif- Effective precipitation in mmeffective_precip_fraction_YYYY_MM.tif- Effective/total ratio (non-PCML methods)effective_precip_fraction_YYYY.tif- Annual (water year) fraction (PCML method only)
For the USDA-SCS method, AWC and ETo data are automatically downloaded and cached for efficiency.
Examples:
Process all months in parallel:
Process only summer months:
Save input data for debugging:
See Also
process_sequential: Sequential processing for debugging.
Source code in pycropwat/core.py
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 | |
process_sequential ¶
process_sequential(output_dir: Union[str, Path], months: Optional[List[int]] = None, input_dir: Optional[Union[str, Path]] = None, save_inputs: bool = False) -> List[Tuple[Optional[Path], Optional[Path]]]
Process all months sequentially (useful for debugging).
Same as :meth:process but without parallel processing. Useful for
debugging issues, testing on small datasets, or when GEE rate limits
are a concern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str or Path
|
Directory to save output rasters. Will be created if it doesn't exist. |
required |
months
|
list of int
|
List of months to process (1-12). If None, processes all months in the date range. |
None
|
input_dir
|
str or Path
|
Directory to save downloaded input data (precipitation, AWC, ETo).
If None and save_inputs is True, uses |
None
|
save_inputs
|
bool
|
Whether to save downloaded input data. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
list of tuple
|
List of tuples containing paths to saved files:
|
Examples:
Debug a single month:
ep = EffectivePrecipitation(...)
results = ep.process_sequential(
output_dir='./output',
months=[1] # Process only January
)
See Also
process: Parallel processing method (recommended for production).
Source code in pycropwat/core.py
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 | |