Skip to content

DELI-276 include historical refactor for get_descendant() #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"source": [
"## Drought\n",
"\n",
"There are many data series related to drought. Here we use the [Gro Drought Index (GDI)](https://gro-intelligence.com/gro-models/gro-drought-index), which is available at the district and province level, daily and weekly. For simplicity, let us take the weekly GDI series at the province level."
"There are many data series related to drought. Here we use the [Gro Drought Index (GDI)](https://gro-intelligence.com/models/gro-drought-index), which is available at the district and province level, daily and weekly. For simplicity, let us take the weekly GDI series at the province level."
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/modeling-resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Modeling Resources
Gro Crop Cover
==============

Gro's proprietary high-resolution crop covers are currently used in the `Gro yield models <https://gro-intelligence.com/gro-models>`_. These have proven very successful i.e. more accurate for yield modeling than the best available alternatives. Gro does not plan on developing a yield model for every crop or region in the world, so our models will always be limited to the regions and crops where we can help push the envelope. Users can access our crop covers in the `Gro web app <https://app.gro-intelligence.com/displays/jdOQrvERw>`_ and the API, or from the download links below. In the web app and API, users can interact with detailed cropland covers that indicate the intensity of crop cover for a particular pixel. Below users can download .tif files of low and high-confidence crop covers which represent, as a binary value, whether a crop is growing in a specific pixel.
Gro's proprietary high-resolution crop covers are currently used in the `Gro yield models <https://gro-intelligence.com/platform/models-and-applications>`_. These have proven very successful i.e. more accurate for yield modeling than the best available alternatives. Gro does not plan on developing a yield model for every crop or region in the world, so our models will always be limited to the regions and crops where we can help push the envelope. Users can access our crop covers in the `Gro web app <https://app.gro-intelligence.com/displays/jdOQrvERw>`_ and the API, or from the download links below. In the web app and API, users can interact with detailed cropland covers that indicate the intensity of crop cover for a particular pixel. Below users can download .tif files of low and high-confidence crop covers which represent, as a binary value, whether a crop is growing in a specific pixel.

Methodology
-----------
Expand Down Expand Up @@ -148,7 +148,7 @@ A low-confidence cover and a high-confidence cover were made from the yearly cro
Gro Yield Model Backtest Data
=============================

`Gro yield models <https://gro-intelligence.com/gro-models>`_ provide live forecasts for crops in different regions around the world. To supplement our in-depth papers on the models, we provide backtesting data for model evaluation and comparisons.
`Gro yield models <https://gro-intelligence.com/platform/models-and-applications>`_ provide live forecasts for crops in different regions around the world. To supplement our in-depth papers on the models, we provide backtesting data for model evaluation and comparisons.

File Formats
------------
Expand Down
2 changes: 1 addition & 1 deletion groclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def get_descendant(
descendant_level : integer, optional
The region level of interest. See REGION_LEVELS constant. This should only be specified
if the `entity_type` is 'regions'. If provided along with `distance`, `distance` will
take precedence. If not provided, and `distance` not provided, get all ancestors.
take precedence. If not provided, and `distance` not provided, get all descendants.
include_historical : boolean, optional
True by default. If False is specified, regions that only exist in historical data
(e.g. the Soviet Union) will be excluded.
Expand Down
13 changes: 4 additions & 9 deletions groclient/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,20 +675,15 @@ def get_descendant(access_token, api_host, entity_type, entity_id, distance=None
else:
params['distance'] = -1

params['includeHistorical'] = include_historical

resp = get_data(url, headers, params)
descendant_entity_ids = resp.json()['data'][str(entity_id)]

# Filter out regions with the 'historical' flag set to true
if not include_historical or include_details:
if include_details:
entity_details = lookup(access_token, api_host, entity_type, descendant_entity_ids)

if not include_historical:
descendant_entity_ids = [entity['id'] for entity in entity_details.values()
if not entity['historical']]

if include_details:
return [entity_details[str(child_entity_id)] for child_entity_id in
descendant_entity_ids]
return [entity_details[str(child_entity_id)] for child_entity_id in descendant_entity_ids]

return [{'id': descendant_entity_id} for descendant_entity_id in descendant_entity_ids]

Expand Down
10 changes: 6 additions & 4 deletions groclient/lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,21 @@ def test_get_descendant(mock_requests_get, lookup_mocked):
{'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False}
]

assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3, include_historical=False) == [
{'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False}
]

assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3,
include_historical=True, include_details=True) == [
{'id': 1, 'name': 'region 1', 'contains': [], 'belongsTo': [3], 'historical': True},
{'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False}
]

mock_requests_get.return_value.json.return_value = {'data': {'3': [2]}}
assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3, include_historical=False,
include_details=False) == [{'id': 2}]

assert lib.get_descendant(MOCK_TOKEN, MOCK_HOST, 'regions', 3, include_historical=False,
include_details=True) == [
{'id': 2, 'name': 'region 2', 'contains': [], 'belongsTo': [3], 'historical': False}
]


@mock.patch('requests.get')
def test_get_top(mock_requests_get):
Expand Down