ochanticipy package¶
Subpackages¶
- ochanticipy.config package
- ochanticipy.datasources package
- Subpackages
- Submodules
- ochanticipy.datasources.datasource module
- Module contents
- ochanticipy.utils package
- Submodules
- ochanticipy.utils.check_extra_imports module
- ochanticipy.utils.check_file_existence module
- ochanticipy.utils.dates module
- ochanticipy.utils.geoboundingbox module
- ochanticipy.utils.hdx_api module
- ochanticipy.utils.io module
- ochanticipy.utils.raster module
- Module contents
Module contents¶
OCHA AnticiPy: Access data for anticipating humanitarian risk.
OCHA AnticiPy is a Python library for simple downloading and processing of data related to the anticipation of humanitarian risk, from climate observations and forecasts to food insecurity.
- class ochanticipy.ChirpsDaily(country_config: CountryConfig, geo_bounding_box: GeoBoundingBox, resolution: float = 0.05, start_date: date | str | None = None, end_date: date | str | None = None)[source]¶
Bases:
_ChirpsClass object to retrieve CHIRPS observational monthly precipitation data.
- Parameters:
country_config (CountryConfig) – Country configuration
geo_bounding_box (GeoBoundingBox) – the bounding coordinates of the area that should be included in the data.
resolution (float, default = 0.05) – resolution of data to be downloaded. Can be 0.05 or 0.25.
start_date (Optional[Union[datetime.date, str]], default = None) – Data will be considered starting from date start_date. Input can be an ISO8601 string or datetime.date object. If None, it is set to 1981-1-1.
end_date (Optional[Union[datetime.date, str]], default = None) – Data will be considered up to date end_date. Input can be an ISO8601 string or datetime.date object. If None, it is set to the date for which most recent data is available.
Examples
>>> from ochanticipy import create_country_config, CodAB, GeoBoundingBox, ... ChirpsDaily >>> import datetime >>> >>> country_config = create_country_config(iso3="bfa") >>> codab = CodAB(country_config=country_config) >>> codab.download() >>> admin0 = codab.load(admin_level=0) >>> geo_bounding_box = GeoBoundingBox.from_shape(admin0) >>> start_date = datetime.date(year=2007, month=10, day=23) >>> end_date = datetime.date(year=2020, month=3, day=2) >>> chirps_daily = ChirpsDaily( ... country_config=country_config, ... geo_bounding_box=geo_bounding_box, ... start_date=start_date, ... end_date=end_date ... ) >>> chirps_daily.download() >>> chirps_daily.process() >>> chirps_daily_data = chirps_daily.load()
- class ochanticipy.ChirpsMonthly(country_config: CountryConfig, geo_bounding_box: GeoBoundingBox, start_date: date | str | None = None, end_date: date | str | None = None)[source]¶
Bases:
_ChirpsClass object to retrieve CHIRPS observational monthly precipitation data.
- Parameters:
country_config (CountryConfig) – Country configuration
geo_bounding_box (GeoBoundingBox) – the bounding coordinates of the area that should be included in the data.
start_date (Optional[Union[datetime.date, str]], default = None) – Data will be considered starting from date start_date. Input can be an ISO8601 string or datetime.date object. If None, it is set to 1981-1-1.
end_date (Optional[Union[datetime.date, str]], default = None) – Data will be considered up to date end_date. Input can be an ISO8601 string or datetime.date object. If None, it is set to the date for which most recent data is available.
Examples
>>> from ochanticipy import create_country_config, CodAB, GeoBoundingBox >>> from ochanticipy import ChirpsMonthly >>> import datetime >>> >>> country_config = create_country_config(iso3="bfa") >>> codab = CodAB(country_config=country_config) >>> codab.download() >>> admin0 = codab.load(admin_level=0) >>> geo_bounding_box = GeoBoundingBox.from_shape(admin0) >>> >>> start_date = datetime.date(year=2007, month=10, day=23) >>> end_date = datetime.date(year=2020, month=3, day=2) >>> chirps_monthly = ChirpsMonthly( ... country_config=country_config, ... geo_bounding_box=geo_bounding_box, ... start_date=start_date, ... end_date=end_date ... ) >>> chirps_monthly.download() >>> chirps_monthly.process() >>> chirps_monthly_data = chirps_monthly.load()
- class ochanticipy.CodAB(country_config: CountryConfig)[source]¶
Bases:
DataSourceWork with COD AB (administrative boundaries).
- Parameters:
country_config (CountryConfig) – Country configuration
- download(clobber: bool = False) Path | List[Path][source]¶
Download COD AB file from HDX.
- Parameters:
clobber (bool, default = False) – If True, overwrites existing COD AB files
- Return type:
The downloaded filepath(s)
Examples
>>> from ochanticipy import create_country_config, CodAB >>> # Download COD administrative boundaries for Nepal >>> country_config = create_country_config(iso3="npl") >>> codab = CodAB(country_config=country_config) >>> npl_cod_shapefile = codab.download()
- load(admin_level: int = 0) GeoDataFrame[source]¶
Get the COD AB data by admin level.
- Parameters:
admin_level (int, default = 0) – The administrative level
- Return type:
COD AB geodataframe with specified admin level
- Raises:
AttributeError – If the requested admin level is higher than what is available
FileNotFoundError – If the requested filename or layer name are not found
Examples
>>> from ochanticipy import create_country_config, CodAB >>> >>> # Retrieve admin 2 boundaries for Nepal >>> country_config = create_country_config(iso3="npl") >>> codab = CodAB(country_config=country_config) >>> npl_admin2 = codab.load(admin_level=2)
- load_custom(custom_layer_number: int = 0) GeoDataFrame[source]¶
Get the COD AB data from a custom (non-level) layer.
- Parameters:
custom_layer_number (int) – The 0-indexed number of the layer listed in the custom_layer_names parameter of the country’s config file
- Return type:
COD AB geodataframe with custom admin level
- Raises:
AttributeError – If the requested custom layer number is not available
FileNotFoundError – If the requested filename or layer name are not found
Examples
>>> from ochanticipy import create_country_config, CodAB >>> >>> # Retrieve district boundaries for Nepal >>> country_config = create_country_config(iso3="npl") >>> codab = CodAB(country_config=country_config) >>> npl_district = codab.load_custom(custom_layer_number=0)
- class ochanticipy.CountryConfig(*, iso3: str, codab: CodABConfig | None = None, fewsnet: FewsNetConfig | None = None, glofas: GlofasConfig | None = None, usgs_ndvi: UsgsNdviConfig | None = None)[source]¶
Bases:
BaseModelCountry configuration.
- Parameters:
iso3 (str) – Country ISO3, must be exactly 3 letters long
codab (CodABConfig, optional) – Configuration object for COD AB
fewsnet (FewsNetConfig, optional) – Configuration object for FEWS NET
glofas (GlofasConfig, optional) – Configuration object for GloFAS
usgs_ndvi (UsgsNdviConfig, optional) – Configuration object for USGS NDVI
- codab: CodABConfig | None¶
- fewsnet: FewsNetConfig | None¶
- glofas: GlofasConfig | None¶
- iso3: str¶
- usgs_ndvi: UsgsNdviConfig | None¶
- class ochanticipy.FewsNet(country_config)[source]¶
Bases:
DataSourceBase class to retrieve FewsNet data.
- Parameters:
country_config (CountryConfig) – Country configuration
- download(pub_year: int, pub_month: int, clobber: bool = False) Path[source]¶
Retrieve the raw FEWS NET data.
Depending on the region and date, this data is published per region or per country. This function retrieves the country data if it exists, and else the regional data for pub_year-pub_month.
- Parameters:
pub_year (int) – publication year of the data that should be downloaded
pub_month (int) – publication month of the data that should be downloaded. This commonly refers to the month of the Current Situation period
clobber (bool, default = False) – If True, overwrites existing raw files
- Return type:
Path to the downloaded file.
Examples
>>> from ochanticipy import create_country_config, FewsNet >>> # Download FEWS NET data for ETH published in 2021-06 >>> country_config = create_country_config(iso3="eth") >>> fewsnet = FewsNet(country_config=country_config) >>> eth_fn_202106_path = fewsnet.download(pub_year=2021,pub_month=6)
- load(pub_year: int, pub_month: int, projection_period: ValidProjectionPeriods) GeoDataFrame[source]¶
Load FEWS NET data.
For the given pub_year, pub_month and projection_period.
- Parameters:
pub_year (int) – publication year of the data that should be loaded
pub_month (int) – publication month of the data that should be loaded. This refers to the first month of the Current Situation period
projection_period (str) – The projection period to be loaded. This should be CS, ML1, or ML2. Referring to Current Situation, near term projection, and medium term projection respectively.
- Return type:
Geopandas DataFrame with the specified data.
Examples
>>> from ochanticipy import create_country_config, FewsNet >>> # Load FEWS NET data for ETH published in 2021-06 of medium-term ... projection period (ML1) >>> country_config = create_country_config(iso3="eth") >>> fewsnet = FewsNet(country_config=country_config) >>> gdf_eth_fn_202106 = fewsnet.load(pub_year=2021,pub_month=6, ... projection_period = "ML1")
- class ochanticipy.GeoBoundingBox(lat_max: float, lat_min: float, lon_max: float, lon_min: float)[source]¶
Bases:
objectCreate an object containing the bounds of an area.
Standard geographic coordinate system is used where latitude runs from -90 to 90 degrees, and latitude from -180 to 180. North must always be greater than south, and east greater than west.
- Parameters:
lat_max (float) – The northern latitude boundary of the area (degrees). The value must be between -90 and 90, and greater than or equal to the southern boundary.
lat_min (float) – The southern latitude boundary of the area (degrees). The value must be between -90 and 90, and less than or equal to the northern boundary.
lon_max (float) – The easternmost longitude boundary of the area (degrees). The value must be between -180 and 180, and greater than or equal to the western boundary.
lon_min (float) – The westernmost longitude boundary of the area (degrees). The value must be between -180 and 180, and less than or equal to the eastern boundary.
- classmethod from_shape(shape: GeoSeries | GeoDataFrame) GeoBoundingBox[source]¶
Create
GeoBoundingBoxfrom a geopandas object.- Parameters:
shape (geopandas.GeoSeries, geopandas.GeoDataFrame) – A shape whose bounds will be retrieved
- Return type:
GeoBoundingBoxfrom the total bounds of theGeoDataFrame
Examples
>>> import geopandas as gpd >>> df_admin_boundaries = gpd.read_file("admin0_boundaries.gpkg") >>> geobb = GeoBoundingBox.from_shape(df_admin_boundaries)
- get_filename_repr(precision: int = 0) str[source]¶
Get succinct boundary representation for usage in filenames.
- Parameters:
precision (int, default = 0) – Precision, i.e. number of decimal places to round to. Default is 0 for ints.
- Return type:
String containing N, S, E and W coordinates.
- property lat_max: float¶
Get the northern latitude boundary of the area (degrees).
- property lat_min: float¶
Get the southern latitude boundary of the area (degrees).
- property lon_max: float¶
Get the eastern longitude boundary of the area (degrees).
- property lon_min: float¶
Get the western longitude boundary of the area (degrees).
- round_coords(offset_val: float = 0.0, round_val: int | float = 1) GeoBoundingBox[source]¶
Round the bounding box coordinates.
Rounding is always done outside the original bounding box, i.e. the resulting bounding box is always equal or larger than the original bounding box. Rounding can only be done once per instance.
- Parameters:
offset_val (float, default = 0.0) – Offset the coordinates by this factor.
round_val (int or float, default = 1) – Rounds to the nearest round_val. Can be an int for integer rounding or float for decimal rounding. If 1, round to integers.
- Return type:
GeoBoundingBoxinstance with rounded and offset coordinates
- class ochanticipy.GlofasForecast(country_config: CountryConfig, geo_bounding_box: GeoBoundingBox, leadtime_max: int, start_date: date | str = None, end_date: date | str = None, model_version: int = 4)[source]¶
Bases:
GlofasClass for downloading and processing GloFAS forecast data.
The GloFAS forecast dataset is a global raster presenting river discharge forecast from 26 May 2021 until present day (updated daily), see this paper for more details. While CDS does have version 3 pre-release data from 2020-2021, we understand that there were some small issues that were fixed in the final version, so at this point in time this module does not support downloading the pre-release data.
This class downloads the raw raster data from CDS, and processes it from a raster to a datasets of reporting points from the GloFAS interface. Due to the CDS request size limits, separate files are downloaded per day (that contain all requested lead times).
- Parameters:
country_config (CountryConfig) – Country configuration
geo_bounding_box (GeoBoundingBox) – The bounding coordinates of the area that should be included
leadtime_max (int) – The maximum desired lead time D in days. All forecast data for lead times 1 to D days are downloaded
start_date (Union[date, str], default: date(year=2021, month=5, day=26)) – The starting date for the dataset. If left blank, defaults to the earliest available date
end_date (Union[date, str], default: date.today()) – The ending date for the dataset. If left blank, defaults to the current date
model_version (int, default: 4) – The version of the GloFAS model to use, can only be 3 or 4. If in doubt, always use the latest (default).
Examples
Download, process and load GloFAS forecast data for the past month, for a lead time of 15 days.
>>> from datetime import date >>> from ochanticipy import create_country_config, CodAB, GeoBoundingBox, ... GlofasForecast >>> >>> country_config = create_country_config(iso3="npl") >>> codab = CodAB(country_config=country_config) >>> codab.download() >>> admin_npl = codab.load() >>> geo_bounding_box = GeoBoundingBox.from_shape(admin_npl) >>> >>> glofas_forecast = GlofasForecast( ... country_config=country_config, ... geo_bounding_box=geo_bounding_box, ... leadtime_max=15, ... end_date=date(year=2022, month=10, day=22), ... start_date=date(year=2022, month=9, day=22) ... ) >>> glofas_forecast.download() >>> glofas_forecast.process() >>> >>> npl_glofas_forecast_reporting_points = glofas_forecast.load()
- class ochanticipy.GlofasReanalysis(country_config: CountryConfig, geo_bounding_box: GeoBoundingBox, start_date: date | str = None, end_date: date | str = None, model_version: int = 4)[source]¶
Bases:
GlofasClass for downloading and processing GloFAS reanalysis data.
The GloFAS reanalysis dataset is a global raster presenting river discharnge from 1979 until present day (updated daily), see this paper for more details.
This class downloads the raw raster data from CDS, and processes it from a raster to a datasets of reporting points from the GloFAS interface. Due to the CDS request size limits, separate files are downloaded per year.
- Parameters:
country_config (CountryConfig) – Country configuration
geo_bounding_box (GeoBoundingBox) – The bounding coordinates of the area that should be included
start_date (Union[date, str], default: date(1979, 1, 1)) – The starting date for the dataset. If left blank, defaults to the earliest available date
end_date (Union[date, str], default: date.today()) – The ending date for the dataset. If left blank, defaults to the current date
model_version (int, default: 4) – The version of the GloFAS model to use, can only be 3 or 4. If in doubt, always use the latest (default).
Examples
Download, process and load all historical GloFAS reanalysis data until the current date, set to Oct 22, 2022 for this example.
>>> from datetime import date >>> from ochanticipy import create_country_config, CodAB, GeoBoundingBox, ... GlofasReanalysis >>> >>> country_config = create_country_config(iso3="bgd") >>> codab = CodAB(country_config=country_config) >>> codab.download() >>> admin_npl = codab.load() >>> geo_bounding_box = GeoBoundingBox.from_shape(admin_npl) >>> >>> glofas_reanalysis = GlofasReanalysis( ... country_config=country_config, ... geo_bounding_box=geo_bounding_box, ... end_date=date(year=2022, month=10, day=22) ... ) >>> glofas_reanalysis.download() >>> glofas_reanalysis.process() >>> >>> npl_glofas_reanalysis_reporting_points = glofas_reanalysis.load()
- class ochanticipy.GlofasReforecast(country_config: CountryConfig, geo_bounding_box: GeoBoundingBox, leadtime_max: int, start_date: date | str = None, end_date: date | str = None, model_version: int = 4)[source]¶
Bases:
GlofasClass for downloading and processing GloFAS reforecast data.
The GloFAS reforecast dataset is a global raster presenting river discharge forecasted from 1999 until 2018, see this paper for more details.
This class downloads the raw raster data from CDS, and processes it from a raster to a datasets of reporting points from the GloFAS interface. Due to the CDS request size limits, separate files are downloaded per month (that contain all requested lead times).
- Parameters:
country_config (CountryConfig) – Country configuration
geo_bounding_box (GeoBoundingBox) – The bounding coordinates of the area that should be included
leadtime_max (int) – The maximum desired lead time D in days. All forecast data for lead times 1 to D days are downloaded
start_date (Union[date, str], default: date(year=1999, month=1, day=1)) – The starting date for the dataset. If left blank, defaults to the earliest available date
end_date (Union[date, str], default: date(year=2018, month=12, day=31)) – The ending date for the dataset. If left blank, defaults to the last available date
model_version (int, default: 4) – The version of the GloFAS model to use, can only be 3 or 4. If in doubt, always use the latest (default).
Examples
Download, process and load all available GloFAS reforecast data for a lead time of 15 days.
>>> from ochanticipy import create_country_config, CodAB, GeoBoundingBox, ... GlofasReforecast >>> >>> country_config = create_country_config(iso3="npl") >>> codab = CodAB(country_config=country_config) >>> codab.download() >>> admin_npl = codab.load() >>> geo_bounding_box = GeoBoundingBox.from_shape(admin_npl) >>> >>> glofas_reforecast = GlofasReforecast( ... country_config=country_config, ... geo_bounding_box=geo_bounding_box, ... leadtime_max=15 ... ) >>> glofas_reforecast.download() >>> glofas_reforecast.process() >>> >>> npl_glofas_reforecast_reporting_points = glofas_reforecast.load()
- class ochanticipy.IriForecastDominant(country_config: CountryConfig, geo_bounding_box: GeoBoundingBox)[source]¶
Bases:
_IriForecastClass to retrieve IRI’s forecast dominant tercile data.
The retrieved data contains the dominant probability. Automatically all seasons and leadtimes are downloaded.
- Parameters:
country_config (CountryConfig) – Country configuration
geo_bounding_box (GeoBoundingBox) – the bounding coordinates of the area that should be included in the data.
Examples
>>> from ochanticipy import create_country_config, ... GeoBoundingBox, IriForecastDominant >>> country_config = create_country_config(iso3="bfa") >>> geo_bounding_box = GeoBoundingBox(lat_max=13.0, ... lat_min=12.0, ... lon_max=-3.0, ... lon_min=-2.0) >>> >>> # Initialize class and retrieve data >>> iri = IriForecastDominant(country_config,geo_bounding_box) >>> iri.download() # Must have IRI_AUTH environment variable set >>> iri.process() >>> >>> iri_data = iri.load()
- class ochanticipy.IriForecastProb(country_config, geo_bounding_box: GeoBoundingBox)[source]¶
Bases:
_IriForecastClass to retrieve IRI’s forecast data per tercile.
The retrieved data contains the probability per tercile for the given bounding box. Automatically all seasons and leadtimes are downloaded.
- Parameters:
country_config (CountryConfig) – Country configuration
geo_bounding_box (GeoBoundingBox) – the bounding coordinates of the area that should be included in the data.
Examples
>>> from ochanticipy import create_country_config, ... GeoBoundingBox, IriForecastProb >>> country_config = create_country_config(iso3="bfa") >>> geo_bounding_box = GeoBoundingBox(lat_max=13.0, ... lat_min=12.0, ... lon_max=-3.0, ... lon_min=-2.0) >>> >>> # Initialize class and retrieve data >>> iri = IriForecastProb(country_config,geo_bounding_box) >>> iri.download() # Must have IRI_AUTH environment variable set >>> iri.process() >>> >>> iri_data = iri.load()
- class ochanticipy.UsgsNdviMedianAnomaly(country_config: CountryConfig, start_date: date | str | Tuple[int, int] | None = None, end_date: date | str | Tuple[int, int] | None = None)[source]¶
Bases:
_UsgsNdviBase class to retrieve NDVI anomaly data.
The retrieved data is NDVI anomaly data calculated as a subtraction of the median value, based on data from 2003 - 2017, from the current value. Negative values indicate less vegetation than the median, positive values indicate more vegetation.
- Parameters:
country_config (CountryConfig) – Country configuration
start_date (_DATE_TYPE, default = None) – Start date. Can be passed as a
datetime.dateobject or a data string in ISO8601 format, and the relevant dekad will be determined. Or pass directly as year-dekad tuple, e.g. (2020, 1). IfNone,start_dateis set to earliest date with data: 2002, dekad 19.end_date (_DATE_TYPE, default = None) – End date. Can be passed as a
datetime.dateobject and the relevant dekad will be determined, as a date string in ISO8601 format, or as a year-dekad tuple, i.e. (2020, 1). IfNone,end_dateis set todate.today().
Examples
>>> from ochanticipy import create_country_config, ... CodAB, UsgsNdviMedianAnomaly >>> >>> # Retrieve admin 2 boundaries for Burkina Faso >>> country_config = create_country_config(iso3="bfa") >>> codab = CodAB(country_config=country_config) >>> bfa_admin2 = codab.load(admin_level=2) >>> >>> # setup NDVI >>> bfa_ndvi = UsgsNdviMedianAnomaly( ... country_config=country_config, ... start_date=[2020, 1], ... end_date=[2020, 3] ... ) >>> bfa_ndvi.download() >>> bfa_ndvi.process( ... gdf=bfa_admin2, ... feature_col="ADM2_FR" ... ) >>> >>> # load in processed data >>> df = bfa_ndvi.load(feature_col="ADM2_FR")
- class ochanticipy.UsgsNdviPctMedian(country_config: CountryConfig, start_date: date | str | Tuple[int, int] | None = None, end_date: date | str | Tuple[int, int] | None = None)[source]¶
Bases:
_UsgsNdviBase class to retrieve % of median NDVI.
The retrieved data is the percent of median NDVI values calculated from 2003 - 2017, as processed by the USGS.
- Parameters:
country_config (CountryConfig) – Country configuration
start_date (_DATE_TYPE, default = None) – Start date. Can be passed as a
datetime.dateobject or a data string in ISO8601 format, and the relevant dekad will be determined. Or pass directly as year-dekad tuple, e.g. (2020, 1). IfNone,start_dateis set to earliest date with data: 2002, dekad 19.end_date (_DATE_TYPE, default = None) – End date. Can be passed as a
datetime.dateobject and the relevant dekad will be determined, as a date string in ISO8601 format, or as a year-dekad tuple, i.e. (2020, 1). IfNone,end_dateis set todate.today().
Examples
>>> from ochanticipy import create_country_config, ... CodAB, UsgsNdviPctMedian >>> >>> # Retrieve admin 2 boundaries for Burkina Faso >>> country_config = create_country_config(iso3="bfa") >>> codab = CodAB(country_config=country_config) >>> bfa_admin2 = codab.load(admin_level=2) >>> >>> # setup NDVI >>> bfa_ndvi = UsgsNdviPctMedian( ... country_config=country_config, ... start_date=[2020, 1], ... end_date=[2020, 3] ... ) >>> bfa_ndvi.download() >>> bfa_ndvi.process( ... gdf=bfa_admin2, ... feature_col="ADM2_FR" ... ) >>> >>> # load in processed data >>> df = bfa_ndvi.load(feature_col="ADM2_FR")
- class ochanticipy.UsgsNdviSmoothed(country_config: CountryConfig, start_date: date | str | Tuple[int, int] | None = None, end_date: date | str | Tuple[int, int] | None = None)[source]¶
Bases:
_UsgsNdviBase class to retrieve smoothed NDVI data.
The retrieved data is the smoothed NDVI values processed by the USGS. Temporal smoothing is done to adjust for cloud cover and other errors. Data for the 3 most recent dekads is not fully smoothed, and are re-smoothed at the end of the 3 dekad period.
- Parameters:
country_config (CountryConfig) – Country configuration
start_date (_DATE_TYPE, default = None) – Start date. Can be passed as a
datetime.dateobject or a data string in ISO8601 format, and the relevant dekad will be determined. Or pass directly as year-dekad tuple, e.g. (2020, 1). IfNone,start_dateis set to earliest date with data: 2002, dekad 19.end_date (_DATE_TYPE, default = None) – End date. Can be passed as a
datetime.dateobject and the relevant dekad will be determined, as a date string in ISO8601 format, or as a year-dekad tuple, i.e. (2020, 1). IfNone,end_dateis set todate.today().
Examples
>>> from ochanticipy import create_country_config, ... CodAB, UsgsNdviSmoothed >>> >>> # Retrieve admin 2 boundaries for Burkina Faso >>> country_config = create_country_config(iso3="bfa") >>> codab = CodAB(country_config=country_config) >>> bfa_admin2 = codab.load(admin_level=2) >>> >>> # setup NDVI >>> bfa_ndvi = UsgsNdviSmoothed( ... country_config=country_config, ... start_date=[2020, 1], ... end_date=[2020, 3] ... ) >>> bfa_ndvi.download() >>> bfa_ndvi.process( ... gdf=bfa_admin2, ... feature_col="ADM2_FR" ... ) >>> >>> # load in processed data >>> df = bfa_ndvi.load(feature_col="ADM2_FR")
- class ochanticipy.UsgsNdviYearDifference(country_config: CountryConfig, start_date: date | str | Tuple[int, int] | None = None, end_date: date | str | Tuple[int, int] | None = None)[source]¶
Bases:
_UsgsNdviBase class to retrieve NDVI year difference data.
The retrieved data is NDVI yearly difference data, calculated as the subtraction of the previous year’s NDVI value from the current year’s. Negative values indicate the current vegetation is less than the previous year’s, positive that there is more vegetation in the current year.
- Parameters:
country_config (CountryConfig) – Country configuration
start_date (_DATE_TYPE, default = None) – Start date. Can be passed as a
datetime.dateobject or a data string in ISO8601 format, and the relevant dekad will be determined. Or pass directly as year-dekad tuple, e.g. (2020, 1). IfNone,start_dateis set to earliest date with data: 2002, dekad 19.end_date (_DATE_TYPE, default = None) – End date. Can be passed as a
datetime.dateobject and the relevant dekad will be determined, as a date string in ISO8601 format, or as a year-dekad tuple, i.e. (2020, 1). IfNone,end_dateis set todate.today().
Examples
>>> from ochanticipy import create_country_config, ... CodAB, UsgsNdviDifference >>> >>> # Retrieve admin 2 boundaries for Burkina Faso >>> country_config = create_country_config(iso3="bfa") >>> codab = CodAB(country_config=country_config) >>> bfa_admin2 = codab.load(admin_level=2) >>> >>> # setup NDVI >>> bfa_ndvi = UsgsNdviDifference( ... country_config=country_config, ... start_date=[2020, 1], ... end_date=[2020, 3] ... ) >>> bfa_ndvi.download() >>> bfa_ndvi.process( ... gdf=bfa_admin2, ... feature_col="ADM2_FR" ... ) >>> >>> # load in processed data >>> df = bfa_ndvi.load(feature_col="ADM2_FR")
- ochanticipy.create_country_config(iso3: str) CountryConfig[source]¶
Return a country configuration object from AA Toolbox.
- Parameters:
iso3 (str) – Country ISO3, must be exactly 3 letters long
- Return type:
CountryConfig instance
- ochanticipy.create_custom_country_config(filepath: str | Path) CountryConfig[source]¶
Return a custom country configuration object.
- Parameters:
filepath (str, pathlib.Path) – Path to the configuration file
- Return type:
CountryConfig instance