Exemple #1
0
def _wind_speed_axes_labels(ax, plot_data, theme):
    ax["mps"].set_title(
        "Winds at Sand Heads",
        fontproperties=theme.FONTS["axes title"],
        color=theme.COLOURS["text"]["axes title"],
    )
    ax["mps"].set_xlim(plot_data.hrdps_speed.time.values[0],
                       plot_data.hrdps_speed.time.values[-1])
    mps_limits = numpy.array((0, 20))
    ax["mps"].set_ylabel(
        f'{plot_data.hrdps_speed.attrs["long_name"]} '
        f'[{plot_data.hrdps_speed.attrs["units"]}]',
        fontproperties=theme.FONTS["axis"],
        color=theme.COLOURS["text"]["axis"],
    )
    ax["mps"].set_ylim(mps_limits)
    ax["knots"].set_ylabel(
        f'{plot_data.hrdps_speed.attrs["long_name"]} [knots]',
        fontproperties=theme.FONTS["axis"],
        color=theme.COLOURS["text"]["axis"],
    )
    ax["knots"].set_ylim(unit_conversions.mps_knots(mps_limits))
    ax["mps"].legend(loc="best")
    ax["mps"].grid(axis="both")
    for k in ax:
        theme.set_axis_colors(ax[k])
Exemple #2
0
def _render_entry_content(feed, max_ssh_info, config):
    max_ssh_time_local = arrow.get(max_ssh_info["max_ssh_time"]).to("local")
    feed_config = config["storm surge feeds"]["feeds"][feed]
    tide_gauge_stn = feed_config["tide gauge stn"]
    max_ssh_info.update(_calc_wind_4h_avg(feed, max_ssh_info["max_ssh_time"], config))
    values = {
        "city": feed_config["city"],
        "tide_gauge_stn": tide_gauge_stn,
        "conditions": {
            tide_gauge_stn: {
                "risk_level": max_ssh_info["risk_level"],
                "max_ssh_msl": max_ssh_info["max_ssh"],
                "wind_speed_4h_avg_kph": converters.mps_kph(
                    max_ssh_info["wind_speed_4h_avg"]
                ),
                "wind_speed_4h_avg_knots": converters.mps_knots(
                    max_ssh_info["wind_speed_4h_avg"]
                ),
                "wind_dir_4h_avg_heading": converters.bearing_heading(
                    converters.wind_to_from(max_ssh_info["wind_dir_4h_avg"])
                ),
                "wind_dir_4h_avg_bearing": converters.wind_to_from(
                    max_ssh_info["wind_dir_4h_avg"]
                ),
                "max_ssh_time": max_ssh_time_local,
                "max_ssh_time_tzname": max_ssh_time_local.tzinfo.tzname(
                    max_ssh_time_local.datetime
                ),
                "humanized_max_ssh_time": converters.humanize_time_of_day(
                    max_ssh_time_local
                ),
            }
        },
    }
    template = mako.template.Template(
        filename=os.path.join(
            os.path.dirname(__file__),
            config["storm surge feeds"]["feed entry template"],
        ),
        input_encoding="utf-8",
    )
    rendered_rst = template.render(**values)
    html = docutils.core.publish_parts(rendered_rst, writer_name="html")
    return html["body"]
def _render_entry_content(feed, max_ssh_info, config):
    max_ssh_time_local = arrow.get(max_ssh_info['max_ssh_time']).to('local')
    feed_config = config['storm surge feeds']['feeds'][feed]
    tide_gauge_stn = feed_config['tide gauge stn']
    max_ssh_info.update(
        _calc_wind_4h_avg(feed, max_ssh_info['max_ssh_time'], config))
    values = {
        'city': feed_config['city'],
        'tide_gauge_stn': tide_gauge_stn,
        'conditions': {
            tide_gauge_stn: {
                'risk_level':
                max_ssh_info['risk_level'],
                'max_ssh_msl':
                max_ssh_info['max_ssh'],
                'wind_speed_4h_avg_kph':
                converters.mps_kph(max_ssh_info['wind_speed_4h_avg']),
                'wind_speed_4h_avg_knots':
                converters.mps_knots(max_ssh_info['wind_speed_4h_avg']),
                'wind_dir_4h_avg_heading':
                converters.bearing_heading(
                    converters.wind_to_from(max_ssh_info['wind_dir_4h_avg'])),
                'wind_dir_4h_avg_bearing':
                converters.wind_to_from(max_ssh_info['wind_dir_4h_avg']),
                'max_ssh_time':
                max_ssh_time_local,
                'max_ssh_time_tzname':
                max_ssh_time_local.tzinfo.tzname(max_ssh_time_local.datetime),
                'humanized_max_ssh_time':
                converters.humanize_time_of_day(max_ssh_time_local),
            }
        }
    }
    template = mako.template.Template(filename=os.path.join(
        os.path.dirname(__file__),
        config['storm surge feeds']['feed entry template']),
                                      input_encoding='utf-8')
    rendered_rst = template.render(**values)
    html = docutils.core.publish_parts(rendered_rst, writer_name='html')
    return html['body']
Exemple #4
0
def test_mps_knots_ndarray():
    knots = unit_conversions.mps_knots(np.array([0, 1]))
    np.testing.assert_allclose(knots, np.array([0, 1.94384]), rtol=1e-05)
Exemple #5
0
def test_mps_knots(m_per_s, expected):
    np.testing.assert_allclose(unit_conversions.mps_knots(m_per_s),
                               expected,
                               rtol=1e-05)