From 41b14de4d23b5d75847c79cbf7e29d36d87bb6b6 Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Mon, 29 Jan 2024 22:08:36 -0500 Subject: [PATCH] use colorcet instead of dismp for cyclic --- conda-env.yml | 1 + requirements.txt | 1 + src/sweets/plotting.py | 37 ++++--------------------------------- 3 files changed, 6 insertions(+), 33 deletions(-) diff --git a/conda-env.yml b/conda-env.yml index 3aa5d7e..f5d679c 100644 --- a/conda-env.yml +++ b/conda-env.yml @@ -23,6 +23,7 @@ dependencies: # - sentineleof>=0.7.0 # - shapely>=1.8 - isce3>=0.14.0 + - colorcet - compass>=0.4.1 - dask - dolphin>=0.5.1 diff --git a/requirements.txt b/requirements.txt index 11a0809..3f96750 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,7 @@ # Conda ones # SYNC THIS WITH conda-env # These are the packages easily-installable through pip +colorcet dask>=2022.6.0 h5py>=3.6 numpy>=1.20 diff --git a/src/sweets/plotting.py b/src/sweets/plotting.py index f9bf20c..f5b2e8d 100644 --- a/src/sweets/plotting.py +++ b/src/sweets/plotting.py @@ -5,6 +5,7 @@ import cartopy.crs as ccrs import cartopy.feature as cfeature +import colorcet import geopandas as gpd import ipywidgets import matplotlib as mpl @@ -14,7 +15,6 @@ from cartopy.io import shapereader from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER from dolphin import io -from matplotlib.colors import LinearSegmentedColormap from matplotlib.image import AxesImage from numpy.typing import ArrayLike from shapely.geometry import Polygon, box @@ -26,7 +26,7 @@ def plot_ifg( img: Optional[ArrayLike] = None, filename: Optional[Filename] = None, - phase_cmap: str = "dismph", + phase_cmap: str = colorcet.m_CET_C8, ax: Optional[plt.Axes] = None, add_colorbar: bool = True, title: str = "", @@ -324,6 +324,7 @@ def browse_arrays( ref_unw : Optional[tuple[int, int]] Reference point for all .unw files. If not passed, subtracts the mean of each file. + cmap : str or matplotlib.cmap subsample_factor : int or tuple[int, int] Amount to downsample when loading images. """ @@ -343,7 +344,7 @@ def browse_arrays( if num_panels == 2: # plot once with colorbar - axim_img = axes[0].imshow(img, cmap="dismph", vmin=-3.14, vmax=3.14) + axim_img = axes[0].imshow(img, cmap=cmap, vmin=-3.14, vmax=3.14) amp_vmax = np.percentile(np.abs(img_stack), 99) axim_amp = axes[1].imshow(amp, cmap=cmap, vmax=amp_vmax) @@ -367,36 +368,6 @@ def browse_plot(idx=0): fig.suptitle(titles[idx]) -def _make_dismph_colors(): - """Create a cyclic colormap for insar phase.""" - red, green, blue = [], [], [] - for i in range(120): - red.append(i * 2.13 * 155.0 / 255.0 + 100) - green.append((119.0 - i) * 2.13 * 155.0 / 255.0 + 100.0) - blue.append(255) - for i in range(120): - red.append(255) - green.append(i * 2.13 * 155.0 / 255.0 + 100.0) - blue.append((119 - i) * 2.13 * 155.0 / 255.0 + 100.0) - for i in range(120): - red.append((119 - i) * 2.13 * 155.0 / 255.0 + 100.0) - green.append(255) - blue.append(i * 2.13 * 155.0 / 255.0 + 100.0) - return np.vstack((red, green, blue)) - - -try: - plt.get_cmap("dismph") -except ValueError: - DISMPH = LinearSegmentedColormap.from_list("dismph", _make_dismph_colors().T / 256) - plt.register_cmap(cmap=DISMPH) - - -# # @lru_cache(maxsize=30) -# def io.load_gdal(filename: , subsample_factor=subsample_factorFilename): -# return io.load_gdal(filename) - - def plot_area_of_interest( state: Optional[str] = None, bbox: Optional[Tuple[float, float, float, float]] = None,