コード例 #1
0
 def test_spectral_256(self):
     victim = ColorRange('spectral', 256)
     self.assertEquals(256, len(victim))
     self.assertEquals('spectral', victim.name())
     for c in victim:
         self.check_color(c)
     self.check_unique(victim)
コード例 #2
0
 def test_spectral_256(self):
     victim = ColorRange('spectral', 256)
     self.assertEquals(256, len(victim))
     self.assertEquals('spectral', victim.name())
     for c in victim:
         self.check_color(c)
     self.check_unique(victim)
コード例 #3
0
 def test_names(self):
     names = ColorRange.color_map_names()
     self.assertIn('rainbow', names)
     self.assertIn('spectral', names)
     self.assertIn('ocean', names)
コード例 #4
0
def plot_multi(data, beginDate, endDate, show_logo=True):
    # data is an iterator over tuples.
    # each tuple has a timestamp as first column,
    # then 3 columns for each well: Observed, Estimated, Dry

    fig = figure()

    if show_logo:
        logo_im(fig)

    # axx = axes([0.1, 0.3, 0.5, 0.5])
    # left, bottom, width, height
    # ax1 = subplot(2, 1, 1)

    # left, bottom, width, height -- 0..1
    ax1 = axes([0.1, 0.3, 0.8, 0.55])
    fig.suptitle("Water level elevation above NAVD88 datum, in feet", y=0.9)

    xlabel('Date')
    ylabel('Water Level (NAVD88 ft)')
    # xlim handles None gracefully
    xlim(beginDate, endDate)

    # axhline(y = 0.5) could be used for depicting ground elevation
    # labels = [ _clean_label(s) for s in keys[1:] ]
    # legend(labels, loc='upper left', bbox_to_anchor=(1, 1))
    xticks(rotation=90)

    labels = data.keys()
    # columns is a list of lists, one for each column.
    columns = [list() for _l in labels]
    for r in data:
        for i, v in enumerate(r):
            columns[i].append(v)

    for i in range(1, len(columns), 3):
        gap_fill(columns[i], columns[i + 1], columns[i + 2])

    line_colors = ColorRange(count=(len(labels) - 1) / 3)

    _logger.debug("In plot_multi generation, colors = %s", list(line_colors))

    ax1.yaxis.set_major_formatter(
        matplotlib.ticker.FormatStrFormatter('%0.2f'))

    lines = []
    for i in range(1, len(labels)):
        marker = _line_styles[(i - 1) % 3]
        color = line_colors[(i - 1) / 3]
        label = "_nolegend_"
        if (i % 3) == 1:
            label = labels[i]
        markerprops = {
            'markerfacecolor': color,
            'markersize': _marker_size,
            'markeredgecolor': color
        }
        l = plot_date(columns[0],
                      columns[i],
                      fmt=marker,
                      color=color,
                      label=label,
                      **markerprops)
        lines.append(l[0])

    grid(color="0.7", linestyle="-"
         )  # float-ish color is interpreted as gray level, 1.0=white

    h, l = ax1.get_legend_handles_labels()

    # position legend in lower sub-plot, not to graphed subplot
    # ax2 = subplot(2, 1, 2)
    fig.legend(h, l, loc='lower right', ncol=1 + (len(l) / 6))

    # make another legend for the dot'n'dashes, from the first 3 lines
    _legend_for_line_styles(fig)

    return len(columns[0]), fig
コード例 #5
0
def plot_single(data,
                beginDate=None,
                endDate=None,
                dry_elevation=None,
                ground_elevation=None,
                ngvd29_correction=None,
                show_logo=True):
    f = figure()

    labels = data.keys()

    if show_logo:
        logo_im(f)

    # left, bottom, width, height
    ax1 = axes([0.1, 0.25, 0.8, 0.55])

    f.suptitle("Water level elevation above NAVD88 datum, in feet\nGage " +
               labels[1],
               y=0.9)

    xlabel('Date')
    ylabel('Water Level (NAVD88 ft)')
    xlim(beginDate, endDate)

    # labels = [ _clean_label(s) for s in keys[1:] ]
    # legend(labels, loc='upper left', bbox_to_anchor=(1, 1))
    xticks(rotation=90)

    ylabel(labels[1] + "\nWater Level (NAVD88 ft)")

    # data has exactly 4 columns: date, O, E, D
    columns = [[], [], [], []]
    for r in data:
        for i, v in enumerate(r):
            columns[i].append(v)

    gap_fill(*columns[1:3])

    if dry_elevation is not None:
        axhline(y=dry_elevation, linewidth=4, color=gray_ish, zorder=-100)
    if ground_elevation is not None:
        axhline(y=ground_elevation, linewidth=4, color=brown_ish, zorder=-100)

    line_colors = ColorRange(count=1)
    c = line_colors[0]
    _logger.debug("In plot_single, color = %s", c)

    grid(color="0.7", linestyle="-"
         )  # float-ish color is interpreted as gray level, 1.0=white

    markerprops = {
        'markerfacecolor': c,
        'markersize': _marker_size,
        'markeredgecolor': c
    }
    (l1, ) = plot_date(columns[0],
                       columns[1],
                       _line_styles[0],
                       color=c,
                       label="Obs",
                       **markerprops)
    (l2, ) = plot_date(columns[0],
                       columns[2],
                       _line_styles[1],
                       color=c,
                       label="Est",
                       **markerprops)
    (l3, ) = plot_date(columns[0],
                       columns[3],
                       _line_styles[2],
                       color=c,
                       label="Dry",
                       **markerprops)

    # Set options to make legend horizontal, across bottom
    h, l = ax1.get_legend_handles_labels()
    f.legend(h, l, loc='lower center', bbox_to_anchor=(0.5, 0.0), ncol=3)

    # logo(f)

    # _legend_for_line_styles(f, [l1, l2, l3])

    ax1.yaxis.set_major_formatter(
        matplotlib.ticker.FormatStrFormatter('%0.2f'))

    if ngvd29_correction is not None:
        # ax1 = f.axes[0]
        ax2 = ax1.twinx()  # new axis overlay, ticks on right, shared x axis

        lim = ax1.get_ylim()
        ax2.set_ylim([d - ngvd29_correction for d in lim])
        ax2.set_ylabel("NAVD29 ft")

        # twinx does not preserve this, so restore it now
        ax2.xaxis_date()
        ax2.yaxis.set_major_formatter(
            matplotlib.ticker.FormatStrFormatter('%0.2f'))

        # tight_layout()
        draw()

    # tight_layout() # does not look good

    return len(columns[0]), f
