roms-tools 0.0.2__py3-none-any.whl → 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,58 @@
1
+ import cartopy.crs as ccrs
2
+ import matplotlib.pyplot as plt
3
+ import xarray as xr
4
+
5
+
6
+ def _plot(grid_ds, field=None, straddle=False, c="red", kwargs={}):
7
+ lon_deg = grid_ds["lon_rho"]
8
+ lat_deg = grid_ds["lat_rho"]
9
+
10
+ if field is not None:
11
+ # check if North or South pole are in domain
12
+ if lat_deg.max().values > 89 or lat_deg.min().values < -89:
13
+ raise NotImplementedError(
14
+ "Plotting is not implemented for the case that the domain contains the North or South pole."
15
+ )
16
+
17
+ if straddle:
18
+ lon_deg = xr.where(lon_deg > 180, lon_deg - 360, lon_deg)
19
+
20
+ # Define projections
21
+ proj = ccrs.PlateCarree()
22
+
23
+ trans = ccrs.NearsidePerspective(
24
+ central_longitude=lon_deg.mean().values, central_latitude=lat_deg.mean().values
25
+ )
26
+
27
+ lon_deg = lon_deg.values
28
+ lat_deg = lat_deg.values
29
+
30
+ # find corners
31
+ corners = [
32
+ (lon_deg[0, 0], lat_deg[0, 0]),
33
+ (lon_deg[0, -1], lat_deg[0, -1]),
34
+ (lon_deg[-1, -1], lat_deg[-1, -1]),
35
+ (lon_deg[-1, 0], lat_deg[-1, 0]),
36
+ ]
37
+
38
+ # transform coordinates to projected space
39
+ transformed_corners = [trans.transform_point(lo, la, proj) for lo, la in corners]
40
+ transformed_lons, transformed_lats = zip(*transformed_corners)
41
+
42
+ fig, ax = plt.subplots(1, 1, figsize=(13, 7), subplot_kw={"projection": trans})
43
+
44
+ ax.plot(
45
+ list(transformed_lons) + [transformed_lons[0]],
46
+ list(transformed_lats) + [transformed_lats[0]],
47
+ "o-",
48
+ c=c,
49
+ )
50
+
51
+ ax.coastlines(
52
+ resolution="50m", linewidth=0.5, color="black"
53
+ ) # add map of coastlines
54
+ ax.gridlines()
55
+
56
+ if field is not None:
57
+ p = ax.pcolormesh(lon_deg, lat_deg, field, transform=proj, **kwargs)
58
+ plt.colorbar(p, label=f"{field.long_name} [{field.units}]")