Exemple #1
0
    def setUp(self):
        self.path = 'ph5/test_data/miniseedph5'
        try:
            os.mkdir(self.path)
        except OSError:
            print ("Creation of the directory %s failed" % self.path)
        else:
            print ("Successfully created the directory %s " % self.path)

        ph5_object = experiment.ExperimentGroup(
            nickname='master.ph5',
            currentpath=self.path)
        ph5_object.ph5open(True)
        ph5_object.initgroup()
        default_receiver_t = initialize_ph5.create_default_receiver_t()
        initialize_ph5.set_receiver_t(default_receiver_t)
        os.remove(default_receiver_t)
        ph5_object.initgroup()
        self.obs = obspytoph5.ObspytoPH5(
            ph5_object,
            self.path,
            1,
            1)
        self.obs.verbose = True
        ph5_object.ph5flush()
        ph5_object.ph5_g_sorts.update_local_table_nodes()
Exemple #2
0
def main():

    args = get_args(sys.argv[1:])

    if args.nickname[-3:] == 'ph5':
        ph5file = os.path.join(args.ph5path, args.nickname)
    else:
        ph5file = os.path.join(args.ph5path, args.nickname + '.ph5')
        args.nickname += '.ph5'

    PATH = os.path.dirname(args.ph5path) or '.'
    # Debugging
    os.chdir(PATH)
    # Write log to file
    ch = logging.FileHandler(os.path.join(".", "metadatatoph5.log"))
    ch.setLevel(logging.INFO)
    # Add formatter
    formatter = logging.Formatter(LOGGING_FORMAT)
    ch.setFormatter(formatter)
    LOGGER.addHandler(ch)

    if not os.path.exists(ph5file):
        LOGGER.warning("{0} not found. Creating...".format(ph5file))
        # Create ph5 file
        ex = experiment.ExperimentGroup(nickname=ph5file,
                                        currentpath=args.ph5path)
        ex.ph5open(True)  # Open ph5 file for editing
        ex.initgroup()
        # Update /Experiment_g/Receivers_g/Receiver_t
        default_receiver_t = initialize_ph5.create_default_receiver_t()
        initialize_ph5.set_receiver_t(default_receiver_t)
        LOGGER.info(
            "Removing temporary {0} kef file.".format(default_receiver_t))
        os.remove(default_receiver_t)
        ex.ph5close()
        LOGGER.info("Done... Created new PH5 file {0}.".format(ph5file))
    ph5_object = experiment.ExperimentGroup(nickname=args.nickname,
                                            currentpath=args.ph5path)
    ph5_object.ph5open(True)
    ph5_object.initgroup()
    metadata = MetadatatoPH5(ph5_object)
    path, file_name = os.path.split(args.infile)
    f = open(args.infile, "r")
    inventory = metadata.read_metadata(f, file_name)
    if inventory:
        parsed_array = metadata.parse_inventory(inventory)
        metadata.toph5(parsed_array)

    ph5_object.ph5close()
Exemple #3
0
    def setUp(self):
        self.path = 'ph5/test_data/miniseedph5'
        try:
            os.mkdir(self.path)
        except OSError:
            print("Creation of the directory %s failed" % self.path)
        else:
            print("Successfully created the directory %s " % self.path)

        self.ph5_object = experiment.ExperimentGroup(nickname='master.ph5',
                                                     currentpath=self.path)
        self.ph5_object.ph5open(True)
        self.ph5_object.initgroup()
        default_receiver_t = initialize_ph5.create_default_receiver_t()
        initialize_ph5.set_receiver_t(default_receiver_t)
        os.remove(default_receiver_t)
        self.metadata = metadatatoph5.MetadatatoPH5(self.ph5_object)
