pds.naif_pds4_bundler.utils package

Submodules

pds.naif_pds4_bundler.utils.decorators module

Decorator module that contains decorator functions.

pds.naif_pds4_bundler.utils.decorators.spice_exception_handler(func)[source]

SPICE Exception handler.

This function is used as a decorator to catch and display SpiceyPy errors.

A wrapper is inserted as a workaround to unmask the docstring of the wrapped function. See: https://github.com/sphinx-doc/sphinx/issues/3783

pds.naif_pds4_bundler.utils.files module

File and Text Management Functions to support NPB Classes.

pds.naif_pds4_bundler.utils.files.add_carriage_return(line, eol, setup=False)[source]

Adds Carriage Return (<CR>) to a line.

Parameters:
  • line (str) – Input line

  • eol (str) – EOL defined by the configuration file

Returns:

Input line with CR

Return type:

str

pds.naif_pds4_bundler.utils.files.add_crs_to_file(file, eol, setup=False)[source]

Adds Carriage Return (<CR>) to a file.

Parameters:
  • line (str) – Input file

  • eol (str) – End of Line character as indicated by the configuration file

Raise:

If CR cannot be added to the file

pds.naif_pds4_bundler.utils.files.check_badchar(file)[source]

Check NON-ASCII characters for a file.

Parameters:

file – Path to file to check

Returns:

Resulting error messages

Return type:

list

pds.naif_pds4_bundler.utils.files.check_binary_endianness(path)[source]

Check if the SPICE Kernel has the adequate architecture.

PDS4 Bundles require LTL-IEEE binary kernels and PDS3 data sets require BIG-IEEE binary kernels. This behavior can be changed via configuration.

This method ensures that the endianness of binary kernels is the appropriate one according to the configuration.

Parameters:

path (str) – Binary SPICE kernel path

Returns:

Error message if error present

Return type:

list

pds.naif_pds4_bundler.utils.files.check_consecutive(lst)[source]

Check if a list has consecutive numbers.

Check if a list of names with enumeration include all the elements in such a way that the enumeration contains all expected numbers.

Parameters:

lst (list) – List of names that include an enumeration

Returns:

Check if the list has a complete enumeration

Return type:

bool

pds.naif_pds4_bundler.utils.files.check_eol(file, eol)[source]

Check file EOL.

Parameters:
  • file – Path to file to check

  • eol – Expected End of Line

Returns:

Resulting error messages

Return type:

str

pds.naif_pds4_bundler.utils.files.check_kernel_integrity(path)[source]

Check if the SPICE Kernel has the adequate architecture.

All SPICE kernels must have a NAIF file ID word as the first “word” on the first line of the kernel. This “word” describes the architecture of the kernel.

A binary kernel could have the following architectures:

  • DAF: The file is based on the DAF architecture.

  • DAS: The file is based on the DAS architecture.

  • XFR: The file is in a SPICE transfer file format.

For an archive only DAF is acceptable.

Text kernels must have KPL (Kernel Pool File) architecture.

NPB checks if binary kernels have a DAF architecture and text kernels a KPL architecture.

Parameters:

path (str) – SPICE Kernel or ORBNUM path

Returns:

Error message if error present

Return type:

str

pds.naif_pds4_bundler.utils.files.check_line_length(file)[source]

Check SPICE text kernel line length.

Parameters:

file – Path to file to check

Returns:

Resulting error messages

Return type:

str

pds.naif_pds4_bundler.utils.files.check_list_duplicates(list_of_elements)[source]

Check if given list contains any duplicates.

Parameters:

list_of_elements (list) – List of SPICE kernel names

Returns:

True if the input list contains duplicates, False otherwise

Return type:

bool

pds.naif_pds4_bundler.utils.files.check_permissions(path)[source]

Check if the file has read permissions.

This method ensures that the file has the adequate file permissions.

Parameters:

path (str) – file path

Returns:

Error message if error present

Return type:

none

pds.naif_pds4_bundler.utils.files.checksum_from_label(path)[source]

Extract checksum from a label rather than calculating it.

Parameters:

path (str) – Product path

Returns:

MD5 Sum for the file indicated by path

Return type:

str

pds.naif_pds4_bundler.utils.files.checksum_from_registry(path, working_directory)[source]

Extract checksum from the checksum registry.

All the checksum registries will be checked.

Parameters:
  • path (str) – Product path

  • working_directory (str) – checksum registry path

Returns:

MD5 Sum for the file indicated by path

