def select_windows(
        self,
        window_set_name: str,
        event: str,
        mpi=True,
        n=12,
        validation=False,
    ):
        """
        Select window for a certain event in an iteration.

        :param window_set_name: Name of window set
        :type window_set_name: str
        :param event: Name of event to pick windows on
        :type event: str
        :param mpi: Switch on/off for running with MPI
        :type mpi: bool
        :param n: How many ranks to use
        :type n: int
        """
        # Check if window set exists:
        path = os.path.join(self.lasif_root, "SETS", "WINDOWS",
                            f"{window_set_name}.sqlite")
        # Need to tackle this differently for mono-batch
        if os.path.exists(path) and not validation:
            print(f"Window set for event {event} exists.")
            return

        if mpi:
            os.chdir(self.comm.project.lasif_root)
            command = f"mpirun -n {n} lasif select_windows "
            command += f"{self.comm.project.current_iteration} "
            command += f"{window_set_name} {event}"
            process = subprocess.Popen(command,
                                       shell=True,
                                       stdout=subprocess.PIPE,
                                       bufsize=1)
            for line in process.stdout:
                print(line, end=" \n", flush=True)
            process.wait()
            print(process.returncode)
            os.chdir(self.comm.project.inversion_root)
        else:
            lapi.select_windows(
                self.lasif_comm,
                iteration=self.comm.project.current_iteration,
                window_set=window_set_name,
                events=[event],
            )
示例#2
0
def lasif_select_windows(parser, args):
    """
    Autoselect windows for a given event and iteration combination.

    This function works with MPI. Don't use too many cores, I/O quickly
    becomes the limiting factor. It also works without MPI but then only one
    core actually does any work.
    """
    parser.add_argument("iteration", help="name of the iteration")
    parser.add_argument("window_set_name", help="name of the window_set")
    parser.add_argument(
        "events",
        help="One or more events. If none given, all will be done.",
        nargs="*",
    )
    args = parser.parse_args(args)
    api.select_windows(
        lasif_root=".",
        iteration=args.iteration,
        window_set=args.window_set_name,
        events=args.events if args.events else None,
    )