annotate xarray_select.py @ 4:b393815e4cb7 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:20:41 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
1 # xarray tool for:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
2 # - getting metadata information
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
3 # - select data and save results in csv file for further post-processing
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
4
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
5 import argparse
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
6 import os
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
7 import warnings
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
8
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
9 import geopandas as gdp
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
10
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
11 import pandas as pd
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
12
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
13 from shapely.geometry import Point
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
14 from shapely.ops import nearest_points
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
15
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
16 import xarray as xr
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
17
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
18
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
19 class XarraySelect ():
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
20 def __init__(self, infile, select="", outfile="", outputdir="",
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
21 latname="", latvalN="", latvalS="", lonname="",
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
22 lonvalE="", lonvalW="", filter_list="", coords="",
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
23 time="", verbose=False, no_missing=False,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
24 tolerance=None):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
25 self.infile = infile
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
26 self.select = select
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
27 self.outfile = outfile
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
28 self.outputdir = outputdir
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
29 self.latname = latname
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
30 if tolerance != "" and tolerance is not None:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
31 self.tolerance = float(tolerance)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
32 else:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
33 self.tolerance = -1
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
34 if latvalN != "" and latvalN is not None:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
35 self.latvalN = float(latvalN)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
36 else:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
37 self.latvalN = ""
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
38 if latvalS != "" and latvalS is not None:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
39 self.latvalS = float(latvalS)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
40 else:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
41 self.latvalS = ""
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
42 self.lonname = lonname
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
43 if lonvalE != "" and lonvalE is not None:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
44 self.lonvalE = float(lonvalE)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
45 else:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
46 self.lonvalE = ""
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
47 if lonvalW != "" and lonvalW is not None:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
48 self.lonvalW = float(lonvalW)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
49 else:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
50 self.lonvalW = ""
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
51 self.filter = filter_list
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
52 self.time = time
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
53 self.coords = coords
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
54 self.verbose = verbose
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
55 self.no_missing = no_missing
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
56 # initialization
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
57 self.dset = None
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
58 self.gset = None
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
59 if self.verbose:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
60 print("infile: ", self.infile)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
61 print("outfile: ", self.outfile)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
62 print("select: ", self.select)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
63 print("outfile: ", self.outfile)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
64 print("outputdir: ", self.outputdir)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
65 print("latname: ", self.latname)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
66 print("latvalN: ", self.latvalN)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
67 print("latvalS: ", self.latvalS)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
68 print("lonname: ", self.lonname)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
69 print("lonvalE: ", self.lonvalE)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
70 print("lonvalW: ", self.lonvalW)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
71 print("filter: ", self.filter)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
72 print("time: ", self.time)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
73 print("coords: ", self.coords)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
74
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
75 def rowfilter(self, single_filter):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
76 split_filter = single_filter.split('#')
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
77 filter_varname = split_filter[0]
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
78 op = split_filter[1]
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
79 ll = float(split_filter[2])
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
80 if (op == 'bi'):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
81 rl = float(split_filter[3])
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
82 if filter_varname == self.select:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
83 # filter on values of the selected variable
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
84 if op == 'bi':
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
85 self.dset = self.dset.where(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
86 (self.dset <= rl) & (self.dset >= ll)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
87 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
88 elif op == 'le':
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
89 self.dset = self.dset.where(self.dset <= ll)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
90 elif op == 'ge':
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
91 self.dset = self.dset.where(self.dset >= ll)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
92 elif op == 'e':
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
93 self.dset = self.dset.where(self.dset == ll)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
94 else: # filter on other dimensions of the selected variable
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
95 if op == 'bi':
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
96 self.dset = self.dset.sel({filter_varname: slice(ll, rl)})
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
97 elif op == 'le':
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
98 self.dset = self.dset.sel({filter_varname: slice(None, ll)})
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
99 elif op == 'ge':
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
100 self.dset = self.dset.sel({filter_varname: slice(ll, None)})
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
101 elif op == 'e':
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
102 self.dset = self.dset.sel({filter_varname: ll},
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
103 method='nearest')
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
104
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
105 def selection(self):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
106 if self.dset is None:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
107 self.ds = xr.open_dataset(self.infile)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
108 self.dset = self.ds[self.select] # select variable
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
109 if self.time:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
110 self.datetime_selection()
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
111 if self.filter:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
112 self.filter_selection()
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
113
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
114 self.area_selection()
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
115 if self.gset.count() > 1:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
116 # convert to dataframe if several rows and cols
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
117 self.gset = self.gset.to_dataframe().dropna(how='all'). \
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
118 reset_index()
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
119 self.gset.to_csv(self.outfile, header=True, sep='\t')
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
120 else:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
121 data = {
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
122 self.latname: [self.gset[self.latname].values],
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
123 self.lonname: [self.gset[self.lonname].values],
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
124 self.select: [self.gset.values]
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
125 }
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
126
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
127 df = pd.DataFrame(data, columns=[self.latname, self.lonname,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
128 self.select])
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
129 df.to_csv(self.outfile, header=True, sep='\t')
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
130
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
131 def datetime_selection(self):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
132 split_filter = self.time.split('#')
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
133 time_varname = split_filter[0]
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
134 op = split_filter[1]
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
135 ll = split_filter[2]
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
136 if (op == 'sl'):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
137 rl = split_filter[3]
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
138 self.dset = self.dset.sel({time_varname: slice(ll, rl)})
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
139 elif (op == 'to'):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
140 self.dset = self.dset.sel({time_varname: slice(None, ll)})
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
141 elif (op == 'from'):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
142 self.dset = self.dset.sel({time_varname: slice(ll, None)})
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
143 elif (op == 'is'):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
144 self.dset = self.dset.sel({time_varname: ll}, method='nearest')
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
145
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
146 def filter_selection(self):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
147 for single_filter in self.filter:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
148 self.rowfilter(single_filter)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
149
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
150 def area_selection(self):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
151
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
152 if self.latvalS != "" and self.lonvalW != "":
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
153 # Select geographical area
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
154 self.gset = self.dset.sel({self.latname:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
155 slice(self.latvalS, self.latvalN),
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
156 self.lonname:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
157 slice(self.lonvalW, self.lonvalE)})
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
158 elif self.latvalN != "" and self.lonvalE != "":
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
159 # select nearest location
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
160 if self.no_missing:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
161 self.nearest_latvalN = self.latvalN
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
162 self.nearest_lonvalE = self.lonvalE
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
163 else:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
164 # find nearest location without NaN values
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
165 self.nearest_location()
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
166 if self.tolerance > 0:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
167 self.gset = self.dset.sel({self.latname: self.nearest_latvalN,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
168 self.lonname: self.nearest_lonvalE},
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
169 method='nearest',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
170 tolerance=self.tolerance)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
171 else:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
172 self.gset = self.dset.sel({self.latname: self.nearest_latvalN,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
173 self.lonname: self.nearest_lonvalE},
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
174 method='nearest')
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
175 else:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
176 self.gset = self.dset
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
177
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
178 def nearest_location(self):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
179 # Build a geopandas dataframe with all first elements in each dimension
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
180 # so we assume null values correspond to a mask that is the same for
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
181 # all dimensions in the dataset.
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
182 dsel_frame = self.dset
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
183 for dim in self.dset.dims:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
184 if dim != self.latname and dim != self.lonname:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
185 dsel_frame = dsel_frame.isel({dim: 0})
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
186 # transform to pandas dataframe
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
187 dff = dsel_frame.to_dataframe().dropna().reset_index()
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
188 # transform to geopandas to collocate
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
189 gdf = gdp.GeoDataFrame(dff,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
190 geometry=gdp.points_from_xy(dff[self.lonname],
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
191 dff[self.latname]))
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
192 # Find nearest location where values are not null
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
193 point = Point(self.lonvalE, self.latvalN)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
194 multipoint = gdf.geometry.unary_union
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
195 queried_geom, nearest_geom = nearest_points(point, multipoint)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
196 self.nearest_latvalN = nearest_geom.y
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
197 self.nearest_lonvalE = nearest_geom.x
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
198
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
199 def selection_from_coords(self):
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
200 fcoords = pd.read_csv(self.coords, sep='\t')
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
201 for row in fcoords.itertuples():
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
202 self.latvalN = row[0]
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
203 self.lonvalE = row[1]
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
204 self.outfile = (os.path.join(self.outputdir,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
205 self.select + '_' +
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
206 str(row.Index) + '.tabular'))
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
207 self.selection()
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
208
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
209
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
210 if __name__ == '__main__':
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
211 warnings.filterwarnings("ignore")
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
212 parser = argparse.ArgumentParser()
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
213
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
214 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
215 'infile',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
216 help='netCDF input filename'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
217 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
218 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
219 '--select',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
220 help='Variable name to select'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
221 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
222 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
223 '--latname',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
224 help='Latitude name'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
225 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
226 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
227 '--latvalN',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
228 help='North latitude value'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
229 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
230 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
231 '--latvalS',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
232 help='South latitude value'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
233 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
234 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
235 '--lonname',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
236 help='Longitude name'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
237 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
238 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
239 '--lonvalE',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
240 help='East longitude value'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
241 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
242 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
243 '--lonvalW',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
244 help='West longitude value'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
245 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
246 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
247 '--tolerance',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
248 help='Maximum distance between original and selected value for '
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
249 ' inexact matches e.g. abs(index[indexer] - target) <= tolerance'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
250 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
251 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
252 '--coords',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
253 help='Input file containing Latitude and Longitude'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
254 'for geographical selection'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
255 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
256 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
257 '--filter',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
258 nargs="*",
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
259 help='Filter list variable#operator#value_s#value_e'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
260 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
261 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
262 '--time',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
263 help='select timeseries variable#operator#value_s[#value_e]'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
264 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
265 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
266 '--outfile',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
267 help='csv outfile for storing results of the selection'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
268 '(valid only when --select)'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
269 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
270 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
271 '--outputdir',
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
272 help='folder name for storing results with multiple selections'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
273 '(valid only when --select)'
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
274 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
275 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
276 "-v", "--verbose",
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
277 help="switch on verbose mode",
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
278 action="store_true"
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
279 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
280 parser.add_argument(
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
281 "--no_missing",
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
282 help="""Do not take into account possible null/missing values
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
283 (only valid for single location)""",
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
284 action="store_true"
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
285 )
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
286 args = parser.parse_args()
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
287
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
288 p = XarraySelect(args.infile, args.select, args.outfile, args.outputdir,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
289 args.latname, args.latvalN, args.latvalS, args.lonname,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
290 args.lonvalE, args.lonvalW, args.filter,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
291 args.coords, args.time, args.verbose,
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
292 args.no_missing, args.tolerance)
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
293 if args.select:
b393815e4cb7 planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit fd8ad4d97db7b1fd3876ff63e14280474e06fdf7
ecology
parents:
diff changeset
294 p.selection()