Skip to content

Commit

Permalink
Removed the is_output field of FlightPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-david committed Oct 4, 2024
1 parent 1e832a6 commit 03d5dbf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Version 1.8.0
- In mission computation, added CL as possible target for altitude change. (#563)
- New method get_val() in Variable class to get values in different units. (#570)
- Plots now handle horizontal_tail:center new naming. (#546)
- More control of fields in FlightPoint class. (#558)

- Fixed:
- Better NaN detection in inputs. (#532)
Expand Down
23 changes: 4 additions & 19 deletions src/fastoad/model_base/flight_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class _FieldDescriptor:
"""

is_cumulative: Optional[bool] = False
is_output: Optional[bool] = True
unit: Optional[str] = None


Expand Down Expand Up @@ -80,7 +79,6 @@ class FlightPoint:
... "ion_drive_power",
... unit="W",
... is_cumulative=False, # Tells if quantity sums up during mission
... is_output=True, # Tells if quantity is expected as mission output
... )
# Adding a field and defining its type and default value
Expand Down Expand Up @@ -294,15 +292,6 @@ def is_cumulative(cls, field_name) -> Optional[bool]:
"""
return cls._get_field_descriptor(field_name).is_cumulative

@classmethod
def is_output(cls, field_name) -> Optional[bool]:
"""
Tells if asked field should be a mission output.
Returns None if field not found.
"""
return cls._get_field_descriptor(field_name).is_output

@classmethod
def create(cls, data: Mapping) -> "FlightPoint":
"""
Expand Down Expand Up @@ -332,8 +321,7 @@ def add_field(
annotation_type=float,
default_value: Any = None,
unit="-",
cumulative=False,
output=True,
is_cumulative=False,
):
"""
Adds the named field to FlightPoint class.
Expand All @@ -345,8 +333,7 @@ def add_field(
:param default_value: field default value
:param unit: expected unit for the added field. "-" should be provided for a dimensionless
physical quantity. Set to None, when unit concept does not apply.
:param cumulative: True if field value is summed up during mission
:param output: True if field should be written in mission outputs
:param is_cumulative: True if field value is summed up during mission
"""
cls._redeclare_fields()

Expand All @@ -357,9 +344,7 @@ def add_field(
field(
default=default_value,
metadata={
FIELD_DESCRIPTOR: _FieldDescriptor(
unit=unit, is_cumulative=cumulative, is_output=output
)
FIELD_DESCRIPTOR: _FieldDescriptor(unit=unit, is_cumulative=is_cumulative)
},
),
)
Expand Down Expand Up @@ -401,7 +386,7 @@ def _get_field_descriptor(cls, field_name) -> _FieldDescriptor:
Returns the _FieldDescriptor class for provided field_name.
Returns _FieldDescriptor(None, None, None) if field_name is not present.
"""
return cls._get_field_descriptors().get(field_name, _FieldDescriptor(None, None, None))
return cls._get_field_descriptors().get(field_name, _FieldDescriptor(None, None))

@classmethod
def _redeclare_fields(cls):
Expand Down
9 changes: 2 additions & 7 deletions src/fastoad/model_base/tests/test_flight_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,15 @@ def test_scalarize():

def test_descriptors():
FlightPoint.add_field(
"foo", annotation_type=float, default_value=42.0, unit="m", cumulative=False, output=True
"foo", annotation_type=float, default_value=42.0, unit="m", is_cumulative=False
)
# Testing redeclaration
FlightPoint.add_field(
"foo",
annotation_type=float,
default_value=42.0,
unit="slug/ft",
cumulative=True,
output=False,
is_cumulative=True,
)

assert FlightPoint.get_units()["time"] == "s"
Expand All @@ -106,10 +105,6 @@ def test_descriptors():
assert not FlightPoint.is_cumulative("altitude")
assert FlightPoint.is_cumulative("foo")

assert FlightPoint.is_output("time")
assert FlightPoint.is_output("altitude")
assert not FlightPoint.is_output("foo")

FlightPoint.remove_field("foo")

assert FlightPoint.get_unit("altitude") == "m"
Expand Down

0 comments on commit 03d5dbf

Please sign in to comment.