annotate xarray_tool.py @ 1:7edbe5ae8b72 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:18:55 -0400
parents
children e8650cdf092f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
7edbe5ae8b72 "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:
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
4
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
8
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
10
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
12
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
15
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
17
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
18
7edbe5ae8b72 "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 ():
7edbe5ae8b72 "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="",
7edbe5ae8b72 "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="",
7edbe5ae8b72 "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="",
7edbe5ae8b72 "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="",
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
25 ):
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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:
7edbe5ae8b72 "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)
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
35 else:
7edbe5ae8b72 "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 = ""
7edbe5ae8b72 "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:
7edbe5ae8b72 "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)
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
39 else:
7edbe5ae8b72 "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 = ""
7edbe5ae8b72 "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
7edbe5ae8b72 "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:
7edbe5ae8b72 "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)
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
44 else:
7edbe5ae8b72 "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 = ""
7edbe5ae8b72 "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:
7edbe5ae8b72 "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)
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
48 else:
7edbe5ae8b72 "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 = ""
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
54 # initialization
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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:
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
74
7edbe5ae8b72 "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):
7edbe5ae8b72 "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')
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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()
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
80
7edbe5ae8b72 "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):
7edbe5ae8b72 "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')
7edbe5ae8b72 "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)
7edbe5ae8b72 "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')
7edbe5ae8b72 "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']
7edbe5ae8b72 "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()):
7edbe5ae8b72 "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')
7edbe5ae8b72 "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')
7edbe5ae8b72 "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)
7edbe5ae8b72 "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():
7edbe5ae8b72 "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]
7edbe5ae8b72 "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))
7edbe5ae8b72 "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):
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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():
7edbe5ae8b72 "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]
7edbe5ae8b72 "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))
7edbe5ae8b72 "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):
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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)
7edbe5ae8b72 "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()
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
105
7edbe5ae8b72 "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):
7edbe5ae8b72 "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('#')
7edbe5ae8b72 "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]
7edbe5ae8b72 "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]
7edbe5ae8b72 "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])
7edbe5ae8b72 "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'):
7edbe5ae8b72 "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])
7edbe5ae8b72 "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:
7edbe5ae8b72 "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
7edbe5ae8b72 "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':
7edbe5ae8b72 "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) &
7edbe5ae8b72 "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))
7edbe5ae8b72 "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':
7edbe5ae8b72 "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)
7edbe5ae8b72 "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':
7edbe5ae8b72 "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)
7edbe5ae8b72 "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':
7edbe5ae8b72 "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)
7edbe5ae8b72 "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
7edbe5ae8b72 "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':
7edbe5ae8b72 "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)})
7edbe5ae8b72 "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':
7edbe5ae8b72 "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)})
7edbe5ae8b72 "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':
7edbe5ae8b72 "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)})
7edbe5ae8b72 "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':
7edbe5ae8b72 "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},
7edbe5ae8b72 "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')
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
134
7edbe5ae8b72 "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):
7edbe5ae8b72 "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:
7edbe5ae8b72 "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)
7edbe5ae8b72 "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
7edbe5ae8b72 "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:
7edbe5ae8b72 "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()
7edbe5ae8b72 "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:
7edbe5ae8b72 "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()
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
143
7edbe5ae8b72 "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()
7edbe5ae8b72 "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
7edbe5ae8b72 "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()
7edbe5ae8b72 "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')
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
148
7edbe5ae8b72 "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):
7edbe5ae8b72 "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('#')
7edbe5ae8b72 "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]
7edbe5ae8b72 "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]
7edbe5ae8b72 "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]
7edbe5ae8b72 "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'):
7edbe5ae8b72 "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]
7edbe5ae8b72 "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)})
7edbe5ae8b72 "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'):
7edbe5ae8b72 "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)})
7edbe5ae8b72 "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'):
7edbe5ae8b72 "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)})
7edbe5ae8b72 "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'):
7edbe5ae8b72 "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')
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
163
7edbe5ae8b72 "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):
7edbe5ae8b72 "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:
7edbe5ae8b72 "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)
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
167
7edbe5ae8b72 "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):
7edbe5ae8b72 "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 != "":
7edbe5ae8b72 "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
7edbe5ae8b72 "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:
7edbe5ae8b72 "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),
7edbe5ae8b72 "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:
7edbe5ae8b72 "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)})
7edbe5ae8b72 "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 != "":
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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,
7edbe5ae8b72 "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},
7edbe5ae8b72 "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')
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
181 else:
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
183
7edbe5ae8b72 "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):
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "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.
7edbe5ae8b72 "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
7edbe5ae8b72 "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:
7edbe5ae8b72 "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:
7edbe5ae8b72 "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})
7edbe5ae8b72 "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
7edbe5ae8b72 "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()
7edbe5ae8b72 "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
7edbe5ae8b72 "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,
7edbe5ae8b72 "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],
7edbe5ae8b72 "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]))
7edbe5ae8b72 "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
7edbe5ae8b72 "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)
7edbe5ae8b72 "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
7edbe5ae8b72 "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)
7edbe5ae8b72 "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
7edbe5ae8b72 "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
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
204
7edbe5ae8b72 "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):
7edbe5ae8b72 "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')
7edbe5ae8b72 "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():
7edbe5ae8b72 "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]
7edbe5ae8b72 "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]
7edbe5ae8b72 "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 + '_'
7edbe5ae8b72 "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')
7edbe5ae8b72 "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()
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
213
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
214
7edbe5ae8b72 "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__':
7edbe5ae8b72 "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")
7edbe5ae8b72 "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()
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
218
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
220 'infile',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
222 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
224 '--info',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
226 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
228 '--summary',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
230 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
232 '--select',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
234 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
236 '--latname',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
238 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
240 '--latvalN',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
242 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
244 '--latvalS',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
246 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
248 '--lonname',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
250 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
252 '--lonvalE',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
254 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
256 '--lonvalW',
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
258 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
260 '--coords',
7edbe5ae8b72 "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'
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
263 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
265 '--filter',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
266 nargs="*",
7edbe5ae8b72 "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'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
268 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
270 '--time',
7edbe5ae8b72 "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]'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
272 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
274 '--outfile',
7edbe5ae8b72 "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'
7edbe5ae8b72 "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)'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
277 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
279 '--outputdir',
7edbe5ae8b72 "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'
7edbe5ae8b72 "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)'
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
282 )
7edbe5ae8b72 "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(
7edbe5ae8b72 "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",
7edbe5ae8b72 "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",
7edbe5ae8b72 "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"
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
287 )
7edbe5ae8b72 "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()
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
289
7edbe5ae8b72 "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,
7edbe5ae8b72 "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,
7edbe5ae8b72 "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,
7edbe5ae8b72 "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,
7edbe5ae8b72 "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)
7edbe5ae8b72 "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:
7edbe5ae8b72 "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()
7edbe5ae8b72 "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:
7edbe5ae8b72 "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()
7edbe5ae8b72 "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:
7edbe5ae8b72 "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()
7edbe5ae8b72 "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:
7edbe5ae8b72 "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()