Return type:

str

pds.naif_pds4_bundler.utils.files.compare_files(fromfile, tofile, dir, display)[source]

Compare two files.

Compares two files and provides the logic to determine whether if the comparison should be added to the log or to an individual file with the comparison. The default name of the possible resulting file is:

diff_`fromfile'[extension removed]_`tofile'[extension_removed].html

The format for the log output is ASCII and follows a simplified Unix diff format.

The format for the file output is HTML and mocks a simplified Unix GUI diff tool such as tkdiff.

Parameters:
  • fromfile (str) – Path of first file to be compared

  • tofile (str) – Path of second file to be compared

  • dir (str) – Resulting diff files destination directory

  • display (str) – Indication if the fie will only be written in log or if a specific diff file will be generated

Returns:

True if the files are different, False if they are the same.

Return type:

bool

pds.naif_pds4_bundler.utils.files.copy(src, dest)[source]

Creates a directory and raises an error if the directory exists.

Parameters:
  • src (str) – Source directory with path.

  • dest (str) – Destination directory with path.

pds.naif_pds4_bundler.utils.files.etree_to_dict(etree)[source]

Convert between XML and JSON.

The following XML-to-Python-dict snippet parses entities as well as attributes following this XML-to-JSON “specification”. It is the most general solution handling all cases of XML.

https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html

Parameters:

etree (dict) – Element Tree read from XML file

Returns:

XML File converted into a JSON file

Return type:

dict

pds.naif_pds4_bundler.utils.files.extension_to_type(kernel)[source]

Given a SPICE kernel provide the SPICE kernel type.

Parameters:

kernel (str) – SPICE Kernel name

Returns:

SPICE Kernel type of the input SPICE kernel name

Return type:

str

pds.naif_pds4_bundler.utils.files.extract_comment(path, handle=False)[source]

Extract comment from SPICE DAF file.

Parameters:

path (str) – Path of SPICE kernel

Returns:

SPICE kernel comment

Return type:

list

pds.naif_pds4_bundler.utils.files.fill_template(object, product_file, product_dictionary)[source]

Fill a template with uppercase keywords preceded with $.

Parameters:
  • object (object) – List object

  • product_file (str) – Resulting file

  • product_dictionary (dict) – Dictionary of keys to replace

pds.naif_pds4_bundler.utils.files.format_multiple_values(value)[source]

Reformat multi-line key value for PDS3 labels.

For example if the MAKLABEL key value has multiple entries, it needs to be reformatted.

Parameters:

value (str) – PDS3 key value

Returns:

PDS3 key value reformatted

Return type:

str

pds.naif_pds4_bundler.utils.files.get_context_products(setup)[source]

Obtain PDS4 Context Products.

Obtain the context products from the PDS4 registered context products template or from the XML configuration file.

Parameters:

setup – Setup object already constructed

Returns:

dictionary with the JSON structure of the bundle context products

Return type:

dict

pds.naif_pds4_bundler.utils.files.get_latest_kernel(kernel_type, paths, pattern, dates=False, excluded_kernels=False, mks=False)[source]

Get the latest kernel given a type and a pattern.

Returns the name of the latest SPICE kernel of a given type present in the path. This function is exclusively used find the latest version of the kernels to be included in a meta-kernel.

Parameters:
  • kernel_type (str) – SPICE Kernel type which also defines the subdirectory name.

  • paths (str) – List of paths to the roots of the SPICE Kernels directories where the kernels are store in a subdirectory named “type”.

  • pattern (str) – Patterns to search for that defines the kernel “type” file naming scheme. This pattern follows the format of the meta-kernel grammar provided in the XML configuration file

  • dates (bool) – Indicates that the pattern of the kernel includes dates and that the last version of each kernel with a date has to be included. If this parameter is set to False then only the latest date and latest version is included

  • excluded_kernels (list) – Indicates that a specific kernel might have to be excluded from the search.

  • mks (list) – Indicates that the kernels present in the list of provided meta-kernels have to be included for consideration to obtain the latest version of the given kernel

Returns:

Name of the latest kernels as specified by the pattern.

Return type:

list

pds.naif_pds4_bundler.utils.files.kernel_name(path)[source]

List sorting function.

Parameters:

path (str) – path to be sorted

Returns:

sorting result

Return type:

str

pds.naif_pds4_bundler.utils.files.match_patterns(name, name_w_pattern, patterns)[source]

March patterns to filename.

