5454from .xml_util import getNamespaces
5555
5656from spatialist import crsConvert , sqlite3 , Vector , bbox
57- from spatialist .ancillary import parse_literal , finder
57+ from spatialist .ancillary import parse_literal , finder , multicore
5858
5959from sqlalchemy import create_engine , Table , MetaData , Column , Integer , String , exc , insert
6060from sqlalchemy import inspect as sql_inspect
@@ -129,10 +129,10 @@ def get_subclasses(c):
129129 raise RuntimeError ('data format not supported' )
130130
131131
132- def identify_many (scenes , pbar = False , sortkey = None ):
132+ def identify_many (scenes , pbar = False , sortkey = None , cores = 1 ):
133133 """
134- wrapper function for returning metadata handlers of all valid scenes in a list, similar to function
135- :func:`~pyroSAR.drivers.identify`.
134+ wrapper function for returning metadata handlers of all valid scenes in a list,
135+ similar to function :func:`~pyroSAR.drivers.identify`.
136136
137137 Parameters
138138 ----------
@@ -142,6 +142,9 @@ def identify_many(scenes, pbar=False, sortkey=None):
142142 adds a progressbar if True
143143 sortkey: str or None
144144 sort the handler object list by an attribute
145+ cores: int
146+ the number of cores to parallelize identification
147+
145148 Returns
146149 -------
147150 list[ID]
@@ -153,28 +156,38 @@ def identify_many(scenes, pbar=False, sortkey=None):
153156 >>> files = finder('/path', ['S1*.zip'])
154157 >>> ids = identify_many(files, pbar=False, sortkey='start')
155158 """
156- idlist = []
157- if pbar :
158- progress = pb .ProgressBar (max_value = len (scenes )).start ()
159- else :
160- progress = None
161- for i , scene in enumerate (scenes ):
159+
160+ def handler (scene ):
162161 if isinstance (scene , ID ):
163- idlist . append ( scene )
162+ return scene
164163 else :
165164 try :
166165 id = identify (scene )
167- idlist . append ( id )
166+ return id
168167 except RuntimeError :
169- continue
168+ return None
170169 except PermissionError :
171170 log .warning ("Permission denied: '{}'" .format (scene ))
171+
172+ if cores == 1 :
173+ idlist = []
174+ if pbar :
175+ progress = pb .ProgressBar (max_value = len (scenes )).start ()
176+ else :
177+ progress = None
178+ for i , scene in enumerate (scenes ):
179+ id = handler (scene )
180+ idlist .append (id )
181+ if progress is not None :
182+ progress .update (i + 1 )
172183 if progress is not None :
173- progress .update (i + 1 )
174- if progress is not None :
175- progress .finish ()
176- if sortkey is not None :
177- idlist .sort (key = operator .attrgetter (sortkey ))
184+ progress .finish ()
185+ if sortkey is not None :
186+ idlist .sort (key = operator .attrgetter (sortkey ))
187+ else :
188+ idlist = multicore (function = handler , multiargs = {'scene' : scenes },
189+ pbar = pbar , cores = cores )
190+ idlist = list (filter (None , idlist ))
178191 return idlist
179192
180193
0 commit comments