55import re as _re
66from multiprocessing import Pool as _Pool
77from typing import Optional , Union
8+ import warnings
89
910import numpy as _np
1011import pandas as _pd
5960 _re .IGNORECASE | _re .VERBOSE ,
6061)
6162
63+ # See example here: https://files.igs.org/pub/station/general/blank.log
6264_REGEX_LOC_V2 = _re .compile (
6365 rb"""
6466 2.+\W+City\sor\sTown\s+\:\s*(\w[^\(\n\,/\?]+|).*\W+
@@ -222,15 +224,24 @@ def extract_id_block(
222224 return id_block
223225
224226
225- def extract_location_block (data : bytes , file_path : str , version : Union [str , None ] = None ) -> _np .ndarray :
227+ def extract_location_block (
228+ data : bytes ,
229+ file_path : str ,
230+ version : Union [str , None ] = None ,
231+ raise_on_extract_failure : bool = True ,
232+ raise_on_unexpected_element_count : bool = True ,
233+ ) -> list [str ]:
226234 """Extract the location block given the bytes object read from an IGS site log file
227235
228236 :param bytes data: The bytes object returned from an open() call on a IGS site log in "rb" mode
229237 :param str file_path: The path to the file from which the "data" bytes object was obtained
230238 :param str version: Version number of log file (e.g. "v2.0") - will be determined from input data unless
231239 provided here.
240+ :param bool raise_on_extract_failure: raise (default) rather than just warning, if regex extract fails
241+ :param bool raise_on_unexpected_element_count: raise (default) rather than just warning, if LOC elements count != 8
232242 :raises LogVersionError: Raises an error if an unknown version string is passed in
233- :return _np.ndarray: The location block of the IGS site log, as a numpy NDArray of strings
243+ :raises ValueError: If an the location block regex does not match, or if the number of elements extracted is not 8
244+ :return list[str]: The location block of the IGS site log, as a list of strings
234245 """
235246 if version == None :
236247 version = determine_log_version (data )
@@ -242,11 +253,26 @@ def extract_location_block(data: bytes, file_path: str, version: Union[str, None
242253 else :
243254 raise LogVersionError (f"Incorrect version string '{ version } ' passed to extract_location_block() function" )
244255
245- location_block = _REGEX_LOC .search (data )
246- if location_block is None :
247- logger .warning (f"LOC rejected from { file_path } " )
248- return _np .array ([]).reshape (0 , 12 )
249- return location_block
256+ loc_block_match = _REGEX_LOC .search (data )
257+ if loc_block_match is None :
258+ if raise_on_extract_failure :
259+ raise ValueError (f"Failed to extract LOC block from { file_path } " )
260+ warnings .warn (f"Failed to extract LOC block from { file_path } " )
261+ return []
262+
263+ # List of location properties.
264+ # See example under '2. Site Location Information' here: https://files.igs.org/pub/station/general/blank.log
265+ loc_block_decoded = [group .decode (encoding = "utf8" , errors = "ignore" ) for group in loc_block_match .groups ()]
266+
267+ loc_element_count = len (loc_block_decoded )
268+ if loc_element_count != 8 :
269+ # TODO consider using t-strings in Python 3.14
270+ loc_count_warning = "Expected 8 elements in LOC block, got: {block_length}, file: {file_path}"
271+ if raise_on_unexpected_element_count :
272+ raise ValueError (loc_count_warning .format (block_length = loc_element_count , file_path = file_path ))
273+ warnings .warn (loc_count_warning .format (block_length = loc_element_count , file_path = file_path ))
274+
275+ return loc_block_decoded
250276
251277
252278def extract_receiver_block (data : bytes , file_path : str ) -> Union [list [tuple [bytes ]], _np .ndarray ]:
@@ -304,7 +330,6 @@ def parse_igs_log_data(data: bytes, file_path: str, file_code: str) -> Union[_np
304330 file_path = file_path ,
305331 version = version ,
306332 )
307- blk_loc = [group .decode (encoding = "utf8" , errors = "ignore" ) for group in blk_loc .groups ()]
308333 # Combine ID and Location information:
309334 blk_id_loc = _np .asarray ([0 ] + blk_id + blk_loc , dtype = object )[_np .newaxis ]
310335 # Extract and re-format information from receiver block:
0 commit comments