Example #1
0
def lasif_create_successive_iteration(parser, args):
    """
    Create an iteration based on an existing one.

    It will take all settings in one iteration and transfers them to another
    iteration. Any comments will be deleted.
    """
    parser.add_argument("existing_iteration",
                        help="name of the existing iteration")
    parser.add_argument("new_iteration", help="name of the new iteration")
    args = parser.parse_args(args)
    existing_iteration_name = args.existing_iteration
    new_iteration_name = args.new_iteration

    from lasif.iteration_xml import Iteration

    # Get the old iteration
    proj = _find_project_root(".")
    iterations = proj.get_iteration_dict()
    if existing_iteration_name not in iterations:
        msg = ("Iteration '%s' not found. Use 'lasif list_iterations' to get "
               "a list of all available iterations.") % \
            existing_iteration_name
        raise LASIFCommandLineException(msg)
    existing_iteration = Iteration(iterations[existing_iteration_name])

    # Clone the old iteration, delete any comments and change the name.
    existing_iteration.comments = []
    existing_iteration.iteration_name = new_iteration_name
    print existing_iteration
Example #2
0
def test_iteration_equality():
    """
    Tests equality/inequality for iteration xml files.
    """
    filename = os.path.join(data_dir, "iteration_example.xml")

    iteration = Iteration(filename, stf_fct=__stf_fct_dummy)
    other_iteration = copy.deepcopy(iteration)

    assert iteration == other_iteration
    assert not iteration != other_iteration

    iteration.iteration_name = "blub"
    assert iteration != other_iteration
    assert not iteration == other_iteration
Example #3
0
def test_iteration_equality():
    """
    Tests equality/inequality for iteration xml files.
    """
    filename = os.path.join(data_dir, "iteration_example.xml")

    iteration = Iteration(filename, stf_fct=__stf_fct_dummy)
    other_iteration = copy.deepcopy(iteration)

    assert iteration == other_iteration
    assert not iteration != other_iteration

    iteration.iteration_name = "blub"
    assert iteration != other_iteration
    assert not iteration == other_iteration
Example #4
0
def test_reading_writing_with_empty_description(tmpdir):
    """
    Tests reading and writing with an empty description.
    """
    filename = os.path.join(data_dir, "iteration_example.xml")
    new_filename = os.path.join(str(tmpdir), "iteration.xml")

    iteration = Iteration(filename, stf_fct=__stf_fct_dummy)
    iteration.description = None

    # Write and read again.
    iteration.write(new_filename)
    reread_iteration = Iteration(new_filename, stf_fct=__stf_fct_dummy)

    # Change the name as it is always dependent on the filename.
    reread_iteration.iteration_name = iteration.iteration_name
    assert iteration == reread_iteration
Example #5
0
def test_reading_writing_with_empty_description(tmpdir):
    """
    Tests reading and writing with an empty description.
    """
    filename = os.path.join(data_dir, "iteration_example.xml")
    new_filename = os.path.join(str(tmpdir), "iteration.xml")

    iteration = Iteration(filename, stf_fct=__stf_fct_dummy)
    iteration.description = None

    # Write and read again.
    iteration.write(new_filename)
    reread_iteration = Iteration(new_filename, stf_fct=__stf_fct_dummy)

    # Change the name as it is always dependent on the filename.
    reread_iteration.iteration_name = iteration.iteration_name
    assert iteration == reread_iteration
