Created
May 8, 2023 14:55
-
-
Save previtus/00451008e241ec83edcb156c49e5d5c2 to your computer and use it in GitHub Desktop.
Load the same data from a target tif using the location from a source one ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# more in https://github.com/spaceml-org/georeader/blob/main/notebooks/reading_overlapping_sentinel2_aviris.ipynb | |
from georeader.rasterio_reader import RasterioReader | |
from georeader import read | |
def same_location_as_source_from_target(source_tif, target_tif, show=False): | |
src_reader = RasterioReader(source_tif) | |
src_reader_in_memory = src_reader.load() | |
target_reader = RasterioReader(target_tif) | |
trg_at_aviris_loc = read.read_reproject_like(target_reader, src_reader_in_memory) | |
src_data = src_reader_in_memory.values | |
target_data = trg_at_aviris_loc.values | |
if show: | |
fig, ax = plt.subplots(1,2,figsize=(12,6)) | |
ax[0].imshow(src_data.transpose((1,2,0))) | |
ax[1].imshow(np.clip(trg_at_aviris_loc.values/3_500,0,1).transpose((1,2,0))) | |
return src_data, target_data | |
src_data, target_data = same_location_as_source_from_target(source_tif, target_tif, show=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment