Skip to content

Commit

Permalink
rename PSModel -> PSFlight
Browse files Browse the repository at this point in the history
  • Loading branch information
zebengberg committed Aug 25, 2023
1 parent 28dec66 commit 8d5780d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 26 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Implement a Poll-Schumann (`PSGrid`) theoretical aircraft performance over a gri
### Breaking changes

- Move the `pycontrails.models.aircraft_performance` module to `pycontrails.core.aircraft_performance`.
- Rename `PSModel` -> `PSFlight`.

### Fixes

Expand All @@ -29,7 +30,7 @@ Implement a Poll-Schumann (`PSGrid`) theoretical aircraft performance over a gri
- Add `set_attr` parameter to `Models.get_source_param`.
- Better handle `source`, `source.attrs`, and `params` customizations in `CocipGrid`.
- Include additional classes and functions in the `pycontrails.models.emissions` module.
- Hardcode the paths to the static data files used in the `Emissions` and `PSModel` models. Previously these were configurable by model parameters.
- Hardcode the paths to the static data files used in the `Emissions` and `PSFlight` models. Previously these were configurable by model parameters.
- Add `altitude_ft` parameter to the `GeoVectorDataset` constructor. Warn if at least two of `altitude_ft`, `altitude`, and `level` are provided.
- Allow instantiation of `Model` instances with `params: ModelParams`. Previously, the `params` parameter was required to be a `dict`. The current implementation checks that the `params` parameter is either a `dict` or has type `default_params` on the `Model` class.

Expand Down Expand Up @@ -87,7 +88,7 @@ Add experimental support for simulating radiative effects due to contrail-contra
### Fixes

