-
Notifications
You must be signed in to change notification settings - Fork 29
Open
Description
I am modifying the read_array function inside nco.py as below:
def read_array(self, infile, var_names):
file_handle = self.read_cdf(infile)
for var_name in var_names:
try:
# return the data array for each variable
result[var_name] = file_handle.variables[var_name][:]
except KeyError:
print("Cannot find variable: {0}".format(var_name))
raise KeyError
return result
The usage for my case would be:
variables = ["longitude", "latitude", "time"]
result = nco.ncks(
input="sample.nc", options=["-v " + ",".join(variables)], returnArray=variables
)
lon = result["longitude"][:]
lat = result["latitude"][:]
...
so we don't have to call returnArray=[] one by one.
I remember the native nco commands extract multiple variables such as:
ncks -v latitudes,longitudes
can support extracting multiple variables from netcdf file.
If this kind of actual feature is already existed, feel free to address how should I use/call it, in case I missed it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels