I am facing an issue using xarray xr.open_mfdataset. I assume it happens because my netcdf files do not have a time dimension (daily mean values; only one timestep each file). However; I do not understand how I could merge the files despite this? The files have the same lat and lon dimensions. Any suggestion? Many thanks for hints! Please find my code + netcdf file description + error message below.
CODE:
%matplotlib inline
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import os
import warnings
from shapely.geometry.polygon import LinearRing
from matplotlib import gridspec
MYPATH = os.path.join("C:\\","Users","Judith Marina","phd","Data","Satellite_data","NorthSea_Storms")
print(MYPATH)
input_root = os.path.join(MYPATH,"Xaver_AQUA_MODIS_L3_NSST")
print(input_root)
dir_list = os.listdir(input_root)
print("Files and directories in '", input_root, "' :")
#prints all files
print(dir_list)
ds = xr.open_mfdataset(dir_list)
ERROR MESSAGE:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
C:\Users\JUDITH~2\AppData\Local\Temp/ipykernel_6028/798315470.py in <module>
----> 1 ds = xr.open_mfdataset(dir_list)
~\miniconda3\lib\site-packages\xarray\backends\api.py in open_mfdataset(paths, chunks, concat_dim, compat, preprocess, engine, data_vars, coords, combine, parallel, join, attrs_file, combine_attrs, **kwargs)
934 # Redo ordering from coordinates, ignoring how they were ordered
935 # previously
--> 936 combined = combine_by_coords(
937 datasets,
938 compat=compat,
~\miniconda3\lib\site-packages\xarray\core\combine.py in combine_by_coords(data_objects, compat, data_vars, coords, fill_value, join, combine_attrs, datasets)
973 concatenated_grouped_by_data_vars = []
974 for vars, datasets_with_same_vars in grouped_by_vars:
--> 975 concatenated = _combine_single_variable_hypercube(
976 list(datasets_with_same_vars),
977 fill_value=fill_value,
~\miniconda3\lib\site-packages\xarray\core\combine.py in _combine_single_variable_hypercube(datasets, fill_value, data_vars, coords, compat, join, combine_attrs)
624 )
625
--> 626 combined_ids, concat_dims = _infer_concat_order_from_coords(list(datasets))
627
628 if fill_value is None:
~\miniconda3\lib\site-packages\xarray\core\combine.py in _infer_concat_order_from_coords(datasets)
142
143 if len(datasets) > 1 and not concat_dims:
--> 144 raise ValueError(
145 "Could not find any dimension coordinates to use to "
146 "order the datasets for concatenation"
ValueError: Could not find any dimension coordinates to use to order the datasets for concatenation
NETCDF FILE CHARACTERISTICS
File.variables.keys()
KeysView(Frozen({'sst': <xarray.Variable (lat: 4320, lon: 8640)>
[37324800 values with dtype=float32]
Attributes:
long_name: Sea Surface Temperature
units: degree_C
standard_name: sea_surface_temperature
valid_min: [-1000]
valid_max: [10000]
display_scale: linear
display_min: [-2.]
display_max: [45.], 'qual_sst': <xarray.Variable (lat: 4320, lon: 8640)>
[37324800 values with dtype=float32]
Attributes:
long_name: Quality Levels, Sea Surface Temperature
valid_min: [0]
valid_max: [5], 'lat': <xarray.IndexVariable 'lat' (lat: 4320)>
array([ 89.979164, 89.9375 , 89.89583 , ..., -89.895836, -89.93751 ,
-89.97918 ], dtype=float32)
Attributes:
long_name: Latitude
units: degrees_north
standard_name: latitude
valid_min: [-90.]
valid_max: [90.], 'lon': <xarray.IndexVariable 'lon' (lon: 8640)>
array([-179.97917, -179.9375 , -179.89584, ..., 179.89583, 179.93752,
179.97917], dtype=float32)
Attributes:
long_name: Longitude
units: degrees_east
standard_name: longitude
valid_min: [-180.]
valid_max: [180.], 'palette': <xarray.Variable (rgb: 3, eightbitcolor: 256)>
array([[ 91, 10, 118, ..., 238, 223, 8],
[237, 216, 8, ..., 8, 224, 127],
[ 8, 224, 119, ..., 0, 0, 0]], dtype=uint8)}))