Mercurial > repos > ecology > xarray_import_data
comparison xarray_import_data.py @ 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| -1:000000000000 | 0:f1b185fc409a | 
|---|---|
| 1 """Import OPeNDAP dataset using xarray to a netCDF file.""" | |
| 2 | |
| 3 import argparse | |
| 4 | |
| 5 import xarray as xr | |
| 6 | |
| 7 parser = argparse.ArgumentParser() | |
| 8 | |
| 9 parser.add_argument( | |
| 10 "opendap_url", | |
| 11 help=( | |
| 12 "A valid OPeNDAP URL, also see " | |
| 13 "https://docs.xarray.dev/en/stable/user-guide/io.html#opendap" | |
| 14 ), | |
| 15 ) | |
| 16 parser.add_argument( | |
| 17 "decode_times", | |
| 18 type=lambda x: x == "true", | |
| 19 help='If time should be decoded, e.g. "True" or "False"', | |
| 20 ) | |
| 21 parser.add_argument( | |
| 22 "decode_cf", | |
| 23 type=lambda x: x == "true", | |
| 24 help=( | |
| 25 "Whether to decode according to " | |
| 26 'CF conventions e.g. "true" or "false"' | |
| 27 ), | |
| 28 ) | |
| 29 parser.add_argument("output_dataset", help="netCDF file to output") | |
| 30 args = parser.parse_args() | |
| 31 | |
| 32 xr.open_dataset( | |
| 33 args.opendap_url.strip(), | |
| 34 decode_cf=args.decode_cf, | |
| 35 decode_times=args.decode_times, | |
| 36 ).to_netcdf(args.output_dataset) | 