- Narrow type hints on the ABC `AircraftPerformance` model. The `AircraftPerformance.eval` method requires a `Flight` object for the `source` parameter.
- In `PSModel.eval`, explicitly set any aircraft performance data at waypoints with zero true airspeed to `np.nan`. This avoids numpy `RuntimeWarning`s without affecting the results.
- In `PSFlight.eval`, explicitly set any aircraft performance data at waypoints with zero true airspeed to `np.nan`. This avoids numpy `RuntimeWarning`s without affecting the results.
- Fix corner-case in the `polygon.buffer_and_clean` function in which the polygon created by buffering the `opencv` contour is not valid. Now a second attempt to buffer the polygon is made with a smaller buffer distance.
- Ignore RuntimeError raised in `scipy.optimize.newton` if the maximum number of iterations is reached before convergence. This is a workaround for occasional false positive convergence warnings. The pycontrails use-case may be related to [this GitHub issue](https://github.com/scipy/scipy/issues/8904).
- Update the `Models.__init__` warnings when `humidity_scaling` is not provided. The previous warning provided an outdated code example.
Expand Down Expand Up @@ -203,7 +204,7 @@ Support for the [Poll-Schumann aircraft performance model](https://doi.org/10.10

- Use `ruff` in place of `pydocstyle` for linting docstrings.
- Use `ruff` in place of `isort` for sorting imports.
- Update the `AircraftPerformance` template based on the patterns used in the new `PSModel` class. This may change again in the future.
- Update the `AircraftPerformance` template based on the patterns used in the new `PSFlight` class. This may change again in the future.

## v0.43.0

Expand Down
4 changes: 2 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ Aircraft Performance
:toctree: api/

core.aircraft_performance
models.ps_model.PSModelParams
models.ps_model.PSModel
models.ps_model.PSFlightParams
models.ps_model.PSFlight
models.ps_model.PSGrid
models.ps_model.PSAircraftEngineParams
models.ps_model.ps_nominal_grid
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/CoCiP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@
"metadata": {},
"outputs": [],
"source": [
"from pycontrails.models.ps_model import PSModel"
"from pycontrails.models.ps_model import PSFlight"
]
},
{
Expand All @@ -1250,7 +1250,7 @@
" met=met,\n",
" rad=rad,\n",
" humidity_scaling=ConstantHumidityScaling(rhi_adj=0.99),\n",
" aircraft_performance=PSModel(),\n",
" aircraft_performance=PSFlight(),\n",
")\n",
"\n",
"output_flight = cocip.eval(source=fl)"
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/advection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"from pycontrails.models.cocip import Cocip\n",
"from pycontrails.models.dry_advection import DryAdvection\n",
"from pycontrails.models.humidity_scaling import ConstantHumidityScaling\n",
"from pycontrails.models.ps_model import PSModel\n",
"from pycontrails.models.ps_model import PSFlight\n",
"from pycontrails.physics import units\n",
"\n",
"plt.rcParams[\"figure.figsize\"] = (10, 6)"
Expand Down Expand Up @@ -161,7 +161,7 @@
" \"dt_integration\": dt_integration,\n",
" \"max_age\": max_age,\n",
" \"humidity_scaling\": ConstantHumidityScaling(rhi_adj=0.9),\n",
" \"aircraft_performance\": PSModel(),\n",
" \"aircraft_performance\": PSFlight(),\n",
"}\n",
"cocip = Cocip(met, rad, params)\n",
"cocip.eval(fl)\n",
Expand Down
6 changes: 3 additions & 3 deletions pycontrails/models/ps_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
load_aircraft_engine_params,
)
from pycontrails.models.ps_model.ps_grid import PSGrid, ps_nominal_grid
from pycontrails.models.ps_model.ps_model import PSModel, PSModelParams
from pycontrails.models.ps_model.ps_model import PSFlight, PSFlightParams

__all__ = [
"PSModel",
"PSModelParams",
"PSFlight",
"PSFlightParams",
"PSAircraftEngineParams",
"PSGrid",
"load_aircraft_engine_params",
Expand Down
2 changes: 1 addition & 1 deletion pycontrails/models/ps_model/ps_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def eval(
if isinstance(self.source, Flight):
warnings.warn(
"The 'PSGrid' model is not intended to support 'Flight' objects as 'source' "
"data. Instead, use the 'PSModel'."
"data. Instead, use the 'PSFlight' model."
)

# Extract the relevant source data
Expand Down
10 changes: 5 additions & 5 deletions pycontrails/models/ps_model/ps_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@


@dataclasses.dataclass
class PSModelParams(AircraftPerformanceParams):
"""Default parameters for :class:`PSModel`."""
class PSFlightParams(AircraftPerformanceParams):
"""Default parameters for :class:`PSFlight`."""

#: Clip the ratio of the overall propulsion efficiency to the maximum propulsion
#: efficiency to always exceed this value.
eta_over_eta_b_min: float | None = 0.5


class PSModel(AircraftPerformance):
class PSFlight(AircraftPerformance):
"""Simulate aircraft performance using Poll-Schumann (PS) model.
References
Expand All @@ -51,11 +51,11 @@ class PSModel(AircraftPerformance):
descent and holding. Aero. J., submitted.
"""

name = "PSModel"
name = "PSFlight"
long_name = "Poll-Schumann Aircraft Performance Model"
met_variables = (AirTemperature,)
optional_met_variables = EastwardWind, NorthwardWind
default_params = PSModelParams
default_params = PSFlightParams

aircraft_engine_params: Mapping[str, PSAircraftEngineParams]

Expand Down
16 changes: 8 additions & 8 deletions tests/unit/test_ps_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def test_aircraft_type_coverage() -> None:
ps_model = ps.PSModel()
ps_model = ps.PSFlight()

# There are currently 53 aircraft types supported by the PS model
assert len(ps_model.aircraft_engine_params) == 53
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_ps_model() -> None:
dv_dt = np.array([0.0, 0.0])

# Extract aircraft properties for aircraft type
ps_model = ps.PSModel()
ps_model = ps.PSFlight()
atyp_param = ps_model.aircraft_engine_params[aircraft_type_icao]

# Test Reynolds Number
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_normalised_aircraft_performance_curves() -> None:
air_pressure = units.ft_to_pl(altitude_ft) * 100.0

# Extract aircraft properties for aircraft type
ps_model = ps.PSModel()
ps_model = ps.PSFlight()
atyp_param = ps_model.aircraft_engine_params[aircraft_type_icao]
mach_num_design_opt = atyp_param.m_des

Expand Down Expand Up @@ -184,7 +184,7 @@ def test_total_fuel_burn(load_factor: float) -> None:
flight["true_airspeed"] = units.knots_to_m_per_s(flight["speed"])

# Aircraft performance model
ps_model = ps.PSModel()
ps_model = ps.PSFlight()
out = ps_model.eval(flight)

if load_factor == 0.5:
Expand All @@ -199,7 +199,7 @@ def test_total_fuel_burn(load_factor: float) -> None:

def test_fuel_clipping() -> None:
"""Check the ps.correct_fuel_flow function."""
ps_model = ps.PSModel()
ps_model = ps.PSFlight()
atyp_param = ps_model.aircraft_engine_params["A320"]

# Erroneous fuel flow data
Expand All @@ -226,7 +226,7 @@ def test_fuel_clipping() -> None:


def test_zero_tas_waypoints() -> None:
"""Confirm the PSModel gracefully handles waypoints with zero true airspeed."""
"""Confirm the PSFlight gracefully handles waypoints with zero true airspeed."""
df_flight = pd.read_csv(get_static_path("flight.csv"))
df_flight["longitude"].iat[48] = df_flight["longitude"].iat[47]
df_flight["latitude"].iat[48] = df_flight["latitude"].iat[47]
Expand All @@ -239,10 +239,10 @@ def test_zero_tas_waypoints() -> None:
assert flight["true_airspeed"][47] == 0.0

# Aircraft performance model
ps_model = ps.PSModel()
ps_model = ps.PSFlight()
out = ps_model.eval(flight)

# Confirm the PSModel sets NaN values for the zero TAS waypoint
# Confirm the PSFlight sets NaN values for the zero TAS waypoint
keys = "fuel_flow", "engine_efficiency", "thrust"
for key in keys:
assert np.isnan(out[key][47])
Expand Down

0 comments on commit 8d5780d

Please sign in to comment.