annotate xarray_tool.py @ 0:225d0d275a24 draft

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