Skip to content

Commit

Permalink
utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
j-faria committed Nov 4, 2024
1 parent 606e43c commit e041b81
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions iCCF/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import sys
import re
import warnings
import importlib.resources as resources
from contextlib import contextmanager
from copy import copy
import numpy as np
from astropy.io import fits
Expand Down Expand Up @@ -29,6 +31,29 @@ def get_ncores():
return ncores


def float_exponent(f):
return int(np.floor(np.log10(abs(f)))) if f != 0 else 0

def float_mantissa(f):
return f / 10**float_exponent(f)


def one_line_warning(message, category, filename, lineno, line=None):
return f'{filename}:{lineno}: {category.__name__}: {message}\n'

@contextmanager
def disable_exception_traceback():
if hasattr(sys, 'tracebacklimit'):
old_tb_limit = sys.tracebacklimit
sys.tracebacklimit = 0
yield
sys.tracebacklimit = old_tb_limit
else:
sys.tracebacklimit = 0
yield
delattr(sys, 'tracebacklimit')


# from https://stackoverflow.com/a/30141358/1352183
def running_mean(x, N=2):
cumsum = np.cumsum(np.insert(x, 0, 0))
Expand Down

0 comments on commit e041b81

Please sign in to comment.