Skip to content

Commit

Permalink
Merge pull request #3 from stella-bourdin/revert-2-read_limit_files
Browse files Browse the repository at this point in the history
Revert "Read limit files"
  • Loading branch information
stella-bourdin authored Dec 3, 2020
2 parents d8d3344 + 1a21379 commit c90c289
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 68 deletions.
4 changes: 2 additions & 2 deletions dynamicopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -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.")
12 changes: 2 additions & 10 deletions dynamicopy/cartoplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
56 changes: 0 additions & 56 deletions dynamicopy/ncload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c90c289

Please sign in to comment.