cavapy 2.0.6__tar.gz → 2.0.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cavapy
3
- Version: 2.0.6
3
+ Version: 2.0.8
4
4
  Summary: CAVA Python package. Retrive climate data.
5
5
  License: Apache-2.0
6
6
  License-File: LICENSE
@@ -32,6 +32,22 @@ SPATIAL_COORDS = {
32
32
  }
33
33
 
34
34
 
35
+ def _normalize_longitude_coordinate(data: xr.DataArray) -> xr.DataArray:
36
+ """Normalize 0-360 longitude coordinates to -180..180 for bbox selection."""
37
+ if "longitude" not in data.coords:
38
+ return data
39
+
40
+ longitude = data["longitude"]
41
+ values = np.asarray(longitude.values, dtype=float)
42
+ if values.ndim != 1 or values.size == 0:
43
+ return data
44
+ if np.nanmax(values) <= 180:
45
+ return data
46
+
47
+ data = data.assign_coords(longitude=(longitude + 180) % 360 - 180)
48
+ return data.sortby("longitude")
49
+
50
+
35
51
  @contextmanager
36
52
  def _suppress_stderr_fd():
37
53
  """Temporarily redirect stderr to /dev/null (also silences C-level warnings)."""
@@ -108,6 +124,7 @@ def _select_spatial_subset(
108
124
  log: logging.Logger,
109
125
  ) -> xr.DataArray:
110
126
  """Select bbox cells, falling back to nearest cells if the bbox is sub-grid."""
127
+ data = _normalize_longitude_coordinate(data)
111
128
  selectors = {
112
129
  coord_name: _coordinate_slice(data[coord_name], bbox[bbox_key])
113
130
  for coord_name, bbox_key in SPATIAL_COORDS.items()
@@ -49,7 +49,11 @@ def plot_spatial_map(
49
49
  raise ValueError(f"Unsupported aggregation method: {aggregation}")
50
50
 
51
51
  # Create figure with cartopy
52
- fig, ax = plt.subplots(figsize=figsize, subplot_kw={"projection": ccrs.PlateCarree()})
52
+ fig, ax = plt.subplots(
53
+ figsize=figsize,
54
+ layout="constrained",
55
+ subplot_kw={"projection": ccrs.PlateCarree()},
56
+ )
53
57
 
54
58
  # Plot data
55
59
  im = plot_data.plot(
@@ -84,7 +88,7 @@ def plot_spatial_map(
84
88
  gl.bottom_labels = True
85
89
 
86
90
  # Add colorbar
87
- cbar = plt.colorbar(im, ax=ax, shrink=0.8, pad=0.02)
91
+ cbar = fig.colorbar(im, ax=ax, shrink=0.8, pad=0.02)
88
92
  if hasattr(plot_data, "units"):
89
93
  cbar.set_label(
90
94
  f"{plot_data.name} ({plot_data.units})", rotation=270, labelpad=20
@@ -100,12 +104,11 @@ def plot_spatial_map(
100
104
  else:
101
105
  title = f"{aggregation.title()} {var_name}"
102
106
 
103
- ax.set_title(title, fontsize=14, pad=20)
104
-
105
- plt.tight_layout()
107
+ # Avoid Cartopy's gridliner-based title repositioning producing non-finite bounds.
108
+ ax.set_title(title, fontsize=14, pad=20, y=1.0)
106
109
 
107
110
  if save_path:
108
- plt.savefig(save_path, dpi=300, bbox_inches="tight")
111
+ fig.savefig(save_path, dpi=300, bbox_inches="tight")
109
112
 
110
113
  return fig
111
114
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cavapy"
3
- version = "2.0.6"
3
+ version = "2.0.8"
4
4
  description = "CAVA Python package. Retrive climate data."
5
5
  authors = ["Riccardo Soldan <riccardosoldan@hotmail.it>", "Oleh Lokshyn <olokshyn@gmail.com>"]
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes