comparison netcdf_read.xml @ 0:8da8ec7da45f draft default tip

Uploaded
author mnhn65mo
date Thu, 02 Aug 2018 09:24:38 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8da8ec7da45f
1 <tool id="netcdf_read" name="Netcdf Reader" version="0.2.0">
2 <description>extracts variable values with custom conditions on dimensions</description>
3 <requirements>
4 <requirement type="package" version="2.1.0">matplotlib</requirement>
5 <requirement type="package" version="1.3.1">netCDF4</requirement>
6 <requirement type="package" version="1.0.0">scipy</requirement>
7 <requirement type="package" version="1.1.0">datamash</requirement>
8 </requirements>
9 <command detect_errors="exit_code"><![CDATA[
10 mkdir output_dir &&
11
12 #if $condi_source_coord.coord_source=="coord_from_file"
13 i=0 &&
14 re='^[-+]?[0-9]+\.?[0-9]*$' &&
15 while read line; do
16 lat=\$(echo \$line | cut -d' ' -f1)
17 lon=\$(echo \$line | cut -d' ' -f2)
18 &&
19 if ! [[ \$lat =~ \$re ]] || ! [[ \$lon =~ \$re ]] ; then continue ;fi
20 &&
21 i=\$((\$i+1)) &&
22 python '$__tool_directory__/netcdf_read.py' '$input' '$var_tab' $var
23 #for $i,$uc in enumerate($user_choice)
24 #if $uc.condi_between.comparator=="bi"
25 ${uc.dim} ${uc.condi_between.comparator} ${uc.condi_between.t1}-${uc.condi_between.t2}
26 #elif $uc.condi_between.comparator=="be"
27 ${uc.dim} ${uc.condi_between.comparator} ${uc.condi_between.t1}-${uc.condi_between.t2}
28 #else
29 ${uc.dim} ${uc.condi_between.comparator} ${uc.condi_between.value}
30 #end if
31 #end for
32 '$condi_source_coord.lat_dim'
33 \$lat
34 '$condi_source_coord.lon_dim'
35 \$lon
36
37 &&
38 cat 'header' | sed 's/array(\[//g' | sed 's/], dtype=float32)//g'| sed 's/,\s/_/g' | sed 's/(//g' | sed 's/)//g' > 'header_cleaned'
39 &&
40 cat 'header_cleaned' 'sortie.tabular' > 'supersortie.tabular'
41 &&
42 datamash transpose < 'supersortie.tabular' > 'supersortie_transposed.tabular'
43 &&
44 sed -i 's/_/\t/g' 'supersortie_transposed.tabular'
45 &&
46 cat 'header_names' 'supersortie_transposed.tabular' | sed 's/\s/\t/g' > 'output_dir/coord'\$i'.tabular';
47 done<'$coord_tabular'
48
49 #else
50
51 python '$__tool_directory__/netcdf_read.py' '$input' '$var_tab' $var
52 #for $i,$uc in enumerate($user_choice)
53 #if $uc.condi_between.comparator=="bi"
54 ${uc.dim} ${uc.condi_between.comparator} ${uc.condi_between.t1}-${uc.condi_between.t2}
55 #elif $uc.condi_between.comparator=="be"
56 ${uc.dim} ${uc.condi_between.comparator} ${uc.condi_between.t1}-${uc.condi_between.t2}
57 #else
58 ${uc.dim} ${uc.condi_between.comparator} ${uc.condi_between.value}
59 #end if
60 #end for
61 #if $condi_source_coord.condi_coord.coord=='yes_cust_coord'
62 $condi_source_coord.condi_coord.lat_dim $condi_source_coord.condi_coord.lat_val $condi_source_coord.condi_coord.lon_dim $condi_source_coord.condi_coord.lon_val
63 #end if
64 &&
65 cat 'header' | sed 's/array(\[//g' | sed 's/], dtype=float32)//g'| sed 's/,\s/_/g' | sed 's/(//g' | sed 's/)//g' > 'header_cleaned'
66 &&
67 cat 'header_cleaned' 'sortie.tabular' > 'supersortie.tabular'
68 &&
69 datamash transpose < 'supersortie.tabular' > 'supersortie_transposed.tabular'
70 &&
71 sed -i 's/_/\t/g' 'supersortie_transposed.tabular'
72 &&
73 cat 'header_names' 'supersortie_transposed.tabular' | sed 's/\s/\t/g' > 'final.tabular'
74
75 #end if
76
77
78 ]]></command>
79 <inputs>
80 <param type="data" name="input" label="Input netcdf file" format="netcdf,h5"/>
81 <param type="data" label="Tabular of variables" name="var_tab" format="tabular" help="Select the tabular file which summarize the available variables and dimensions."/>
82
83 <param name="var" type="select" label="Chose the variable to extract">
84 <options from_dataset="var_tab">
85 <column name="name" index="0"/>
86 <column name="value" index="0"/>
87 <column name="n_dim" index="1"/>
88 </options>
89 </param>
90
91 <conditional name="condi_source_coord">
92 <param name="coord_source" type="select" label="Source of coordinates">
93 <option value="coord_from_file">Use coordinates from input file</option>
94 <option value="coord_from_stdin">Manually enter coordinate</option>
95 </param>
96
97 <when value="coord_from_file">
98 <param type="data" label="Tabular of coord" name="coord_tabular" format="tabular" help="Format : Latitude Longitude"/>
99 <param name="lat_dim" type="select" label="Select latitude" >
100 <options from_dataset="var_tab">
101 <column name="value" index="0"/>
102 </options>
103 </param>
104 <param name="lon_dim" type="select" label="Select longitude" >
105 <options from_dataset="var_tab">
106 <column name="value" index="0"/>
107 </options>
108 </param>
109 </when>
110
111 <when value="coord_from_stdin">
112 <conditional name="condi_coord">
113 <param name="coord" type="boolean" label="Search values for custom coordinates" truevalue="yes_cust_coord" checked="true" falsevalue="nope" help="Use this option to get valid values at your custom coordinates. If only NA values are availables the tool will search for the next closest coordinate until valid values."/>
114 <when value="yes_cust_coord">
115 <param name="lat_dim" type="select" label="Select latitude" >
116 <options from_dataset="var_tab">
117 <column name="value" index="0"/>
118 </options>
119 </param>
120 <param name="lat_val" type="float" value="0" label="Latitude"/>
121 <param name="lon_dim" type="select" label="Select longitude" >
122 <options from_dataset="var_tab">
123 <column name="value" index="0"/>
124 </options>
125 </param>
126 <param name="lon_val" type="float" value="0" label="Longitude"/>
127 </when>
128
129 <when value="nope"></when>
130 </conditional>
131 </when>
132
133 </conditional>
134
135 <repeat name="user_choice" title="Filter">
136 <param name="dim" type="select" label="Dimensions">
137 <options from_dataset="var_tab">
138 <column name="value" index="0"/>
139 </options>
140 </param>
141 <conditional name="condi_between">
142 <param name="comparator" type="select" label="Comparator">
143 <option value="e">Equal</option>
144 <option value="g">Greater</option>
145 <option value="ge">Greater or equal</option>
146 <option value="l">Less</option>
147 <option value="le">Less or equal</option>
148 <option value="be">Between-exclude ]threshold1,threshold2[</option>
149 <option value="bi">Between-include [threshold1,threshold2]</option>
150 </param>
151 <when value="bi">
152 <param name="t1" type="float" value="0" label="Inferior threshold"/>
153 <param name="t2" type="float" value="0" label="Superior threshold"/>
154 </when>
155 <when value="be">
156 <param name="t1" type="float" value="0" label="Inferior threshold"/>
157 <param name="t2" type="float" value="0" label="Superior threshold"/>
158 </when>
159 <when value="e">
160 <param name="value" type="float" value="0" label="Value"/>
161 </when>
162 <when value="g">
163 <param name="value" type="float" value="0" label="Value"/>
164 </when>
165 <when value="ge">
166 <param name="value" type="float" value="0" label="Value"/>
167 </when>
168 <when value="l">
169 <param name="value" type="float" value="0" label="Value"/>
170 </when>
171 <when value="le">
172 <param name="value" type="float" value="0" label="Value"/>
173 </when>
174 </conditional>
175 </repeat>
176
177 </inputs>
178
179 <outputs>
180 <collection type="list" name="output">
181 <discover_datasets pattern="__designation_and_ext__" visible="false" format="tabular" directory="output_dir"/>
182 <filter>condi_source_coord['coord_source'] == 'coord_from_file'</filter>
183 </collection>
184 <data name="simpleoutput" from_work_dir="final.tabular" format="tabular">
185 <filter>condi_source_coord['coord_source'] == 'coord_from_stdin'</filter>
186 </data>
187 </outputs>
188
189
190 <tests>
191 <test>
192 <param name="input" value="dataset-ibi-reanalysis-bio-005-003-monthly-regulargrid_1510914389133.nc"/>
193 <param name="var_tab" value="var_tab_dataset-ibi"/>
194 <param name="var" value="phy"/>
195 <param name="dim_tab" value="tab_dim_phy_dataset-ibi"/>
196 <param name="coord" value="yes_cut_coord"/>
197 <param name="lat_dim" value="latitude"/>
198 <param name="lat_val" value="44.0"/>
199 <param name="lon_dim" value="longitude"/>
200 <param name="lon_val" value="-2.0"/>
201 <param name="output" value="Test1.tabular"/>
202 </test>
203 <test>
204 <param name="input" value="dataset-ibi-reanalysis-bio-005-003-monthly-regulargrid_1510914389133.nc"/>
205 <param name="var_tab" value="var_tab_dataset-ibi"/>
206 <param name="var" value="nh4"/>
207 <param name="dim_tab" value="tab_dim_nh4_dataset-ibi"/>
208 <param name="coord" value="nope"/>
209 <param name="dim" value="time"/>
210 <param name="comparator" value="e"/>
211 <param name="value" value="7272.0"/>
212 <param name="dim" value="latitude"/>
213 <param name="comparator" value="ge"/>
214 <param name="value" value="45.0"/>
215 <param name="output" value="Test2.tabular"/>
216 </test>
217
218
219
220
221 </tests>
222
223 <help><![CDATA[
224 **What it does**
225
226 This tool extracts variable values with custom conditions on dimensions.
227
228 It can use manualy given coordinates or automaticaly take them from a tabular file to filter informations.
229
230 If no values are availables at a coordinate X, the tool will search the closest coordinate with a non NA value.
231
232 Filter can be set on every dimension. Available filtering operations are : =, >, <, >=, <=, [interval], ]interval[.
233
234
235
236 **Input**
237
238 A netcdf file (.nc).
239
240 Variable tabular file from 'Netcdf Metadate Info'.
241
242 Tabular file with coordinates and the following structure : 'lat' 'lon'.
243
244
245 **Outputs**
246
247 A single output with values for the wanted variable if there is only one coordinate.
248
249 A data collection where one file is created for every coordinate, if multiple coordinates from tabular file.
250
251
252 -------------------------------------------------
253
254 The Netcdf Read tool can be used after the Netcdf Info.
255 ]]></help>
256 </tool>