#!/usr/bin/env python # coding: utf-8 # # Use TIFFfile to create a Zarr virtual datacube # In[1]: from tifffile import TiffSequence import zarr import fsspec # ### Try local tiff files first: # In[2]: fs = fsspec.filesystem('file') flist = fs.ls('/caldera/projects/usgs/hazards/cmgp/woodshole/rsignell/lcmap/cog/') flist # In[3]: import re ex = re.compile(r".*_(\d+)_V12_LCPRI.tif") ex.search(flist[0]).groups()[0] # In[4]: image_sequence = TiffSequence(flist, pattern=r'.*_(\d+)_V12_LCPRI.tif') # In[5]: image_sequence.shape # In[6]: with image_sequence.aszarr() as store: dz = zarr.open(store, mode='r') # In[7]: image_sequence.close() # In[8]: with image_sequence.aszarr() as store: store.write_fsspec('temp.json', url='file://') # In[9]: import fsspec import tifffile.numcodecs tifffile.numcodecs.register_codec() mapper = fsspec.get_mapper('reference://', fo='temp.json', target_protocol='file') # In[10]: ds = zarr.open(mapper, mode='r') # In[11]: ds.info # ### Try accessing files Open Storage Network # The [Open Storage Network](https://www.openstoragenetwork.org/) is an NSF-supported program that provides about one PB of locally installed, remotely managed, s3-compatible object storage for about $30K/year. # In[12]: fs = fsspec.filesystem('s3', anon=True, client_kwargs={'endpoint_url': 'https://mghp.osn.xsede.org'}) # In[13]: flist = fs.ls('/rsignellbucket1/lcmap/cog') flist # In[14]: s3_flist = [f's3://{f}' for f in flist] # In[15]: image_sequence = TiffSequence(s3_flist, pattern=r'.*_(\d+)_V12_LCPRI.tif') # In[16]: with image_sequence.aszarr() as store: dz = zarr.open(store, mode='r') # In[17]: file_like_object_list = [fs.open(f) for f in flist] # In[18]: image_sequence = TiffSequence(file_like_object_list, pattern=r'.*_(\d+)_V12_LCPRI.tif')