annotate xarray_tool.py @ 1:6baac361495b 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:25 +0000
parents 225d0d275a24
children 123a9a629bef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
1 # xarray tool for:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
2 # - getting metadata information
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
3 # - select data and save results in csv file for further post-processing
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
4
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
5 import argparse
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
6 import csv
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
7 import warnings
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
8
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
9 import geopandas as gdp
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
10
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
11 import pandas as pd
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
12
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
13 from shapely.geometry import Point
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
14 from shapely.ops import nearest_points
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
15
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
16 import xarray as xr
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
17
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
18
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
19 class XarrayTool ():
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
20 def __init__(self, infile, outfile_info="", outfile_summary="",
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
21 select="", outfile="", outputdir="", latname="",
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
22 latvalN="", latvalS="", lonname="", lonvalE="",
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
23 lonvalW="", filter_list="", coords="", time="",
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
24 verbose=False
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
25 ):
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
26 self.infile = infile
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
27 self.outfile_info = outfile_info
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
28 self.outfile_summary = outfile_summary
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
29 self.select = select
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
30 self.outfile = outfile
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
31 self.outputdir = outputdir
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
32 self.latname = latname
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
33 if latvalN != "" and latvalN is not None:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
34 self.latvalN = float(latvalN)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
35 else:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
36 self.latvalN = ""
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
37 if latvalS != "" and latvalS is not None:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
38 self.latvalS = float(latvalS)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
39 else:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
40 self.latvalS = ""
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
41 self.lonname = lonname
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
42 if lonvalE != "" and lonvalE is not None:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
43 self.lonvalE = float(lonvalE)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
44 else:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
45 self.lonvalE = ""
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
46 if lonvalW != "" and lonvalW is not None:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
47 self.lonvalW = float(lonvalW)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
48 else:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
49 self.lonvalW = ""
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
50 self.filter = filter_list
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
51 self.time = time
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
52 self.coords = coords
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
53 self.verbose = verbose
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
54 # initialization
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
55 self.dset = None
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
56 self.gset = None
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
57 if self.verbose:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
58 print("infile: ", self.infile)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
59 print("outfile_info: ", self.outfile_info)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
60 print("outfile_summary: ", self.outfile_summary)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
61 print("outfile: ", self.outfile)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
62 print("select: ", self.select)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
63 print("outfile: ", self.outfile)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
64 print("outputdir: ", self.outputdir)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
65 print("latname: ", self.latname)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
66 print("latvalN: ", self.latvalN)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
67 print("latvalS: ", self.latvalS)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
68 print("lonname: ", self.lonname)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
69 print("lonvalE: ", self.lonvalE)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
70 print("lonvalW: ", self.lonvalW)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
71 print("filter: ", self.filter)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
72 print("time: ", self.time)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
73 print("coords: ", self.coords)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
74
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
75 def info(self):
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
76 f = open(self.outfile_info, 'w')
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
77 ds = xr.open_dataset(self.infile)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
78 ds.info(f)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
79 f.close()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
80
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
81 def summary(self):
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
82 f = open(self.outfile_summary, 'w')
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
83 ds = xr.open_dataset(self.infile)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
84 writer = csv.writer(f, delimiter='\t')
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
85 header = ['VariableName', 'NumberOfDimensions']
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
86 for idx, val in enumerate(ds.dims.items()):
1
6baac361495b "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
ecology
parents: 0
diff changeset
87 header.append('Dim' + str(idx) + 'Name')
6baac361495b "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
ecology
parents: 0
diff changeset
88 header.append('Dim' + str(idx) + 'Size')
0
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
89 writer.writerow(header)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
90 for name, da in ds.data_vars.items():
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
91 line = [name]
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
92 line.append(len(ds[name].shape))
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
93 for d, s in zip(da.shape, da.sizes):
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
94 line.append(s)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
95 line.append(d)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
96 writer.writerow(line)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
97 for name, da in ds.coords.items():
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
98 line = [name]
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
99 line.append(len(ds[name].shape))
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
100 for d, s in zip(da.shape, da.sizes):
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
101 line.append(s)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
102 line.append(d)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
103 writer.writerow(line)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
104 f.close()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
105
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
106 def rowfilter(self, single_filter):
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
107 split_filter = single_filter.split('#')
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
108 filter_varname = split_filter[0]
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
109 op = split_filter[1]
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
110 ll = float(split_filter[2])
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
111 if (op == 'bi'):
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
112 rl = float(split_filter[3])
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
113 if filter_varname == self.select:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
114 # filter on values of the selected variable
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
115 if op == 'bi':
1
6baac361495b "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
ecology
parents: 0
diff changeset
116 self.dset = self.dset.where((self.dset <= rl) & (self.dset >= ll))
0
225d0d275a24 "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':
225d0d275a24 "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)
225d0d275a24 "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':
225d0d275a24 "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)
225d0d275a24 "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':
225d0d275a24 "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)
225d0d275a24 "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
225d0d275a24 "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':
225d0d275a24 "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)})
225d0d275a24 "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':
225d0d275a24 "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)})
225d0d275a24 "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':
225d0d275a24 "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)})
225d0d275a24 "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':
225d0d275a24 "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},
225d0d275a24 "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')
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
133
225d0d275a24 "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):
225d0d275a24 "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:
225d0d275a24 "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)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
137 self.dset = self.ds[self.select] # select variable
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
138 if self.time:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
139 self.datetime_selection()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
140 if self.filter:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
141 self.filter_selection()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
142
225d0d275a24 "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()
225d0d275a24 "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
225d0d275a24 "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()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
146 self.gset.to_csv(self.outfile, header=True, sep='\t')
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
147
225d0d275a24 "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):
225d0d275a24 "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('#')
225d0d275a24 "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]
225d0d275a24 "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]
225d0d275a24 "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]
225d0d275a24 "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'):
225d0d275a24 "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]
225d0d275a24 "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)})
225d0d275a24 "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'):
225d0d275a24 "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)})
225d0d275a24 "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'):
225d0d275a24 "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)})
225d0d275a24 "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'):
225d0d275a24 "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')
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
162
225d0d275a24 "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):
225d0d275a24 "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:
225d0d275a24 "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)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
166
225d0d275a24 "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):
225d0d275a24 "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 != "":
225d0d275a24 "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
225d0d275a24 "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:
225d0d275a24 "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),
225d0d275a24 "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:
225d0d275a24 "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)})
225d0d275a24 "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 != "":
225d0d275a24 "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
225d0d275a24 "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
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
177 self.gset = self.dset.sel({self.latname: self.nearest_latvalN,
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
178 self.lonname: self.nearest_lonvalE},
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
179 method='nearest')
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
180 else:
225d0d275a24 "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
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
182
225d0d275a24 "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):
225d0d275a24 "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
225d0d275a24 "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
225d0d275a24 "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.
225d0d275a24 "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
225d0d275a24 "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:
225d0d275a24 "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:
225d0d275a24 "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})
225d0d275a24 "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
225d0d275a24 "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()
225d0d275a24 "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
225d0d275a24 "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,
225d0d275a24 "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],
225d0d275a24 "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]))
225d0d275a24 "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
225d0d275a24 "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)
225d0d275a24 "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
225d0d275a24 "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)
225d0d275a24 "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
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
202 self.nearest_lonvalE = nearest_geom.x
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
203
225d0d275a24 "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):
225d0d275a24 "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')
225d0d275a24 "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():
225d0d275a24 "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]
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
208 self.lonvalE = row[1]
1
6baac361495b "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit 5cdfeb9e100109892a8490ebb4b9bff498c795b5"
ecology
parents: 0
diff changeset
209 self.outfile = (self.outputdir + '/' + self.select + '_' + str(row.Index) + '.tabular')
0
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
210 self.selection()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
211
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
212
225d0d275a24 "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__':
225d0d275a24 "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")
225d0d275a24 "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()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
216
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
217 parser.add_argument(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
218 'infile',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
220 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
222 '--info',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
224 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
226 '--summary',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
228 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
230 '--select',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
232 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
234 '--latname',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
236 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
238 '--latvalN',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
240 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
242 '--latvalS',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
244 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
246 '--lonname',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
248 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
250 '--lonvalE',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
252 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
254 '--lonvalW',
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
256 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
258 '--coords',
225d0d275a24 "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'
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
261 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
263 '--filter',
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
264 nargs="*",
225d0d275a24 "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'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
266 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
268 '--time',
225d0d275a24 "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]'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
270 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
272 '--outfile',
225d0d275a24 "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'
225d0d275a24 "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)'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
275 )
225d0d275a24 "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(
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
277 '--outputdir',
225d0d275a24 "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'
225d0d275a24 "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)'
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
280 )
225d0d275a24 "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(
225d0d275a24 "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",
225d0d275a24 "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",
225d0d275a24 "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"
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
285 )
225d0d275a24 "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()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
287
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
288 p = XarrayTool(args.infile, args.info, args.summary, args.select,
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
289 args.outfile, args.outputdir, args.latname,
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
290 args.latvalN, args.latvalS, args.lonname,
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
291 args.lonvalE, args.lonvalW, args.filter,
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
292 args.coords, args.time, args.verbose)
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
293 if args.info:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
294 p.info()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
295 if args.summary:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
296 p.summary()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
297 if args.coords:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
298 p.selection_from_coords()
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
299 elif args.select:
225d0d275a24 "planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/data_manipulation/xarray/ commit f1455c158011dc4aab0fd469cf794be6f4142992"
ecology
parents:
diff changeset
300 p.selection()