annotate xarray_mapplot.py @ 0:810820a0d45c draft default tip

planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
author ecology
date Sun, 31 Jul 2022 21:23:21 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
1 #!/usr/bin/env python3
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
2 #
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
3 #
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
4 # usage: xarray_mapplot.py [-h] [--proj PROJ]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
5 # [--cmap CMAP]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
6 # [--output OUTPUT]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
7 # [--time TIMES]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
8 # [--nrow NROW]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
9 # [--ncol NCOL]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
10 # [--title title]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
11 # [--latitude LATITUDE]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
12 # [--longitude LONGITUDE]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
13 # [--land ALPHA-LAND]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
14 # [--ocean ALPHA-OCEAN]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
15 # [--coastline ALPHA-COASTLINE]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
16 # [--borders ALPHA-BORDERS]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
17 # [--xlim "x1,x2"]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
18 # [--ylim "y1,y2"]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
19 # [--range "valmin,valmax"]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
20 # [--threshold VAL]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
21 # [--label label-colorbar]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
22 # [--config config-file]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
23 # [--shift]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
24 # [-v]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
25 # input varname
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
26 #
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
27 # positional arguments:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
28 # input input filename with geographical coordinates (netCDF
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
29 # format)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
30 # varname Specify which variable to plot (case sensitive)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
31 #
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
32 # optional arguments:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
33 # -h, --help show this help message and exit
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
34 # --proj PROJ Specify the projection on which we draw
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
35 # --cmap CMAP Specify which colormap to use for plotting
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
36 # --output OUTPUT output filename to store resulting image (png format)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
37 # --time TIMES time index from the file for multiple plots ("0 1 2 3")
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
38 # --title plot or subplot title
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
39 # --latitude variable name for latitude
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
40 # --longitude variable name for longitude
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
41 # --land add land on plot with alpha value [0-1]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
42 # --ocean add oceans on plot with alpha value [0-1]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
43 # --coastline add coastline with alpha value [0-1]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
44 # --borders add country borders with alpha value [0-1]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
45 # --xlim limited geographical area longitudes "x1,x2"
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
46 # --ylim limited geographical area latitudes "y1,y2"
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
47 # --range "valmin,valmax" for plotting
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
48 # --threshold do not plot values below threshold
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
49 # --label set a label for colormap
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
50 # --config plotting parameters are passed via a config file
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
51 # (overwrite other plotting options)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
52 # --shift shift longitudes if specified
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
53 # -v, --verbose switch on verbose mode
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
54 #
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
55
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
56 import argparse
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
57 import ast
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
58 import warnings
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
59 from pathlib import Path
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
60
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
61 import cartopy.crs as ccrs
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
62 import cartopy.feature as feature
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
63
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
64 from cmcrameri import cm
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
65
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
66 import matplotlib as mpl
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
67 mpl.use('Agg')
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
68 from matplotlib import pyplot # noqa: I202,E402
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
69
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
70 import xarray as xr # noqa: E402
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
71
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
72
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
73 class MapPlotXr ():
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
74 def __init__(self, input, varname, output, verbose=False,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
75 config_file="", proj="", shift=False):
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
76
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
77 li = list(input.split(","))
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
78 if len(li) > 1:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
79 self.input = li
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
80 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
81 self.input = input
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
82
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
83 if proj != "" and proj is not None and Path(proj).exists():
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
84 f = open(proj)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
85 sdict = ''.join(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
86 f.read().replace("\n", "").split('{')[1].split('}')[0]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
87 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
88 self.proj = '{' + sdict.strip() + '}'
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
89 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
90 self.proj = None
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
91 self.varname = varname
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
92 self.shift = shift
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
93 self.xylim_supported = False
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
94 self.colorbar = True
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
95 if output is None:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
96 if type(self.input) is list:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
97 self.output = Path(self.input[0]).stem + '.png'
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
98 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
99 self.output = Path(self.input).stem + '.png'
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
100 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
101 self.output = output
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
102 self.verbose = verbose
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
103 self.label = {}
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
104 self.time = []
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
105 self.xlim = []
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
106 self.ylim = []
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
107 self.range = []
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
108 self.latitude = "latitude"
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
109 self.longitude = "longitude"
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
110 self.land = 0
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
111 self.ocean = 0
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
112 self.coastline = 0
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
113 self.borders = 0
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
114 self.cmap = "coolwarm"
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
115 self.threshold = ""
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
116 self.title = ""
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
117
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
118 if config_file != "" and config_file is not None:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
119 with open(config_file) as f:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
120 sdict = ''.join(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
121 f.read().replace("\n", "").split('{')[1].split('}')[0]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
122 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
123 tmp = ast.literal_eval('{' + sdict.strip() + '}')
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
124 for key in tmp:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
125 if key == 'time':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
126 time = tmp[key]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
127 self.time = list(map(int, time.split(",")))
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
128 if key == 'cmap':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
129 self.get_cmap(tmp[key])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
130 if key == 'latitude':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
131 self.latitude = tmp[key]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
132 if key == 'longitude':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
133 self.longitude = tmp[key]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
134 if key == 'land':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
135 self.land = float(tmp[key])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
136 if key == 'ocean':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
137 self.ocean = float(tmp[key])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
138 if key == 'coastline':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
139 self.coastline = float(tmp[key])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
140 if key == 'borders':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
141 self.borders = float(tmp[key])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
142 if key == 'xlim':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
143 xlim = tmp[key]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
144 self.xlim = list(map(float, xlim.split(",")))
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
145 if key == 'ylim':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
146 ylim = tmp[key]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
147 self.ylim = list(map(float, ylim.split(",")))
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
148 if key == 'range':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
149 range_values = tmp[key]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
150 self.range = list(map(float, range_values.split(",")))
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
151 if key == 'threshold':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
152 self.threshold = float(tmp[key])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
153 if key == 'label':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
154 self.label['label'] = tmp[key]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
155 if key == 'title':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
156 self.title = tmp[key]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
157
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
158 if type(self.input) is list:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
159 self.dset = xr.open_mfdataset(self.input, use_cftime=True)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
160 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
161 self.dset = xr.open_dataset(self.input, use_cftime=True)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
162
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
163 if verbose:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
164 print("input: ", self.input)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
165 print("proj: ", self.proj)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
166 print("varname: ", self.varname)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
167 print("time: ", self.time)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
168 print("minval, maxval: ", self.range)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
169 print("title: ", self.title)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
170 print("output: ", self.output)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
171 print("label: ", self.label)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
172 print("shift: ", self.shift)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
173 print("ocean: ", self.ocean)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
174 print("land: ", self.land)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
175 print("coastline: ", self.coastline)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
176 print("borders: ", self.borders)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
177 print("latitude: ", self.latitude)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
178 print("longitude: ", self.longitude)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
179 print("xlim: ", self.xlim)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
180 print("ylim: ", self.ylim)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
181
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
182 def get_cmap(self, cmap):
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
183 if cmap[0:3] == 'cm.':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
184 self.cmap = cm.__dict__[cmap[3:]]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
185 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
186 self.cmap = cmap
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
187
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
188 def projection(self):
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
189 if self.proj is None:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
190 return ccrs.PlateCarree()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
191
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
192 proj_dict = ast.literal_eval(self.proj)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
193 user_proj = proj_dict.pop("proj")
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
194 if user_proj == 'PlateCarree':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
195 self.xylim_supported = True
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
196 return ccrs.PlateCarree(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
197 elif user_proj == 'AlbersEqualArea':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
198 return ccrs.AlbersEqualArea(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
199 elif user_proj == 'AzimuthalEquidistant':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
200 return ccrs.AzimuthalEquidistant(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
201 elif user_proj == 'EquidistantConic':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
202 return ccrs.EquidistantConic(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
203 elif user_proj == 'LambertConformal':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
204 return ccrs.LambertConformal(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
205 elif user_proj == 'LambertCylindrical':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
206 return ccrs.LambertCylindrical(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
207 elif user_proj == 'Mercator':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
208 return ccrs.Mercator(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
209 elif user_proj == 'Miller':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
210 return ccrs.Miller(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
211 elif user_proj == 'Mollweide':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
212 return ccrs.Mollweide(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
213 elif user_proj == 'Orthographic':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
214 return ccrs.Orthographic(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
215 elif user_proj == 'Robinson':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
216 return ccrs.Robinson(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
217 elif user_proj == 'Sinusoidal':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
218 return ccrs.Sinusoidal(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
219 elif user_proj == 'Stereographic':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
220 return ccrs.Stereographic(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
221 elif user_proj == 'TransverseMercator':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
222 return ccrs.TransverseMercator(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
223 elif user_proj == 'UTM':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
224 return ccrs.UTM(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
225 elif user_proj == 'InterruptedGoodeHomolosine':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
226 return ccrs.InterruptedGoodeHomolosine(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
227 elif user_proj == 'RotatedPole':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
228 return ccrs.RotatedPole(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
229 elif user_proj == 'OSGB':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
230 self.xylim_supported = False
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
231 return ccrs.OSGB(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
232 elif user_proj == 'EuroPP':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
233 self.xylim_supported = False
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
234 return ccrs.EuroPP(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
235 elif user_proj == 'Geostationary':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
236 return ccrs.Geostationary(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
237 elif user_proj == 'NearsidePerspective':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
238 return ccrs.NearsidePerspective(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
239 elif user_proj == 'EckertI':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
240 return ccrs.EckertI(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
241 elif user_proj == 'EckertII':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
242 return ccrs.EckertII(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
243 elif user_proj == 'EckertIII':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
244 return ccrs.EckertIII(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
245 elif user_proj == 'EckertIV':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
246 return ccrs.EckertIV(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
247 elif user_proj == 'EckertV':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
248 return ccrs.EckertV(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
249 elif user_proj == 'EckertVI':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
250 return ccrs.EckertVI(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
251 elif user_proj == 'EqualEarth':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
252 return ccrs.EqualEarth(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
253 elif user_proj == 'Gnomonic':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
254 return ccrs.Gnomonic(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
255 elif user_proj == 'LambertAzimuthalEqualArea':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
256 return ccrs.LambertAzimuthalEqualArea(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
257 elif user_proj == 'NorthPolarStereo':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
258 return ccrs.NorthPolarStereo(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
259 elif user_proj == 'OSNI':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
260 return ccrs.OSNI(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
261 elif user_proj == 'SouthPolarStereo':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
262 return ccrs.SouthPolarStereo(**proj_dict)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
263
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
264 def plot(self, ts=None):
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
265 if self.shift:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
266 if self.longitude == 'longitude':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
267 self.dset = self.dset.assign_coords(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
268 longitude=(((
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
269 self.dset[self.longitude]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
270 + 180) % 360) - 180))
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
271 elif self.longitude == 'lon':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
272 self.dset = self.dset.assign_coords(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
273 lon=(((self.dset[self.longitude]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
274 + 180) % 360) - 180))
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
275
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
276 pyplot.figure(1, figsize=[20, 10])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
277
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
278 # Set the projection to use for plotting
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
279 ax = pyplot.subplot(1, 1, 1, projection=self.projection())
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
280 if self.land:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
281 ax.add_feature(feature.LAND, alpha=self.land)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
282
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
283 if self.ocean:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
284 ax.add_feature(feature.OCEAN, alpha=self.ocean)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
285 if self.coastline:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
286 ax.coastlines(resolution='10m', alpha=self.coastline)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
287 if self.borders:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
288 ax.add_feature(feature.BORDERS, linestyle=':', alpha=self.borders)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
289
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
290 if self.xlim:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
291 min_lon = min(self.xlim[0], self.xlim[1])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
292 max_lon = max(self.xlim[0], self.xlim[1])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
293 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
294 min_lon = self.dset[self.longitude].min()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
295 max_lon = self.dset[self.longitude].max()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
296
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
297 if self.ylim:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
298 min_lat = min(self.ylim[0], self.ylim[1])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
299 max_lat = max(self.ylim[0], self.ylim[1])
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
300 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
301 min_lat = self.dset[self.latitude].min()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
302 max_lat = self.dset[self.latitude].max()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
303
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
304 if self.xylim_supported:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
305 pyplot.xlim(min_lon, max_lon)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
306 pyplot.ylim(min_lat, max_lat)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
307
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
308 # Fix extent
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
309 if self.threshold == "" or self.threshold is None:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
310 threshold = self.dset[self.varname].min()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
311 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
312 threshold = float(self.threshold)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
313
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
314 if self.range == []:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
315 minval = self.dset[self.varname].min()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
316 maxval = self.dset[self.varname].max()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
317 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
318 minval = self.range[0]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
319 maxval = self.range[1]
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
320
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
321 if self.verbose:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
322 print("minval: ", minval)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
323 print("maxval: ", maxval)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
324
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
325 # pass extent with vmin and vmax parameters
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
326 proj_t = ccrs.PlateCarree()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
327 if ts is None:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
328 self.dset.where(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
329 self.dset[self.varname] > threshold
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
330 )[self.varname].plot(ax=ax,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
331 vmin=minval,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
332 vmax=maxval,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
333 transform=proj_t,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
334 cmap=self.cmap,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
335 cbar_kwargs=self.label
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
336 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
337 if self.title != "" and self.title is not None:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
338 pyplot.title(self.title)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
339 pyplot.savefig(self.output)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
340 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
341 if self.colorbar:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
342 self.dset.where(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
343 self.dset[self.varname] > threshold
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
344 )[self.varname].isel(time=ts).plot(ax=ax,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
345 vmin=minval,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
346 vmax=maxval,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
347 transform=proj_t,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
348 cmap=self.cmap,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
349 cbar_kwargs=self.label
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
350 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
351 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
352 self.dset.where(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
353 self.dset[self.varname] > minval
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
354 )[self.varname].isel(time=ts).plot(ax=ax,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
355 vmin=minval,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
356 vmax=maxval,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
357 transform=proj_t,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
358 cmap=self.cmap,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
359 add_colorbar=False)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
360 if self.title != "" and self.title is not None:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
361 pyplot.title(self.title + "(time = " + str(ts) + ')')
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
362 pyplot.savefig(self.output[:-4] + "_time" + str(ts) +
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
363 self.output[-4:]) # assume png format
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
364
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
365
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
366 if __name__ == '__main__':
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
367 warnings.filterwarnings("ignore")
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
368 parser = argparse.ArgumentParser()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
369 parser.add_argument(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
370 'input',
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
371 help='input filename with geographical coordinates (netCDF format)'
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
372 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
373 parser.add_argument(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
374 '--proj',
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
375 help='Config file with the projection on which we draw'
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
376 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
377 parser.add_argument(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
378 'varname',
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
379 help='Specify which variable to plot (case sensitive)'
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
380 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
381 parser.add_argument(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
382 '--output',
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
383 help='output filename to store resulting image (png format)'
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
384 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
385 parser.add_argument(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
386 '--config',
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
387 help='pass plotting parameters via a config file'
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
388 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
389 parser.add_argument(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
390 '--shift',
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
391 help='shift longitudes if specified',
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
392 action="store_true"
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
393 )
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
394 parser.add_argument(
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
395 "-v", "--verbose",
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
396 help="switch on verbose mode",
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
397 action="store_true")
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
398 args = parser.parse_args()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
399
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
400 dset = MapPlotXr(input=args.input, varname=args.varname,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
401 output=args.output, verbose=args.verbose,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
402 config_file=args.config, proj=args.proj,
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
403 shift=args.shift)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
404
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
405 if dset.time == []:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
406 dset.plot()
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
407 else:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
408 for t in dset.time:
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
409 dset.plot(t)
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
410 dset.shift = False # only shift once
810820a0d45c planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
411 dset.colorbar = True