Example #6
0
    def create_successive_iteration(self, existing_iteration_name,
                                    new_iteration_name):
        """
        Create an iteration based on an existing one.

        It will take all settings in one iteration and transfers them to
        another iteration. Any comments will be deleted.

        :param existing_iteration_name: Name of the iteration to be used as
            a template.
        :param new_iteration_name: Name of the new iteration.

        >>> comm = getfixture('iterations_comm')
        >>> comm.iterations.has_iteration("3")
        False
        >>> comm.iterations.create_successive_iteration("1", "3")
        >>> comm.iterations.has_iteration("3")
        True

        Comments of an iteration will be stripped.

        >>> comm.iterations.get("1").comments
        ['Some', 'random comments']
        >>> comm.iterations.get("3").comments
        []

        >>> os.remove(comm.iterations.get_iteration_dict()["3"])

        If the iteration template does not exist, a
        :class:`~lasif.LASIFNotFoundError` will be raised.

        >>> comm.iterations.create_successive_iteration("99", "100")
        Traceback (most recent call last):
            ...
        LASIFNotFoundError: ...

        A ``ValueError`` will be raised if the new iteration already exists.

        >>> comm.iterations.create_successive_iteration("1", "2")
        Traceback (most recent call last):
            ...
        ValueError: ...
        """
        it_dict = self.get_iteration_dict()
        if existing_iteration_name not in it_dict:
            msg = "Iteration %s does not exists." % existing_iteration_name
            raise LASIFNotFoundError(msg)
        if new_iteration_name in it_dict:
            msg = "Iteration %s already exists." % new_iteration_name
            raise ValueError(msg)

        from lasif.iteration_xml import Iteration

        existing_iteration = Iteration(
            it_dict[existing_iteration_name],
            stf_fct=self.comm.project.get_project_function(
                "source_time_function"))

        # Clone the old iteration, delete any comments and change the name.
        existing_iteration.comments = []
        existing_iteration.iteration_name = new_iteration_name
        self.save_iteration(existing_iteration)
Example #7
0
    def create_successive_iteration(self,
                                    existing_iteration_name,
                                    new_iteration_name,
                                    create_folders=True):
        """
        Create an iteration based on an existing one.

        It will take all settings in one iteration and transfers them to
        another iteration. Any comments will be deleted.

        :param existing_iteration_name: Name of the iteration to be used as
            a template.
        :param new_iteration_name: Name of the new iteration.
        :param create_folders: Create the folders for the next iteration's
            synthetic waveforms

        Note that the ``create_folders=False`` argument is only used here
        for testing purposes. In most cases you will want this to be ``True``.

        >>> comm = getfixture('iterations_comm')
        >>> comm.iterations.has_iteration("3")
        False
        >>> comm.iterations.create_successive_iteration("1", "3",
        ...                                             create_folders=False)
        >>> comm.iterations.has_iteration("3")
        True

        Comments of an iteration will be stripped.

        >>> comm.iterations.get("1").comments
        ['Some', 'random comments']
        >>> comm.iterations.get("3").comments
        []

        >>> os.remove(comm.iterations.get_iteration_dict()["3"])

        If the iteration template does not exist, a
        :class:`~lasif.LASIFNotFoundError` will be raised.

        >>> comm.iterations.create_successive_iteration("99", "100")
        Traceback (most recent call last):
            ...
        LASIFNotFoundError: ...

        A ``ValueError`` will be raised if the new iteration already exists.

        >>> comm.iterations.create_successive_iteration("1", "2")
        Traceback (most recent call last):
            ...
        ValueError: ...
        """
        it_dict = self.get_iteration_dict()
        if existing_iteration_name not in it_dict:
            msg = "Iteration %s does not exists." % existing_iteration_name
            raise LASIFNotFoundError(msg)
        if new_iteration_name in it_dict:
            msg = "Iteration %s already exists." % new_iteration_name
            raise ValueError(msg)

        from lasif.iteration_xml import Iteration

        existing_iteration = Iteration(
            it_dict[existing_iteration_name],
            stf_fct=self.comm.project.get_project_function(
                "source_time_function"))

        # Clone the old iteration, delete any comments and change the name.
        existing_iteration.comments = []
        existing_iteration.iteration_name = new_iteration_name
        self.save_iteration(existing_iteration)

        if create_folders:
            self.create_synthetics_folder_for_iteration(new_iteration_name)
            self.create_stf_folder_for_iteration(new_iteration_name)