Exemple #4
0
def main():
    args = get_args(sys.argv[1:])

    if args.nickname[-3:] == 'ph5':
        ph5file = os.path.join(args.ph5path, args.nickname)
    else:
        ph5file = os.path.join(args.ph5path, args.nickname + '.ph5')
        args.nickname += '.ph5'

    PATH = os.path.dirname(args.ph5path) or '.'
    # Debugging
    os.chdir(PATH)
    # Write log to file
    ch = logging.FileHandler(os.path.join(".", "datatoph5.log"))
    ch.setLevel(logging.INFO)
    # Add formatter
    formatter = logging.Formatter(LOGGING_FORMAT)
    ch.setFormatter(formatter)
    LOGGER.addHandler(ch)

    if not os.path.exists(ph5file):
        LOGGER.warning("{0} not found. Creating...".format(ph5file))
        # Create ph5 file
        ex = experiment.ExperimentGroup(nickname=ph5file)
        ex.ph5open(True)  # Open ph5 file for editing
        ex.initgroup()
        # Update /Experiment_g/Receivers_g/Receiver_t
        default_receiver_t = initialize_ph5.create_default_receiver_t()
        initialize_ph5.set_receiver_t(default_receiver_t)
        LOGGER.info(
            "Removing temporary {0} kef file.".format(default_receiver_t))
        os.remove(default_receiver_t)
        ex.ph5close()
        LOGGER.info("Done... Created new PH5 file {0}.".format(ph5file))
    # Produce list of valid files from file, list, and dirs
    valid_files = list()
    if args.rawfile:
        if _is_mseed(args.rawfile):
            LOGGER.info("{0} is a valid miniSEED file. "
                        "Adding to process list.".format(args.rawfile))
            valid_files.append((args.rawfile, 'MSEED'))
        else:
            LOGGER.info("{0} is a  NOT valid miniSEED file.".format(
                args.rawfile))

    try:
        if _is_mseed(args.infile):
            LOGGER.error("The given list file is a miniseed file. You have "
                         "been confused between two option -r and -f.")
            sys.exit()
    except TypeError:
        pass

    if args.infile:
        LOGGER.info("Checking list...")
        with open(args.infile) as f:
            content = f.readlines()
        for line in content:
            if os.path.isfile(line.rstrip()):
                if _is_mseed(line.rstrip()):
                    LOGGER.info("{0} is a valid miniSEED file. "
                                "Adding to"
                                "process list.".format(line.rstrip()))
                    valid_files.append((line.rstrip(), 'MSEED'))
                else:
                    LOGGER.info("{0} is NOT a valid miniSEED "
                                "file.".format(line.rstrip()))
            else:
                LOGGER.info("{0} does not exist".format(line.rstrip()))

    if args.indir:
        LOGGER.info("Scanning directory {0} and sub directories...".format(
            args.indir))
        found_files = getListOfFiles(args.indir)
        found_files.sort()
        for f in found_files:
            if _is_mseed(f):
                LOGGER.info("{0} is a valid miniSEED file. "
                            "Adding to process list.".format(f))
                valid_files.append((f, 'MSEED'))
            else:
                LOGGER.info("{0} is NOT a valid miniSEED file.".format(f))

    # take list of valid files and load them into PH5
    ph5_object = experiment.ExperimentGroup(nickname=args.nickname,
                                            currentpath=args.ph5path)
    ph5_object.ph5open(True)
    ph5_object.initgroup()
    obs = ObspytoPH5(ph5_object, args.ph5path, args.num_mini, args.first_mini)
    if args.verbose:
        obs.verbose = True
    obs.get_minis(args.ph5path)
    if args.num_mini:
        total = 0
        for entry in valid_files:
            total = total + os.path.getsize(entry[0])
        obs.mini_size_max = (total * .60) / args.num_mini
    index_t_full = list()

    for entry in valid_files:
        message, index_t = obs.toph5(entry)
        for e in index_t:
            index_t_full.append(e)
        if message == "stop":
            LOGGER.error("Stopping program...")
            break
    if len(obs.time_t) > 0:
        LOGGER.info('Populating Time table')
        for entry in obs.time_t:
            ph5_object.ph5_g_receivers.populateTime_t_(entry)
    LOGGER.info("Populating Index table")
    for entry in index_t_full:
        ph5_object.ph5_g_receivers.populateIndex_t(entry)

    obs.update_external_references(index_t_full)
    ph5_object.ph5close()