コード例 #6
0
def eden_page(request):
    """
    Allows a user to select a site,
    date in order to view a dygraph
    plot of results.
    """

    # TODO If URL does not end with /, redirect there for ease of form generation

    template_name = 'eve.html'
    query_form = TimeSeriesFilterForm()

    eden_url = settings.EDEN_URL

    has_data = False
    # be careful about initial get with no parameters,
    # so we don't clobber the initial values
    if request.method == 'GET' and request.GET:
        query_form = TimeSeriesFilterForm(request.GET)
        has_data = True
    elif request.method == 'POST':
        query_form = TimeSeriesFilterForm(request.POST)
        has_data = True

    if has_data:
        """
        if not query_form.has_changed():
            return render(request, template_name, {'query_form': query_form, })
        """
        if query_form.is_valid():

            # Avoid the troublesome Nones.
            plot_params = {}
            for k, v in query_form.cleaned_data.items():
                if v:
                    plot_params[k] = v

            plot_query_str = urllib.urlencode(plot_params, doseq=True)

            isIE = 'MSIE' in request.META['HTTP_USER_AGENT']

            gages = query_form.cleaned_data['site_list']
            colors = ColorRange(count=len(gages))

            if query_form.cleaned_data['timeseries_start']:
                str_tstart = '%s' % query_form.cleaned_data['timeseries_start']
            # elif isIE:
            #    str_tstart = min_date(gages)
            else:
                str_tstart = None

            if query_form.cleaned_data['timeseries_end']:
                str_tend = '%s' % query_form.cleaned_data['timeseries_end']
            # elif isIE:
            #     str_tstart = max_date(gages)
            else:
                str_tend = None

            _logger.debug("In page generation, colors = %s", list(colors))

            render_params = {
                'query_form': query_form,
                'plot_params': mark_safe(plot_query_str),
                'series_options': mark_safe(dygraph_series_options(gages)),
                'str_tstart': str_tstart,
                'gages': gages,
                'str_tend': str_tend,
                'colors': mark_safe(json.dumps(list(colors))),
                'color_list': list(colors),
                'DYGRAPH_RANGE_SELECTOR': settings.DYGRAPH_RANGE_SELECTOR,
                'EDEN_URL': eden_url,
            }
            if len(gages) == 1:
                station = stage_queries.station_list(gages)[0]
                render_params['ngvd29_series'] = '%s%s' % (
                    station.station_name_web, '_NGVD29')
                render_params['dry_elevation'] = station.dry_elevation or None
                render_params[
                    'ground_elevation'] = station.duration_elevation or None
                render_params[
                    'ngvd29_correction'] = station.vertical_conversion or 0.0
            else:
                render_params['dry_elevation'] = None
                render_params['ground_elevation'] = None
                render_params['ngvd29_correction'] = "null"

            return render(request, template_name, render_params)
        else:
            return render(request,
                          template_name, {
                              'query_form': query_form,
                              'EDEN_URL': eden_url
                          },
                          status=400)

    return render(request, template_name, {
        'query_form': query_form,
        'EDEN_URL': eden_url
    })
コード例 #7
0
 def test_1(self):
     victim = ColorRange(count=1)
     self.assertEquals(1, len(victim))
     self.check_color(victim[0])
コード例 #8
0
 def test_names(self):
     names = ColorRange.color_map_names()
     self.assertIn('rainbow', names)
     self.assertIn('spectral', names)
     self.assertIn('ocean', names)
コード例 #9
0
 def test_default_12(self):
     victim = ColorRange(None, 12)
     self.assertEquals(12, len(victim))
     for c in victim:
         self.check_color(c)
     self.check_unique(victim)