# HG changeset patch # User ecology # Date 1755161647 0 # Node ID f1b185fc409a716401650aa82b89c3a1736beb85 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/xarray_import_data commit 99843e9b86bfb355026559d36e29ed5a262aa9b0 diff -r 000000000000 -r f1b185fc409a xarray_import_data.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xarray_import_data.py Thu Aug 14 08:54:07 2025 +0000 @@ -0,0 +1,36 @@ +"""Import OPeNDAP dataset using xarray to a netCDF file.""" + +import argparse + +import xarray as xr + +parser = argparse.ArgumentParser() + +parser.add_argument( + "opendap_url", + help=( + "A valid OPeNDAP URL, also see " + "https://docs.xarray.dev/en/stable/user-guide/io.html#opendap" + ), +) +parser.add_argument( + "decode_times", + type=lambda x: x == "true", + help='If time should be decoded, e.g. "True" or "False"', +) +parser.add_argument( + "decode_cf", + type=lambda x: x == "true", + help=( + "Whether to decode according to " + 'CF conventions e.g. "true" or "false"' + ), +) +parser.add_argument("output_dataset", help="netCDF file to output") +args = parser.parse_args() + +xr.open_dataset( + args.opendap_url.strip(), + decode_cf=args.decode_cf, + decode_times=args.decode_times, +).to_netcdf(args.output_dataset) diff -r 000000000000 -r f1b185fc409a xarray_import_data.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xarray_import_data.xml Thu Aug 14 08:54:07 2025 +0000 @@ -0,0 +1,68 @@ + + + Import a dataset from an OPeNDAP URL and convert it to a local NetCDF file using xarray. + + + xarray + python + netcdf4 + + + + + ^(https:|http:|\.)\S* + + + + + + + + + + + + + + + + + + ?var_name1[start:step:end],var_name2[start:step:end]` + +| + +**Links** + https://docs.xarray.dev/en/stable/user-guide/io.html#opendap + https://www.opendap.org/ + ]]> + + + 10.5334/jors.148 + + \ No newline at end of file