Given a SPICE kernel name, a SPICE Kernel name with patterns, and the possible patterns, provide a dictionary with the patterns as keys and the patterns values as value after matching it between the SPICE Kernel name with patterns and without patterns.

For example, given the following arguments:

  • name: insight_v01.tm

  • name_w_pattern: insight_v$VERSION.tm

The function will return: {VERSION: '01'}

Parameters:
  • name (str) – Name of the SPICE Kernel

  • name_w_pattern (str) – Name of the SPICE Kernel with patterns

  • patterns (list) – List of the possible patterns present in the SPICE Kernel name with patterns

Returns:

Dictionary providing the patterns and their value as defined by the SPICE kernel

Return type:

dict

pds.naif_pds4_bundler.utils.files.md5(fname)[source]

Returns the MD5 sum (checksum) of the provided file.

Parameters:

fname (str) – Filename

Returns:

Checksum value of the file

Return type:

str

pds.naif_pds4_bundler.utils.files.mk_to_list(mk, setup)[source]

Generate a list of kernels from a Meta-kernel.

This function assumes that the meta-kernel will contain a PATH_SYMBOLS definition that will be present in each kernel entry preceded by a dollar sign $.

If no kernel is found an error is raised.

Parameters:
  • mk (str) – Meta-kernel path from which the list of kernels is generated

  • setup (object) – NPB run Setup Object

Returns:

List of kernels present in the meta-kernel

Return type:

list

pds.naif_pds4_bundler.utils.files.product_mapping(name, setup, cleanup=True)[source]

Obtain the kernel mapping.

Returns:

Kernel Mapping

Return type:

str

pds.naif_pds4_bundler.utils.files.replace_string_in_file(file, old_string, new_string, setup)[source]

Replace string in a file.

Parameters:
  • file (str) – File to replace the string from

  • old_string (str) – String present in file to be substituted

  • new_string (str) – String to be replaced

  • setup (object) – NPB run Setup Object

pds.naif_pds4_bundler.utils.files.safe_make_directory(dir)[source]

Creates a directory if not present.

Parameters:

dir (str) – Directory path.

pds.naif_pds4_bundler.utils.files.string_in_file(file, str_to_check, repetitions=1)[source]

Check if a string is present in a file.

You can also provide the number of times that string is repeated.

Parameters:
  • file (str) – File where the string is searched

  • str_to_check (str) – String to search

  • repetitions (int) – Number of repetitions, default is 1

Returns:

True if the string is present in the file, False otherwise

Return type:

bool

pds.naif_pds4_bundler.utils.files.type_to_extension(kernel_type)[source]

Given a SPICE kernel type provide the SPICE kernel extension.

Parameters:

kernel_type (str) – SPICE kernel type

Returns:

SPICE Kernel extension

Return type:

str

pds.naif_pds4_bundler.utils.files.type_to_pds3_type(kernel)[source]

Given a SPICE kernel provide the PDS3 SPICE kernel type.

Parameters:

kernel (str) – SPICE Kernel name

Returns:

PDS3 SPICE Kernel type of the input SPICE kernel name

Return type:

str

pds.naif_pds4_bundler.utils.files.utf8len(strn)[source]

Length of a string in bytes.

Parameters:

strn (str) – string

Returns:

length of string in bytes

Return type:

int

pds.naif_pds4_bundler.utils.time module

Time Functions to support NPB Classes.

pds.naif_pds4_bundler.utils.time.ck_coverage(path, timsys='TDB', date_format='infomod2', system='UTC')[source]

Returns the coverage of a CK file.

The function assumes that the appropriate kernels have already been loaded.

Parameters:
  • path (str) – File path

  • timsys (str) – Determines whether if the time system is SCLK or not

  • date_format (str) – Date format, the default is the one provided by the PDS4 Information Model 2.0 that rounds the milliseconds and then implements an inward addition for the coverage start time and inward subtraction for the coverage stop time. The other option is the MAKLABEL style that rounds to the millisecond.

  • system (str) – If the time system is not SCLK, then it can be UTC or TDB

Raise:

if the date_format parameter argument is not infomod2 or maklabel

Returns:

start and finish coverage

Return type:

list of str

pds.naif_pds4_bundler.utils.time.creation_time(format='infomod2')[source]

Returns the creation date and time.

The date is either in maklabel or infomod2 %Y-%m-%dT%H:%M:%S.%f format.

Parameters:

format (str) – Time format

Returns:

Current time

Return type:

str

pds.naif_pds4_bundler.utils.time.current_date(date='')[source]

