dynacrop package¶
Submodules¶
dynacrop.api_handles module¶
- class dynacrop.api_handles.RequestsHelper¶
Bases:
object
Interface for handling requests.
- classmethod get(id: str, endpoint: str) dict ¶
Creates a GET request for the supplied id and endpoint.
- Parameters
id (str) – Used to indentify the endpoint instance.
endpoint (str) – One of the DynaCrop API endpoints.
- Returns
Reponse to the request.
- Return type
dict
- classmethod patch(id: str, data: dict, endpoint: str) dict ¶
Creates a PATCH request for the supplied id, endpoint and patch data.
- Args:
id (str): Used to indentify the endpoint instance. data (dict): Used to patch the existing backend data. endpoint (str): One of the DynaCrop API endpoints.
- Returns:
dict: Response to the request with patched data.
- classmethod post(data: dict, endpoint: str) dict ¶
Creates a POST request for the supplied id, endpoint and post data.
- Parameters
id (str) – Used to indentify the endpoint instance.
data (dict) – Used to create new instance of the endpoint
backend. (on the) –
endpoint (str) – One of the DynaCrop API endpoints.
- Returns
Response to the request with a new instance of endpoint.
- Return type
dict
- classmethod delete(id: str, endpoint: str)¶
Creates a DELETE request for the supplied endpoint and id.
- Parameters
id (str) – Used to indentify the endpoint instance.
endpoint (str) – One of the DynaCrop API endpoints.
- Returns
[description]
- Return type
[type]
- classmethod list(endpoint: Optional[str] = None, url: Optional[str] = None) dict ¶
Fetches bulk version of an endpoint to return pagination info and multiple endpoint results.
- Parameters
endpoint (str) – One of the DynaCrop API endpoints. Either endpoint or url must be stated.
url (int) – URL to list endpoints. Either endpoint or url must be stated.
- Returns
Response to the request.
- Return type
dict
- classmethod handle_response(response: requests.models.Response)¶
Handles response from the request methods.
- Parameters
response (dict) – Reponse supplied via request methods
class (of the RequestHelper) –
- Raises
APIObjectNotFound – 404 Not Found. Might be a non-existent response content or a API-side error.
APIRequestNotValid – 400 Bad Request. Might be a wrongly defined request.
UnexpectedServerError – 500 Internal Server Error. Might be an API error that can only be resolved on server side.
ServiceNotImplementedError – 501 Not Implemented. The request was not recognized by the API server. Might be implemented in the future.
BadGatewayError – 502 Bad Gateway. There could have been an error beyond the DynaCrop API.
ServiceUnavailableError – 503 Service Unavailable. The API is temporarily unavailable.
HandlingResponseError – Some other unrecognized error.
Returns: None
- classmethod build_url(*args: Optional[str]) str ¶
Builds internet url based on parameters
- Returns
Built URL.
- Return type
str
- class dynacrop.api_handles.APIObject(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
object
Metaclass for various endpoints of the API.
- classmethod get(id: Optional[int] = None) dynacrop.api_handles.APIObject ¶
Acquires APIObject instatiated into one of the DynaCrop API endpoints.
- Parameters
id (int) – ID of an endpoint request.
- Returns
APIObject made to an API endpoint.
- Return type
- classmethod create(**kwargs) dynacrop.api_handles.APIObject ¶
Creates APIObject later instatiated into one of the DynaCrop API endpoints.
- Parameters
kwargs (Optional[str]) –
- Returns
APIObject made to an API endpoint.
- Return type
- delete()¶
Deletes APIObject from the API.
- classmethod list() Iterator[dynacrop.api_handles.APIObject] ¶
Fetches APIObjects in bulk as an iterator.
- Returns
Iterator of APIObjects.
- Return type
- is_ready() bool ¶
Checks whether the request is ready.
- Returns
Is ready statement.
- Return type
bool
- is_failed() bool ¶
Checks whether the request failed.
- Returns
Failure statement.
- Return type
bool
- block_till_completed(polling_interval: int = 1)¶
Suspends the code execution until the request response is returned as finished/with error/with no data.
- Args:
polling_interval (int, optional): Time to wait between checking iterations. Defaults to 1.
- refresh()¶
Updates response data.
- class dynacrop.api_handles.APIObjectIterator(cls: Type[dynacrop.api_handles.APIObject])¶
Bases:
object
Iterator for listing existing APIObjects.
- map_to_correct_instance(endpoint_data: dict) dynacrop.api_handles.APIObject ¶
Maps an APIObject (like ProcessingRequest) to a correct child if necessary.
- Parameters
endpoint_data (dict) – Data of the API endpoint/object.
- Returns
Profound APIObject instance.
- Return type
dynacrop.constants module¶
- class dynacrop.constants.Layer(value)¶
Bases:
enum.Enum
An enumeration.
- NDVI = 'NDVI'¶
- EVI = 'EVI'¶
- FAPAR = 'FAPAR'¶
- LAI = 'LAI'¶
- NDMI = 'NDMI'¶
- CCC = 'CCC'¶
- CWC = 'CWC'¶
- NDWI = 'NDWI'¶
- MSAVI2 = 'MSAVI2'¶
- NDRE = 'NDRE'¶
- NDREX = 'NDREX'¶
- SMI = 'SMI'¶
- IRECI = 'IRECI'¶
- NDDI = 'NDDI'¶
- NMDI = 'NMDI'¶
- MNDWI = 'MNDWI'¶
- WIW = 'WIW'¶
- class dynacrop.constants.RenderingType(value)¶
Bases:
enum.Enum
An enumeration.
- OBSERVATION = 'observation'¶
- TIME_SERIES = 'time_series'¶
- FIELD_ZONATION = 'field_zonation'¶
- FIELD_ZONATION_BY_MEDIAN = 'field_zonation_by_median'¶
- class dynacrop.constants.Result(value)¶
Bases:
enum.Enum
An enumeration.
- RAW = 'raw'¶
- COLOR = 'color'¶
- PNG = 'png'¶
- TILES_COLOR = 'tiles_color'¶
- TILES_DEMO = 'tiles_demo'¶
- SHP = 'shp'¶
- GEOJSON = 'geojson'¶
- SHP_SIMPLIFIED = 'shp_simplified'¶
- GEOJSON_SIMPLIFIED = 'geojson_simplified'¶
- JSON = 'json'¶
- STATISTICS = 'statistics'¶
- FREQUENCIES = 'frequencies'¶
dynacrop.processing_request_base module¶
- class dynacrop.processing_request_base.ProcessingRequest(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.api_handles.APIObject
,dynacrop.attrs.processing_request.ProcessingRequestAttrs
Processing request endpoint object
- refresh()¶
Updates the response data of the Processing request.
- Raises
InvalidRenderingTypeError – If an already-created processing request is a different rendering type than requested.
- classmethod create(**kwargs) dynacrop.api_handles.APIObject ¶
Creates Processing request endpoint object.
- Returns
APIObject instatiated into ProcessingRequest child.
- Return type
- classmethod validate(kwargs: dict)¶
Validates Processing request result status.
- Parameters
kwargs (dict) –
- Raises
PolygonNotReadyForProcessingError – If the Processing request is created or requested while the target Polygon is not yet processed.
- static correct_dates(dates: list) list ¶
Checks if dates need to be corrected and does so.
- Parameters
dates (list) – Dates within a processing request.
- Returns
List with converted dates.
- Return type
tuple
- static convert_date_to_str(date: datetime.datetime) str ¶
Converts datetime.date to string if necessary
- Parameters
date (datetime) – Date in datetime.datetime format.
- Returns
Date in string format.
- Return type
str
- has_data() bool ¶
Checks whether the Processing request returned any data.
- Returns
Data filling statetment.
- Return type
bool
- class dynacrop.processing_request_base.RasterProcessingRequest(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.processing_request_base.ProcessingRequest
Baseclass for raster and vector Processing request results. Mainly serves for handlig results.
- as_array(clouds_as_nan: bool = True, outwards_as_nan: bool = True) numpy.ndarray ¶
Wrapper method for private _get_raster.
- Parameters
clouds_as_nan (bool) – Whether convert clouds to NumPy.nan instead of default -999
outwards_as_nan (bool) – Whether convert values outside of the field shape to NumPy.nan instead of deafult -998
- Returns
Multidimensional NumPy array.
- Return type
numpy.ndarray
- get_tiff_url() str ¶
Returns RAW (TIFF) URL.
- Returns
RAW (TIFF) URL.
- Return type
str
- save_tiff(path: str)¶
Saves result in RAW TIFF format.
- Parameters
path (str) – Path to save the file.
- get_colored_tiff_url() str ¶
Returns COLORED TIFF URL.
- Returns
COLORED TIFF URL.
- Return type
str
- save_colored_tiff(path: str)¶
Saves result in COLORED TIFF format.
- Parameters
path (str) – Path to save the file.
- get_png_url() str ¶
Returns PNG URL.
- Returns
PNG URL.
- Return type
str
- save_png(path: str)¶
Saves result in PNG format.
- Parameters
path (str) – Path to save the file.
- get_tiles_url() str ¶
Get tiles URL.
- Returns
Tiles URL.
- Return type
str
- get_demo_tiles_url() str ¶
Get demo tiles URL for preview.
- Returns
Demo tiles URL.
- Return type
str
- preview()¶
Opens default browser in a new tab using demo tiles URL. This is an easy result preview.
- as_geodataframe() geopandas.geodataframe.GeoDataFrame ¶
Wrapper method for private _get_vector.
- Returns
Geopandas GeoDataFrame.
- Return type
gpd.GeoDataFrame
- get_shapefile_url() str ¶
Returns shapefile URL.
- Returns
Shapefile URL.
- Return type
str
- save_shapefile(path: str)¶
Saves result in as shapefile.
- Parameters
path (str) – Path to save the file.
- get_geojson_url() str ¶
Returns GeoJSON URL.
- Returns
GeoJSON URL.
- Return type
str
- save_geojson(path: str)¶
Saves result as GeoJSON.
- Parameters
path (str) – Path to save the file.
- get_frequencies_url() str ¶
Returns frequencies URL.
- Returns
Frequencies URL.
- Return type
str
- get_frequencies() dict ¶
Acquires percentual shares of value intervals of the field area.
- Returns
- Keys are tuples of intervals, values are percentual
shares.
- Return type
dict
- class dynacrop.processing_request_base.JSONProcessingRequest(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.processing_request_base.ProcessingRequest
Baseclass for JSON Processing request results. Mainly serves for handlig results.
- get_json() dict ¶
Acquires JSON result as a dictionary from the Processing request response.
- Raises
RequestHasNoData – If result has returned no data. This might be caused due to unavailability of satellite images within the date range.
- Returns
JSON data as Python dictionary.
- Return type
dict
- save_json(path: str)¶
Saves JSON result.
- Parameters
path (str) – Path to save the file.
- class dynacrop.processing_request_base.ObservationBase(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.processing_request_base.RasterProcessingRequest
Baseclass for specific methods of Observation
- get_stats_url() str ¶
Returns stats URL.
- Returns
Stats URL.
- Return type
str
- get_mean() float ¶
Returns mean of the field from the Observation endpoint.
- Returns
Mean of the field values.
- Return type
float
- get_median() float ¶
Returns median of the field from the Observation endpoint.
- Returns
Median of the field values.
- Return type
float
- get_sd() float ¶
Returns standard deviation of the field from the Observation endpoint.
- Returns
Standard deviation of the field values.
- Return type
float
- get_min() float ¶
Returns minimum of the field from the Observation endpoint.
- Returns
Minimum of the field values.
- Return type
float
- get_max() float ¶
Returns maximum of the field from the Observation endpoint.
- Returns
Maximum of the field values.
- Return type
float
- get_percentiles() dict ¶
Returns percentiles of the field from the Observation endpoint.
- Returns
Percentiles of the field values.
- Return type
float
- class dynacrop.processing_request_base.FieldZonationBase(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.processing_request_base.RasterProcessingRequest
Baseclass for specific methods of FieldZonation
- get_simplified_geojson_url() str ¶
Returns simplified GeoJSON URL.
- Returns
Simplified GeoJSON URL.
- Return type
str
- save_simplified_geojson(path: str)¶
Saves simplified GeoJSON result.
- Parameters
path (str) – Path to save the file.
- get_simplified_shapefile_url() str ¶
Returns simplified shapefile URL.
- Returns
Simplified shapefile URL.
- Return type
str
- save_simplified_shapefile(path: str)¶
Saves simplified shapefile result.
- Parameters
path (str) – Path to save the file.
dynacrop.sdk module¶
- class dynacrop.sdk.User¶
Bases:
dynacrop.api_handles.APIObject
,dynacrop.attrs.user.UserAttrs
User endpoint object
- class dynacrop.sdk.Polygon(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.api_handles.APIObject
,dynacrop.attrs.polygon.PolygonAttrs
Polygon endpoint object
- classmethod create(geometry: str, label: Optional[str] = None, max_mean_cloud_cover: Optional[int] = None, smi_enabled: bool = False, **kwargs) dynacrop.sdk.Polygon ¶
Creates Polygon endpoint object.
- Parameters
geometry (str) – Valid polygon shape in Well Known Text (WKT) representation (see: https://en.wikipedia.org/wiki/Well- known_text_representation_of_geometry).
label (Optional[str], optional) – Description to the Polygon (user field). Defaults to None.
max_mean_cloud_cover (Optional[int], optional) – Maximum mean cloud coverage in decimal percentage (i.e. 0.3). Defaults to None.
smi_enabled (bool, optional) – To enable Soil Moisture Index pre-computation. Defaults to False.
- Returns
APIObject instantiated into Polygon child.
- Return type
- static as_geodataframe(polygons: list, fields: list = ['id', 'area', 'last_valid_observation', 'smi_enabled', 'max_mean_cloud_cover', 'label', 'valid_observations', 'cloud_cover_percent', 'last_updated', 'created_date', 'completed_date', 'last_updated'], iterables_to_strings: Optional[bool] = True) geopandas.geodataframe.GeoDataFrame ¶
Create a Geopandas GeoDataFrame from a list of Polygon objects. This can be then saved to a file by GeoDataFrame to_file method.
- Parameters
polygons (list) – A list of polygons to create the GeoDataFrame from.
fields (Optional[list], optional) – Polygon attributes that will be represented as fields in the GeoDataFrame. Iterable attributes are converted to string for save . Defaults to [“id”, “area”, “last_valid_observation”, “smi_enabled”, “max_mean_cloud_cover” , “label”, “valid_observations”, “cloud_cover_percent”, “last_updated”, “created_date”, “completed_date”, “last_updated “].
iterables_to_strings (Optional[bool], optional) – If True, all iterable Polygon attributes will be converted to strings for saving purposes. Spatial files usually reject saving Python iterables to attribute tables.
- Returns
GeoDataFrame of polygons.
- Return type
GeoDataFrame
- class dynacrop.sdk.TimeSeries(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.processing_request_base.JSONProcessingRequest
Time series endpoint object. Time series is the service of DynaCrop API.
- rendering_type = 'time_series'¶
- classmethod create(polygon: dynacrop.sdk.Polygon, layer: dynacrop.constants.Layer, date_from: str, date_to: str) dynacrop.sdk.TimeSeries ¶
Creates Time series endpoint object.
- Parameters
polygon (Polygon) – Polygon endpoint object.
layer (str) – Should be Layer enumration. One of the DynaCrop API layers. See https://dynacrop.worldfromspace.cz/docs/#/products for further information.
date_from (str) – Date to record time series from.
date_to (str) – Date to record time series to.
- Returns
APIObject instatiated into TimeSeries child.
- Return type
- date_from: str¶
- date_to: str¶
- value_no_data: int¶
- value_clouds: int¶
- result: dict¶
- layer: dynacrop.constants.Layer¶
- polygon_id: int¶
- number_of_zones: Optional[int]¶
- thresholds: list¶
- id: int¶
- status: str¶
- error: Optional[str]¶
- completed_date: str¶
- created_date: str¶
- rendering_time: int¶
- class dynacrop.sdk.Observation(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.processing_request_base.ObservationBase
Observation endpoint object. Observation is the service of DynaCrop API.
- rendering_type = 'observation'¶
- classmethod create(polygon: dynacrop.sdk.Polygon, layer: dynacrop.constants.Layer, date_from: str, date_to: str) dynacrop.sdk.Observation ¶
Creates Observation endpoint object.
- Parameters
polygon (Polygon) – Polygon endpoint object.
layer (str) – Should be Layer enumration. One of the DynaCrop API layers. See https://dynacrop.worldfromspace.cz/docs/#/products for further information.
date_from (str) – Date to watch for observation from.
date_to (str) – Date to watch for observation to.
- Returns
APIObject instatiated into Observation child.
- Return type
- date_from: str¶
- date_to: str¶
- value_no_data: int¶
- value_clouds: int¶
- result: dict¶
- layer: dynacrop.constants.Layer¶
- polygon_id: int¶
- number_of_zones: Optional[int]¶
- thresholds: list¶
- id: int¶
- status: str¶
- error: Optional[str]¶
- completed_date: str¶
- created_date: str¶
- rendering_time: int¶
- class dynacrop.sdk.FieldZonation(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.processing_request_base.FieldZonationBase
Field zonation endpoint object. Field zonation is the service of DynaCrop API.
- rendering_type = 'field_zonation'¶
- classmethod create(polygon: dynacrop.sdk.Polygon, layer: dynacrop.constants.Layer, date_from: str, date_to: str, number_of_zones: int = 3) dynacrop.sdk.FieldZonation ¶
Creates Field zonation endpoint object.
- Parameters
polygon (Polygon) – Polygon endpoint object.
layer (str) – Should be Layer enumration. One of the DynaCrop API layers. See https://dynacrop.worldfromspace.cz/docs/#/products for further information.
date_from (str) – Date to compute field zonation from.
date_to (str) – Date to compute field zonation to.
number_of_zones (int) – Number of zones to separate the field to. The number of zones must be one of 3, 5, 10, 20, 255.
- Returns
APIObject instatiated into FieldZonation child.
- Return type
- date_from: str¶
- date_to: str¶
- value_no_data: int¶
- value_clouds: int¶
- result: dict¶
- layer: dynacrop.constants.Layer¶
- polygon_id: int¶
- number_of_zones: Optional[int]¶
- thresholds: list¶
- id: int¶
- status: str¶
- error: Optional[str]¶
- completed_date: str¶
- created_date: str¶
- rendering_time: int¶
- class dynacrop.sdk.FieldZonationByMedian(id: Optional[int] = None, ext_data: Optional[dict] = None)¶
Bases:
dynacrop.processing_request_base.FieldZonationBase
Field zonation by median endpoint object. Field zonation by median is the service of DynaCrop API.
- rendering_type = 'field_zonation_by_median'¶
- classmethod create(polygon: dynacrop.sdk.Polygon, layer: dynacrop.constants.Layer, date_from: str, date_to: str, thresholds: Optional[list] = None) dynacrop.sdk.FieldZonationByMedian ¶
Creates Field zonation by median endpoint object.
- Parameters
polygon (Polygon) – Polygon endpoint object.
layer (str) – Should be Layer enumration. One of the DynaCrop API layers. See https://dynacrop.worldfromspace.cz/docs/#/products for further information.
date_from (str) – Date to compute field zonation by median from.
date_to (str) – Date to compute field zonation by median to.
thresholds (list) – Thresholds to zone the field in between. The number of thresholds must be one of 2, 4, 9, 19, 254.
- Returns
APIObject instatiated into FieldZonationByMedian child.
- Return type
- date_from: str¶
- date_to: str¶
- value_no_data: int¶
- value_clouds: int¶
- result: dict¶
- layer: dynacrop.constants.Layer¶
- polygon_id: int¶
- number_of_zones: Optional[int]¶
- thresholds: list¶
- id: int¶
- status: str¶
- error: Optional[str]¶
- completed_date: str¶
- created_date: str¶
- rendering_time: int¶