When I try to import netCDF4 files using xarray I get the following error:
MissingDimensionsError: 'name' has more than 1-dimension and the same name as one of its dimensions ('time', 'name'). xarray disallows such variables because they conflict with the coordinates used to label dimensions.
However, I can successfully import these data using the netCDF4 python library, and get the data I need from it. The problem is that this method is very slow, so I was looking for something faster and wanted to try xarray. Here is an example file, and the code that is giving me the bug in question.
from netCDF4 import Dataset
#import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
#import seaborn as sns
from tkinter import Tk
from tkinter.filedialog import askdirectory
import os
import xarray as xr
#use this function to get a directory name where the files are
def get_dat():
root = Tk()
root.withdraw()
root.focus_force()
root.attributes("-topmost", True) #makes the dialog appear on top
filename = askdirectory() # Open single file
root.destroy()
root.quit()
return filename
directory=get_dat()
#loop through files in directory and read the netCDF4 files
for filename in os.listdir(directory): #loop through files in user's dir
if filename.endswith(".nc"): #all my files are .nc not .nc4
runstart=pd.datetime.now()
#I get the error right here
rootgrp3 = xr.open_dataset(directory+'/'+filename)
#more stuff happens here with the data, but this stuff works