xarray-contrib/cf-xarray

Use `cf_xarray.accessor._get_with_standard_name` in gsw_xarray

rcaneill opened this issue · 2 comments

Hello,

In gsw_xarray we are relying on cf_xarray for finding variables based on standard names. I remarked that using function cf_xarray.accessor._get_with_standard_name was about 1000 times faster than using the usual ds.cf["standard_name_of_variable"].
I guess that the difference comes from the fact that the ds.cf method also checks for e.g. units, axes, etc.
It would be better for us to only use the cf_xarray.accessor._get_with_standard_name function.

My question is the following: would it be possible to open this function as a public and not internal one? This would more or less be a guaranty for us that we don't base our code on something internal to cf_xarray. The other option would be that we copy the function to gsw_xarray, does the license authorize us to do it? (I guess so but I'm not sure)

Thanks!

use ds.cf.standard_names . That way you can grab the dict once and do lookups on it.

1000 times faster than using

Yes this is unfortunate. I made a bad choice on the order of inner loops. Its fixable but I don't know when I'll get to it.

Perfect! That works fine :)
Thanks