# HG changeset patch # User climate # Date 1556230333 14400 # Node ID 5708a3a46f2e4ce69b9205a57c8be703c8403107 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/shift-longitudes commit c1362af034361b6fb869411f1ea928388f230d72 diff -r 000000000000 -r 5708a3a46f2e README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Thu Apr 25 18:12:13 2019 -0400 @@ -0,0 +1,7 @@ + +# shift longitudes from netCDF file + +The wrapper aims at providing a simple utility to shift longitudes ranging from +0. and 360 degrees to -180. and 180. degrees. +The input file must be in netCDF format with geographical coordinates +(latitudes, longitudes) given in degrees. diff -r 000000000000 -r 5708a3a46f2e shift-longitudes.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shift-longitudes.xml Thu Apr 25 18:12:13 2019 -0400 @@ -0,0 +1,78 @@ + + from netCDF data + + python + netcdf4 + xarray + + + + + + + + + + + + + + + + + + + + + + + diff -r 000000000000 -r 5708a3a46f2e shift_lon.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shift_lon.py Thu Apr 25 18:12:13 2019 -0400 @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# +import argparse +import warnings + +import xarray as xr + +if __name__ == '__main__': + warnings.filterwarnings("ignore") + parser = argparse.ArgumentParser() + parser.add_argument( + 'input', + help='input filename with geographical coordinates (netCDF format)' + ) + + parser.add_argument( + 'lon', + help='name of the variable for longitudes' + ) + + parser.add_argument( + 'output', + help='output filename to store resulting image (png format)' + ) + parser.add_argument("-v", "--verbose", help="switch on verbose mode", + action="store_true") + args = parser.parse_args() + + dset = xr.open_dataset(args.input, decode_cf=False) + + if dset[args.lon].max() > 180.: + for i in range(dset[args.lon].size): + if dset[args.lon].values[i] > 180.: + dset[args.lon].values[i] = dset[args.lon].values[i] - 360. + + dset.sortby(args.lon).to_netcdf(args.output) + if args.verbose: + print("Longitudes shifted to -180. and 180.") diff -r 000000000000 -r 5708a3a46f2e test-data/TS.f2000.T31T31.control.cam.h0.0014-12.180.nc Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12.180.nc has changed diff -r 000000000000 -r 5708a3a46f2e test-data/TS.f2000.T31T31.control.cam.h0.0014-12.nc Binary file test-data/TS.f2000.T31T31.control.cam.h0.0014-12.nc has changed