From c947df7e7408802a3f0302f27e90fa1fd5475752 Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Mon, 14 Aug 2023 13:52:35 -0400 Subject: [PATCH 01/10] Remove `scikit-image`, call `solid.for` for all grid point Although slower, the time difference for a (400, 500) image is 0.02 vs 0.2 seconds --- environment.yml | 1 - requirements.txt | 1 - setup.py | 1 - src/pysolid/grid.py | 34 +++++++++------------------------- 4 files changed, 9 insertions(+), 28 deletions(-) diff --git a/environment.yml b/environment.yml index 8f069af..fc86a05 100644 --- a/environment.yml +++ b/environment.yml @@ -8,7 +8,6 @@ dependencies: - numpy - scipy - matplotlib - - scikit-image # for packaging and installation - fortran-compiler # Fortran compiler across platforms through conda-forge channel - pip diff --git a/requirements.txt b/requirements.txt index 2a32a24..6ae98e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,6 @@ numpy scipy matplotlib -scikit-image # for packaging and installation #fortran-compiler # Fortran compiler across platforms through conda-forge channel pip diff --git a/setup.py b/setup.py index e6d254e..20ed3f4 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,6 @@ def readme(): "numpy", "scipy", "matplotlib", - "scikit-image", ], # package discovery diff --git a/src/pysolid/grid.py b/src/pysolid/grid.py index b81133d..71a75e7 100644 --- a/src/pysolid/grid.py +++ b/src/pysolid/grid.py @@ -13,9 +13,6 @@ import os -import numpy as np -from skimage.transform import resize - ################################## Earth tides - grid mode ################################### def calc_solid_earth_tides_grid(dt_obj, atr, step_size=1e3, display=False, verbose=True): @@ -54,38 +51,25 @@ def calc_solid_earth_tides_grid(dt_obj, atr, step_size=1e3, display=False, verbo # location lat0 = float(atr['Y_FIRST']) lon0 = float(atr['X_FIRST']) - lat1 = lat0 + float(atr['Y_STEP']) * int(atr['LENGTH']) - lon1 = lon0 + float(atr['X_STEP']) * int(atr['WIDTH']) + width = int(atr['WIDTH']) + length = int(atr['LENGTH']) + lat_step = float(atr['Y_STEP']) + lon_step = float(atr['X_STEP']) + lat1 = lat0 + lat_step * length + lon1 = lon0 + lon_step * width vprint('PYSOLID: ----------------------------------------') vprint('PYSOLID: datetime: {}'.format(dt_obj.isoformat())) vprint('PYSOLID: SNWE: {}'.format((lat1, lat0, lon0, lon1))) - - # step size - num_step = int(step_size / 108e3 / abs(float(atr['Y_STEP']))) - num_step = max(1, num_step) - length = np.rint(int(atr['LENGTH']) / num_step - 1e-4).astype(int) - width = np.rint(int(atr['WIDTH']) / num_step - 1e-4).astype(int) - lat_step = float(atr['Y_STEP']) * num_step - lon_step = float(atr['X_STEP']) * num_step vprint('SOLID : calculate solid Earth tides in east/north/up direction') vprint('SOLID : shape: {s}, step size: {la:.4f} by {lo:.4f} deg'.format( s=(length, width), la=lat_step, lo=lon_step)) - ## calc solid Earth tides + # calc solid Earth tides tide_e, tide_n, tide_u = solid_grid(dt_obj.year, dt_obj.month, dt_obj.day, dt_obj.hour, dt_obj.minute, dt_obj.second, - lat0, lat_step, length, - lon0, lon_step, width) - - # resample to the input size - if num_step > 1: - out_shape = (int(atr['LENGTH']), int(atr['WIDTH'])) - vprint('PYSOLID: resize data to the shape of {} using order-1 spline interpolation'.format(out_shape)) - kwargs = dict(order=1, mode='edge', anti_aliasing=True, preserve_range=True) - tide_e = resize(tide_e, out_shape, **kwargs) - tide_n = resize(tide_n, out_shape, **kwargs) - tide_u = resize(tide_u, out_shape, **kwargs) + lat0, float(atr['Y_STEP']), int(atr['LENGTH']), + lon0, float(atr['X_STEP']), int(atr['WIDTH'])) # plot if display: From b630f38261038f5482a94d8cf7861cb616c3939f Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Mon, 14 Aug 2023 15:03:30 -0400 Subject: [PATCH 02/10] add back resize, but using scipy --- src/pysolid/grid.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/pysolid/grid.py b/src/pysolid/grid.py index 71a75e7..b3e0155 100644 --- a/src/pysolid/grid.py +++ b/src/pysolid/grid.py @@ -13,6 +13,9 @@ import os +import numpy as np +import scipy.ndimage as ndi + ################################## Earth tides - grid mode ################################### def calc_solid_earth_tides_grid(dt_obj, atr, step_size=1e3, display=False, verbose=True): @@ -51,25 +54,38 @@ def calc_solid_earth_tides_grid(dt_obj, atr, step_size=1e3, display=False, verbo # location lat0 = float(atr['Y_FIRST']) lon0 = float(atr['X_FIRST']) - width = int(atr['WIDTH']) - length = int(atr['LENGTH']) - lat_step = float(atr['Y_STEP']) - lon_step = float(atr['X_STEP']) - lat1 = lat0 + lat_step * length - lon1 = lon0 + lon_step * width + lat1 = lat0 + float(atr['Y_STEP']) * int(atr['LENGTH']) + lon1 = lon0 + float(atr['X_STEP']) * int(atr['WIDTH']) vprint('PYSOLID: ----------------------------------------') vprint('PYSOLID: datetime: {}'.format(dt_obj.isoformat())) vprint('PYSOLID: SNWE: {}'.format((lat1, lat0, lon0, lon1))) + + # step size + num_step = int(step_size / 108e3 / abs(float(atr['Y_STEP']))) + num_step = max(1, num_step) + length = np.rint(int(atr['LENGTH']) / num_step - 1e-4).astype(int) + width = np.rint(int(atr['WIDTH']) / num_step - 1e-4).astype(int) + lat_step = float(atr['Y_STEP']) * num_step + lon_step = float(atr['X_STEP']) * num_step vprint('SOLID : calculate solid Earth tides in east/north/up direction') vprint('SOLID : shape: {s}, step size: {la:.4f} by {lo:.4f} deg'.format( s=(length, width), la=lat_step, lo=lon_step)) - # calc solid Earth tides + ## calc solid Earth tides tide_e, tide_n, tide_u = solid_grid(dt_obj.year, dt_obj.month, dt_obj.day, dt_obj.hour, dt_obj.minute, dt_obj.second, - lat0, float(atr['Y_STEP']), int(atr['LENGTH']), - lon0, float(atr['X_STEP']), int(atr['WIDTH'])) + lat0, lat_step, length, + lon0, lon_step, width) + + # resample to the input size + if num_step > 1: + in_shape = tide_e.shape + out_shape = (int(atr['LENGTH']), int(atr['WIDTH'])) + vprint('PYSOLID: resize data to the shape of {} using order-1 spline interpolation'.format(out_shape)) + kwargs = dict(order=1, mode='edge', anti_aliasing=True, preserve_range=True) + kwargs = dict(order=1, mode="nearest", grid_mode=True) + ndi.zoom(np.stack([tide_e, tide_n, tide_u]), [1, *np.divide(out_shape, in_shape)], **kwargs) # plot if display: From dee58af45bbf44addc2c416594467fef2cd61a45 Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Mon, 14 Aug 2023 15:04:02 -0400 Subject: [PATCH 03/10] remove old kwargs for skimage --- src/pysolid/grid.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pysolid/grid.py b/src/pysolid/grid.py index b3e0155..4cc7e21 100644 --- a/src/pysolid/grid.py +++ b/src/pysolid/grid.py @@ -83,7 +83,6 @@ def calc_solid_earth_tides_grid(dt_obj, atr, step_size=1e3, display=False, verbo in_shape = tide_e.shape out_shape = (int(atr['LENGTH']), int(atr['WIDTH'])) vprint('PYSOLID: resize data to the shape of {} using order-1 spline interpolation'.format(out_shape)) - kwargs = dict(order=1, mode='edge', anti_aliasing=True, preserve_range=True) kwargs = dict(order=1, mode="nearest", grid_mode=True) ndi.zoom(np.stack([tide_e, tide_n, tide_u]), [1, *np.divide(out_shape, in_shape)], **kwargs) From e32aea64a9a078d4648d453773d8d5f584d9c3d5 Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Tue, 15 Aug 2023 16:27:43 -0400 Subject: [PATCH 04/10] Update src/pysolid/grid.py Co-authored-by: Zhang Yunjun --- src/pysolid/grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pysolid/grid.py b/src/pysolid/grid.py index 4cc7e21..e6c1359 100644 --- a/src/pysolid/grid.py +++ b/src/pysolid/grid.py @@ -14,7 +14,7 @@ import os import numpy as np -import scipy.ndimage as ndi +from scipy import ndimage ################################## Earth tides - grid mode ################################### From d6b277324afbedb9e4dfd81f303cabc3e4110e7a Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Tue, 15 Aug 2023 16:29:28 -0400 Subject: [PATCH 05/10] fix output of zoomed e/n/u arrays --- src/pysolid/grid.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pysolid/grid.py b/src/pysolid/grid.py index e6c1359..7348348 100644 --- a/src/pysolid/grid.py +++ b/src/pysolid/grid.py @@ -83,8 +83,11 @@ def calc_solid_earth_tides_grid(dt_obj, atr, step_size=1e3, display=False, verbo in_shape = tide_e.shape out_shape = (int(atr['LENGTH']), int(atr['WIDTH'])) vprint('PYSOLID: resize data to the shape of {} using order-1 spline interpolation'.format(out_shape)) + + enu = np.stack([tide_e, tide_n, tide_u]) + zoom_factors = [1, *np.divide(out_shape, in_shape)] kwargs = dict(order=1, mode="nearest", grid_mode=True) - ndi.zoom(np.stack([tide_e, tide_n, tide_u]), [1, *np.divide(out_shape, in_shape)], **kwargs) + tide_e, tide_u, tide_n = ndimage.zoom(enu, zoom_factors, **kwargs) # plot if display: From 1aa049acafda2af6380da3925e229023a53336c4 Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Tue, 15 Aug 2023 13:43:51 -0700 Subject: [PATCH 06/10] also remove scikit from `pyproject.toml` --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7c153c9..ba9fb9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,6 @@ dependencies = [ "numpy", "scipy", "matplotlib", - "scikit-image", ] dynamic = ["version"] From ef306e232e6fd5cf6c6cdabba58e9b81d539ca5b Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Wed, 16 Aug 2023 09:07:14 +0800 Subject: [PATCH 07/10] swap tide_n/u --- src/pysolid/grid.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pysolid/grid.py b/src/pysolid/grid.py index 7348348..39d3a2e 100644 --- a/src/pysolid/grid.py +++ b/src/pysolid/grid.py @@ -79,6 +79,7 @@ def calc_solid_earth_tides_grid(dt_obj, atr, step_size=1e3, display=False, verbo lon0, lon_step, width) # resample to the input size + # via scipy.ndimage.zoom or skimage.transform.resize if num_step > 1: in_shape = tide_e.shape out_shape = (int(atr['LENGTH']), int(atr['WIDTH'])) @@ -87,7 +88,7 @@ def calc_solid_earth_tides_grid(dt_obj, atr, step_size=1e3, display=False, verbo enu = np.stack([tide_e, tide_n, tide_u]) zoom_factors = [1, *np.divide(out_shape, in_shape)] kwargs = dict(order=1, mode="nearest", grid_mode=True) - tide_e, tide_u, tide_n = ndimage.zoom(enu, zoom_factors, **kwargs) + tide_e, tide_n, tide_u = ndimage.zoom(enu, zoom_factors, **kwargs) # plot if display: From de83d5fde1a7917cbaaea15d5590c98db8c27b67 Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Tue, 15 Aug 2023 18:55:10 -0700 Subject: [PATCH 08/10] remove redundant `environment.yml` Also hopefully this fixes this CI that was stuck --- environment.yml | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 environment.yml diff --git a/environment.yml b/environment.yml deleted file mode 100644 index fc86a05..0000000 --- a/environment.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: pysolid -channels: - - conda-forge - - defaults -dependencies: - - python>=3.8 - # for running - - numpy - - scipy - - matplotlib - # for packaging and installation - - fortran-compiler # Fortran compiler across platforms through conda-forge channel - - pip - - setuptools - - setuptools_scm - - wheel From caa75a06ace271c6677e2868e0a4e584ff2ffca8 Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Wed, 16 Aug 2023 10:09:58 +0800 Subject: [PATCH 09/10] update README after del environment.yml file --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b740428..e6747e6 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ git clone https://github.com/insarlab/PySolid.git # option 1: use conda to install dependencies into an existing, activated environment conda install -c conda-forge fortran-compiler --file PySolid/requirements.txt -# option 2: use conda to create a new environment named "pysolid" -conda env create -f PySolid/environment.yml +# option 2: use conda to install dependencoes into a new environment, e.g. named "pysolid" +conda create --name pysolid fortran-compiler --file PySolid/requirements.txt conda activate pysolid # option 3: have a Fortran compiler already installed and use pip to install the rest dependencies From 0bb414577aeee09260fdb7943f90951fb6406da0 Mon Sep 17 00:00:00 2001 From: Zhang Yunjun Date: Wed, 16 Aug 2023 11:40:10 +0800 Subject: [PATCH 10/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6747e6..d7af653 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ git clone https://github.com/insarlab/PySolid.git # option 1: use conda to install dependencies into an existing, activated environment conda install -c conda-forge fortran-compiler --file PySolid/requirements.txt -# option 2: use conda to install dependencoes into a new environment, e.g. named "pysolid" +# option 2: use conda to install dependencies into a new environment, e.g. named "pysolid" conda create --name pysolid fortran-compiler --file PySolid/requirements.txt conda activate pysolid