def __getitem__()

in Damage Assessment Visualizer/utils/utils.py [0:0]


    def __getitem__(self, idx):
        """
        Returns:
            A tuple (chip, (y,x)): `chip` is the chip that we sampled from the larger tile. (y,x) are the indices of the upper left corner of the chip.
        """
        y, x = self.chip_coordinates[idx]

        if self.windowed_sampling:
            try:
                with rasterio.Env():
                    with rasterio.open(self.fn) as f:
                        img = np.rollaxis(
                            f.read(
                                window=rasterio.windows.Window(
                                    x, y, self.chip_size, self.chip_size
                                )
                            ),
                            0,
                            3,
                        )
            except RasterioIOError as e:
                print("Reading %d failed, returning 0's" % (idx))
                img = np.zeros(
                    (self.chip_size, self.chip_size, self.num_channels), dtype=np.uint8
                )
        else:
            img = self.data[y : y + self.chip_size, x : x + self.chip_size]

        if self.transform is not None:
            img = self.transform(img)

        return img, np.array((y, x))