示例#1
0
    def redraw_yaxis(self):
        """ Redraws the y-axis on map after setting the values from sideview options dialog box"""

        self.checknconvert()
        vaxis = self.settings_dict["vertical_axis"]
        if vaxis == "pressure":
            # Compute the position of major and minor ticks. Major ticks are labelled.
            major_ticks = self._pres_maj[(self._pres_maj <= self.p_bot) & (self._pres_maj >= self.p_top)]
            minor_ticks = self._pres_min[(self._pres_min <= self.p_bot) & (self._pres_min >= self.p_top)]
            labels = [f"{int(_x / 100)}"
                      if (_x / 100) - int(_x / 100) == 0 else f"{float(_x / 100)}" for _x in major_ticks]
            if len(labels) > 20:
                labels = ["" if x.split(".")[-1][0] in "975" else x for x in labels]
            elif len(labels) > 10:
                labels = ["" if x.split(".")[-1][0] in "9" else x for x in labels]
            self.ax.set_ylabel("pressure (hPa)")
        elif vaxis == "pressure altitude":
            bot_km = thermolib.pressure2flightlevel(self.p_bot) * 0.03048
            top_km = thermolib.pressure2flightlevel(self.p_top) * 0.03048
            ma_dist, mi_dist = 4, 1.0
            if (top_km - bot_km) <= 20:
                ma_dist, mi_dist = 1, 0.5
            elif (top_km - bot_km) <= 40:
                ma_dist, mi_dist = 2, 0.5
            major_heights = np.arange(0, top_km + 1, ma_dist)
            minor_heights = np.arange(0, top_km + 1, mi_dist)
            major_ticks = thermolib.flightlevel2pressure_a(major_heights / 0.03048)
            minor_ticks = thermolib.flightlevel2pressure_a(minor_heights / 0.03048)
            labels = major_heights
            self.ax.set_ylabel("pressure altitude (km)")
        elif vaxis == "flight level":
            bot_km = thermolib.pressure2flightlevel(self.p_bot) * 0.03048
            top_km = thermolib.pressure2flightlevel(self.p_top) * 0.03048
            ma_dist, mi_dist = 50, 10
            if (top_km - bot_km) <= 10:
                ma_dist, mi_dist = 20, 10
            elif (top_km - bot_km) <= 40:
                ma_dist, mi_dist = 40, 10
            major_fl = np.arange(0, 2132, ma_dist)
            minor_fl = np.arange(0, 2132, mi_dist)
            major_ticks = thermolib.flightlevel2pressure_a(major_fl)
            minor_ticks = thermolib.flightlevel2pressure_a(minor_fl)
            labels = major_fl
            self.ax.set_ylabel("flight level (hft)")
        else:
            raise RuntimeError("Unsupported vertical axis type: '{}'".format(vaxis))

        # Draw ticks and tick labels.
        self.ax.set_yticks(minor_ticks, minor=True)
        self.ax.set_yticks(major_ticks, minor=False)
        self.ax.set_yticklabels([], minor=True, fontsize=10)
        self.ax.set_yticklabels(labels, minor=False, fontsize=10)
        self.ax.set_ylim(self.p_bot, self.p_top)
示例#2
0
def test_flightlevel2pressure():
    assert tl.flightlevel2pressure(182.8850) == pytest.approx(50000)
    assert tl.flightlevel2pressure(530.8279) == pytest.approx(10000)
    assert tl.flightlevel2pressure(782.4335) == pytest.approx(3000)
    assert tl.flightlevel2pressure(1151.9583) == pytest.approx(550)
    assert tl.flightlevel2pressure(1626.8966) == pytest.approx(80)
    assert tl.flightlevel2pressure(1804.2727) == pytest.approx(40)
    with pytest.raises(ValueError):
        tl.flightlevel2pressure(72000 / 30.48)
    fls = np.arange(0, 71000, 1000) / 30.48
    assert np.allclose([tl.flightlevel2pressure(_x) for _x in fls],
                       tl.flightlevel2pressure_a(fls))
