Пример #1
0
def blend(color1: Color, color2: Color) -> Color:
    """Blends two colors together

    Args:
        color1 (:class:`~pigment.Color`): The first color
        color2 (:class:`~pigment.Color`): The second color

    Returns:
        :class:`~pigment.Color`
    """

    colors = (color1.rgb, color2.rgb)

    return Color(*(round(sqrt(average([c[i]**2 for c in colors])))
                   for i in range(3)))
Пример #2
0
 def check(self, i1: float, i2: float, exp: float):
     """Checks the inputs for a case with an expected output and prints a helpful message upon failure."""
     average_found = average(i1, i2)
     self.assertEqual(average_found, exp, f"Error: Average of {i1} and {i2} was found to be {average_found}, not {exp}")
Пример #3
0
 def test_average_six(self):
     self.check(-6, 6, 0)
     self.assertEqual(average(-6, 6), 0)
Пример #4
0
def test_average(values, expected):
    result = average(*values)

    assert result == approx(expected)
    assert type(result) == type(expected)
Пример #5
0
def test_average_one_value(value):
    result = average(value)

    assert result == approx(value)
    assert type(result) == type(value)
Пример #6
0
def test_average_no_values():
    with raises(ZeroDivisionError):
        average()
Пример #7
0
def record_pointing(d, s, l, b, point, file_name='raw/'+time.strftime("%m-%d-%Y_%H%M%S"),
        int_time=150, repoint_freq=30):
    """Records data from a point on the sky for a specified integration time.
    Spectra for an observation at two different LO frequencies and a separate
    10 second observation with the noise diode on are saved in the specified
    files.

    Args:
        d (dish.Dish): an interface to the Leuschner dish
        s (dish_synth.Synth): an interface to the synthesizer used to set the LO
          frequency
        file_name (String, optional): file name prefix to save the data
        int_time (float, optional): integration time (in seconds).
    """
    logger = logging.getLogger('leuschner')
    logger.debug('Recording data')
    status = 0

    # lets us keep data from this pointing in unique directory,
    # since each time we point we will have different noise/background spectrums
    record_id = time.strftime("%m-%d-%Y_%H%M%S")

    # Compute number of spectra to record (integration time/3)
    num_spec = int(int_time*3)
    num_spec_noise = 5 * 3

    OBS.date = ephem.now()
    point.compute(OBS)
    d.point(np.rad2deg(point.alt), np.rad2deg(point.az))

    # Take measurement with noise diode off at the higher LO frequency (ON frequency)
    s.set_freq(LO_ON)
    s.set_amp(10.0)
    d.noise_off()
    try:
        takespec.takeSpec(file_name+'_ON', numSpec=num_spec)
    except IOError:
        logger.error('%s not saved or averaged.' % (file_name+'_ON'))
        status = -1
    else:
        # Only want to average if the takespec was successful!
        averager.average(file_name+'_ON0.log', lo=LO_ON, l=l, b=b, record_id=record_id)

    # Take 10 second measurement with the noise diode on at the ON frequency
    d.noise_on()
    try:
        takespec.takeSpec(file_name+'_ON_noise', numSpec=num_spec_noise)
    except IOError:
        logger.error('%s not saved or averaged.' % (file_name+'_ON_noise'))
        status = -1
    else:
        averager.average(file_name+'_ON_noise0.log', lo=LO_ON, l=l, b=b, record_id=record_id, noise=True)

    # repoint for the second half of the measurement
    OBS.date = ephem.now()
    point.compute(OBS)
    d.point(np.rad2deg(point.alt), np.rad2deg(point.az))

    # Take 10 second measurement with the noise diode on at the OFF frequency
    s.set_freq(LO_OFF)
    s.set_amp(10.0)
    try:
        takespec.takeSpec(file_name+'_OFF_noise', numSpec=num_spec_noise)
    except IOError:
        logger.error('%s not saved or averaged.' % (file_name+'_OFF_noise'))
        status = -1
    else:
        averager.average(file_name+'_OFF_noise0.log', lo=LO_OFF, l=l, b=b, record_id=record_id, noise=True)

    d.noise_off()

    # Take measurement with noise diode off at the lower LO frequency (OFF frequency)
    s.set_freq(LO_OFF)
    s.set_amp(10.0)
    d.noise_off()
    try:
        takespec.takeSpec(file_name+'_OFF', numSpec=num_spec)
    except IOError:
        logger.error('%s not saved or averaged.' % (file_name+'_OFF'))
        status = -1
    else:
        averager.average(file_name+'_OFF0.log', lo=LO_OFF, l=l, b=b, record_id=record_id)

    logger.debug('Finished recording data')
Пример #8
0
print 'Print Stat'
print stat

print 'Print Syst names'
trimsnames = map(str.strip, snames)
print trimsnames

#initialization (optional information)
averager.avin.initvariables()
averager.avin.setoutputfolder('./TOutP')
averager.avin.initeration = 5
averager.avin.setsnames(snames)

#perform averaging
dataAv, statAv, systAv = averager.average(data, stat, syst)

#print output information
print averager.avout.pulldata

print averager.avout.pullsyst
print averager.avout.shiftsyst
print averager.avout.squeezesyst

print averager.avout.chi2
print averager.avout.ndof

#plotting

# Averaged data
# rotate initial arrays of data and stat uncertainty