def get_colorscalerange(request, default_min, default_max): try: climits = sorted( [float(x) for x in request.GET.get('colorscalerange').split(',')]) return DotDict(min=climits[0], max=climits[-1]) except (AttributeError, TypeError): return DotDict(min=default_min, max=default_max)
def get_dimensions(request, default_width=None, default_height=None): """ Return width and height of requested view. RETURNS width, height request should be in pixel units. """ try: width = float(request.GET.get("width")) height = float(request.GET.get("height")) return DotDict(width=width, height=height) except: return DotDict(width=default_width, height=default_height)
def get_bbox(request): """ Return the [lonmin, latmin, lonmax, lonmax] - [lower (x,y), upper(x,y)] Units will be specified by projection. """ elements = [ float(el) for el in request.GET["bbox"].split(",") ] return DotDict(minx=elements[0], miny=elements[1], maxx=elements[2], maxy=elements[3])
def wgs84_bounds(self, layer): with netCDF4.Dataset(self.topology_file) as nc: try: data_location = nc.variables['u'].location mesh_name = nc.variables['u'].mesh # Use local topology for pulling bounds data ug = UGrid.from_ncfile(self.topology_file, mesh_name=mesh_name) coords = np.empty(0) if data_location == 'node': coords = ug.nodes elif data_location == 'face': coords = ug.face_coordinates elif data_location == 'edge': coords = ug.edge_coordinates minx = np.nanmin(coords[:, 0]) miny = np.nanmin(coords[:, 1]) maxx = np.nanmax(coords[:, 0]) maxy = np.nanmax(coords[:, 1]) return DotDict(minx=minx, miny=miny, maxx=maxx, maxy=maxy, bbox=(minx, miny, maxx, maxy)) except AttributeError: pass
def get_gfi_positions(xy, bbox, crs, dims): """ Returns the latitude and longitude the GFI should be performed at""" EPSG4326 = pyproj.Proj(init='EPSG:4326') lon, lat = pyproj.transform( crs, EPSG4326, bbox.minx + ((bbox.maxx - bbox.minx) * (xy.x / dims.width)), bbox.maxy - ((bbox.maxy - bbox.miny) * (xy.y / dims.height))) return DotDict(latitude=lat, longitude=lon)
def get_times(request): """ Return the min and max times """ time = request.GET.get('time') if not time: time = date.today().isoformat() + "T00:00:00" times = sorted([ parse(t) for t in time.split("/") ]) return DotDict(min=times[0], max=times[-1])
def get_times(request): """ Return the min and max times """ time = request.GET.get('time') if not time: time = date.today().isoformat() + "T00:00:00" times = sorted([ parse(t) for t in time.split("/") ]) # Convert tz-aware datetimes to native datetimes times = [ tz_aware_to_native(t) for t in times ] return DotDict(min=times[0], max=times[-1])
def get_wgs84_bbox(request): """ Return the [lonmin, latmin, lonmax, lonmax] - [lower (x,y), upper(x,y)] in WGS84 """ EPSG4326 = pyproj.Proj(init='EPSG:4326') crs = get_projection(request) bbox = get_bbox(request) wgs84_minx, wgs84_miny = pyproj.transform(crs, EPSG4326, bbox.minx, bbox.miny) wgs84_maxx, wgs84_maxy = pyproj.transform(crs, EPSG4326, bbox.maxx, bbox.maxy) return DotDict(minx=wgs84_minx, miny=wgs84_miny, maxx=wgs84_maxx, maxy=wgs84_maxy)
def get_xy(request): """ Returns list of floats """ try: x = float(request.GET.get('x')) except ValueError: x = None try: y = float(request.GET.get('y')) except ValueError: y = None return DotDict(x=x, y=y)
def defaults(self): lmin = self.default_min lmax = self.default_max llog = self.logscale default = Variable.objects.filter(std_name=self.std_name, units=self.units).first() if default: if lmin is None and default.default_min: lmin = default.default_min if lmax is None and default.default_max: lmax = default.default_max if llog is None and default.logscale is not None: llog = default.logscale return DotDict(min=lmin, max=lmax, logscale=llog)
def wgs84_bounds(self, layer): try: cached_sg = load_grid(self.topology_file) except BaseException: pass else: lon_name, lat_name = cached_sg.face_coordinates lon_var_obj = getattr(cached_sg, lon_name) lat_var_obj = getattr(cached_sg, lat_name) lon_trimmed = cached_sg.center_lon[lon_var_obj.center_slicing] lat_trimmed = cached_sg.center_lat[lat_var_obj.center_slicing] lon_max = lon_trimmed.max() lon_min = lon_trimmed.min() lat_max = lat_trimmed.max() lat_min = lat_trimmed.min() return DotDict(minx=lon_min, miny=lat_min, maxx=lon_max, maxy=lat_max, bbox=(lon_min, lat_min, lon_max, lat_max))
def wgs84_bounds(self, layer): try: cached_sg = from_ncfile(self.topology_file) except: pass else: centers = cached_sg.centers longitudes = centers[..., 0] latitudes = centers[..., 1] lon_name, lat_name = cached_sg.face_coordinates lon_var_obj = getattr(cached_sg, lon_name) lat_var_obj = getattr(cached_sg, lat_name) lon_trimmed = longitudes[lon_var_obj.center_slicing] lat_trimmed = latitudes[lat_var_obj.center_slicing] lon_max = lon_trimmed.max() lon_min = lon_trimmed.min() lat_max = lat_trimmed.max() lat_min = lat_trimmed.min() return DotDict(minx=lon_min, miny=lat_min, maxx=lon_max, maxy=lat_max)
def defaults(self): lmin = self.default_min lmax = self.default_max llog = self.logscale default = Variable.objects.filter(std_name=self.std_name, units=self.units).first() if default: if lmin is None and default.default_min: lmin = default.default_min if lmax is None and default.default_max: lmax = default.default_max if llog is None and default.logscale is not None: llog = default.logscale image_type, colormap = split(self.default_style.code, '_', maxsplit=1) return DotDict(min=lmin, max=lmax, logscale=llog, image_type=image_type, colormap=colormap, numcontours=self.default_numcontours)
def depth_bounds(self, layer): depths = self.depths(layer) try: return DotDict(min=depths[0], max=depths[-1]) except IndexError: return DotDict(min=None, max=None)
def time_bounds(self, layer): times = self.times(layer) try: return DotDict(min=times[0], max=times[-1]) except IndexError: return DotDict(min=None, max=None)