I’m using this code to combine my tiff file into a .nc file :
import glob
import xarray as xr
import rioxarray as rxr
import pandas as pd
filenames = glob.glob('*.tif')
print(filenames)
transformed_filenames = [filename.replace("-", "") for filename in filenames]
print(transformed_filenames)
def time_index_from_filenames(filenames):
'''helper function to create a pandas DatetimeIndex
Filename example: 20150520_0164.tif'''
return pd.DatetimeIndex([pd.Timestamp(f[:8]) for f in filenames])
time = xr.Variable('time', time_index_from_filenames(transformed_filenames))
chunks = {'x': 1529, 'y': 2777, 'band': 1}
da = xr.concat([rxr.open_rasterio(f) for f in filenames], dim=time)
da = da.drop_vars('band')
da.to_netcdf('OC3_AR.nc')
Eventhough this code worked well for one of my dataset it deforms my images for the second :
Tif file :
enter image description here
Nc file :
enter image description here
How to fix it ? Is it due to the projection (which is the same between the 2 images)? The dimensions are doubled on the nc file compared to the .tif (1529×2777 for tif vs 3058×5554)