def get(self, request,resampling_serie_id, *args, **kwargs): resampling_serie = ResamplingSerie.objects.get(id=resampling_serie_id) if not resampling_serie.probabilities: pass self.context['resampling_serie'] = resampling_serie self.context["graph"] = plot_web([[resampling_serie.data,resampling_serie.probabilities],], 'Permanence Curve',"percent","%",['quantile',],'m3/s',mode='markers') return render(request,'resampling_information.html',self.context)
def ReferenceFlow(self): data = {} xys = [] names = [] for type_data in self.daily: daily = self.daily[type_data] daily['month'] = [o.month for o in daily.index] mean_by_month = daily.groupby('month').quantile(q=0.05, numeric_only=True) data[type_data] = [d[0] for d in mean_by_month.values] date = pd.DatetimeIndex( [datetime(1900, m, 1) for m in set(daily['month'].values)]) xys.append([date, data[type_data]]) names.append(type_data) graph = plot_web(xys=xys, title=_("Reference Flow"), variable=_("Flow"), unit="m³/s", names=names) return [ Table(month_names[i], data['pre_data'][i], data['pos_data'][i]) for i in range(12) ], graph
def get_or_create_reduced_series(self): self.update_originals() self.update_variables_and_sources() self.reduceds = [] graphs = [] for original in self.originals: temporals = TemporalSerie.objects.filter( id=original.temporal_serie_id) daily = self.create_daily_data_pandas(temporals) anos_hidrologicos = self.hydrologic_years_dict(daily) discretizations = self.discretizations[:] for discretization in discretizations: graph, names = self.get_graphs_data(daily, original, discretization) if graph.xys: graph.graph = self.create_graph(graph.xys, original.variable, original.unit, discretization, names) graphs.append(graph) if self.plot_permancence_curve: xys = self.get_permancence_curve_data(daily) graph = generic_obj() graph.graph = plot_web(xys, _('Permanence Curve'), original.variable, original.unit, [ _('data'), ], '%') graph.title = _('Permanence Curve') graphs.append(graph) self.reduceds = graphs return self.reduceds
def create_graph(self, xys, variable, unit, discretization, names): return plot_web(xys=xys, title=_("%(discretization)s %(variable)s") % { 'variable': _('frequency of change'), 'discretization': str(discretization) }, variable=_('frequency'), unit='un', names=names)
def Group2cv(self): datas = [] discretizations = list( Discretization.objects.filter(stats_type__type='rolling mean')) discretizations.sort(key=lambda x: int(x.pandas_code)) graphs = [] for discretization in discretizations: for reduction in Reduction.objects.filter( stats_type__type='rolling mean'): data_mean = {} xys = [] names = [] for type_data in self.daily: daily_data = self.daily[type_data] basic_stats = RollingMean(self.station.id, self.variable.id) reduced, date, data = basic_stats.get_or_create_reduced_data( self.daily[type_data], self.original[type_data], discretization, reduction, None, None, self.start_year, self.end_year) mean_ = sum(data) / len(data) std_ = std(data) cv = std_ / mean_ data_mean[type_data] = round(cv, 2) xys.append([date, data]) names.append(type_data) xys.append([[date[0], date[-1]], [mean_, mean_]]) names.append(type_data + " " + _("mean")) graph = plot_web( xys=xys, title=_("%(discretization)s %(variable)s %(reduction)s") % { 'variable': str(self.variable), 'discretization': str(discretization), 'reduction': str(reduction.type) }, variable=self.variable, unit="m³/s", names=names) graphs.append(graph) line = Table( 'Annual %(reduction)s %(discretization)s means' % { 'reduction': reduction.type, 'discretization': discretization.type }, data_mean['pre_data'], data_mean['pos_data'], ) datas.append(line) return datas, graphs
def create_graph(self, xys, variable, unit, discretization, names): ''' This method is responsible to return the graph. To change the graph. ''' return plot_web(xys=xys, title=_("%(discretization)s %(variable)s") % { 'variable': str(variable), 'discretization': str(discretization) }, variable=variable, unit=unit, names=names)