Skip to main content

ValueError: operands could not be broadcast together with shapes (0,1)

  • April 26, 2024
  • 8 replies
  • 306 views

I use the following code and example provided in Sentinel-Hub to calculate the area of lakes:

Here

For me this code worked for one region but the other 7 got this error:

ValueError: operands could not be broadcast together with shapes (0,1) (818,1003,1)

8 replies

orginal error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [15], in <cell line: 4>()
      1 # The download task requires additional arguments at execution. These are linked to the node the task is in.
      2 download_node = workflow_nodes[0]
----> 4 result = workflow.execute(
      5     {
      6         download_node: {"bbox": dam_bbox, "time_interval": time_interval},
      7     }
      8 )

File c:\users\basin\appdata\local\programs\python\python38\lib\site-packages\eolearn\core\eoworkflow.py:152, in EOWorkflow.execute(self, input_kwargs, raise_errors)
    149 self.validate_input_kwargs(input_kwargs)
    150 uid_input_kwargs = {node.uid: args for node, args in input_kwargs.items()}
--> 152 output_results, stats_dict = self._execute_nodes(
    153     uid_input_kwargs=uid_input_kwargs, out_degrees=out_degrees, raise_errors=raise_errors
    154 )
    156 results = WorkflowResults(
    157     outputs=output_results, start_time=start_time, end_time=dt.datetime.now(), stats=stats_dict
    158 )
    160 LOGGER.debug("EOWorkflow ended with results %s", repr(results))

File c:\users\basin\appdata\local\programs\python\python38\lib\site-packages\eolearn\core\eoworkflow.py:205, in EOWorkflow._execute_nodes(self, uid_input_kwargs, out_degrees, raise_errors)
    202 stats_dict = {}
    204 for node in self._nodes:
--> 205     result, stats = self._execute_node(
    206         node=node,
    207         node_input_values=[intermediate_results[input_node.uid] for input_node in node.inputs],
    208         node_input_kwargs=uid_input_kwargs.get(node.uid, {}),
    209         raise_errors=raise_errors,
    210     )
    212     stats_dict[node.uid] = stats
    213     if stats.exception is not None:

File c:\users\basin\appdata\local\programs\python\python38\lib\site-packages\eolearn\core\eoworkflow.py:239, in EOWorkflow._execute_node(self, node, node_input_values, node_input_kwargs, raise_errors)
    237 LOGGER.debug("Computing %s(*%s, **%s)", node.task.__class__.__name__, str(task_args), str(node_input_kwargs))
    238 start_time = dt.datetime.now()
--> 239 result, is_success = self._execute_task(node.task, task_args, node_input_kwargs, raise_errors=raise_errors)
    240 end_time = dt.datetime.now()
    242 if is_success:

File c:\users\basin\appdata\local\programs\python\python38\lib\site-packages\eolearn\core\eoworkflow.py:267, in EOWorkflow._execute_task(task, task_args, task_kwargs, raise_errors)
    265 """Executes an EOTask and handles any potential exceptions."""
    266 if raise_errors:
--> 267     return task.execute(*task_args, **task_kwargs), True
    269 try:
    270     return task.execute(*task_args, **task_kwargs), True

Input In [12], in WaterDetectionTask.execute(self, eopatch)
     13 water_masks = np.asarray([self.detect_water(ndwi[..., 0]) for ndwi in eopatch.data["NDWI"]])
     15 # we're only interested in the water within the dam borders
---> 16 water_masks = water_masks[..., np.newaxis] * eopatch.mask_timeless["NOMINAL_WATER"]
     18 water_levels = np.asarray(
     19     [np.count_nonzero(mask) / np.count_nonzero(eopatch.mask_timeless["NOMINAL_WATER"]) for mask in water_masks]
     20 )
     22 eopatch[FeatureType.MASK, "WATER_MASK"] = water_masks

ValueError: operands could not be broadcast together with shapes (0,1) (818,197303,1) 

Would you mind sharing one of the AOIs that ran into an error? I can take a closer look for you.


Thank you very much for your reply

After removing “water_detection” from line 13 of the code, I ran it again. This time, no errors were received during the processing of lines 15 and 16. But by checking the Sentinel 2 images in EO browser I know there is water in the selected area for the selected time period.

Is it possible that there is a problem in the creation of the WKT file? I didn’t have this problem for another scope.


Hi @www.wrm.ir ,

The error message indicated that the dimensions of the two arrays were not compatible for broadcasting in line 16:

16 water_masks = water_masks[..., np.newaxis] * eopatch.mask_timeless["NOMINAL_WATER"]

The issue could be that there is no data in your EOPatch.data["NDWI"]. Could you check if the data is downloaded and processed correctly as EOPatch before the water_detection step via removing water_detection from the workflow_nodes in cell 13 and run it again?


Hi @www.wrm.ir ,

Those problematic geometries that led to the value error cover a huge area and there are no tile that covers the area more than 95%, which is the threshold we set for the filter in the example notebook. As a result, there is no data after filtering.

This can be solved by adding the following argument to the SentinelHubInputTask to create a simple mosaic for each available acquisition date which should cover the entire area.

time_difference=datetime.timedelta(days=1)

Thank you for your attention

I have attached 5 WKT files (AOIs) among them only “Maharlou.wkt” works correctly for the period November 13, 2022 to February 20, 2023.

Thankful.


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.


excellent. This works well.