curryer.kernels.classes ======================= .. py:module:: curryer.kernels.classes .. autoapi-nested-parse:: classes @author: Brandon Stone Attributes ---------- .. autoapisummary:: curryer.kernels.classes.logger Classes ------- .. autoapisummary:: curryer.kernels.classes.TypedDataDescriptor curryer.kernels.classes.AbstractKernelProperties curryer.kernels.classes.AbstractKernelWriter Module Contents --------------- .. py:data:: logger .. py:class:: TypedDataDescriptor(*, default, dtype) Data descriptor that enforces typing through casting. .. py:attribute:: _default .. py:attribute:: _dtype .. py:method:: __set_name__(owner, name) .. py:method:: __get__(instance, owner) .. py:method:: __set__(instance, value) .. py:class:: AbstractKernelProperties Kernel properties abstraction. .. py:attribute:: SUPPORTED_INPUT_DATA_TYPES :type: ClassVar :value: None .. py:attribute:: input_data_type :type: enum.Enum .. py:attribute:: input_gap_threshold :type: str :value: None .. py:attribute:: leapsecond_kernel :type: str :value: None .. py:attribute:: version :type: int :value: 1 .. py:attribute:: author :type: str :value: 'LASP' .. py:attribute:: mappings :type: dict :value: None .. py:attribute:: relative_dir :type: pathlib.Path :value: None .. py:method:: __post_init__() .. py:method:: _update_paths(attr_names) .. py:method:: to_dict() :abstractmethod: Convert properties to a dict. .. py:class:: AbstractKernelWriter(properties: AbstractKernelProperties, bin_dir: str = None, parent_dir: str = None) Write to a SPICE kernel. .. py:attribute:: KTYPE :value: None .. py:attribute:: FILE_EXT :value: None .. py:attribute:: properties .. py:attribute:: bin_dir :value: None .. py:attribute:: parent_dir :value: None .. py:attribute:: input_file :value: None .. py:attribute:: setup_file :value: None .. py:attribute:: _temp_kernel_files :value: [] .. py:method:: __call__(input_data: pandas.DataFrame, filename, overwrite=False, append=False) Prepare and then create a kernel file. .. py:method:: prepare_input_data(input_data: pandas.DataFrame) -> list[pandas.DataFrame] :abstractmethod: Prepare an accessor that will provide input data for the kernel. .. py:method:: _chunk_table_by_gaps(table: pandas.DataFrame, index_dt_type='utc') Chunk a table by the `input_gap_threshold` (if any). .. py:method:: write_input_data(fobj_or_str, input_data: pandas.DataFrame) :abstractmethod: Write input data. .. py:method:: _safe_write_input_data(input_data: pandas.DataFrame) Context to write the input data to a CSV file. A temporary file is used if one wasn't defined; it's deleted on exit. :param input_data: Data frame to use as the input data source. :type input_data: pd.DataFrame :Yields: *str* -- Path to the input data file (CSV format). Either `self.input_file`, if it was a str, or a temporary file if it was None. .. py:method:: _auto_shorten_kernel_paths(config, max_length=80) Auto-shorten kernel file paths that exceed SPICE's string length limit. Uses a two-strategy approach: try symlinks first, then try file copying if symlinks fail. Both strategies are enabled by default, but copying can be disabled. :param config: Kernel configuration dictionary :type config: dict :param max_length: Maximum allowed path length (default: 80 for SPICE) :type max_length: int :returns: Modified config with shortened paths :rtype: dict .. rubric:: Notes Created temporary files (symlinks or copies) are tracked in self._temp_kernel_files for automatic cleanup after kernel generation. .. py:method:: _cleanup_temp_kernel_files() Clean up temporary kernel files created during path shortening. These are kernel files that were copied to /tmp to avoid the 80-character path limit. They need to exist during kernel generation but should be cleaned up afterward to avoid accumulating in /tmp. .. rubric:: Notes This method is called automatically in the finally block of write_kernel() to ensure cleanup happens even if kernel generation fails. Errors during cleanup are logged but do not interrupt the process. .. py:method:: prepare_setup_config() Prepare the kernel file's setup configuration (pseudo kernel). .. py:method:: _safe_write_setup_config(setup_txt) Context to write the setup configuration to a text file. A temporary file is used if one wasn't defined; it's deleted on exit. :param setup_txt: Setup configuration text. :type setup_txt: str :Yields: *str* -- Path to the setup file. Either `self.setup_file`, if it was a str, or a temporary file if it was None. .. py:method:: _backup_file(filename) Context to create a temporary backup of a file (if it exists). The original file is restored if an exception occurs. The temporary backup is deleted when the context exits. .. py:method:: _check_write_behavior(kernel_file, overwrite=False, append=False) :staticmethod: Check if file exists and if writer should overwrite vs. append. Required because the SPICE utils have different behavior. .. py:method:: _get_bin(name) Get the path to an executable. .. py:method:: _write_kernel(setup_file, input_file, kernel_file, append=False) :abstractmethod: Write to the kernel. .. py:method:: write_kernel(filename, input_data, setup_txt, overwrite=False, append=False) Create a new kernel or append to an existing one (config setting).