I'm working with a time series stack of 28 raster bands. Each band is an image for a specific date, spanning all of the year 2020, and they are stacked in order. The stack (
change_point_raster) is in the form of a 3D array where the first dimension is the date band. I also have an associated raster (
change_point_index) that is just one band, where each pixel represents the number of the band in
change_point_raster where there is detected change. I want to do some statistics before and after the change occurred for each pixel. To do this, I want to get the bands before and after the change band, then find the ratio between the two band values for each pixel in the stack. I'm doing this in Python. I'm kind of a beginner in python, so I'm unsure what to do, but here is a code snippet of what I have:
#Identify change date (or band number) and subset/index time series stack by before change and after change. cpr_before = next(x for x, val in enumerate(change_point_raster) if val < change_point_index) cpr_after = next(x for x, val in enumerate(change_point_raster) if val > change_point_index)
I'm getting an error that says
"ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()". It seems like the problem is that I have a raster stack instead of just one raster, but I'm unsure how to solve this with a loop, or any other method.