コード例 #1
0
ファイル: test_thermolib.py プロジェクト: Open-MSS/MSS
def test_pressure2flightlevel():
    assert thermolib.pressure2flightlevel(100000 * units.Pa).magnitude == pytest.approx(3.6378724)
    assert thermolib.pressure2flightlevel(75000 * units.Pa).magnitude == pytest.approx(80.91139)
    assert thermolib.pressure2flightlevel(50000 * units.Pa).magnitude == pytest.approx(182.8850)
    assert thermolib.pressure2flightlevel(10000 * units.Pa).magnitude == pytest.approx(530.8279)
    assert thermolib.pressure2flightlevel(3000 * units.Pa).magnitude == pytest.approx(782.4335)
    assert thermolib.pressure2flightlevel(550 * units.Pa).magnitude == pytest.approx(1151.9583)
    assert thermolib.pressure2flightlevel(80 * units.Pa).magnitude == pytest.approx(1626.8966)
    assert thermolib.pressure2flightlevel(40 * units.Pa).magnitude == pytest.approx(1804.2727)
    with pytest.raises(ValueError):
        thermolib.pressure2flightlevel(3.9 * units.Pa)
コード例 #2
0
 def verticalunitsclicked(self, index):
     new_unit = self._suffixes[index]
     old_unit = self.sbPbot.suffix().strip()
     if new_unit == old_unit:
         return
     self.setBotTopLimits("maximum")
     for sb in (self.sbPbot, self.sbPtop):
         sb.setSuffix(" " + new_unit)
         if new_unit == "hPa":
             sb.setValue(
                 thermolib.flightlevel2pressure(
                     convert_to(sb.value(), old_unit, "hft", 1) *
                     units.hft).to(units.hPa).magnitude)
         elif old_unit == "hPa":
             sb.setValue(
                 convert_to(
                     thermolib.pressure2flightlevel(
                         sb.value() * units.hPa).magnitude, "hft",
                     new_unit))
         else:
             sb.setValue(convert_to(sb.value(), old_unit, new_unit, 1))
     self.setBotTopLimits(self.cbVerticalAxis.currentText())
コード例 #3
0
ファイル: flighttrack.py プロジェクト: aravindm711/MSS
    def setData(self, index, value, role=QtCore.Qt.EditRole, update=True):
        """
        Change a data element of the flight track; overrides the
        corresponding QAbstractTableModel method.

        NOTE: Performance computations loose their validity if a change is made.
        """
        if index.isValid() and 0 <= index.row() < len(self.waypoints):
            waypoint = self.waypoints[index.row()]
            column = index.column()
            index2 = index  # in most cases only one field is being changed
            if column == LOCATION:
                waypoint.location = variant_to_string(value)
            elif column == LAT:
                try:
                    # The table fields accept basically any input.
                    # If the string cannot be converted to "float" (raises ValueError), the user input is discarded.
                    value = variant_to_float(value)
                except TypeError as ex:
                    logging.error("unexpected error: %s %s %s %s", type(ex),
                                  ex, type(value), value)
                except ValueError as ex:
                    logging.error("%s", ex)
                else:
                    waypoint.lat = value
                    waypoint.location = ""
                    loc = find_location(waypoint.lat, waypoint.lon, 1e-3)
                    if loc is not None:
                        waypoint.lat, waypoint.lon = loc[0]
                        waypoint.location = loc[1]
                    # A change of position requires an update of the distances.
                    if update:
                        self.update_distances(index.row())
                    # Notify the views that items between the edited item and
                    # the distance item of the corresponding waypoint have been
                    # changed.
                    # Delete the location name -- it won't be valid anymore
                    # after its coordinates have been changed.
                    index2 = self.createIndex(index.row(), LOCATION)
            elif column == LON:
                try:
                    # The table fields accept basically any input.
                    # If the string cannot be converted to "float" (raises ValueError), the user input is discarded.
                    value = variant_to_float(value)
                except TypeError as ex:
                    logging.error("unexpected error: %s %s %s %s", type(ex),
                                  ex, type(value), value)
                except ValueError as ex:
                    logging.error("%s", ex)
                else:
                    waypoint.lon = value
                    waypoint.location = ""
                    loc = find_location(waypoint.lat, waypoint.lon, 1e-3)
                    if loc is not None:
                        waypoint.lat, waypoint.lon = loc[0]
                        waypoint.location = loc[1]
                    if update:
                        self.update_distances(index.row())
                    index2 = self.createIndex(index.row(), LOCATION)
            elif column == FLIGHTLEVEL:
                try:
                    # The table fields accept basically any input.
                    # If the string cannot be converted to "float" (raises ValueError), the user input is discarded.
                    flightlevel = variant_to_float(value)
                    pressure = float(
                        thermolib.flightlevel2pressure(flightlevel *
                                                       units.hft).magnitude)
                except TypeError as ex:
                    logging.error("unexpected error: %s %s %s %s", type(ex),
                                  ex, type(value), value)
                except ValueError as ex:
                    logging.error("%s", ex)
                else:
                    waypoint.flightlevel = flightlevel
                    waypoint.pressure = pressure
                    if update:
                        self.update_distances(index.row())
                    # need to notify view of the second item that has been
                    # changed as well.
                    index2 = self.createIndex(index.row(), PRESSURE)
            elif column == PRESSURE:
                try:
                    # The table fields accept basically any input.
                    # If the string cannot be converted to "float" (raises ValueError), the user input is discarded.
                    pressure = variant_to_float(
                        value) * 100  # convert hPa to Pa
                    if pressure > 200000:
                        raise ValueError
                    flightlevel = float(
                        round(
                            thermolib.pressure2flightlevel(
                                pressure * units.Pa).magnitude))
                    pressure = float(
                        thermolib.flightlevel2pressure(flightlevel *
                                                       units.hft).magnitude)
                except TypeError as ex:
                    logging.error("unexpected error: %s %s %s %s", type(ex),
                                  ex, type(value), value)
                except ValueError as ex:
                    logging.error("%s", ex)
                else:
                    waypoint.pressure = pressure
                    waypoint.flightlevel = flightlevel
                    if update:
                        self.update_distances(index.row())
                    index2 = self.createIndex(index.row(), FLIGHTLEVEL)
            else:
                waypoint.comments = variant_to_string(value)
            self.modified = True
            # Performance computations loose their validity if a change is made.
            if update:
                self.dataChanged.emit(index, index2)
            return True
        return False
コード例 #4
0
ファイル: test_thermolib.py プロジェクト: aravindm711/MSS
def test_pressure2flightlevel2pressure():
    ps = np.arange(5, 105000, 1.)[::-1] * units.Pa
    fs = thermolib.pressure2flightlevel(ps)
    ps_p = thermolib.flightlevel2pressure(fs).magnitude
    assert ps.magnitude == pytest.approx(ps_p)
コード例 #5
0
ファイル: test_thermolib.py プロジェクト: aravindm711/MSS
def test_flightlevel2pressure2flightlevel():
    fs = (np.arange(1, 71000, 1000.) * units.m).to(units.hft)
    ps = thermolib.flightlevel2pressure(fs)
    fs_p = thermolib.pressure2flightlevel(ps).magnitude
    assert fs.magnitude == pytest.approx(fs_p)