RuntimeError: Failed to parse 'None' as decimal integer: pattern 'None' not found
I am trying to coregister RGB planet images. I keep running into a RuntimeError and I am unable to find out what is the problem.
from arosics import COREG
from arosics import COREG_LOCAL, DESHIFTER, COREG
import numpy as np
im_reference = '../data/planet_data/2018-04-19_rgb.tiff'
im_target = '../data/planet_data/2018-06-27_rgb.tiff'
CR = COREG(im_reference,im_target, wp=(538390.500, 5809675.500), ws=(100,100), nodata=(0.0,0.0))
CR.calculate_spatial_shifts()
Output
Calculating footprint polygon and actual data corner coordinates for reference image...
Polygonize progress |==================================================| 100.0% Complete => 0:00:00
Bounding box of calculated footprint for reference image:
(532920.0, 5805474.0, 543234.0, 5811900.0)
Calculating footprint polygon and actual data corner coordinates for image to be shifted...
Polygonize progress |==================================================| 100.0% Complete => 0:00:00
Bounding box of calculated footprint for image to be shifted:
(532920.0, 5805474.0, 543861.0, 5816967.0)
Matching window position (X,Y): 538390.5/5809675.5
done calculate_spatial_shifts
done
done
Detected integer shifts (X/Y): 0/-1
Detected subpixel shifts (X/Y): -0.27775942812211324/-0.4621829237469832
Calculated total shifts in fft pixel units (X/Y): -0.27775942812211324/-1.4621829237469832
Calculated total shifts in reference pixel units (X/Y): -0.27775942812211324/-1.4621829237469832
Calculated total shifts in target pixel units (X/Y): -0.27775942812211324/-1.4621829237469832
Calculated map shifts (X,Y): -0.8332782844081521/4.386548771522939
Calculated absolute shift vector length in map units: 4.46499303742073
Calculated angle of shift vector in degrees from North: 169.24412539705764
Original map info: ['UTM', 1.0, 1.0, 532920.0, 5816967.0, 3.0, 3.0, 32, 'North', 'WGS-84']
Updated map info: ['UTM', 1.0, 1.0, '532919.1667217156', '5816971.3865487715', 3.0, 3.0, 32, 'North', 'WGS-84']
function coreg_info
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[17], line 24
22 geoArr_target = GeoArray(tgt_ndarray, tgt_gt, tgt_prj)
23 CR = COREG(geoArr_reference, geoArr_target, wp=(538390.500, 5809675.500), ws=(100,100), nodata=(0.0,0.0))
---> 24 CR.calculate_spatial_shifts()
File ~/garbsen_co2_monitoring/.venv/lib/python3.11/site-packages/arosics/CoReg.py:1630, in COREG.calculate_spatial_shifts(self)
1627 self._get_updated_map_info()
1629 # set self.ssim_before and ssim_after
-> 1630 self._validate_ssim_improvement()
1631 print(self._validate_ssim_improvement() ) # FIXME uses the not updated matchWin size
1632 self.shift_reliability = self._calc_shift_reliability(scps)
File ~/garbsen_co2_monitoring/.venv/lib/python3.11/site-packages/arosics/CoReg.py:1425, in COREG._validate_ssim_improvement(self, v)
1415 self.ssim_orig = ssim(normalize(np.ma.masked_equal(self.matchWin[:],
1416 self.matchWin.nodata)),
1417 normalize(np.ma.masked_equal(self.otherWin[:],
1418 self.otherWin.nodata)),
1419 data_range=1)
1421 # compute SSIM AFTER shift correction #
1422 #######################################
1423
1424 # resample otherWin while correcting detected shifts and match geographic bounds of matchWin
-> 1425 otherWin_deshift_geoArr = self._get_deshifted_otherWin()
1427 # get the corresponding matchWin data
1428 matchWinData = self.matchWin[:]
File ~/garbsen_co2_monitoring/.venv/lib/python3.11/site-packages/arosics/CoReg.py:1382, in COREG._get_deshifted_otherWin(self)
1374 matchFull = self.ref if self.matchWin.imID == 'ref' else self.shift
1375 otherFull = self.ref if self.otherWin.imID == 'ref' else self.shift
1377 ds_results = DESHIFTER(otherFull, coreg_info,
1378 band2process=otherFull.band4match + 1,
1379 clipextent=self.matchBox.mapPoly.bounds,
1380 target_xyGrid=matchFull.xygrid_specs,
1381 q=True
-> 1382 ).correct_shifts()
1383 return ds_results['GeoArray_shifted']
File ~/garbsen_co2_monitoring/.venv/lib/python3.11/site-packages/arosics/DeShifter.py:380, in DESHIFTER.correct_shifts(self)
376 self.shift_gt[0], self.shift_gt[3] = self.updated_gt[0], self.updated_gt[3]
378 # get resampled array
379 out_arr, out_gt, out_prj = \
--> 380 warp_ndarray(in_arr, self.shift_gt, self.shift_prj, self.ref_prj,
381 rspAlg=_dict_rspAlg_rsp_Int[self.rspAlg],
382 in_nodata=self.nodata,
383 out_nodata=self.nodata,
384 out_gsd=self.out_gsd,
385 out_bounds=self._get_out_extent(), # always returns an extent snapped to the target grid
386 gcpList=self.GCPList,
387 # polynomialOrder=str(3),
388 # options='-refine_gcps 500 1.9',
389 # warpOptions=['-refine_gcps 500 1.9'],
390 # options='-wm 10000',# -order 3',
391 # options=['-order 3'],
392 # options=['GDAL_CACHEMAX 800 '],
393 # warpMemoryLimit=125829120, # 120MB
394 CPUs=self.CPUs,
395 progress=self.progress,
396 q=self.q)
398 out_geoArr = GeoArray(out_arr, out_gt, out_prj, q=self.q)
399 out_geoArr.nodata = self.nodata # equals self.im2shift.nodata after __init__()
File ~/garbsen_co2_monitoring/.venv/lib/python3.11/site-packages/py_tools_ds/geo/raster/reproject.py:478, in warp_ndarray(ndarray, in_gt, in_prj, out_prj, out_dtype, out_gsd, out_bounds, out_bounds_prj, out_XYdims, rspAlg, in_nodata, out_nodata, in_alpha, out_alpha, targetAlignedPixels, gcpList, polynomialOrder, options, transformerOptions, warpOptions, CPUs, warpMemoryLimit, progress, q)
469 in_ds = gdal.Translate(
470 '', in_ds, format='MEM',
471 outputSRS=get_SRS(out_prj),
472 GCPs=gcpList,
473 callback=ProgressBar(prefix='Translating progress', timeout=None) if progress and not q else None
474 )
475 # NOTE: options = ['SPARSE_OK=YES'] ## => what is that for?
476
477 # GDAL Warp
--> 478 res_ds = gdal.Warp(
479 '', in_ds, format='MEM',
480 dstSRS=get_SRS(out_prj),
481 outputType=get_GDT(out_dtype) if out_dtype else get_GDT(in_dtype_np),
482 xRes=out_gsd[0],
483 yRes=out_gsd[1],
484 outputBounds=out_bounds,
485 outputBoundsSRS=get_SRS(out_bounds_prj),
486 width=out_XYdims[0],
487 height=out_XYdims[1],
488 resampleAlg=rspAlg,
489 srcNodata=in_nodata,
490 dstNodata=out_nodata,
491 srcAlpha=in_alpha,
492 dstAlpha=out_alpha,
493 options=options if options else [],
494 warpOptions=warpOptions or [],
495 transformerOptions=transformerOptions or [],
496 targetAlignedPixels=targetAlignedPixels,
497 tps=True if gcpList else False,
498 polynomialOrder=polynomialOrder,
499 warpMemoryLimit=warpMemoryLimit,
500 callback=ProgressBar(prefix='Warping progress ', timeout=None) if progress and not q else None,
501 callback_data=[0],
502 errorThreshold=0.125, # this is needed to get exactly the same output as the console version of gdal.Warp
503 )
505 gdal.SetConfigOption('GDAL_NUM_THREADS', None)
507 if res_ds is None:
File ~/garbsen_co2_monitoring/.venv/lib/python3.11/site-packages/osgeo/gdal.py:1135, in Warp(destNameOrDestDS, srcDSOrSrcDSTab, **kwargs)
1132 _WarnIfUserHasNotSpecifiedIfUsingExceptions()
1134 if 'options' not in kwargs or isinstance(kwargs['options'], (list, str)):
-> 1135 (opts, callback, callback_data) = WarpOptions(**kwargs)
1136 else:
1137 (opts, callback, callback_data) = kwargs['options']
File ~/garbsen_co2_monitoring/.venv/lib/python3.11/site-packages/osgeo/gdal.py:1115, in WarpOptions(options, format, srcBands, dstBands, outputBounds, outputBoundsSRS, xRes, yRes, targetAlignedPixels, width, height, srcSRS, dstSRS, coordinateOperation, srcAlpha, dstAlpha, warpOptions, errorThreshold, warpMemoryLimit, creationOptions, outputType, workingType, resampleAlg, srcNodata, dstNodata, multithread, tps, rpc, geoloc, polynomialOrder, transformerOptions, cutlineDSName, cutlineWKT, cutlineSRS, cutlineLayer, cutlineWhere, cutlineSQL, cutlineBlend, cropToCutline, copyMetadata, metadataConflictValue, setColorInterpretation, overviewLevel, callback, callback_data)
1112 if return_option_list:
1113 return new_options
-> 1115 return (GDALWarpAppOptions(new_options), callback, callback_data)
File ~/garbsen_co2_monitoring/.venv/lib/python3.11/site-packages/osgeo/gdal.py:8987, in GDALWarpAppOptions.__init__(self, *args)
8985 def __init__(self, *args):
8986 r"""__init__(GDALWarpAppOptions self, char ** options) -> GDALWarpAppOptions"""
-> 8987 _gdal.GDALWarpAppOptions_swiginit(self, _gdal.new_GDALWarpAppOptions(*args))
**RuntimeError: Failed to parse 'None' as decimal integer: pattern 'None' not found**
Edited by Daniel Scheffler