Skip to content

Commit

Permalink
python: More conversion of util functions to integer math only.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanvolz committed Dec 13, 2023
1 parent 4304ac8 commit f092077
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 72 deletions.
8 changes: 6 additions & 2 deletions python/digital_rf/digital_rf_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import six

# local imports
from . import _py_rf_write_hdf5, digital_metadata, list_drf
from . import _py_rf_write_hdf5, digital_metadata, list_drf, util
from ._version import get_versions

__version__ = get_versions()["version"]
Expand Down Expand Up @@ -1235,6 +1235,7 @@ def read_metadata(self, start_sample, end_sample, channel_name, method="ffill"):
For convenience, some pertinent metadata inherent to the Digital RF
channel is added to the Digital Metadata, including:
sample_rate : fractions.Fraction
sample_rate_numerator : int
sample_rate_denominator : int
samples_per_second : np.longdouble (don't rely on this!)
Expand All @@ -1244,6 +1245,7 @@ def read_metadata(self, start_sample, end_sample, channel_name, method="ffill"):
added_metadata = {
key: properties[key]
for key in (
"sample_rate",
"sample_rate_numerator",
"sample_rate_denominator",
"samples_per_second",
Expand Down Expand Up @@ -1995,13 +1997,15 @@ def _read_properties(self):
# if no sample_rate_numerator/sample_rate_denominator, then we must
# have an older version with samples_per_second as uint64
sps = ret_dict["samples_per_second"]
spsfrac = fractions.Fraction(sps).limit_denominator()
spsfrac = util.get_samplerate_frac(sps)
ret_dict["samples_per_second"] = np.longdouble(sps)
ret_dict["sample_rate_numerator"] = spsfrac.numerator
ret_dict["sample_rate_denominator"] = spsfrac.denominator
ret_dict["sample_rate"] = spsfrac
else:
sps = np.longdouble(np.uint64(srn)) / np.longdouble(np.uint64(srd))
ret_dict["samples_per_second"] = sps
ret_dict["sample_rate"] = util.get_samplerate_frac(srn, srd)

# success
return ret_dict
Expand Down
Loading

0 comments on commit f092077

Please sign in to comment.