Returns the current date in %Y-%m-%d format.

Parameters:

date (str) – If present, forces a current date otherwise is obtained from the system

Returns:

Current date

Return type:

str

pds.naif_pds4_bundler.utils.time.current_time(format='infomod2')[source]

Returns the current date and time in %Y-%m-%dT%H:%M:%S format.

Parameters:

format (string) – Time format from configuration.

Returns:

Current date and time

Return type:

str

pds.naif_pds4_bundler.utils.time.dsk_coverage(path, date_format='infomod2', system='UTC')[source]

Returns the coverage of a DSK file.

The function assumes that the appropriate kernels (LSK) have already been loaded.

This function is based on the DSKLBL ( Generate an MGSO or PDS DSK label file ) subroutine that belongs to the MAKLABEL NAIF utility.

Parameters:
  • path (str) – File path

  • date_format (str) – Date format, the default is the one provided by the PDS4 Information Model 2.0 that rounds the milliseconds and then implements an inward addition for the coverage start time and inward subtraction for the coverage stop time. The other option is the MAKLABEL style that rounds to the second

  • system (str) – Determine the output ime system: UTC or TDB

Raise:

if the date_format parameter argument is not infomod2 or maklabel

Returns:

start and finish coverage

Return type:

list of str

pds.naif_pds4_bundler.utils.time.et_to_date(beget, endet, date_format='infomod2', kernel_type='Text', system='UTC')[source]

Convert ET (ephemeris time) to a Date Time string.

Parameters:
  • beget (float) – Start ephemeris time (ET)

  • endet (float) – End ephemeris time (ET)

  • date_format (str) – Date format, the default is the one provided by the PDS4 Information Model 2.0 that rounds the milliseconds and then implements an inward addition for the coverage start time and inward subtraction for the coverage stop time. The other option is the MAKLABEL style that rounds to the second

  • kernel_type (str) – Indicates whether if it is a text or binary kernel

  • system (str) – Determine the output ime system: UTC or TDB

Returns:

Start and Stop dates

Return type:

list of str

pds.naif_pds4_bundler.utils.time.get_years(start_time, stop_time)[source]

Get years contained in a time period.

Returns the list of years contained in between the provided start time and the stop time.

Parameters:
  • start_time (str) – Start time to determine list of years

  • stop_time (str) – Stop time to determine list of years

Returns:

Creation date

Return type:

list of str

pds.naif_pds4_bundler.utils.time.parse_date(date_str)[source]
Parses a date string using the following formats:
  • %Y-%b-%d-%H:%M:%S

  • %Y-%m-%dT%H:%M:%S

Parameters:

date_str (str) – Stop time to determine list of years

Returns:

date corresponding to the input str

Return type:

datetime

pds.naif_pds4_bundler.utils.time.pck_coverage(path, date_format='infomod2', system='UTC')[source]

Returns the coverage of a PCK file.

The function assumes that the appropriate kernels have already been loaded.

Parameters:
  • path (str) – File path

  • date_format (str) – Date format, the default is the one provided by the PDS4 Information Model 2.0 that rounds the milliseconds and then implements an inward addition for the coverage start time and inward subtraction for the coverage stop time. The other option is the MAKLABEL style that rounds to the second.

  • system (str) – Determine the output ime system: UTC or TDB

Raise:

if the date_format parameter argument is not infomod2 or maklabel

Returns:

start and finish coverage

Return type:

list of str

pds.naif_pds4_bundler.utils.time.pds3_label_gen_date(file)[source]

Returns the creation date of a given PDS3 label.

Parameters:

path (str) – File path

Returns:

Creation date

Return type:

str

pds.naif_pds4_bundler.utils.time.spk_coverage(path, main_name='', date_format='infomod2', system='UTC')[source]

Returns the coverage of a SPK file.

The function assumes that the appropriate kernels have already been loaded.

Parameters:
  • path (str) – File path

  • main_name (str) – Mission observer name.

  • date_format (str) – Date format, the default is the one provided by the PDS4 Information Model 2.0 that rounds the milliseconds and then implements an inward addition for the coverage start time and inward subtraction for the coverage stop time. The other option is the MAKLABEL style that rounds to the second.

Raise:

if the date_format parameter argument is not infomod2 or maklabel

Returns:

start and finish coverage

Return type:

list of str

Module contents

NAIF PDS4 Bundle Utils Namespace.

The utils module implements general utility capabilities used elsewhere in NPB.