ValueError: The length of the given lists must be equal to the number of bands
Hi Daniel,
I received this error message when calulating the remaining shifts after co-registration between a PlanetScope (3m spatial res., reference image) and a SPOT6 image (1.5m spatial res., target image). Could it be that the reason for this error message is that the target image is of higher spatial res. or is that not a problem? Thanks in advance!
Code:
from arosics import COREG_LOCAL
grid_size= 100
CRL = COREG_LOCAL('C:/Users/path...',
'C:/Users/path...', grid_size)
# shift vector map
CRL.view_CoRegPoints(shapes2plot='vectors', vector_scale=5)
# plot shift distribution
CRL.tiepoint_grid.plot_shift_distribution()
# compute statistics
CRL.tiepoint_grid.calc_overall_stats()
ValueError Traceback (most recent call last)
Cell In[12], line 11
7 CRL = COREG_LOCAL('C:/Users/sbarth/Masterproject/reference_image/2020_kolguev_north_AnalyticMS_SR_merged.tif',
8 'C:/Users/sbarth/Masterproject/input_images/IMG_SPOT6_PMS_201607010818597_ORT_5697295101_R1C1_coreg.tif', grid_size)
10 # shift vector map
---> 11 CRL.view_CoRegPoints(shapes2plot='vectors', vector_scale=1)
13 # plot shift distribution
14 CRL.tiepoint_grid.plot_shift_distribution()
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\arosics\CoReg_local.py:590, in COREG_LOCAL.view_CoRegPoints(self, shapes2plot, attribute2plot, cmap, exclude_fillVals, backgroundIm, hide_filtered, figsize, figsize_multiplier, title, vector_scale, savefigPath, savefigDPI, showFig, vmin, vmax, return_map)
586 else:
587 raise ValueError(attribute2plot, "Invalid value for 'attribute2plot'. Valid values are: %s."
588 % ", ".join(self.CoRegPoints_table.columns))
--> 590 if not self.CoRegPoints_table.empty:
591 # get GeoDataFrame containing everything needed for plotting
592 outlierCols = [c for c in self.CoRegPoints_table.columns if 'OUTLIER' in c]
593 attr2include = ['geometry', attribute2plot] + outlierCols + ['X_SHIFT_M', 'Y_SHIFT_M']
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\arosics\CoReg_local.py:461, in COREG_LOCAL.CoRegPoints_table(self)
454 @property
455 def CoRegPoints_table(self) -> GeoDataFrame:
456 """Return a GeoDataFrame containing all the results from coregistration for all points in the tie point grid.
457
458 Columns of the GeoDataFrame: 'geometry','POINT_ID','X_IM','Y_IM','X_MAP','Y_MAP','X_WIN_SIZE', 'Y_WIN_SIZE',
459 'X_SHIFT_PX','Y_SHIFT_PX', 'X_SHIFT_M', 'Y_SHIFT_M', 'ABS_SHIFT' and 'ANGLE'
460 """
--> 461 return self.tiepoint_grid.CoRegPoints_table
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\arosics\CoReg_local.py:451, in COREG_LOCAL.tiepoint_grid(self)
449 return self._tiepoint_grid
450 else:
--> 451 self.calculate_spatial_shifts()
452 return self._tiepoint_grid
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\arosics\CoReg_local.py:484, in COREG_LOCAL.calculate_spatial_shifts(self)
468 def calculate_spatial_shifts(self) -> None:
469 self._tiepoint_grid = \
470 Tie_Point_Grid(self.COREG_obj, self.grid_res,
471 max_points=self.max_points,
(...)
482 v=self.v,
483 q=self.q)
--> 484 self._tiepoint_grid.get_CoRegPoints_table()
486 if self.v:
487 print('Visualizing CoReg points grid...')
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\arosics\Tie_Point_Grid.py:364, in Tie_Point_Grid.get_CoRegPoints_table(self)
360 # equalize pixel grids in order to save warping time
361 if len(GDF) > 100:
362 # NOTE: actually grid res should be also changed here because self.shift.xgsd changes and grid res is
363 # connected to that
--> 364 self.COREG_obj.equalize_pixGrids()
365 self.ref = self.COREG_obj.ref
366 self.shift = self.COREG_obj.shift
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\arosics\CoReg.py:634, in COREG.equalize_pixGrids(self)
630 return gA_from
632 if self.grid2use == 'ref':
633 # resample target to reference image
--> 634 self.shift = equalize(gA_from=self.shift, gA_to=self.ref)
636 else:
637 # resample reference to target image
638 self.ref = equalize(gA_from=self.ref, gA_to=self.shift)
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\arosics\CoReg.py:626, in COREG.equalize_pixGrids.<locals>.equalize(gA_from, gA_to)
624 def equalize(gA_from: GeoArray, gA_to: GeoArray) -> GeoArray:
625 if gA_from.bands > 1:
--> 626 gA_from = gA_from.get_subset(zslice=slice(gA_from.band4match, gA_from.band4match + 1))
627 gA_from.reproject_to_new_grid(prototype=gA_to, CPUs=self.CPUs)
628 gA_from.band4match = 0 # after resampling there is only one band in the GeoArray
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\geoarray\baseclasses.py:1784, in GeoArray.get_subset(self, xslice, yslice, zslice, return_GeoArray, reset_bandnames)
1782 if zslicing:
1783 bNs_out = list(np.array(list(self._bandnames))[zslice]) if self._bandnames else None
-> 1784 _meta_out = self.metadata.get_subset(bands2extract=zslice)
1785 else:
1786 bNs_out = list(self._bandnames) if self._bandnames else None
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\geoarray\metadata.py:252, in GDAL_Metadata.get_subset(self, bands2extract, keys2extract)
249 else:
250 raise TypeError(bands2extract)
--> 252 meta_sub.band_meta = self.band_meta.copy()
254 for k, v in meta_sub.band_meta.items():
255 meta_sub.band_meta[k] = list(np.array(v)[bands2extract])
File ~\Miniconda3\envs\arosics_env\Lib\site-packages\geoarray\metadata.py:108, in GDAL_Metadata.band_meta(self, meta_dict)
106 raise TypeError('The values of the given dictionary must be lists. Received %s for %s.' % (type(v), k))
107 if len(v) != self.bands:
--> 108 raise ValueError("The length of the given lists must be equal to the number of bands. "
109 "Received a list with %d items for '%s'." % (len(v), k))
111 self._band_meta = OrderedDict(meta_dict)
ValueError: The length of the given lists must be equal to the number of bands. Received a list with 3 items for 'STATISTICS_APPROXIMATE'.