diff --git a/oceannavigator/dataset_config.py b/oceannavigator/dataset_config.py index c4979b4c6..9716bc409 100644 --- a/oceannavigator/dataset_config.py +++ b/oceannavigator/dataset_config.py @@ -39,19 +39,15 @@ def _get_dataset_config() -> dict: f"Loaded dataset config file from: {settings.dataset_config_file}" ) - for name in config: + for name in config: stub_file = f"{settings.dataset_config_stub_path}{name}.json" - with open(stub_file, "r") as f: + with open(stub_file, "r") as f: config[name] = json.load(f)[name] - log().debug( - f"Loaded stub dataset config file from: {stub_file}" - ) + log().debug(f"Loaded stub dataset config file from: {stub_file}") return config - - def _get_attribute(self, key: str) -> Union[str, dict]: return self._config.get(key) if not None else "" @@ -369,14 +365,14 @@ def scale(self) -> list: return [self._variable.valid_min, self._variable.valid_max] else: return [0, 100] - + @property def data_categories(self) -> list | None: """ Returns ordered category labels for discrete/categorical variables. """ try: - return self.__get_attribute('data_categories') + return self.__get_attribute("data_categories") except KeyError: return None diff --git a/oceannavigator/frontend/src/components/data-selectors/TimeSlider.jsx b/oceannavigator/frontend/src/components/data-selectors/TimeSlider.jsx index c8ad3f5ef..5058483bb 100644 --- a/oceannavigator/frontend/src/components/data-selectors/TimeSlider.jsx +++ b/oceannavigator/frontend/src/components/data-selectors/TimeSlider.jsx @@ -409,8 +409,6 @@ function TimeSlider({ id, dataset, timestamps, selected, onChange }) { /> )); - console.log(dataset.id, timestamps.length, thumbLeft, selectedIndex); - return (
1: - raise ClientError( - f"MapPlotter only supports 1 variable. \ - Received multiple: {self.variables}" - ) + raise ClientError(f"MapPlotter only supports 1 variable. \ + Received multiple: {self.variables}") self.projection = query.get("projection") @@ -143,28 +139,21 @@ def __apply_poly_mask(self, data: np.ma.MaskedArray) -> np.ma.MaskedArray: def get_land_geoms(self, extent: tuple) -> list: # Returns a list of land shape geometries that intersect the plot extent scaler = cfeature.AdaptiveScaler("110m", (("50m", 50), ("10m", 15))) - land_shp = cfeature.NaturalEarthFeature( - "physical", "land", scale=scaler.scale_from_extent(extent) - ) + scale = scaler.scale_from_extent(extent) - lon_min, lon_max, lat_min, lat_max = extent + land_feats = cfeature.NaturalEarthFeature("physical", "land", scale=scale) + + land_geoms = land_feats.intersecting_geometries(extent) + land_geoms = unary_union(list(land_geoms)) geometries = [] - if lon_min <= lon_max: - bbox = box(lon_min, lat_min, lon_max, lat_max) - for geom in land_shp.geometries(): - inter = geom.intersection(bbox) - if not inter.is_empty: - geometries.append(inter) - else: - # plot wraps longitudes - west_box = box(lon_min, lat_min, 180, lat_max) - east_box = box(-180, lat_min, lon_max, lat_max) - for geom in land_shp.geometries(): - for bb in (west_box, east_box): - inter = geom.intersection(bb) - if not inter.is_empty: - geometries.append(inter) + if not land_geoms.is_empty: + lake_feats = cfeature.NaturalEarthFeature("physical", "lakes", scale=scale) + + lake_geoms = lake_feats.intersecting_geometries(extent) + lake_geoms = unary_union(list(lake_geoms)) + + geometries.append(land_geoms.difference(lake_geoms)) return geometries @@ -173,7 +162,7 @@ def load_map( extent: list, figuresize: list, dpi: int, - ) -> Union[plt.figure, plt.axes]: + ) -> tuple: CACHE_DIR = settings.cache_dir filename = self._get_filename(self.plot_projection.proj4_params["proj"], extent) @@ -286,18 +275,10 @@ def load_data(self): ] ) - elif abs(self.centroid[1] - self.bounds[1]) > 90: - - if abs(self.bounds[3] - self.bounds[1]) > 360: - raise ClientError( - ( # gettext( - "You have requested an area that exceeds the width \ - of the world. Thinking big is good but plots need to \ - be less than 360 deg wide." - ) - ) - self.plot_projection = ccrs.Mercator(central_longitude=self.centroid[1]) - + elif abs(self.bounds[3] - self.bounds[1]) > 360: + raise ClientError(("You have requested an area that exceeds the width \ + of the world. Thinking big is good but plots need to \ + be less than 360 deg wide.")) # gettext() else: self.plot_projection = ccrs.Mercator( central_longitude=self.centroid[1], @@ -816,7 +797,9 @@ def plot(self): self.data, self.dataset_config.variable[f"{self.variables[0]}"] ) - data_categories = self.dataset_config.variable[self.variables[0]].data_categories + data_categories = self.dataset_config.variable[ + self.variables[0] + ].data_categories c = ax.imshow( self.data, vmin=vmin, @@ -914,6 +897,7 @@ def plot(self): self.longitude, self.latitude, self.bathymetry, + transform_first=True, linewidths=0.5, norm=FuncNorm( (lambda x: np.log10(x), lambda x: 10**x), vmin=1, vmax=6000