annotate xarray_tool.py @ 2:e8650cdf092f draft

"planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
author ecology
date Sat, 31 Oct 2020 11:00:53 +0000
parents 7edbe5ae8b72
children 663268794710
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()):
2
e8650cdf092f "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
ecology
parents: 1
diff changeset
87 header.append('Dim' + str(idx) + 'Name')
e8650cdf092f "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
ecology
parents: 1
diff changeset
88 header.append('Dim' + str(idx) + 'Size')
1
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':
2
e8650cdf092f "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
ecology
parents: 1
diff changeset
116 self.dset = self.dset.where((self.dset <= rl) & (self.dset >= ll))
1
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
143 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
144 # 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
145 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
146 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
147
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161 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
162
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
163 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
164 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
165 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
166
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
167 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
168 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
169 # 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
170 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
171 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
172 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
173 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
174 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
175 # 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
176 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
177 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
178 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
179 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
180 else:
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
181 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
182
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
183 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
184 # 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
185 # 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
186 # 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
187 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
188 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
189 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
190 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
191 # 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
192 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
193 # 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
194 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
195 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
196 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
197 # 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
198 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
199 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
200 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
201 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
202 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
203
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
204 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
205 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
206 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
207 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
208 self.lonvalE = row[1]
2
e8650cdf092f "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
ecology
parents: 1
diff changeset
209 self.outfile = (self.outputdir + '/' + self.select + '_' + str(row.Index) + '.tabular')
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.selection()
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
211
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
212
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
213 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
214 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
215 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
216
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.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
218 'infile',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
219 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
220 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
221 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
222 '--info',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
223 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
224 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
225 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
226 '--summary',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
227 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
228 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
229 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
230 '--select',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
231 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
232 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
233 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
234 '--latname',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
235 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
236 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
237 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
238 '--latvalN',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
239 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
240 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
241 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
242 '--latvalS',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
243 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
244 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
245 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
246 '--lonname',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
247 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
248 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
249 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
250 '--lonvalE',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
251 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
252 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
253 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
254 '--lonvalW',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
255 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
256 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
257 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
258 '--coords',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
259 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
260 '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
261 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
262 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
263 '--filter',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
264 nargs="*",
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
265 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
266 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
267 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
268 '--time',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
269 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
270 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
271 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
272 '--outfile',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
273 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
274 '(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
275 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
276 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
277 '--outputdir',
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
278 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
279 '(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
280 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
281 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
282 "-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
283 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
284 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
285 )
7edbe5ae8b72 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
286 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
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 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
289 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
290 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
291 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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299 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
300 p.selection()