Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions oceannavigator/dataset_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,6 @@ function TimeSlider({ id, dataset, timestamps, selected, onChange }) {
/>
));

console.log(dataset.id, timestamps.length, thumbLeft, selectedIndex);

return (
<div
className="time-slider"
Expand Down
64 changes: 24 additions & 40 deletions plotting/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import threading
import tempfile
from textwrap import wrap
from typing import Union

import cartopy.crs as ccrs
import cartopy.feature as cfeature
Expand All @@ -17,7 +16,7 @@
from matplotlib.patches import Patch, PathPatch, Polygon
from matplotlib.path import Path
from osgeo import gdal, osr
from shapely.geometry import box, LinearRing, MultiPolygon, Point, Polygon as Poly
from shapely.geometry import LinearRing, MultiPolygon, Point, Polygon as Poly
from shapely.ops import unary_union

import plotting.colormap as colormap
Expand All @@ -31,7 +30,6 @@

from oceannavigator.settings import get_settings


settings = get_settings()


Expand All @@ -47,10 +45,8 @@ def parse_query(self, query):
super().parse_query(query)

if len(self.variables) > 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")

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading