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

Revision d378a5fbb6db29f7153fad784f322f2f48e9d7c2 authored by Matt Garthwaite on 08 September 2020, 04:23:27 UTC, committed by GitHub on 08 September 2020, 04:23:27 UTC
Merge pull request #295 from GeoscienceAustralia/develop
Release 0.5.0
2 parent s f77ad6e + df7cb1e
  • Files
  • Changes
  • b6c6ee3
  • /
  • tests
  • /
  • test_gamma_vs_roipac.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.

  • revision
  • directory
  • content
revision badge
swh:1:rev:d378a5fbb6db29f7153fad784f322f2f48e9d7c2
directory badge
swh:1:dir:4ef8efd2cb0394dc8a8f6910e1e4a7a74f84c7e4
content badge
swh:1:cnt:3920c8f3d78038a28152eb0c6cdcb2a1de22a788

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.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
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_gamma_vs_roipac.py
#   This Python module is part of the PyRate software package.
#
#   Copyright 2020 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.
"""
This Python module contains tests that compare GAMMA and ROI_PAC
functionality in PyRate.
"""
import os
import shutil
import pytest
from pathlib import Path

import pyrate.configuration
from pyrate.core.shared import DEM
from pyrate.core import ifgconstants as ifc, config as cf
from pyrate.core.prepifg_helper import _is_number
from pyrate import prepifg, conv2tif, configuration
from tests.common import SML_TEST_DIR, small_data_setup, copytree, TEST_CONF_ROIPAC, TEST_CONF_GAMMA


SMLNEY_GAMMA_TEST = os.path.join(SML_TEST_DIR, "gamma_obs")


def test_files_are_same(tempdir, get_config):
    roipac_params = get_config(TEST_CONF_ROIPAC)
    roipac_tdir = Path(tempdir())
    roipac_params = __workflow(roipac_params, roipac_tdir)

    gamma_params = get_config(TEST_CONF_GAMMA)
    gamma_tdir = Path(tempdir())
    gamma_params = __workflow(gamma_params, gamma_tdir)

    # conv2tif output equal
    __assert_same_files_produced(roipac_params[cf.OUT_DIR], gamma_params[cf.OUT_DIR], "*_unw.tif", 17)

    # prepifg output equal
    __assert_same_files_produced(roipac_params[cf.OUT_DIR], gamma_params[cf.OUT_DIR], f"*_ifg.tif", 17)

    __assert_same_files_produced(roipac_params[cf.OUT_DIR], gamma_params[cf.OUT_DIR], "dem.tif", 1)

    # clean up
    shutil.rmtree(roipac_params[cf.OBS_DIR])
    shutil.rmtree(gamma_params[cf.OBS_DIR])


def __workflow(params, tdir):
    copytree(params[cf.OBS_DIR], tdir)
    # manipulate params
    params[cf.OBS_DIR] = tdir.as_posix()
    outdir = tdir.joinpath('out')
    outdir.mkdir(exist_ok=True)
    params[cf.OUT_DIR] = outdir.as_posix()

    params[cf.DEM_FILE] = tdir.joinpath(Path(params[cf.DEM_FILE]).name).as_posix()
    params[cf.DEM_HEADER_FILE] = tdir.joinpath(Path(params[cf.DEM_HEADER_FILE]).name).as_posix()
    params[cf.HDR_FILE_LIST] = tdir.joinpath(Path(params[cf.HDR_FILE_LIST]).name).as_posix()
    params[cf.SLC_DIR] = tdir.as_posix()
    params[cf.IFG_FILE_LIST] = tdir.joinpath(Path(params[cf.IFG_FILE_LIST]).name).as_posix()
    params[cf.COH_FILE_DIR] = tdir.as_posix()
    params[cf.APS_INCIDENCE_MAP] = tdir.joinpath(Path(params[cf.APS_INCIDENCE_MAP]).name).as_posix()
    params[cf.TMPDIR] = tdir.joinpath(Path(params[cf.TMPDIR]).name).as_posix()
    output_conf = tdir.joinpath('roipac_temp.conf')
    pyrate.configuration.write_config_file(params=params, output_conf_file=output_conf)
    params = configuration.Configuration(output_conf).__dict__
    conv2tif.main(params)
    prepifg.main(params)
    return params


def __assert_same_files_produced(dir1, dir2, ext, num_files):
    dir1_files = list(Path(dir1).glob(ext))
    dir2_files = list(Path(dir2).glob(ext))
    dir1_files.sort()
    dir2_files.sort()
    # 17 unwrapped geotifs
    # 17 cropped multilooked tifs + 1 dem
    assert len(dir1_files) == num_files
    assert len(dir2_files) == num_files
    c = 0

    all_roipac_ifgs = [f for f in small_data_setup(dir1_files) if not isinstance(f, DEM)]
    all_gamma_ifgs = [f for f in small_data_setup(dir2_files) if not isinstance(f, DEM)]

    for c, (i, j) in enumerate(zip(all_roipac_ifgs, all_gamma_ifgs)):
        mdi = i.meta_data
        mdj = j.meta_data
        for k in mdi:  # all key values equal
            if k == "INCIDENCE_DEGREES":
                pass  # incidence angle not implemented for roipac
            elif _is_number(mdi[k]):
                assert pytest.approx(float(mdj[k]), 0.00001) == float(mdi[k])
            elif mdi[k] == "ROIPAC" or "GAMMA":
                pass  # INSAR_PROCESSOR can not be equal
            else:
                assert mdj[k] == mdi[k]

        if i.data_path.__contains__("_ifg.tif"):
            # these are multilooked tifs
            # test that DATA_STEP is MULTILOOKED
            assert mdi[ifc.DATA_TYPE] == ifc.MULTILOOKED
            assert mdj[ifc.DATA_TYPE] == ifc.MULTILOOKED
        else:
            assert mdi[ifc.DATA_TYPE] == ifc.ORIG
            assert mdj[ifc.DATA_TYPE] == ifc.ORIG
    if not all_gamma_ifgs:  # checking for dem
        return
    assert c + 1 == len(all_gamma_ifgs)
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

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