"""Test :func:`~vacumm.misc.plot.section2` in quiver mode""" # Imports from vcmq import create_lon, N, MV2, create_dep, os, code_file_name, section2 from vacumm.misc.phys.units import deg2m # Init data with z 1D nz = 11 nx = 11 x = create_lon(N.arange(nx)) xm = deg2m(x[:],lat=45.) # meters dx = xm[:].ptp() z = create_dep((-nz+1, 1.), units='m', long_name='Depth') dz = z[:].ptp() scale = dz/dx u = MV2.ones((nz,nx)) # 1 m/s w = u*scale # 1 m/s * scale for var in u,w: var.setAxis(0, z) var.setAxis(1, x) var.units = 'm/s' # Plot figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) s = section2((u,w), quiver_norm=1, fill=False, show=False, savefig=figfile, close=False, axes_aspect=1) # Result result = dict(files=figfile)
def _search(self, nom=None, regexp=True, nmax=5, **kwargs): """ Generic search within stations """ stations = [] if nom is not None: # Search within names using regular expression of strict comparisons nom = nom.strip() if regexp: # Regular expression import re this_re = re.compile(nom, re.I) for station in self._stations: if this_re.search(station['nom']) is not None: stations.append(station) if len(stations) == nmax: break else: # Strict equality for station in self._stations: if station['nom'].lower() == nom.lower(): stations.append(station) if len(stations) == nmax: break else: # Search using other specific arguments for key, val in kwargs.items(): if key in self._ids: # Use ids for station in self._stations: if station in stations: continue if station[key] is not None and \ station[key].lower() == val.lower(): stations.append(station) break elif key == 'position' and len(val) == 2: # Find the closest station import vacumm.misc as M, math distances = [] x0 = deg2m(*val) y0 = deg2m(val[1]) for station in self._stations: if station in stations: continue x = deg2m(station['longitude'], station['latitude']) y = deg2m(station['latitude']) distances.append(math.sqrt((x - x0)**2 + (y - y0)**2)) stations.append(self._stations[N.argmin(distances)]) if len(stations) == nmax: break if len(stations): if nmax == 1: return stations[0] else: return stations else: return None
def _search(self,nom=None,regexp=True,nmax=5,**kwargs): """ Generic search within stations """ stations = [] if nom is not None: # Search within names using regular expression of strict comparisons nom = nom.strip() if regexp: # Regular expression import re this_re = re.compile(nom, re.I) for station in self._stations: if this_re.search(station['nom']) is not None: stations.append(station) if len(stations) == nmax: break else: # Strict equality for station in self._stations: if station['nom'].lower() == nom.lower(): stations.append(station) if len(stations) == nmax: break else: # Search using other specific arguments for key,val in kwargs.items(): if key in self._ids: # Use ids for station in self._stations: if station in stations: continue if station[key] is not None and \ station[key].lower() == val.lower(): stations.append(station) break elif key == 'position' and len(val) == 2: # Find the closest station import vacumm.misc as M,math distances = [] x0 = deg2m(*val) y0 = deg2m(val[1]) for station in self._stations: if station in stations: continue x = deg2m(station['longitude'], station['latitude']) y = deg2m(station['latitude']) distances.append(math.sqrt((x-x0)**2+(y-y0)**2)) stations.append(self._stations[N.argmin(distances)]) if len(stations) == nmax: break if len(stations): if nmax == 1: return stations[0] else: return stations else: return None
"""Test :func:`~vacumm.misc.plot.section2` in quiver mode""" # Imports from vcmq import create_lon, N, MV2, create_dep, os, code_file_name, section2 from vacumm.misc.phys.units import deg2m # Init data with z 1D nz = 11 nx = 11 x = create_lon(N.arange(nx)) xm = deg2m(x[:], lat=45.) # meters dx = xm[:].ptp() z = create_dep((-nz + 1, 1.), units='m', long_name='Depth') dz = z[:].ptp() scale = dz / dx u = MV2.ones((nz, nx)) # 1 m/s w = u * scale # 1 m/s * scale for var in u, w: var.setAxis(0, z) var.setAxis(1, x) var.units = 'm/s' # Plot figfile = code_file_name(ext='png') if os.path.exists(figfile): os.remove(figfile) s = section2((u, w), quiver_norm=1, fill=False, show=False, savefig=figfile, close=True,