def get_imagetype(request, parameter=None, default=None): parameter = parameter or 'styles' default = default or 'filledcontours' try: z = split(request.GET.get(parameter).split(',')[0], '_', maxsplit=1)[0].lower() assert z return z except (AssertionError, IndexError, AttributeError, TypeError): return default
def get_colormap(request, parameter=None, default=None): parameter = parameter or 'styles' default = default or 'cubehelix' try: from matplotlib.pyplot import colormaps requested_cm = split(request.GET.get(parameter).split(',')[0], '_', maxsplit=1)[1] assert requested_cm return next(x for x in colormaps() if x.lower() == requested_cm.lower()) except (AssertionError, IndexError, AttributeError, TypeError, StopIteration): return default
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 to_internal_value(self, data): image_type, colormap = split(data, '_', maxsplit=1) try: return Style.objects.get(image_type=image_type, colormap=colormap) except Style.DoesNotExist: return None