Skip to content

Commit

Permalink
Merge pull request #261 from vermeulendivan/dev_samz_auto_custom
Browse files Browse the repository at this point in the history
Dev samz auto custom
  • Loading branch information
vermeulendivan committed Apr 10, 2023
2 parents 8eab008 + 039e550 commit c4818cd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
7 changes: 3 additions & 4 deletions geosys/bridge_api/field_level_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,15 @@ def get_field_map(
)
elif map_type['key'] == SAMZ['key']:
full_url = self.full_url(
'season-fields',
seasonfield_id,
'maps',
'management-zones-map',
'SAMZ'
)

response = self.get(
response = self.post(
full_url,
headers=headers,
params=params,
# params=params,
json=data
)
elif map_type['key'] == SOIL['key']:
Expand Down
8 changes: 5 additions & 3 deletions geosys/bridge_api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,15 @@ def get_difference_map(
return self._get_field_map(
difference_map_definition['key'], request_data, params=params)

def get_samz_map(self, season_field_id, list_of_image_date=None, **kwargs):
def get_samz_map(self, season_field_id, list_of_image_ids, list_of_image_date=None, **kwargs):
"""Get requested SAMZ map.
:param season_field_id: ID of the season field.
:param season_field_id: str
:param list_of_image_ids: IDs of selected images.
:param list_of_image_ids: list
:param list_of_image_date: List of image date indicating the maps
which are going to be compiled.
:type list_of_image_date: list
Expand All @@ -458,14 +461,13 @@ def get_samz_map(self, season_field_id, list_of_image_date=None, **kwargs):
Map data specification based on given criteria.
:rtype: dict
"""
list_of_image_date = list_of_image_date if list_of_image_date else []
# Construct map creation parameters
request_data = {
"SeasonField": {
"Id": season_field_id
},
"Images": [
{"Date": image_date} for image_date in list_of_image_date
{"id": image_id} for image_id in list_of_image_ids
]
}
request_data.update(kwargs)
Expand Down
10 changes: 9 additions & 1 deletion geosys/ui/widgets/geosys_coverage_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ def create_difference_map(

def create_samz_map(
season_field_id,
list_of_image_ids,
list_of_image_date,
output_dir,
filename,
Expand All @@ -715,6 +716,9 @@ def create_samz_map(
:param season_field_id: ID of the season field.
:param season_field_id: str
:param list_of_image_ids: List of selected image IDs
:param list_of_image_ids: list
:param list_of_image_date: List of image date indicating the maps
which are going to be compiled.
:type list_of_image_date: list
Expand Down Expand Up @@ -749,7 +753,11 @@ def create_samz_map(
*credentials_parameters_from_settings(),
proxies=QGISSettings.get_qgis_proxy())
samz_map_json = bridge_api.get_samz_map(
season_field_id, list_of_image_date, **data)
season_field_id,
list_of_image_ids,
list_of_image_date,
**data
)

return download_field_map(
field_map_json=samz_map_json,
Expand Down
11 changes: 10 additions & 1 deletion geosys/ui/widgets/geosys_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,14 @@ def _start_map_creation(self, map_specifications):
zone_cnt = self.samz_zone_form.value()
if map_product_definition == SAMZ:
image_dates = []
image_ids = []
samz_mode = 'auto'
if map_specifications:
season_field_id = map_specifications[0]['seasonField']['id']
samz_mode = 'custom'
for map_specification in map_specifications:
image_dates.append(map_specification['image']['date'])
image_ids.append(map_specification['image']['id'])
else:
# take season field id from the first item in coverage results
item = self.coverage_result_list.item(0)
Expand All @@ -831,7 +833,7 @@ def _start_map_creation(self, map_specifications):
)

is_success, message = create_samz_map(
season_field_id, image_dates, self.output_directory, filename,
season_field_id, image_ids, image_dates, self.output_directory, filename,
output_map_format=self.output_map_format, params=data)

if not is_success:
Expand Down Expand Up @@ -1193,6 +1195,13 @@ def product_type_change(self):
# Other maps types makes use of the weather type
self.cb_weather.setEnabled(True)

if map_product == SAMZ['name']:
self.start_date_edit.setEnabled(False)
self.end_date_edit.setEnabled(False)
else:
self.start_date_edit.setEnabled(True)
self.end_date_edit.setEnabled(True)

list_nitrogen_maps = [
INSEASONFIELD_AVERAGE_NDVI['name'],
INSEASONFIELD_AVERAGE_REVERSE_NDVI['name'],
Expand Down

0 comments on commit c4818cd

Please sign in to comment.