layup.convert
Attributes
Functions
|
Congruence-scale the flattened 6x6 covariance of a structured array. |
|
Shift a barycentric equatorial state to heliocentric by subtracting the Sun. |
|
Rotate an equatorial (coords, vels) state pair into ecliptic coordinates. |
Get the output column names and types for the converted data. |
|
|
Column-stacked (3, N) form of sorcha's per-vector rotations. |
|
Sun equatorial state as a (6, N) array, evaluating the ephemeris once per |
|
Vectorized |
|
Vectorized ecliptic Cartesian -> Keplerian/cometary elements. |
|
Vectorized |
|
Vectorized |
|
Apply the appropriate conversion function to the data |
|
Reference per-row implementation of |
|
Convert a structured numpy array to a different orbital format with support for parallel processing. |
|
Convert an orbit file from one format to another with support for parallel processing. |
Module Contents
- ORBIT_FIT_COLS = [('csq', 'f8'), ('ndof', 'i4'), ('niter', 'i4'), ('method', 'O'), ('flag', 'i4')][source]
- _scale_degree_cov(arr, fmt, factor, mask=None)[source]
Congruence-scale the flattened 6x6 covariance of a structured array.
Applies
diag(s) C diag(s)wheresisfactoron each offmt’s degree columns and 1 elsewhere – i.e. the covariance transform for rescaling those state elements byfactor. Passfactor = 180/piwhen the matching state values were just converted radians->degrees, orpi/180for the inverse. Restricted to rows inmaskwhen given, else applied to the whole column.Relies on the invariant that
element_order[fmt]indexes thecov_i_jrows/cols (see element_order; guarded by test_element_order_matches_degree_columns).
- _subtract_sun(coords, vels, sun)[source]
Shift a barycentric equatorial state to heliocentric by subtracting the Sun.
- _to_ecliptic(coords, vels)[source]
Rotate an equatorial (coords, vels) state pair into ecliptic coordinates.
- get_output_column_names_and_types(primary_id_column_name, has_covariance, extra_cols_to_keep)[source]
Get the output column names and types for the converted data.
- Parameters:
primary_id_column_name (str) – The name of the column in the data that contains the primary ID of the object.
has_covariance (bool) – Whether the data has covariance information.
extra_cols_to_keep (list) – List of tuples containing extra column names and dtypes to keep in the output data.
- Returns:
A tuple containing two elements: - A dictionary mapping orbit formats to the required column names for that format. - A list of default column dtypes for the output data.
- Return type:
tuple
- _rotate_batch(rot_mat, states)[source]
Column-stacked (3, N) form of sorcha’s per-vector rotations.
equatorial_to_ecliptic/ecliptic_to_equatorialuse thev @ rot_matconvention (row vectors); for a state stacked as columns that isrot_mat.T @ states.
- _sun_states_by_epoch(ephem, epochs_mjd)[source]
Sun equatorial state as a (6, N) array, evaluating the ephemeris once per unique epoch (mirrors parse_orbit_row’s per-epoch
sun_dictcache).
- _parse_to_bcart_eq(data, gm_sun, gm_total, sun)[source]
Vectorized
parse_orbit_row: any input FORMAT -> equatorial barycentric Cartesian(coords, vels), each a (3, N) array.Mirrors
sorcha.ephemeris.simulation_parsing.parse_orbit_rowelement for element.universal_cartesiansolves Kepler’s equation with a numba (non- jax) Halley iteration, so element inputs are converted per row; Cartesian and BCART_EQ inputs are fully vectorized.
- _bcart_eq_to_elements(mu, coords, vels, epoch_mjd, cometary)[source]
Vectorized ecliptic Cartesian -> Keplerian/cometary elements.
Closed-form counterpart of
universal_keplerian/universal_cometary(validated to reproduce them to ~1e-11; seetest_convert_vectorized_matches_rowwise). The closed form covers elliptic orbits; the raree >= 1rows are recomputed with the exact routine, which also carries the parabolic/hyperbolic branches.
- _parse_cov_to_bcart_eq(data, gm_sun, gm_total)[source]
Vectorized
parse_covariance_row_to_CART: each row’s flattened input covariance -> equatorial Cartesian, as an (N, 6, 6) array.Cartesian inputs are a batched rotation congruence; element inputs use the per-row (numba)
parse_covariance_row_to_CART(its Jacobian goes throughuniversal_cartesian, which is not jax-traceable). Assumes any degree-format input covariance has already been rescaled to radians by the caller.
- _apply_convert_vectorized(data, convert_to, ephem, gm_sun, gm_total, primary_id_column_name, has_covariance, output_dtype, cols_to_keep)[source]
Vectorized
_apply_convertfor all input/output formats.Numerically reproduces the per-row path (
_apply_convert_rowwise; pinned bytest_convert_vectorized_matches_rowwise) while avoiding the per-row jax dispatch, per-row ephemeris query and per-row struct-array build. ~250x for Cartesian/BCART_EQ inputs (the bulk case), ~30x for element inputs (bounded by the per-rowuniversal_cartesianKepler solve; element-input covariances likewise fall back to the per-row Jacobian).
- _apply_convert(data, convert_to, cache_dir=None, primary_id_column_name=None, extra_cols_to_keep=None)[source]
Apply the appropriate conversion function to the data
- Parameters:
data (numpy structured array) – The data to convert.
convert_to (str) – The orbital format to convert the data to. Must be one of: “BCART”, “BCART_EQ”, “BCOM”, “BKEP”, “CART”, “COM”, “KEP”
cache_dir (str, optional) – The base directory for downloaded files.
primary_id_column_name (str, optional) – The name of the column in the data that contains the primary ID of the object.
extra_cols_to_keep (list, optional) – List of tuples containing extra column names and dtypes to keep in the output data.
- Returns:
data – The converted data
- Return type:
numpy structured array
- _apply_convert_rowwise(data, convert_to, ephem, gm_sun, gm_total, primary_id_column_name, has_covariance, output_dtype, cols_to_keep)[source]
Reference per-row implementation of
_apply_convert.Superseded in production by
_apply_convert_vectorized(which reproduces it to ~1e-11); retained as the equivalence oracle fortest_convert_vectorized_matches_rowwise.
- convert(data, convert_to, num_workers=1, cache_dir=None, primary_id_column_name='ObjID', extra_cols_to_keep=None)[source]
Convert a structured numpy array to a different orbital format with support for parallel processing.
- Parameters:
data (numpy structured array) – The data to convert.
convert_to (str) – The format to convert the data to. Must be one of: “BCART_EQ”, “BCOM”, “BKEP”, “CART”, “COM”, “KEP”
num_workers (int, optional (default=1)) – The number of workers to use for parallel processing.
cache_dir (str, optional) – The base directory for downloaded files.
primary_id_column_name (str, optional (default="ObjID")) – The name of the column in the data that contains the primary ID of the object.
extra_cols_to_keep (list, optional) – List of tuples containing additional column names and dtypes to keep in the output data.
- Returns:
data – The converted data
- Return type:
numpy structured array
- convert_cli(input: str, output_file_stem: str, convert_to: Literal['BCART', 'BCART_EQ', 'BCOM', 'BKEP', 'CART', 'COM', 'KEP'], file_format: Literal['csv', 'hdf5'] = 'csv', chunk_size: int = 10000, num_workers: int = -1, cli_args: dict = None)[source]
Convert an orbit file from one format to another with support for parallel processing.
Note that the output file will be written in the caller’s current working directory.
- Parameters:
input (str) – The path to the input file.
output_file_stem (str) – The stem of the output file.
convert_to (str) – The format to convert the input file to. Must be one of: “BCART”, “BCART_EQ”, “BCOM”, “BKEP”, “CART”, “COM”, “KEP”
file_format (str, optional (default="csv")) – The format of the output file. Must be one of: “csv”, “hdf5”
chunk_size (int, optional (default=10_000)) – The number of rows to read in at a time.
num_workers (int, optional (default=-1)) – The number of workers to use for parallel processing of the individual chunk. If -1, the number of workers will be set to the number of CPUs on the system.
cli_args (argparse, optional (default=None)) – The argparse object that was created when running from the CLI.