# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Import libraries

import xarray as xr
from glob import glob
import numpy as np

pattern_netcdf = 'F:/data/sat_data/aviso/data/*/*.nc'
pattern_zarr = 'F:/data/sat_data/aviso/zarr/'

# # Reading netCDF files

# %%time
#list files
files = [x for x in glob(pattern_netcdf)]
#open dataset
ds=xr.open_mfdataset(files,combine='nested',concat_dim='time')
ds.close()
#remove any duplicates
_, index = np.unique(ds['time'], return_index=True)
ds=ds.isel(time=index)
#rechunck data  #data in int16 = 2 bytes 
ds_netcdf = ds.chunk({'time':1000,'latitude':180,'longitude':180})

# # Reading Zarr files

# %%time
ds_zarr= xr.open_zarr(pattern_zarr)

# # Compare NetCDF and Zarr computations

# %%time
ts = ds_netcdf.sla.sel(latitude=slice(-10,0),longitude=slice(170,180)).mean({'latitude','longitude'}).plot()

# %%time
ts = ds_zarr.sla.sel(latitude=slice(-10,0),longitude=slice(170,180)).mean({'latitude','longitude'}).plot()



StarcoderdataJupyterScriptsDedupFiltered