diff --git a/binarycpython/utils/functions.py b/binarycpython/utils/functions.py index dbf90f1139e80be0a615ea21c6d9a199635f5b41..60876ea0c3b80be464f1d3e6c3ae559c722c5d3b 100644 --- a/binarycpython/utils/functions.py +++ b/binarycpython/utils/functions.py @@ -8,39 +8,36 @@ Tasks: - TODO: change all prints to verbose_prints """ +import astropy.units as u +import binarycpython.utils.moe_di_stefano_2017_data as moe_di_stefano_2017_data +from binarycpython import _binary_c_bindings +import bz2 +from collections import ( + defaultdict, + OrderedDict, +) +from colorama import Fore, Back, Style +import copy import datetime as dt -import json -import os import gc -import tempfile -import copy -import humanize +import gzip import inspect +import h5py +import humanize +from io import StringIO +import json +import numpy as np +import os +import psutil +import py_rinterpolate import re +import resource import sys import subprocess +import tempfile import time import types -import resource -import psutil -from colorama import Fore, Back, Style - -from io import StringIO from typing import Union, Any -from collections import ( - defaultdict, - OrderedDict, -) - -import h5py -import numpy as np - -import astropy.units as u - -from binarycpython import _binary_c_bindings -import binarycpython.utils.moe_di_stefano_2017_data as moe_di_stefano_2017_data - -import py_rinterpolate ######################################################## # Unsorted @@ -2258,3 +2255,16 @@ class BinaryCEncoder(json.JSONEncoder): # Let the base class default method raise the TypeError return json.JSONEncoder.default(self, o) + +def load_ensemble(filename): + """ + Function to load an ensemeble file, even if it is compressed, + and return its contents to as a Python dictionary. + """ + if(filename.endswith('.bz2')): + jfile = bz2.open(filename) + elif(filename.endswith('.gz')): + jfile = gzip.open(filename) + else: + jfile = open(filename) + return json.load(jfile)