示例#3
0
def test_flightlevel2pressure():
    assert tl.flightlevel2pressure(182.8913020844737) == pytest.approx(50000)
    assert tl.flightlevel2pressure(530.8390754393636) == pytest.approx(10000)
    assert tl.flightlevel2pressure(782.4486256345779) == pytest.approx(3000)
    assert tl.flightlevel2pressure(1151.9849776810745) == pytest.approx(550)
    assert tl.flightlevel2pressure(1626.9512858549855) == pytest.approx(80)
    assert tl.flightlevel2pressure(1804.3261490037305) == pytest.approx(40)
    with pytest.raises(ValueError):
        tl.flightlevel2pressure(72000 / 30.48)
    fls = np.arange(0, 71000, 1000) / 30.48
    assert np.allclose([tl.flightlevel2pressure(_x) for _x in fls],
                       tl.flightlevel2pressure_a(fls))
示例#4
0
 def _prepare_datafields(self):
     """Computes potential temperature from pressure and temperature if
     it has not been passed as a data field.
     """
     if self.name[-2:] == "al":
         # CAMS Regional Ensemble doesn't provide any pressure information,
         # but we want to plot vertical sections anyways, so we do a
         # poor-man's on-the-fly conversion here.
         if 'air_pressure' not in self.data:
             self.data["air_pressure"] = np.empty_like(self.data[self.dataname])
             self.data['air_pressure'][:] = thermolib.flightlevel2pressure_a(convert_to(
                 self.driver.vert_data[::-self.driver.vert_order, np.newaxis],
                 self.driver.vert_units, "hft"))
示例#5
0
    def redraw_xaxis(self, lats, lons, times):
        """Redraw the x-axis of the side view on path changes. Also remove
           a vertical section image if one exists, as it is invalid after
           a path change.
        """
        logging.debug("redrawing x-axis")

        # Re-label x-axis.
        self.ax.set_xlim(0, len(lats) - 1)
        # Set xticks so that they display lat/lon. Plot "numlabels" labels.
        lat_inds = np.arange(len(lats))
        tick_index_step = len(lat_inds) // self.numlabels
        self.ax.set_xticks(lat_inds[::tick_index_step])
        if self.waypoints_model is not None and self.waypoints_model.performance_settings["visible"]:
            self.ax.set_xticklabels(["{:2.1f}, {:2.1f}\n{}Z".format(d[0], d[1], d[2].strftime("%H:%M"))
                                     for d in zip(lats[::tick_index_step],
                                                  lons[::tick_index_step],
                                                  times[::tick_index_step])],
                                    rotation=25, fontsize=10, horizontalalignment="right")
        else:
            self.ax.set_xticklabels(["{:2.1f}, {:2.1f}".format(d[0], d[1])
                                     for d in zip(lats[::tick_index_step],
                                                  lons[::tick_index_step],
                                                  times[::tick_index_step])],
                                    rotation=25, fontsize=10, horizontalalignment="right")

        for _line in self.ceiling_alt:
            _line.remove()
        self.ceiling_alt = []
        if self.waypoints_model is not None and self.waypoints_interactor is not None:
            vertices = self.waypoints_interactor.pathpatch.get_path().vertices
            vx, vy = list(zip(*vertices))
            wpd = self.waypoints_model.all_waypoint_data()
            xs, ys = [], []
            aircraft = self.waypoints_model.performance_settings["aircraft"]
            for i in range(len(wpd) - 1):
                weight = np.linspace(wpd[i].weight, wpd[i + 1].weight, 5, endpoint=False)
                ceil = [aircraft.get_ceiling_altitude(_w) for _w in weight]
                xs.extend(np.linspace(vx[i], vx[i + 1], 5, endpoint=False))
                ys.extend(ceil)
            xs.append(vx[-1])
            ys.append(aircraft.get_ceiling_altitude(wpd[-1].weight))

            self.ceiling_alt = self.ax.plot(
                xs, thermolib.flightlevel2pressure_a(np.asarray(ys)),
                color="k", ls="--")
            self.update_ceiling(
                self.settings_dict["draw_ceiling"] and self.waypoints_model.performance_settings["visible"],
                self.settings_dict["colour_ceiling"])

        self.draw()
示例#6
0
def test_pressure2flightlevel2pressure():
    ps = np.arange(5, 105000, 1.)[::-1]
    fs = tl.pressure2flightlevel_a(ps)
    ps_p = tl.flightlevel2pressure_a(fs)
    assert ps == pytest.approx(ps_p)
示例#7
0
def test_flightlevel2pressure2flightlevel():
    fs = np.arange(1, 71000, 1000.) / 30.48
    ps = tl.flightlevel2pressure_a(fs)
    fs_p = tl.pressure2flightlevel_a(ps)
    assert fs == pytest.approx(fs_p)