From d057adf69807965fc36b012aec75a3a0d1beeecd Mon Sep 17 00:00:00 2001 From: Jeffrey Milloy Date: Mon, 20 Apr 2020 20:41:35 -0400 Subject: [PATCH] WIP: Don't worry about lat-lon-alt dependent case when transforming. --- podpac/core/coordinates/coordinates.py | 65 ++++++------------- .../core/coordinates/dependent_coordinates.py | 2 +- 2 files changed, 21 insertions(+), 46 deletions(-) diff --git a/podpac/core/coordinates/coordinates.py b/podpac/core/coordinates/coordinates.py index 91fbedc26..5aca91af9 100644 --- a/podpac/core/coordinates/coordinates.py +++ b/podpac/core/coordinates/coordinates.py @@ -1355,27 +1355,25 @@ def transform(self, crs): if tc: cs[self.dims.index("lat")] = tc[0] cs[self.dims.index("lon")] = tc[1] - if "alt" in self.dims: - cs[self.dims.index("alt")] = tc[2] - return Coordinates(cs, crs=crs, validate_crs=False) # otherwise convert lat-lon to dependent coordinates - ilat = self.dims.index("lat") - ilon = self.dims.index("lon") - if ilat == ilon - 1: - c1, c2 = self["lat"], self["lon"] - elif ilon == ilat - 1: - c1, c2 = self["lon"], self["lat"] - - c = DependentCoordinates( - np.meshgrid(c1.coordinates, c2.coordinates, indexing="ij"), dims=[c1.name, c2.name] - ) + else: + ilat = self.dims.index("lat") + ilon = self.dims.index("lon") + if ilat == ilon - 1: + c1, c2 = self["lat"], self["lon"] + elif ilon == ilat - 1: + c1, c2 = self["lon"], self["lat"] + + c = DependentCoordinates( + np.meshgrid(c1.coordinates, c2.coordinates, indexing="ij"), dims=[c1.name, c2.name] + ) - # replace 'lat' and 'lon' entries with single 'lat,lon' entry - i = min(ilat, ilon) - cs.pop(i) - cs.pop(i) - cs.insert(i, c) + # replace 'lat' and 'lon' entries with single 'lat,lon' entry + i = min(ilat, ilon) + cs.pop(i) + cs.pop(i) + cs.insert(i, c) # transform ts = [] @@ -1392,12 +1390,8 @@ def _simplified_transform(self, crs, transformer): """ Transform coordinates to simple Coordinates1d (instead of DependentCoordinates) if possible """ # check if we can simplify the coordinates by transforming a downsampled grid - if "alt" in self.dims: - dims = ["lat", "lon", "alt"] - else: - dims = ["lat", "lon"] - sample = [np.linspace(self[dim].coordinates[0], self[dim].coordinates[-1], 5) for dim in dims] - temp_coords = DependentCoordinates(np.meshgrid(*sample, indexing="ij"), dims=dims) + sample = [np.linspace(self[dim].coordinates[0], self[dim].coordinates[-1], 5) for dim in ["lat", "lon"]] + temp_coords = DependentCoordinates(np.meshgrid(*sample, indexing="ij"), dims=["lat", "lon"]) t = temp_coords._transform(transformer) # if we get DependentCoordinates from the transform, they are not independent @@ -1428,28 +1422,9 @@ def _simplified_transform(self, crs, transformer): [self["lon"].coordinates, np.full_like(self["lon"].coordinates, self["lat"].coordinates.mean())], name="lon_lat", ) - temp_coords._transform(transformer)["lon"].simplify() - - # no alt coordinates, return now - if len(t) < 3: - return (t_lat, t_lon) - - # alt - if isinstance(t[2], UniformCoordinates1d): - t_alt = clinspace(t[2].coordinates[0], t[2].coordinates[-1], self["alt"].size, name="alt") - else: - # compute the non-uniform coordinates (and simplify to uniform if they are *now* uniform) - temp_coords = StackedCoordinates( - [ - self["alt"].coordinates, - np.full_like(self["alt"].coordinates, self["lat"].coordinates.mean()), - np.full_like(self["alt"].coordinates, self["lat"].coordinates.mean()), - ], - name="alt_lon_lat", - ) - t_alt = temp_coords._transform(transformer)["alt"].simplify() + t_lon = temp_coords._transform(transformer)["lon"].simplify() - return (t_lat, t_lon, t_alt) + return t_lat, t_lon # ------------------------------------------------------------------------------------------------------------------ # Operators/Magic Methods diff --git a/podpac/core/coordinates/dependent_coordinates.py b/podpac/core/coordinates/dependent_coordinates.py index 1952b7f54..f0434c0c5 100644 --- a/podpac/core/coordinates/dependent_coordinates.py +++ b/podpac/core/coordinates/dependent_coordinates.py @@ -449,7 +449,7 @@ def simplify(self): i = self.dims.index(dim) slc = slc_start.copy() slc[i] = slice(None) - if not np.allclose(coords[i][tuple(slc)], coords[i], atol=1e-7): + if dim in ["lat", "lon"] and not np.allclose(coords[i][tuple(slc)], coords[i], atol=1e-7): return self coords[i] = ArrayCoordinates1d(coords[i][tuple(slc)].squeeze(), name=dim).simplify()