Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • ffa71e2
  • /
  • test_closure_check.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:3beefcf6e79a3654120189a678a5f24417a8b651
directory badge
swh:1:dir:ffa71e2f3a3d087d94e68d79f38e7d20f3dc5e89

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
test_closure_check.py
#   This Python module is part of the PyRate software package.
#
#   Copyright 2021 Geoscience Australia
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.


import numpy as np

import pyrate.constants as C
from pyrate.core.phase_closure.mst_closure import (
    sort_loops_based_on_weights_and_date,
)
from pyrate.core.phase_closure.closure_check import (
    discard_loops_containing_max_ifg_count,
    __drop_ifgs_if_not_part_of_any_loop
)


def test_discard_loops_containing_max_ifg_count(closure_params):
    params = closure_params
    loops1 = retain_loops(params)
    loops2 = retain_loops(params)
    m_weights = [m.weight for m in loops1]
    s_weights = [m.weight for m in loops2]
    np.testing.assert_array_equal(m_weights, s_weights)


def retain_loops(params):
    sorted_loops = sort_loops_based_on_weights_and_date(params)
    params[C.MAX_LOOPS_PER_IFG] = 2
    params[C.MAX_LOOP_LENGTH] = 3
    retained_loops_meeting_max_loop_criteria = [sl for sl in sorted_loops
                                                if len(sl) <= params[C.MAX_LOOP_LENGTH]]
    msg = f"After applying MAX_LOOP_LENGTH={params[C.MAX_LOOP_LENGTH]} criteria, " \
          f"{len(retained_loops_meeting_max_loop_criteria)} loops are retained"
    print(msg)
    retained_loops = discard_loops_containing_max_ifg_count(retained_loops_meeting_max_loop_criteria, params)
    msg = f"After applying MAX_LOOPS_PER_IFG={params[C.MAX_LOOPS_PER_IFG]} criteria, " \
          f"{len(retained_loops)} loops are retained"
    print(msg)
    return retained_loops


def test_drop_ifgs_if_not_part_of_any_loop(closure_params):
    params = closure_params
    params[C.NO_DATA_VALUE] = 0.0
    geotiffs = params['geotiffs']

    loops1 = retain_loops(params)
    selected_tifs1 = __drop_ifgs_if_not_part_of_any_loop(geotiffs, loops1, params)

    loops2 = retain_loops(params)
    selected_tifs2 = __drop_ifgs_if_not_part_of_any_loop(geotiffs, loops2, params)
    assert all([a == b for a, b in zip(selected_tifs1, selected_tifs2)])

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API