@@ -85,7 +85,12 @@ def from_dataset(ds: xr.Dataset) -> xr.Dataset:
8585
8686
8787def from_binary (
88- slc_files , shape , vlabel = "complex" , dtype = np .complex64 , chunks = None , ratio = 1
88+ slc_files : list [str | Path ],
89+ shape : tuple [int , int ],
90+ vlabel : str = "complex" ,
91+ dtype : np .dtype = np .complex64 ,
92+ chunks : tuple [int , int ] | None = None ,
93+ ratio : float = 1 ,
8994):
9095 """Read a SLC stack or related variables from binary files.
9196
@@ -131,6 +136,15 @@ def from_binary(
131136 if chunks is None :
132137 chunks = _calc_chunksize (shape , dtype , ratio )
133138
139+ # Check if slc_files is a non empty Iterable and not a string
140+ if not hasattr (slc_files , "__iter__" ) or isinstance (slc_files , str ):
141+ raise ValueError (
142+ "slc_files should be a non-empty Iterable and not a string."
143+ "If you have only one file, please put it in a list, e.g. slc_files=[file]."
144+ )
145+ if len (slc_files ) == 0 :
146+ raise ValueError ("slc_files should be a non-empty Iterable." )
147+
134148 # Read in all SLCs
135149 slcs = None
136150 for f_slc in slc_files :
@@ -382,11 +396,6 @@ def _parse_metadata(file, driver, ifg_file_name):
382396 elif driver == "doris4" :
383397 patterns = RE_PATTERNS_DORIS4
384398 patterns_ifg = None
385- else :
386- raise NotImplementedError (
387- f"Driver '{ driver } ' is not implemented. "
388- "Supported drivers are: 'doris4', 'doris5'."
389- )
390399
391400 # Open the file
392401 with open (file ) as f :
@@ -416,18 +425,11 @@ def _parse_metadata(file, driver, ifg_file_name):
416425 with open (file_ifg ) as f_ifg :
417426 content_ifg = f_ifg .read ()
418427 for key , pattern in RE_PATTERNS_DORIS5_IFG .items ():
419- if key in META_ARRAY_KEYS .keys (): # multiple hits allowed
420- matches = re .findall (pattern , content_ifg )
421- if matches :
422- results [key ] = matches
423- else :
424- results [key ] = None
428+ match = re .search (pattern , content_ifg )
429+ if match :
430+ results [key ] = match .group (1 )
425431 else :
426- match = re .search (pattern , content_ifg )
427- if match :
428- results [key ] = match .group (1 )
429- else :
430- results [key ] = None
432+ results [key ] = None
431433
432434 return results
433435
@@ -447,16 +449,8 @@ def _regulate_metadata(metadata, driver):
447449 elif driver == "doris4" :
448450 time_format = TIME_FORMAT_DORIS4
449451 unit_conversions = META_UNIT_CONVERSION_MULTIPLICATION_KEYS_DORIS4
450- else :
451- raise NotImplementedError (
452- f"Driver '{ driver } ' is not implemented. "
453- "Supported drivers are: 'doris4', 'doris5'."
454- )
455452
456453 list_time = []
457- # If the time is a single string, convert it to a list
458- if isinstance (metadata [TIME_STAMP_KEY ], str ):
459- metadata [TIME_STAMP_KEY ] = [metadata [TIME_STAMP_KEY ]]
460454 for time in metadata [TIME_STAMP_KEY ]:
461455 try :
462456 dt = datetime .strptime (time , time_format )
0 commit comments