-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
240 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,11 @@ | |
setup( | ||
name='stixdcpy', | ||
description='STIX data center APIs and data analysis tools', | ||
version='2.2', | ||
version='3.0', | ||
author='Hualin Xiao', | ||
author_email='[email protected]', | ||
long_description=open('README.md').read(), | ||
install_requires=['numpy', 'requests', 'python-dateutil', | ||
install_requires=['numpy', 'requests', 'python-dateutil', 'ipython', | ||
'astropy', 'matplotlib','tqdm','pandas','joblib', 'roentgen', 'simplejson', 'sunpy','wget'], | ||
long_description_content_type='text/markdown', | ||
#packages=find_packages(where='stixdcpy'), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" | ||
This script provides functions for decompressing integer values and creating error lookup tables. | ||
It includes the following functions: | ||
- decompress(x, K, M): Decompresses a compressed integer value. | ||
- make_lut(k, m): Creates a lookup table for error calculation based on k and m values. | ||
Additionally, it defines error lookup tables for specific combinations of k and m values. | ||
Author: Hualin Xiao([email protected]) | ||
""" | ||
|
||
import numpy as np | ||
|
||
MAX_STORED_INTEGER = 1e8 | ||
|
||
def decompress(x, K, M): | ||
""" | ||
Decompresses a compressed integer value. | ||
Parameters: | ||
x (int): The compressed integer value to decompress. | ||
K (int): The number of bits reserved for the exponent. | ||
M (int): The number of bits reserved for the mantissa. | ||
Returns: | ||
tuple: A tuple containing the error and the decompressed value. | ||
The error represents the uncertainty in the decompressed value. | ||
The decompressed value is the original integer value. | ||
""" | ||
S = 0 | ||
if S + K + M > 8 or S not in (0, 1) or K > 7 or M > 7: | ||
return None, None | ||
if K == 0 or M == 0: | ||
return None, None | ||
|
||
sign = 1 | ||
if S == 1: # signed | ||
MSB = x & (1 << 7) | ||
if MSB != 0: | ||
sign = -1 | ||
x = x & ((1 << 7) - 1) | ||
|
||
x0 = 1 << (M + 1) | ||
if x < x0: | ||
return None, x | ||
mask1 = (1 << M) - 1 | ||
mask2 = (1 << M) | ||
mantissa1 = x & mask1 | ||
exponent = (x >> M) - 1 | ||
# number of shifted bits | ||
mantissa2 = mask2 | mantissa1 # add 1 before mantissa | ||
low = mantissa2 << exponent # minimal possible value | ||
high = low | ((1 << exponent) - 1) # maximal possible value | ||
mean = (low + high) >> 1 # mean value | ||
error = np.sqrt((high - low) ** 2 / 12) | ||
|
||
if mean > MAX_STORED_INTEGER: | ||
return error, float(mean) | ||
|
||
return error, sign * mean | ||
|
||
def make_lut(k, m): | ||
""" | ||
Creates a lookup table for error calculation based on k and m values. | ||
Parameters: | ||
k (int): The number of bits reserved for the exponent. | ||
m (int): The number of bits reserved for the mantissa. | ||
Returns: | ||
dict: A dictionary mapping decompressed values to their respective errors. | ||
""" | ||
res = {} | ||
for i in range(256): | ||
err, val = decompress(i, k, m) | ||
if err is not None: | ||
res[val] = np.sqrt(err ** 2 + val) | ||
return res | ||
|
||
error_luts = {'035': make_lut(3, 5), '044': make_lut(4, 4), '053': make_lut(5, 3)} | ||
|
||
if __name__ == '__main__': | ||
from pprint import pprint | ||
pprint(error_luts) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters