3
"""Create a Fsspec ReferenceFileSystem for a sequence of TIFF files on S3
5
This Python script uses the Tifffile and Fsspec libraries to create a
6
multiscale ReferenceFileSystem JSON file for a sequence of cloud optimized
7
GeoTIFF (COG) files stored on S3. The tiles of the COG files are used as
8
chunks. No additional Numcodecs codec needs to be registered since the COG
9
files use Zlib compression. A Xarray dataset is created from the
10
ReferenceFileSystem file and a subset of the dataset is plotted.
12
See https://github.com/cgohlke/tifffile/issues/125
19
from matplotlib import pyplot
24
'client_kwargs': {'endpoint_url': 'https://mghp.osn.xsede.org'},
26
fs = fsspec.filesystem('s3', **remote_options)
27
files = [f's3://{f}' for f in fs.ls('/rsignellbucket1/lcmap/cog')]
30
with open('issue125.json', 'w', encoding='utf-8', newline='\n') as jsonfile:
31
for i, filename in enumerate(tifffile.natural_sorted(files)):
32
url, name = filename.rsplit('/', 1)
33
with fs.open(filename) as fh:
34
with tifffile.TiffFile(fh, name=name) as tif:
35
print(tif.geotiff_metadata)
36
with tif.series[0].aszarr() as store:
45
_close=i == len(files) - 1,
50
mapper = fsspec.get_mapper(
53
target_protocol='file',
55
remote_options=remote_options,
59
dataset = xarray.open_zarr(mapper, consolidated=False)
63
xarray.plot.imshow(dataset['5'][0, 32:-32, 32:-32])