<jupyter_start><jupyter_text>maybe run on bigship - tony<jupyter_code>import xarray as xr
! aws s3 ls ws-out/good/
! aws s3 ls ws-out/good/tile_aoi/
#! aws s3 sync s3://ws-out/good/tile_aoi/ ./tile_aoi/
! ls ./tile_aoi/
tile_list = ['r50.0_tile5.geojson','r50.0_tile6.geojson', 'r50.0_tile7.geojson', 'r50.0_tile8.geojson', 'r50.0_tile9.geojson',
            'r37.0_tile0.geojson', 'r37.0_tile1.geojson', 'r37.0_tile2.geojson', 'r37.0_tile3.geojson']
tile_dir = './tile_aoi/'
import geopandas as gpd
from shapely.geometry import mapping
import hvplot.xarray
def make_geom(aoi_filename):
    '''creates a geom/Polygon/Coordinates - bbox - from an geojson file'''
    # read in AOI as a GeoDataFrame
    aoi = gpd.read_file(aoi_filename)

    # get the geometry of the AOI as a dictionary for use with PySTAC Client
    geom = mapping(aoi.to_dict()['geometry'][0])
    return geom
import rioxarray
rds = rioxarray.open_rasterio('s3://ws-out/good/etasw_202005.tif')
rds
my_ds_list = []
for tile in tile_list:
    aoif = aoif = tile_dir + tile
    geom = make_geom(aoif)
    my_ds = rds.rio.clip([geom], crs='epsg:4326')
    my_ds = my_ds.squeeze().drop(labels='band')
    my_ds.name='ETASW'
    my_ds_list.append(my_ds)
from datacube.utils.cog import write_cog

for i in range(0,len(tile_list)):
    print(tile_list[i])
    my_filename = tile_list[i].replace('.geojson', '.tif')
    write_cog(my_ds_list[i], my_filename, overwrite=True)
    
# tif_file_name = 's3://ws-out/good/tmp/a.tif'
# write_cog(my_ds_list[0], tif_file_name, overwrite=True)
! ls *.tif
#! echo '*.tif' >> .gitignore<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14745972738537794, 'fraction_numerical': 0.03407682775712516, 'mean_word_length': 4.159744408945687, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '215591', 'license': 'MIT', 'n_tokens_mistral': 715, 'n_tokens_neox': 681, 'n_words': 128, 'path': '01_1_cut_to_tiles_the_USA_make_cogs.ipynb', 'repo_name': 'tonybutzer/et-surgery', 'size': '1614'}