<commit_before>import sys
from pathlib import Path

import numpy as np
import pandas as pd
from astropy.io import fits

import SpicepyPy as spice

from .spice import load_kernels


def format_times(sec, subsec):
    return "{:010d}.{:05d}".format(int(sec), int(subsec))


def calc_utc_from_sclk(coarse, fine):
    load_kernels()  # load SPICE kernels
    timestamp_ = coarse
    ss = fine
    mavenid, _ = spice.bodn2c('MAVEN')
    timestamp = timestamp_ + ss / 65536  # timestamp_ and ss are already float
    sec = np.uint64(timestamp)
    subsec = np.uint64((timestamp - sec) * 65536)
    sclkch = np.vectorize(format_times)(sec, subsec)
    sclkdp = np.vectorize(spice.scencd)(mavenid, sclkch)
    et = np.vectorize(spice.sct2e)(mavenid, sclkdp)
    utc = np.vectorize(spice.et2utc)(et, 'ISOC', 50, 100)
    return pd.to_datetime(utc)


class HKReader(object):

    def __init__(self, fname):
        self.hdulist = fits.open(fname)
        for hdu in self.hdulist[1:]:
            name = hdu.header['EXTNAME']
            setattr(self, name + '_header', hdu.header)
            setattr(self, name, hdu.data)

        temp_cols = [value for value in getattr(self, 'AnalogConv_header').values()
                     if 'temp' in str(value).lower()]
        self.temp_cols = temp_cols
        self.get_temp_table()
        self.fpath = Path(fname)<commit_msg>fixing spelling in spice module and avoid loading for each calc_utc_.. call<commit_after>import sys
from pathlib import Path

import numpy as np
import pandas as pd
import SpiceyPy as spice
from astropy.io import fits

from .spice import load_kernels


def format_times(sec, subsec):
    return "{:010d}.{:05d}".format(int(sec), int(subsec))


def calc_utc_from_sclk(coarse, fine):
    """Requires to have SPICE kernels loaded (use load_kernels()).

    I'm not doing the loading of SPICE kernels in here so that I can
    run this function in a loop without using up kernel space.
    The caller should load and unload kernels as required.
    """
    # load_kernels()  # load SPICE kernels
    timestamp_ = coarse
    ss = fine
    mavenid, _ = spice.bodn2c('MAVEN')
    timestamp = timestamp_ + ss / 65536  # timestamp_ and ss are already float
    sec = np.uint64(timestamp)
    subsec = np.uint64((timestamp - sec) * 65536)
    sclkch = np.vectorize(format_times)(sec, subsec)
    sclkdp = np.vectorize(spice.scencd)(mavenid, sclkch)
    et = np.vectorize(spice.sct2e)(mavenid, sclkdp)
    utc = np.vectorize(spice.et2utc)(et, 'ISOC', 50, 100)
    return pd.to_datetime(utc)


class HKReader(object):

    def __init__(self, fname):
        self.hdulist = fits.open(fname)
        for hdu in self.hdulist[1:]:
            name = hdu.header['EXTNAME']
            setattr(self, name + '_header', hdu.header)
            setattr(self, name, hdu.data)

        temp_cols = [value for value in getattr(self, 'AnalogConv_header').values()
                     if 'temp' in str(value).lower()]
        self.temp_cols = temp_cols
        self.get_temp_table()
        self.fpath = Path(fname)
{'fraction_non_alphanumeric': 0.10980006555227795, 'fraction_numerical': 0.018354637823664373, 'mean_word_length': 3.0423841059602648, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5025771', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1024, 'n_words': 278}