I wasn't able to find an answer to this after searching the help files and the forums.
I have a (virtual) raster with 60 bands, where each band represents a realization in time (think of frames of a video). I want to be able to load in cropped, specific band sets from this virtual raster without loading all of them--something like
myVRT = gdal.Open(vrtfile)
bands = myVRT.GetRasterBand([2,4,6,14,35])
cropped_bandstack = bands.ReadAsArray(
xoff = xoffset,
yoff = yoffset,
xsize = xsz,
ysize = ysz)
which would create an array with only bands 2,4,6,14, and 35.
I haven't been able to find a way to do this without loading each band separately and filling in a 3D matrix.
Another alternative that I also want to avoid is to re-create each of the individual cropped bands (which are also virtual), then create a new virtual raster stack using only the bands I want, and finally read it into an array.
I saw this was listed as a feature to add to rasterio but I couldn't find any evidence of it actually being added.
Edit: After receiving an answer, I think I should clarify that I'm asking if this can be performed in a single call, rather than implementing a loop to read each band individually.