<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Utilities for computations related to noise density
"""
from .Resistors import *
from .EngineerIO import *
import numpy as np

def noise(density, bandwith):
    """
    Compute the actual noise given:
     - A noise density in x/√Hz where x is any unit
     - A bandwith in ΔHz

    >>> noise("100 mV", "100 Hz")
    1.0
    """
    if isinstance(density, str):
        density, _ = normalizeEngineerInput(density)
    if isinstance(bandwith, str):
        bandwith, _ = normalizeEngineerInput(bandwith)
    return np.sqrt(bandwith) * density

if __name__ == "__main__":
    import doctest
    doctest.testmod()<commit_msg>More noise density functions<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Utilities for computations related to noise density
"""
from .Resistors import *
from .EngineerIO import *
import numpy as np

def actualNoise(density, bandwith):
    """
    Compute the actual noise given:
     - A noise density in x/√Hz where x is any unit
     - A bandwith in ΔHz

    >>> formatValue(actualNoise("100 µV", "100 Hz"), "V")
    '1.00 mV'
    """
    if isinstance(density, str):
        density, _ = normalizeEngineerInput(density)
    if isinstance(bandwith, str):
        bandwith, _ = normalizeEngineerInput(bandwith)
    return np.sqrt(bandwith) * density

def noiseDensity(actual_noise, bandwith):
    """
    Compute the noise density given:
     - A noise density in x/√Hz where x is any unit
     - A bandwith in ΔHz

    >>> formatValue(noiseDensity("1.0 mV", "100 Hz"), "V/√Hz")
    '100 μV/√Hz'
    """
    if isinstance(actual_noise, str):
        actual_noise, _ = normalizeEngineerInput(actual_noise)
    if isinstance(bandwith, str):
        bandwith, _ = normalizeEngineerInput(bandwith)
    return actual_noise / np.sqrt(bandwith)

if __name__ == "__main__":
    import doctest
    doctest.testmod()
{'fraction_non_alphanumeric': 0.1178925404277517, 'fraction_numerical': 0.015127803860198226, 'mean_word_length': 3.1336206896551726, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6789871', 'n_tokens_mistral': 639, 'n_tokens_neox': 600, 'n_words': 180}