Coverage for sarvey/geolocation.py: 0%
24 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-10-17 12:36 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2024-10-17 12:36 +0000
1#!/usr/bin/env python
3# SARvey - A multitemporal InSAR time series tool for the derivation of displacements.
4#
5# Copyright (C) 2021-2024 Andreas Piter (IPI Hannover, piter@ipi.uni-hannover.de)
6#
7# This software was developed together with FERN.Lab (fernlab@gfz-potsdam.de) in the context
8# of the SAR4Infra project with funds of the German Federal Ministry for Digital and
9# Transport and contributions from Landesamt fuer Vermessung und Geoinformation
10# Schleswig-Holstein and Landesbetrieb Strassenbau und Verkehr Schleswig-Holstein.
11#
12# This program is free software: you can redistribute it and/or modify it under
13# the terms of the GNU General Public License as published by the Free Software
14# Foundation, either version 3 of the License, or (at your option) any later
15# version.
16#
17# Important: This package uses PyMaxFlow. The core of PyMaxflows library is the C++
18# implementation by Vladimir Kolmogorov. It is also licensed under the GPL, but it REQUIRES that you
19# cite [BOYKOV04] (see LICENSE) in any resulting publication if you use this code for research purposes.
20# This requirement extends to SARvey.
21#
22# This program is distributed in the hope that it will be useful, but WITHOUT
23# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
25# details.
26#
27# You should have received a copy of the GNU Lesser General Public License along
28# with this program. If not, see <https://www.gnu.org/licenses/>.
30"""Module for correcting the geolocation of the scatterers."""
31import logging
32from os.path import join
33import numpy as np
35from miaplpy.objects.slcStack import slcStack
37from sarvey.objects import Points
40def getHeading(input_path: str, logger: logging.Logger):
41 """
42 Read heading angle from slcStack.h5.
44 Parameters
45 ----------
46 input_path: str
47 Path to directory containing 'slcStack.h5' and 'geometryRadar.h5'.
48 logger: Logger
49 Logger handle
51 Returns
52 -------
53 heading_angle: float
54 heading angle of the satellite in radians
55 for ascending ~ -12*pi/180
56 for descending ~ 190*pi/180
57 """
58 # get heading from slcStack.h5
59 slc_stack_file = join(input_path, 'slcStack.h5')
60 slc_stack_obj = slcStack(slc_stack_file)
61 try:
62 meta_dict = slc_stack_obj.get_metadata()
63 lower_case_meta_dict = {k.lower(): v for k, v in meta_dict.items()}
65 heading_angle = float(lower_case_meta_dict["heading"])
66 logger.info(msg=f"Heading_angle of satellite: {heading_angle} deg")
67 heading_angle = np.deg2rad(heading_angle)
68 except Exception as exc:
69 logger.error(f'Failed to retrieve heading angle from {slc_stack_file}: {exc}')
70 raise Exception
71 return heading_angle
74def calculateGeolocationCorrection(*, path_geom: str, point_obj: Points, demerr: np.array, logger: logging.Logger):
75 """
76 Calculate geolocation correction.
78 Parameters
79 ----------
80 path_geom: str
81 Path to directory containing 'slcStack.h5' or 'geometryRadar.h5'.
82 point_obj: Points
83 Point object with incidence angle for points
84 demerr: np.array
85 Array of dem error per pixel
86 logger: Logger
87 Logger handle
89 Returns
90 -------
91 coord_correction: np.array
92 array of geolocation corrections, two columns [x_correction, y_correction] per point.
93 """
94 heading_angle = getHeading(input_path=path_geom, logger=logger)
96 coord_correction = np.zeros_like(point_obj.coord_xy, dtype=float)
97 coord_correction[:, 0] = demerr * np.cos(heading_angle) / np.tan(point_obj.loc_inc)
98 coord_correction[:, 1] = -demerr * np.sin(heading_angle) / np.tan(point_obj.loc_inc)
100 return coord_correction