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
#!/usr/bin/python3 | |
# Generate requirements.txt automatically from live environment | |
# Run like this: ./get_package_versions.py >> requirements.txt | |
# Requires pip>=22.* (if fails, try: python3 -m pip install --upgrade pip) | |
from pip._internal.metadata import get_default_environment | |
wildcard_bugfix = lambda ver: ".".join(ver.split(".")[:2]) + ".*" | |
reqs = "\n".join( | |
f"{package.metadata_dict['name']}=={wildcard_bugfix(package.metadata_dict['version'])}" | |
for package in sorted(list(get_default_environment().iter_installed_distributions()), key=lambda x: str(x).lower()) | |
) |
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
import numpy as np | |
from numpy.typing import ArrayLike, NDArray | |
def clip_histogram(histogram: NDArray, bin_edges: NDArray, threshold: float): | |
# Apply threshold to the distribution to exclude all values below the threshold. Note: Since | |
# we're using histograms, we might have the threshold fall within a bin, so we need to | |
# interpolate the value of the bin to the threshold, and artificially reduce the ratio for | |
# the bin by the fractional amount of the bin that's below the threshold. |