Mercurial > repos > ecology > xarray_import_data
changeset 0:f1b185fc409a draft default tip
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/xarray_import_data commit 99843e9b86bfb355026559d36e29ed5a262aa9b0
author | ecology |
---|---|
date | Thu, 14 Aug 2025 08:54:07 +0000 |
parents | |
children | |
files | xarray_import_data.py xarray_import_data.xml |
diffstat | 2 files changed, 104 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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)
--- /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 @@ +<tool id="xarray_import_data" name="Xarray Import Data" version="0.1.0" profile="22.05"> + <description> + Import a dataset from an OPeNDAP URL and convert it to a local NetCDF file using xarray. + </description> + <requirements> + <requirement type="package" version="2025.4.0">xarray</requirement> + <requirement type="package" version="3">python</requirement> + <requirement type="package" version="1.6.0">netcdf4</requirement> + </requirements> + <command detect_errors="exit_code"><![CDATA[ + python '$__tool_directory__/xarray_import_data.py' '$opendap_url' '$decode_times' '$decode_cf' '$output_dataset' + ]]></command> + <inputs> + <param name="opendap_url" type="text" format="netcdf" label="OPeNDAP URL" + help="OPeNDAP URL to a dataset, also see https://docs.xarray.dev/en/stable/user-guide/io.html#opendap" + optional="false"> + <validator type="regex" message="Type a valid url">^(https:|http:|\.)\S*</validator> + </param> + <param name="decode_times" type="boolean" label="Decode times" + help="If true, decode time variables to datetime objects. If false, keep them as raw data." + checked="true" /> + <param name="decode_cf" type="boolean" label="Decode CF conventions" + help="Whether to decode according to CF conventions" + checked="true" /> + </inputs> + <outputs> + <data name="output_dataset" from_work_dir="xarray_imported_data" format="netcdf" + label="xarray dataset" /> + </outputs> + <tests> + <test> + <param name="opendap_url" + value="http://test.opendap.org:8080/opendap/catalog/data/nc/data.nc" /> + <output name="output_dataset" ftype="netcdf"> + <assert_contents> + <has_size min="17K" max="18K" /> + </assert_contents> + </output> + </test> + </tests> + <help><![CDATA[ +================== +Xarray Import Data +================== + +**What it does** + +Open a dataset from an OPeNDAP URL and convert it to a NetCDF file using xarray and netcdf4. + +| + +**How to use it** + +Pass a valid OPeNDAP URL to the `opendap_url` parameter. The tool will download the dataset and save it as a local NetCDF file. + +For big datasets consider subsetting the dataset in the url using `<URL>?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/ + ]]> + </help> + <citations> + <citation type="doi">10.5334/jors.148</citation> + </citations> +</tool> \ No newline at end of file