From 0c1878db55c847aaaf356b71514c1762eb1e469d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:00:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[pre-commit.ci]=20pyupgrade:=20v3.18.0=20?= =?UTF-8?q?=E2=86=92=20v3.19.0=20(#1283)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.18.0 → v3.19.0](https://github.com/asottile/pyupgrade/compare/v3.18.0...v3.19.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4188c8b21..43aee58e0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,7 +36,7 @@ repos: '--combine-as'] - repo: https://github.com/asottile/pyupgrade - rev: "v3.18.0" + rev: "v3.19.0" hooks: - id: pyupgrade name: modernize python From 718027c2e97daf7f03b193e22439b579399247bb Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Mon, 11 Nov 2024 13:38:49 +0800 Subject: [PATCH 2/3] `view`: convert integer to floating to enable masking with `nan` (#1289) + view.viewer.plot(): convert integer to floating to enable masking with nan for one subplot scenario --- src/mintpy/utils/readfile.py | 2 +- src/mintpy/view.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mintpy/utils/readfile.py b/src/mintpy/utils/readfile.py index 24c1c029c..677a3325d 100644 --- a/src/mintpy/utils/readfile.py +++ b/src/mintpy/utils/readfile.py @@ -699,7 +699,7 @@ def read_binary_file(fname, datasetName=None, box=None, xstep=1, ystep=1): cpx_band = 'magnitude' elif fext in ['.mli', '.rmli']: - byte_order = 'little-endian' + byte_order = 'little-endian' # big-endian # SNAP # BEAM-DIMAP data format diff --git a/src/mintpy/view.py b/src/mintpy/view.py index 569b776fe..e45c6776e 100644 --- a/src/mintpy/view.py +++ b/src/mintpy/view.py @@ -1652,9 +1652,15 @@ def plot(self): no_data_val = readfile.get_no_data_value(self.file) if self.no_data_value is not None: vprint(f'masking pixels with NO_DATA_VALUE of {self.no_data_value}') + # convert integer to floating to enable masking with nan + if np.issubdtype(data.dtype, np.integer): + data = np.array(data, np.float32) data[data == self.no_data_value] = np.nan elif no_data_val is not None and not np.isnan(no_data_val): vprint(f'masking pixels with NO_DATA_VALUE of {no_data_val}') + # convert integer to floating to enable masking with nan + if np.issubdtype(data.dtype, np.integer): + data = np.array(data, np.float32) data[data == no_data_val] = np.nan # update/save mask info From c7e77ccd46c57f0a96cce214a73d4b5dfb9165b5 Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Mon, 11 Nov 2024 18:48:34 +0800 Subject: [PATCH 3/3] `gnss`: handle longitude <=-180 or >=360 (#1290) + `utils.utils0.py`: add `standardize_longitude()` to handle the longitude data range - ensure longitude is within (-180, 360) - could specify the data range format, in either [0, 360) or (-180, 180] via `lon_range` arg + `objects.gnss.py`: call `ut.standardize_longitude()` in all the child class of GNSS This error occurs for the GNSS_UNR sites in Japan, where the longitude of G073 can be -229. In the old code, this results in a NaN value for inc/az_angle extraction from the geometry file. --- src/mintpy/objects/gnss.py | 19 +++++++++++++++---- src/mintpy/utils/utils0.py | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/mintpy/objects/gnss.py b/src/mintpy/objects/gnss.py index b4de31d27..89bea2c19 100644 --- a/src/mintpy/objects/gnss.py +++ b/src/mintpy/objects/gnss.py @@ -71,7 +71,8 @@ def search_gnss(SNWE, start_date=None, end_date=None, source='UNR', site_list_fi # ensure that site data formatting is consistent sites['site'] = np.array([site.upper() for site in sites['site']]) - sites['lon'][sites['lon'] > 180] -= 360 # ensure lon values in (-180, 180] + # ensure longitude values in (-180, 180] + sites['lon'] = ut.standardize_longitude(sites['lon'], limit='-180to180') vprint(f'load {len(sites["site"]):d} GNSS sites with fields: {" ".join(sites.keys())}') # limit in space @@ -867,6 +868,9 @@ def get_site_lat_lon(self, print_msg=False) -> (float, float): data = np.loadtxt(self.file, dtype=bytes, skiprows=1, max_rows=10) self.site_lat, self.site_lon = data[0, 20:22].astype(float) + # ensure longitude in the range of (-180, 180] + self.site_lon = ut.standardize_longitude(self.site_lon, limit='-180to180') + return self.site_lat, self.site_lon @@ -987,8 +991,9 @@ def get_site_lat_lon(self, print_msg=False) -> (float, float): # longitude lon_line = [x for x in lines if x.startswith('# East Longitude')][0].strip('\n') self.site_lon = float(lon_line.split()[-1]) - # ensure longitude in the range of (-180, 180] - self.site_lon -= 0 if self.site_lon <= 180 else 360 + + # ensure longitude in the range of (-180, 180] + self.site_lon = ut.standardize_longitude(self.site_lon, limit='-180to180') return self.site_lat, self.site_lon @@ -1094,6 +1099,8 @@ def get_site_lat_lon(self, print_msg=False) -> (float, float): # format self.site_lat = float(site_lat) self.site_lon = float(site_lon) + # ensure longitude in the range of (-180, 180] + self.site_lon = ut.standardize_longitude(self.site_lon, limit='-180to180') if print_msg == True: print(f'\t{self.site_lat:f}, {self.site_lon:f}') @@ -1185,7 +1192,11 @@ def get_site_lat_lon(self, print_msg=False) -> (str, str): """ sites = read_GENERIC_site_list('GenericList.txt') ind = sites['site'].tolist().index(self.site) - return sites['lat'][ind], sites['lon'][ind] + site_lat, site_lon = sites['lat'][ind], sites['lon'][ind] + # ensure longitude in the range of (-180, 180] + site_lon = ut.standardize_longitude(site_lon, limit='-180to180') + + return site_lat, site_lon def read_displacement(self, start_date=None, end_date=None, print_msg=True, display=False): diff --git a/src/mintpy/utils/utils0.py b/src/mintpy/utils/utils0.py index d410a13af..cb7f31594 100644 --- a/src/mintpy/utils/utils0.py +++ b/src/mintpy/utils/utils0.py @@ -267,6 +267,30 @@ def touch(fname_list, times=None): ################################## Coordinate ########################################## +def standardize_longitude(lon, limit='-180to180'): + """Normalize the longitude value range into (-180, 180] or [0, 360). + + Parameters: lon - float / np.ndarray, longitude in degree + limit - str, -180to180 or 0to360 + Returns: lon - float / np.ndarray, longitude in degree + """ + lon = np.asarray(lon) + + # ensure data within (-180, 360) + lon = np.where(lon >= 360, lon - 360, lon) + lon = np.where(lon <= -180, lon + 360, lon) + + # range option 1: ensure data within (-180, 180] + if limit == '-180to180': + lon = np.where(lon > 180, lon - 360, lon) + + # range option 2: ensure data within [0, 360) + elif limit == '0to360' and np.nanmin(lon) < 0: + lon = np.where(lon < 0, lon + 360, lon) + + return float(lon) if np.isscalar(lon) else lon + + def utm_zone2epsg_code(utm_zone): """Convert UTM Zone string to EPSG code.