88import sys
99
1010from ..read_machinery import FilenameInfo
11- from ..reader import H5File , RunDirectory
12-
13-
14- def describe_file (path , details_for_sources = (), with_aggregators = False ,
15- with_auxiliary = False , group_sources = True ):
16- """Describe a single HDF5 data file"""
17- basename = os .path .basename (path )
18- print (basename , ": Data file" )
19-
20- h5file = H5File (path )
21- h5file .info (details_for_sources , with_aggregators , with_auxiliary , group_sources )
11+ from ..reader import DataCollection , H5File , RunDirectory
2212
2313
2414def summarise_file (path ):
@@ -29,16 +19,6 @@ def summarise_file(path):
2919 print (f" { len (f .train_ids )} trains, { len (f .all_sources )} sources" )
3020
3121
32- def describe_run (path , details_for_sources = (), with_aggregators = False ,
33- with_auxiliary = False , group_sources = True ):
34- basename = os .path .basename (path )
35- print (basename , ": Run directory" )
36- print ()
37-
38- run = RunDirectory (path )
39- run .info (details_for_sources , with_aggregators , with_auxiliary , group_sources )
40-
41-
4222def summarise_run (path , indent = '' ):
4323 basename = os .path .basename (path )
4424
@@ -74,6 +54,10 @@ def main(argv=None):
7454 prog = 'lsxfel' , description = "Summarise XFEL data in files or folders"
7555 )
7656 ap .add_argument ('paths' , nargs = '*' , help = "Files/folders to look at" )
57+ ap .add_argument ('--source' , '-s' , action = 'append' , default = [],
58+ help = "Filter the list of sources, with wildcard patterns like "
59+ "'*XGM/*:output' or partial matches like 'XGM'. Can be used more "
60+ "than once." )
7761 ap .add_argument ('--detail' , '-d' , action = 'append' , default = [],
7862 help = "Show details on keys & data for specified sources. "
7963 "This can slow down lsxfel considerably. "
@@ -82,6 +66,10 @@ def main(argv=None):
8266 "Can be used more than once to include several patterns. "
8367 "Only used when inspecting a single run or file."
8468 )
69+ ap .add_argument ('--counts' , '-c' , action = 'store_true' ,
70+ help = "Show data counts for instrument sources." )
71+ ap .add_argument ('--no-group' , action = 'store_true' ,
72+ help = "Don't try to group similar source names; show each individually." )
8573 ap .add_argument ('--aggregators' , '-g' , action = 'store_true' ,
8674 help = "Include the aggregator each source is saved in. "
8775 "Only used when inspecting a single run or file and can slow "
@@ -90,16 +78,32 @@ def main(argv=None):
9078 help = "Include auxiliary sources alongside regular sources. "
9179 "Only used when inspecting a single run or file and can slow "
9280 "down lsxfel." )
93- ap .add_argument ('--no-group' , action = 'store_true' ,
94- help = "Don't try to group similar source names; show each individually." )
9581 args = ap .parse_args (argv )
9682 paths = args .paths or [os .path .abspath (os .getcwd ())]
9783
9884 # If --detail doesn't contain glob wildcards, treat it as a substring
9985 detail_patterns = [p if re .search (r'[*?[]' , p ) else f'*{ p } *'
10086 for p in args .detail ]
101-
102- group_sources = not args .no_group
87+ source_patterns = [p if re .search (r'[*?[]' , p ) else f'*{ p } *'
88+ for p in args .source ]
89+
90+ def dc_info (dc : DataCollection ):
91+ if source_patterns :
92+ try :
93+ sel = dc .select (source_patterns )
94+ except ValueError as e : # No matching sources
95+ sys .exit (str (e ))
96+ print (f"Showing { len (sel .all_sources )} / { len (dc .all_sources )} sources" )
97+ else :
98+ sel = dc
99+ print ()
100+ sel .info (
101+ detail_patterns ,
102+ counts = args .counts ,
103+ group_sources = (not args .no_group ),
104+ with_aggregators = args .aggregators ,
105+ with_auxiliary = args .auxiliary ,
106+ )
103107
104108 if len (paths ) == 1 :
105109 path = paths [0 ]
@@ -109,8 +113,8 @@ def main(argv=None):
109113 contents = sorted (os .listdir (path ))
110114 if any (f .endswith ('.h5' ) for f in contents ):
111115 # Run directory
112- describe_run ( path , detail_patterns , args . aggregators ,
113- args . auxiliary , group_sources = group_sources )
116+ print ( basename , ": Run directory" )
117+ dc_info ( RunDirectory ( path ) )
114118 elif any (re .match (r'r\d+' , f ) for f in contents ):
115119 # Proposal directory, containing runs
116120 print (basename , ": Proposal data directory" )
@@ -131,8 +135,8 @@ def main(argv=None):
131135 print (basename , ": Unrecognised directory" )
132136 elif os .path .isfile (path ):
133137 if path .endswith ('.h5' ):
134- describe_file ( path , detail_patterns , args . aggregators ,
135- args . auxiliary , group_sources = group_sources )
138+ print ( basename , ": Data file" )
139+ dc_info ( H5File ( path ) )
136140 else :
137141 print (basename , ": Unrecognised file" )
138142 return 2
0 commit comments