pyflightstream.post.custom_polar (stable)¶
Generated from the docstrings at build time: every one of the 10 names in the __all__ of pyflightstream.post.custom_polar has an entry below. The names a guide or an example uses come first; the others follow under Advanced.
Read and write the fixed-width custom polar product.
The format shares the polar's coefficient and reference blocks from
:mod:pyflightstream.post._tables. Its existing import spellings remain
available through :mod:pyflightstream.post.products.
Advanced¶
pyflightstream.post.custom_polar.CUSTOM_DATE_FORMAT
module-attribute
¶
CUSTOM_DATE_FORMAT = '%a %b %d %H:%M:%S %Y'
pyflightstream.post.custom_polar.CUSTOM_REFERENCE_COLUMNS
module-attribute
¶
CUSTOM_REFERENCE_COLUMNS: tuple[str, ...] = (
"MNOM",
*_REFERENCE_COLUMNS,
)
pyflightstream.post.custom_polar.CUSTOM_TITLE_PREFIX
module-attribute
¶
CUSTOM_TITLE_PREFIX = 'FlightStream - '
pyflightstream.post.custom_polar.CustomPolarTable
dataclass
¶
CustomPolarTable(
description: str,
polar: str,
mach: float,
date: str,
group: int,
reference: ReferenceValues,
columns: tuple[str, ...],
rows: list[dict[str, float]],
)
One file of the custom polar format, read back: the header block and the rows.
Attributes:
| Name | Type | Description |
|---|---|---|
description |
str
|
The title line's description, after |
polar |
str
|
The polar identifier, line 2 without its two-digit Mach code. |
mach |
float
|
The nominal Mach number, |
date |
str
|
Line 3 as written; :func: |
group |
int
|
The group number of line 4. |
reference |
ReferenceValues
|
The reference block of line 6. |
columns |
tuple of str
|
The column names of line 9, in the file's order. |
rows |
list of dict
|
One mapping per data row, column name to value. |
pyflightstream.post.custom_polar.custom_count
¶
custom_count(
line: str, path: Path, number: int, what: str
) -> int
Read a count from a custom polar line, naming malformed input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
The line read. |
required |
path
|
Path
|
The file, named in the refusal. |
required |
number
|
int
|
The line's number, named in the refusal. |
required |
what
|
str
|
What the count counts, named in the refusal. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The count. |
Raises:
| Type | Description |
|---|---|
ProductError
|
If the line does not open with the count as digits. |
pyflightstream.post.custom_polar.custom_field
¶
custom_field(value: object) -> str
Right-align one custom polar field to the fixed format width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
The field's value. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The value as text, right-aligned to the format's width. |
Raises:
| Type | Description |
|---|---|
ProductError
|
If the text does not fit the width with a blank before it. |
pyflightstream.post.custom_polar.group_number
¶
group_number(
group: str | int, *, position: int | None = None
) -> int
Return the NUMBER line four of the fixed-width format states for a group.
The format has room for two digits and nothing else, and it was written when
a group WAS a number. A group is named and int(group) on a
name was a bare ValueError that no handler of the products stage catches:
a pproc naming its groups and asking for this format stopped the whole stage.
A named group states its 1-based POSITION in the [groups] table, which is
the number it would have had; the file's NAME carries the alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
str or int
|
The group: a number, or a name. |
required |
position
|
int
|
A named group's 1-based position in the |
None
|
Returns:
| Type | Description |
|---|---|
int
|
The group's number, or its position for a named group. |
Raises:
| Type | Description |
|---|---|
ProductError
|
If the group is a name and no position is given. |
pyflightstream.post.custom_polar.read_custom_polar_format
¶
read_custom_polar_format(
path: str | Path,
) -> CustomPolarTable
Read a custom polar format file back, as :func:write_custom_polar_format specifies it.
The counts the file states are checked against what it holds, which is what makes the round trip (write, read, write again) a proof rather than a re-echo: a reference line, a row or a row's width that does not fit its count is refused naming the line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
A file in the custom format. |
required |
Returns:
| Type | Description |
|---|---|
CustomPolarTable
|
The header block and the rows, each row a mapping of column name to value. |
Raises:
| Type | Description |
|---|---|
ProductError
|
If the file does not have the shape the writer's docstring states. |
pyflightstream.post.custom_polar.write_custom_polar_format
¶
write_custom_polar_format(
path: str | Path,
*,
polar: str | int,
description: str,
group: str | int,
mach: float,
reference: ReferenceValues,
rows: Sequence[Sequence[float]],
date: str | None = None,
configuration: str | None = None,
group_number: int | None = None,
columns: Sequence[str] = COEFFICIENT_COLUMNS,
overwrite: bool = True,
) -> Path
Write one polar of one group in the fixed-width text format the reference tooling opens.
THIS DOCSTRING IS THE SPECIFICATION OF THE FORMAT (PFS-2014.01.02). The
shape was read off a recorded file and is pinned by the committed fixture
tests/tier1_offline/fixtures/custom_polar_format_sample.dat, whose
every value is synthetic; the tier-1 test feeds the fixture's rows
through this writer and requires byte equality with the fixture,
except line 3. The file is ASCII, one line feed per line, a line feed
after the last line, and no line carries a trailing space beyond the
width of its fields:
- line 1: the title,
FlightStream - <description>, with- <configuration>appended where the row states one (FR-94). A character outside ASCII is TRANSLITERATED (:func:_ascii_title): an accent is dropped from its letter, and anything with no ASCII letter under it is written?. THE HEADER IS EXACTLY NINE LINES AND THE READER COUNTS THEM, so the label joins a line rather than taking one of its own; - line 2: the polar identifier followed by the two-digit Mach code,
<polar><round(mach * 100):02d>, the same code the polar table's file name carries (3207at Mach 0.20 is320720); - line 3: the write time,
%a %b %d %H:%M:%S %Yof the local clock (Tue Sep 08 23:41:07 2026, two spaces before the year), ordateverbatim when given, which is how a read file is rewritten byte for byte; - line 4: the number of reference columns as three digits, a space,
and the group number as two digits:
007 01; - line 5: the reference column names
MNOM SREF CREF BREF XMOM YMOM ZMOM, each right-aligned to width 10; - line 6: their values, the nominal Mach and the reference block, each
written as Python writes a float (
50.0and2.526) when it fits with a leading blank; otherwise significant digits are reduced until it fits. Each field is right-aligned to width 10; - line 7: the number of data rows as three digits,
013; - line 8:
len(columns)as three digits,024for the default schema; - line 9: the names in
columns, in the supplied order, each right-aligned to width 10; the default is :data:COEFFICIENT_COLUMNS; - then one line per data row, every number right-aligned to width 10
with up to five decimals. Decimal places are reduced until a leading
blank fits; a value that cannot fit is refused; an infinite value is written NA
(a NaN stays
nan, the declined column). Values follow the order of line 9, the rows in the order given (the stage gives them alpha ascending, as the polar table).
The rows carry the selected columns of the polar table, so the two
files are two serializations of one table; :func:read_custom_polar_format reads this one back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Destination, |
required |
polar
|
str or int
|
The polar identifier, the simulation id. |
required |
description
|
str
|
The row's description, as the polar table carries it. |
required |
group
|
str or int
|
The group number. |
required |
mach
|
float
|
The nominal Mach number, written as |
required |
reference
|
ReferenceValues
|
The reference block. |
required |
rows
|
sequence of sequence of float
|
The coefficient rows, each with |
required |
date
|
str
|
Line 3 as it should be written; the local clock when None. |
None
|
configuration
|
str
|
The row's |
None
|
group_number
|
int
|
The number line 4 states for the group: the post passes the group's
|
None
|
columns
|
sequence of str
|
The data columns of lines 8 and 9, :data: |
COEFFICIENT_COLUMNS
|
overwrite
|
bool
|
Replace a file that already exists, as the writer always did (the default). False refuses an existing file, naming it, before it is replaced. |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
The file written. |
Raises:
| Type | Description |
|---|---|
ProductError
|
If a row has a different length from |