@@ -76,7 +76,8 @@ def progress(count, total, status='', bar_len=60):
76
76
filled_len = int (percents * bar_len )
77
77
prog_bar = '=' * filled_len + '-' * (bar_len - filled_len )
78
78
79
- sys .stderr .write ('[%s] %.2f%s ...%s\r ' % (prog_bar , percents * 100 , '%' , status ))
79
+ sys .stderr .write ('[%s] %.2f%s ...%s\r ' %
80
+ (prog_bar , percents * 100 , '%' , status ))
80
81
sys .stderr .flush ()
81
82
82
83
@@ -102,10 +103,12 @@ def assemble_files(arguments):
102
103
else :
103
104
candidates = sorted (glob .glob (filename ))
104
105
if len (candidates ) == 0 :
105
- print ("Error: invalid file or directory! No matches found. '{}'" .format (filename ))
106
+ print (
107
+ "Error: invalid file or directory! No matches found. '{}'" .format (filename ))
106
108
for candidate in candidates :
107
109
if os .path .isdir (candidate ):
108
- candidate = os .sep .join ((candidate , "*." + arguments .suffix ))
110
+ candidate = os .sep .join (
111
+ (candidate , "*." + arguments .suffix ))
109
112
all_files .extend (sorted (glob .glob (candidate )))
110
113
elif os .path .isfile (candidate ):
111
114
all_files .append (candidate )
@@ -127,27 +130,33 @@ def dimension_description(data_array, _):
127
130
128
131
def array_structure (data_array , verbosity ):
129
132
dims = dimension_description (data_array , verbosity )
130
- content = "\n shape: %s, dtype: %s %s" % (data_array .shape , data_array .dtype , dims )
133
+ content = "\n shape: %s, dtype: %s %s" % (
134
+ data_array .shape , data_array .dtype , dims )
131
135
return content
132
136
133
- content = " Data Arrays:\n " if len (block .data_arrays ) > 0 else ""
137
+ content = " Data Arrays:\n " if len (
138
+ block .data_arrays ) > 0 else ""
134
139
for da in block .data_arrays :
135
- array_struct = array_structure (da , verbosity ) if verbosity > 2 else ""
136
- content += " %s [%s] --- id: %s %s\n " % (da .name , da .type , da .id , array_struct )
140
+ array_struct = array_structure (
141
+ da , verbosity ) if verbosity > 2 else ""
142
+ content += " %s [%s] --- id: %s %s\n " % (
143
+ da .name , da .type , da .id , array_struct )
137
144
return content
138
145
139
146
def group_content (block , _ ):
140
147
content = " Groups:\n " if len (block .groups ) > 0 else ""
141
148
for grp in block .groups :
142
- content += " %s [%s] -- id: %s\n " % (grp .name , grp .type , grp .id )
149
+ content += " %s [%s] -- id: %s\n " % (
150
+ grp .name , grp .type , grp .id )
143
151
return content
144
152
145
153
def tag_content (block , verbosity ):
146
154
def tag_details (tag , verbosity ):
147
155
if verbosity < 3 :
148
156
return ""
149
157
150
- content = " start: %s, extent: %s" % (tag .position , tag .extent )
158
+ content = " start: %s, extent: %s" % (
159
+ tag .position , tag .extent )
151
160
for ref in tag .references :
152
161
content += "\n refers to -> %s" % ref .name
153
162
for feat in tag .features :
@@ -157,15 +166,17 @@ def tag_details(tag, verbosity):
157
166
158
167
content = " Tags:\n "
159
168
for tag in block .tags :
160
- content += " %s [%s] --- id: %s\n %s" % (tag .name , tag .type , tag .id , tag_details (tag , verbosity ))
169
+ content += " %s [%s] --- id: %s\n %s" % (
170
+ tag .name , tag .type , tag .id , tag_details (tag , verbosity ))
161
171
return content
162
172
163
173
def mtag_content (block , verbosity ):
164
174
def tag_details (tag , verbosity ):
165
175
if verbosity < 3 :
166
176
return ""
167
177
168
- content = " start: %s, extent: %s" % (tag .position [:], tag .extent [:])
178
+ content = " start: %s, extent: %s" % (
179
+ tag .position [:], tag .extent [:])
169
180
for ref in tag .references :
170
181
content += "\n segment refers to -> %s" % ref .name
171
182
for feat in tag .features :
@@ -180,15 +191,18 @@ def tag_details(tag, verbosity):
180
191
return content
181
192
182
193
def frame_content (block , _ ):
183
- content = " Data frames:\n " if len (block .data_frames ) > 0 else ""
194
+ content = " Data frames:\n " if len (
195
+ block .data_frames ) > 0 else ""
184
196
for df in block .data_frames :
185
- content += " %s [%s] -- id: %s\n " % (df .name , df .type , df .id )
197
+ content += " %s [%s] -- id: %s\n " % (
198
+ df .name , df .type , df .id )
186
199
return content
187
200
188
201
def source_content (block , _ ):
189
202
content = " Sources:\n " if len (block .groups ) > 0 else ""
190
203
for src in block .sources :
191
- content += " %s [%s] -- id: %s\n " % (src .name , src .type , src .id )
204
+ content += " %s [%s] -- id: %s\n " % (
205
+ src .name , src .type , src .id )
192
206
return content
193
207
194
208
content = ""
@@ -220,7 +234,8 @@ def subsections(section, _):
220
234
content = ""
221
235
sections = section .find_sections ()
222
236
prop_count = sum ([len (sec ) for sec in sections ])
223
- content += "\n %i sub-section(s), %i properties\n " % (len (sections ), prop_count )
237
+ content += "\n %i sub-section(s), %i properties\n " % (
238
+ len (sections ), prop_count )
224
239
return content
225
240
226
241
content = ""
@@ -229,18 +244,21 @@ def subsections(section, _):
229
244
else :
230
245
for section in nix_file .sections :
231
246
subs_props = subsections (section , verbosity )
232
- content += " %s [%s] --- id: %s%s" % (section .name , section .type , section .id , subs_props )
247
+ content += " %s [%s] --- id: %s%s" % (
248
+ section .name , section .type , section .id , subs_props )
233
249
return content
234
250
235
251
def file_content (nix_file , verbosity ):
236
252
if verbosity is None :
237
253
verbosity = 0
238
254
content = ""
239
255
if verbosity < 1 :
240
- content += "%s\n %s" % (block_content (nix_file , verbosity ), section_content (nix_file , verbosity ))
256
+ content += "%s\n %s" % (block_content (nix_file , verbosity ),
257
+ section_content (nix_file , verbosity ))
241
258
else :
242
259
content += " data:\n %s" % block_content (nix_file , verbosity )
243
- content += " metadata:\n %s\n " % section_content (nix_file , verbosity )
260
+ content += " metadata:\n %s\n " % section_content (
261
+ nix_file , verbosity )
244
262
return content
245
263
246
264
print ("\n %s\n \n " % file_content (nix_file , verbosity ))
@@ -321,15 +339,17 @@ def disp_metadata(filename, arguments):
321
339
part = parts [1 ] if case_sensitive else parts [1 ].lower ()
322
340
pname = prop .name if case_sensitive else prop .name .lower ()
323
341
if part == pname if full_match else part in pname :
324
- print ("[section: %s, type: %s, id: %s] >> " % (sec .name , sec .type , sec .id ), end = "" )
342
+ print ("[section: %s, type: %s, id: %s] >> " %
343
+ (sec .name , sec .type , sec .id ), end = "" )
325
344
prop .pprint ()
326
345
else :
327
346
sections = find_section (nf , patt , case_sensitive )
328
347
if len (sections ) == 0 :
329
348
props = find_props (nf , patt , case_sensitive )
330
349
for sec in props .keys ():
331
350
for prop in props [sec ]:
332
- print ("[section: %s, type: %s, id: %s] >> " % (sec .name , sec .type , sec .id ), end = "" )
351
+ print ("[section: %s, type: %s, id: %s] >> " %
352
+ (sec .name , sec .type , sec .id ), end = "" )
333
353
prop .pprint ()
334
354
else :
335
355
for sec in sections :
@@ -454,15 +474,20 @@ def dump_twod(data, dimensions, label, unit, outfile, fmt="%.6f", end="\n\n",
454
474
numeric_2nd_dim_ticks = isinstance (second_dim_ticks [0 ], (int , float ))
455
475
numeric_data = isinstance (data [0 , 0 ], (int , float ))
456
476
data_conv_func = (lambda x : fmt % x ) if numeric_data else str
457
- dim_ticks_conv_func1 = (lambda x : fmt % x ) if numeric_1st_dim_ticks else str
458
- dim_ticks_conv_func2 = (lambda x : fmt % x ) if numeric_2nd_dim_ticks else str
477
+ dim_ticks_conv_func1 = (lambda x : fmt %
478
+ x ) if numeric_1st_dim_ticks else str
479
+ dim_ticks_conv_func2 = (lambda x : fmt %
480
+ x ) if numeric_2nd_dim_ticks else str
459
481
460
- max_tick_len = max ([len (dim_ticks_conv_func1 (first_dim_ticks [- 1 ])), len (first_dim_label )])
482
+ max_tick_len = max (
483
+ [len (dim_ticks_conv_func1 (first_dim_ticks [- 1 ])), len (first_dim_label )])
461
484
print ("# data label: %s" % label , file = outfile )
462
485
print ("# data unit: %s\n " % unit , file = outfile )
463
- padding = " " * (max_tick_len - (len (first_dim_label ) if first_dim_unit else 0 ))
486
+ padding = " " * (max_tick_len - (len (first_dim_label )
487
+ if first_dim_unit else 0 ))
464
488
print ("# %s%s%s" % (first_dim_label , padding , second_dim_label ), file = outfile )
465
- padding = " " * (max_tick_len - (len (first_dim_unit ) if first_dim_unit else 0 ))
489
+ padding = " " * (max_tick_len - (len (first_dim_unit )
490
+ if first_dim_unit else 0 ))
466
491
print ("# %s%s%s" % (first_dim_unit , padding , second_dim_unit ), file = outfile )
467
492
# first line contains 2nd dim ticks
468
493
print (" " * max_tick_len + " " + (" " * max_tick_len + " " ).join (map (dim_ticks_conv_func2 , second_dim_ticks )),
@@ -521,7 +546,8 @@ def data_dump(filename, arguments, outfile, show_progress=False):
521
546
entities = find_data_entity (nix_file , arguments )
522
547
for ent in entities :
523
548
if isinstance (ent , nix .DataArray ):
524
- sys .stderr .write ("Dumping %s to %s...\n " % (ent .name , arguments .outfile ))
549
+ sys .stderr .write ("Dumping %s to %s...\n " %
550
+ (ent .name , arguments .outfile ))
525
551
dump_data_array (ent , filename , outfile , show_progress )
526
552
sys .stderr .write ("\n " )
527
553
nix_file .close ()
@@ -537,7 +563,8 @@ def data_plotter(filename, arguments):
537
563
plotter .plot ()
538
564
plotter .show ()
539
565
else :
540
- print ("Could not find a suitable plotter for the DataArray: %s" % str (ent ))
566
+ print (
567
+ "Could not find a suitable plotter for the DataArray: %s" % str (ent ))
541
568
else :
542
569
print ("Sorry, so far I can only try to plot DataArrays." )
543
570
@@ -549,7 +576,8 @@ def disp_data(filename, arguments):
549
576
entities = find_data_entity (nix_file , arguments )
550
577
print ("# File: %s" % filename )
551
578
for ent in entities :
552
- print ("# entity: %s\n # type: %s\n # id: %s" % (ent .name , ent .type , ent .id ))
579
+ print ("# entity: %s\n # type: %s\n # id: %s" %
580
+ (ent .name , ent .type , ent .id ))
553
581
print ("# created at: %s\n # last edited at: %s\n " % (str (dt .datetime .fromtimestamp (ent .created_at )),
554
582
str (dt .datetime .fromtimestamp (ent .updated_at ))))
555
583
print (ent )
@@ -574,7 +602,8 @@ def dump_worker(arguments):
574
602
func = data_dump
575
603
if len (arguments .outfile ) > 0 :
576
604
if os .path .exists (arguments .outfile ):
577
- response = input ("File %s already exists, are you sure to overwrite it? y/N:" % arguments .outfile )
605
+ response = input (
606
+ "File %s already exists, are you sure to overwrite it? y/N:" % arguments .outfile )
578
607
if response .lower () != "y" :
579
608
print ("... data dump aborted." )
580
609
return
@@ -601,25 +630,25 @@ def add_default_file_args(parent_parser):
601
630
parent_parser .add_argument ("file" , type = str , nargs = "+" ,
602
631
help = "Path to file (at least one)" )
603
632
parent_parser .add_argument ("-s" , "--suffix" , type = str , default = "nix" , nargs = "?" ,
604
- help = ( "The file suffix used for nix data files (default: %(default)s)." ) )
633
+ help = "The file suffix used for nix data files (default: %(default)s)." )
605
634
606
635
607
636
def add_default_args (parent_parser ):
608
637
parent_parser .add_argument ("-c" , "--case_sensitive" , action = "store_true" ,
609
638
help = ("matching of entitiy names and types is case sensitive, "
610
639
"by default the case is ignored" ))
611
640
parent_parser .add_argument ("-fm" , "--full_match" , action = "store_true" ,
612
- help = ( "names and types must be full matches, by default a partial match is sufficient" ) )
641
+ help = "names and types must be full matches, by default a partial match is sufficient" )
613
642
614
643
615
644
def create_metadata_parser (parent_parser ):
616
645
meta_parser = parent_parser .add_parser ("metadata" , help = "Filter and display metadata" ,
617
646
aliases = ["mdata" ],
618
- description = ( "Search for metadata items or display metadata (sub)trees." ) )
647
+ description = "Search for metadata items or display metadata (sub)trees." )
619
648
meta_parser .add_argument ("-p" , "--pattern" , type = str , action = "append" ,
620
649
help = METADATA_PATTERN_HELP )
621
650
meta_parser .add_argument ("-d" , "--depth" , type = int , default = - 1 ,
622
- help = ( "maximum depth of metadata tree output, default is %(default)s, full depth" ) )
651
+ help = "maximum depth of metadata tree output, default is %(default)s, full depth" )
623
652
add_default_args (meta_parser )
624
653
add_default_file_args (meta_parser )
625
654
meta_parser .set_defaults (func = mdata_worker )
@@ -629,18 +658,23 @@ def create_metadata_parser(parent_parser):
629
658
630
659
def create_data_parser (parent_parser ):
631
660
data_parser = parent_parser .add_parser ("data" ,
632
- help = ("Search and display information about data entities" ),
661
+ help = (
662
+ "Search and display information about data entities" ),
633
663
description = DATA_PARSER_HELP )
634
- data_parser .add_argument ("-p" , "--pattern" , default = "" , type = str , help = DATA_PATTERN_HELP )
664
+ data_parser .add_argument (
665
+ "-p" , "--pattern" , default = "" , type = str , help = DATA_PATTERN_HELP )
635
666
add_default_args (data_parser )
636
667
add_default_file_args (data_parser )
637
668
data_parser .set_defaults (func = data_worker )
638
669
639
670
640
671
def create_dump_parser (parent_parser ):
641
- dump_parser = parent_parser .add_parser ("dump" , help = "Dump stored data to stdout" , description = DUMP_PARSER_HELP )
642
- dump_parser .add_argument ("-p" , "--pattern" , default = "" , type = str , help = DUMP_PATTERN_HELP )
643
- dump_parser .add_argument ("-o" , "--outfile" , default = "" , type = str , help = DUMP_OUTFILE_HELP )
672
+ dump_parser = parent_parser .add_parser (
673
+ "dump" , help = "Dump stored data to stdout" , description = DUMP_PARSER_HELP )
674
+ dump_parser .add_argument (
675
+ "-p" , "--pattern" , default = "" , type = str , help = DUMP_PATTERN_HELP )
676
+ dump_parser .add_argument (
677
+ "-o" , "--outfile" , default = "" , type = str , help = DUMP_OUTFILE_HELP )
644
678
add_default_args (dump_parser )
645
679
add_default_file_args (dump_parser )
646
680
dump_parser .set_defaults (func = dump_worker )
@@ -651,7 +685,8 @@ def create_plot_parser(parent_parser):
651
685
return
652
686
plot_parser = parent_parser .add_parser ("plot" , help = "Create basic plots of stored data." ,
653
687
description = PLOT_PARSER_HELP )
654
- plot_parser .add_argument ("-p" , "--pattern" , type = str , help = DATA_PATTERN_HELP )
688
+ plot_parser .add_argument (
689
+ "-p" , "--pattern" , type = str , help = DATA_PATTERN_HELP )
655
690
add_default_args (plot_parser )
656
691
add_default_file_args (plot_parser )
657
692
plot_parser .set_defaults (func = plot_worker )
@@ -662,7 +697,7 @@ def create_file_parser(parent_parser):
662
697
description = ("Quick display of file information such as creation date, "
663
698
"file size and structure etc." ))
664
699
file_parser .add_argument ("-v" , "--verbosity" , action = "count" ,
665
- help = ( "increase output verbosity, use -v, -vv, -vvv for more verbose output" ) )
700
+ help = "increase output verbosity, use -v, -vv, -vvv for more verbose output" )
666
701
add_default_file_args (file_parser )
667
702
file_parser .set_defaults (func = file_worker )
668
703
0 commit comments