def is_esm(filename, config=None): """Check to see if file is an ESM strong motion file. Args: filename (str): Path to possible ESM strong motion file. config (dict): Dictionary containing configuration. Returns: bool: True if ESM, False otherwise. """ logging.debug("Checking if format is esm.") if is_binary(filename): return False if not os.path.isfile(filename): return False try: open(filename, "rt").read(os.stat(filename).st_size) except UnicodeDecodeError: return False try: with open(filename, "rt") as f: lines = [next(f) for x in range(TEXT_HDR_ROWS)] if lines[0].startswith(HDR1) and lines[1].startswith(HDR2): return True except BaseException: return False return False
def is_geonet(filename, config=None): """Check to see if file is a New Zealand GNS V1 or V2 strong motion file. Args: filename (str): Path to possible GNS V1/V2 data file. config (dict): Dictionary containing configuration. Returns: bool: True if GNS V1/V2, False otherwise. """ logging.debug("Checking if format is geonet.") if is_binary(filename): return False try: line = open(filename, "rt").readline() if line.find("GNS Science") >= 0: c1 = line.find("Corrected accelerogram") >= 0 c2 = line.find("Uncorrected accelerogram") >= 0 if c1 or c2: return True return False except UnicodeDecodeError: return False
def is_usc(filename, config=None, **kwargs): """Check to see if file is a USC strong motion file. Args: filename (str): Path to possible USC V1 data file. config (dict): Dictionary containing configuration. kwargs (ref): Other arguments will be ignored. Returns: bool: True if USC, False otherwise. """ logging.debug("Checking if format is usc.") if is_binary(filename): return False # USC requires unique integer values # in column 73-74 on all text header lines # excluding the first file line return_alternate = kwargs.get("return_alternate", False) try: f = open(filename, "rt") first_line = f.readline() if first_line.find("OF UNCORRECTED ACCELEROGRAM DATA OF") >= 0: volume = "V1" start = 1 stop = 12 alternate_start = start + 2 alternate_stop = stop - 2 elif first_line.find("CORRECTED ACCELEROGRAM") >= 0: volume = "V2" start = 2 stop = 12 alternate_start = start + 2 alternate_stop = stop - 2 elif first_line.find("RESPONSE") >= 0: raise ValueError( "USC: Derived response spectra and fourier " "amplitude spectra not supported: %s" % filename ) else: f.close() return False f.close() except BaseException: return False finally: f.close() valid = _check_header(start, stop, filename) alternate = False if not valid: valid = _check_header(alternate_start, alternate_stop, filename) if valid: alternate = True if return_alternate: return valid, alternate else: return valid
def is_cwb(filename, config=None): """Check to see if file is a Taiwan Central Weather Bureau strong motion file. Args: filename (str): Path to possible CWB data file. config (dict): Dictionary containing configuration. Returns: bool: True if CWB, False otherwise. """ logging.debug("Checking if format is cwb.") if is_binary(filename): return False try: f = open(filename, "rt", encoding="utf-8") line = f.readline() f.close() if line.startswith("#Earthquake Information"): return True except UnicodeDecodeError: return False return False
def is_bhrc(filename, config=None): """Check to see if file is Iran's BHRC format. Args: filename (str): Path to possible BHRC format. config (dict): Dictionary containing configuration. Returns: bool: True if BHRC supported, otherwise False. """ if is_binary(filename): return False try: with open(filename, "rt", encoding="utf-8") as f: lines = [next(f) for x in range(TEXT_HDR_ROWS)] has_line1 = lines[0].startswith("* VOL") has_line7 = lines[6].startswith("COMP") if has_line1 and has_line7: return True except UnicodeDecodeError: return False return False
def is_nsmn(filename, config=None): """Check to see if file is Turkish NSMN format. Args: filename (str): Path to possible Turkish NSMN format. config (dict): Dictionary containing configuration. Returns: bool: True if Turkish NSMN format, otherwise False. """ if is_binary(filename): return False with open(filename, "rt", encoding=ENCODING) as f: line = f.readline() if MARKER in line: return True return False
def is_smc(filename, config=None): """Check to see if file is a SMC (corrected, in acc.) strong motion file. Args: filename (str): Path to possible SMC corrected data file. config (dict): Dictionary containing configuration. Returns: bool: True if SMC, False otherwise. """ logging.debug("Checking if format is smc.") if is_binary(filename): return False try: with open(filename, "rt") as f: lines = f.readlines() firstline = lines[0].strip() if firstline in VALID_HEADERS: return True if "DISPLACEMENT" in firstline: raise BaseException( "SMC: Diplacement records are not supported.") elif "VELOCITY" in firstline: raise BaseException("SMC: Velocity records are not supported.") elif "*" in firstline: end_ascii = lines[10] if "*" in end_ascii: comment_row = int(lines[12].strip().split()[-1]) for r in range(27, 27 + comment_row): row = lines[r] if not row.startswith("|"): return False return True else: return False return False except UnicodeDecodeError: return False
def is_renadic(filename, config=None): """Check to see if file is Chilean RENADIC format. Args: filename (str): Path to file to check. config (dict): Dictionary containing configuration. Returns: bool: True if Chilean RENADIC supported, otherwise False. """ if is_binary(filename): return False with open(filename, "rt", encoding=ENCODING) as f: lines = [next(f) for x in range(TEXT_HDR_ROWS)] if MARKER in lines[7]: return True return False
def is_dmg(filename, config=None): """Check to see if file is a DMG strong motion file. Notes: CSMIP is synonymous to as DMG in this reader. Args: filename (str): Path to possible DMG data file. config (dict): Dictionary containing configuration. Returns: bool: True if DMG , False otherwise. """ logging.debug("Checking if format is dmg.") if is_binary(filename): return False try: f = open(filename, "rt", encoding="utf-8") first_line = f.readline().upper() second_line = f.readline().upper() third_line = f.readline().upper() f.close() # dmg/csmip both have the same markers so is_usc must be checked if first_line.find(V1_MARKER) >= 0 and not is_usc(filename, config): return True elif first_line.find(V2_MARKER) >= 0 and not is_usc(filename, config): if second_line.find(V1_MARKER) >= 0: return True elif first_line.find(V3_MARKER) >= 0 and not is_usc(filename, config): if second_line.find(V2_MARKER) >= 0 and third_line.find( V1_MARKER) >= 0: return True else: return False except UnicodeDecodeError: return False
def is_unam(filename, config=None): """Check to see if file is a UNAM format. Args: filename (str): Path to possible UNAM format. config (dict): Dictionary containing configuration. Returns: bool: True if UNAM supported, otherwise False. """ if is_binary(filename): return False try: with open(filename, "rt") as myfile: header = [next(myfile) for x in range(7)] except BaseException: return False if MARKER in header[6]: return True return False
def is_cosmos(filename, config=None): """Check to see if file is a COSMOS V0/V1 strong motion file. Args: filename (str): Path to possible COSMOS V0/V1 data file. config (dict): Dictionary containing configuration. Returns: bool: True if COSMOS V0/V1, False otherwise. """ logging.debug("Checking if format is cosmos.") if is_binary(filename): return False try: line = open(filename, "rt", encoding="utf-8").readline() for marker in VALID_MARKERS: if line.lower().find(marker.lower()) >= 0: if line.lower().find("(format v") >= 0: return True except UnicodeDecodeError: return False return False