Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable read_array function to return multiple arrays #77

Open
Suizer98 opened this issue Jan 12, 2024 · 2 comments
Open

Enable read_array function to return multiple arrays #77

Suizer98 opened this issue Jan 12, 2024 · 2 comments

Comments

@Suizer98
Copy link
Contributor

Suizer98 commented Jan 12, 2024

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.

@czender
Copy link
Member

czender commented Jan 12, 2024

Your suggestion looks reasonable to me. Would you please submit a PR that implements it, so we can see if it passes all the tests?

@Suizer98
Copy link
Contributor Author

Your suggestion looks reasonable to me. Would you please submit a PR that implements it, so we can see if it passes all the tests?

Okay sure, will do one PR for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants