diff --git a/dynamicopy/__init__.py b/dynamicopy/__init__.py index 750602d..7b0e795 100644 --- a/dynamicopy/__init__.py +++ b/dynamicopy/__init__.py @@ -2,7 +2,7 @@ # If any private function or specific import is defined in a module, remove '*' and list the functions. from .utils import idx_closest, sign_change_detect from .utils_geo import * -from .ncload import var_load, get_lon_lat, var_load_from_limit +from .ncload import var_load, get_lon_lat from .compute import * from .plot import lon_lat_plot from .basins import * @@ -12,4 +12,4 @@ from .cartoplot import lon_lat_plot_map, scatterplot_map, zooms except ImportError: print("Failure in importing the cartopy library, the dynamicopy.cartoplot will not be loaded. \ - Please install cartopy if you wish to use it. Other dynamicopy modules are imported.") + Please install cartopy if you wish to use it.") diff --git a/dynamicopy/cartoplot.py b/dynamicopy/cartoplot.py index 649bd05..f167924 100644 --- a/dynamicopy/cartoplot.py +++ b/dynamicopy/cartoplot.py @@ -6,7 +6,6 @@ import matplotlib.pyplot as plt import cartopy.crs as ccrs from .plot import _var2d -from .utils_geo import apply_mask_axis from matplotlib.axes import Axes from cartopy.mpl.geoaxes import GeoAxes @@ -60,12 +59,6 @@ def lon_lat_plot_map(lon, lat, var, lon_axis=-1, lat_axis=-2, fig_ax=None, title # Obtain 2D variable to plot var2D = _var2d(var, lon_axis, lat_axis) - # Truncate if latitude coordinates array go too far - mask = ~((lat > 88) | (lat < -88)) - var2D = apply_mask_axis(var2D, mask, axis=lat_axis) - lat = lat[mask] - if any(mask == False) : print("Warning, values too close to the pole(s) were not displayed.") - # Plotting if fig_ax == None: fig = plt.figure() @@ -81,12 +74,11 @@ def lon_lat_plot_map(lon, lat, var, lon_axis=-1, lat_axis=-2, fig_ax=None, title if not smooth: C = ax.pcolormesh(lon, lat, var2D, cmap=cmap, - norm=norm, transform=ccrs.PlateCarree(), - shading = "nearest") + norm=norm, transform=ccrs.PlateCarree(), shading = "nearest") else: C = ax.contourf(lon, lat, var2D, cmap=cmap, norm=norm, transform=ccrs.PlateCarree()) - fig.colorbar(C, ax=ax, label=colorbar_label) + fig.colorbar(C, ax=ax, label=colorbar_label,) ax.set_ylabel("Latitude (°)") ax.set_xlabel("Longitude (°)") ax.set_title(title) diff --git a/dynamicopy/ncload.py b/dynamicopy/ncload.py index 7885e9b..61828b2 100644 --- a/dynamicopy/ncload.py +++ b/dynamicopy/ncload.py @@ -73,62 +73,6 @@ def get_lon_lat(file_path, lon_name='lon', lat_name='lat'): return np.array(lon), np.array(lat) -def var_load_from_limit(varname, limit_file='limit.nc', lon_name='longitude', lat_name='latitude'): - """ Loads a field from a limit.nc file (LMDZ standard structure) - - Parameters - ---------- - varname : str - Name of the variable to load in the file - limit_file : str - The path (relative or absolute) to the limit.nc file; - lon_name : str, optional - name of the longitude coordinate in the file (default 'longitude'); - lat_name : str, optional - name of the latitude coordinate in the file (default 'latitute'); - - Returns - ------- - list of np.ndarray (lon, lat, var) - The field reshaped in lon/lat coordinates and the corresponding coordinate arrays; - """ - - lon = var_load(lon_name, limit_file) - lat = var_load(lat_name, limit_file) - var = var_load(varname, limit_file) - - lat_dim_no_pole = len(np.unique(lat)) - 2 - lon_dim = len(np.unique(lon)) - - if (len(np.shape(var)) == 1) : - var_north_pole = var[0] - var_south_pole = var[-1] - var_no_pole = var[1:-1] - - var_no_pole_reshape = np.reshape(var_no_pole, [lat_dim_no_pole, lon_dim]) - var_north_pole_reshape = [[var_north_pole] * lon_dim] - var_south_pole_reshape = [[var_south_pole] * lon_dim] - var_reshape = np.concatenate([var_north_pole_reshape, var_no_pole_reshape, var_south_pole_reshape], 0) - - elif (len(np.shape(var)) == 2) : - var_north_pole = var[:,0] - var_south_pole = var[:,-1] - var_no_pole = var[:,1:-1] - - var_no_pole_reshape = [np.reshape(var_no_pole[i], [lat_dim_no_pole, lon_dim]) for i in range(len(var))] - var_north_pole_reshape = [[[var_north_pole[i]] * lon_dim] for i in range(len(var))] - var_south_pole_reshape = [[[var_south_pole[i]] * lon_dim] for i in range(len(var))] - var_reshape = np.concatenate([var_north_pole_reshape, var_no_pole_reshape, var_south_pole_reshape], 1) - - else : - print("Problem with the variable dimensions") - - lat_reshape = np.flip(np.unique(lat)) - lon_reshape = np.unique(lon) - - return lon_reshape, lat_reshape, var_reshape - - if __name__ == "__main__": pass