示例#1
0
def test_calc_rad_loss_errors():
    # Define input variables
    temp = 11.0 * Quantity(np.ones(6), unit="MK")
    em = 4.0e+48 * Quantity(np.ones(6), unit="1/cm**3")
    obstime = np.array([datetime.datetime(2014, 1, 1, 0, 0, 0),
                        datetime.datetime(2014, 1, 1, 0, 0, 2),
                        datetime.datetime(2014, 1, 1, 0, 0, 4),
                        datetime.datetime(2014, 1, 1, 0, 0, 6),
                        datetime.datetime(2014, 1, 1, 0, 0, 8),
                        datetime.datetime(2014, 1, 1, 0, 0, 10)], dtype=object)
    temp_toolong = Quantity(np.append(temp.value, 0), unit="MK")
    obstime_toolong =  np.array([datetime.datetime(2014, 1, 1, 0, 0, 0),
                                 datetime.datetime(2014, 1, 1, 0, 0, 2),
                                 datetime.datetime(2014, 1, 1, 0, 0, 4),
                                 datetime.datetime(2014, 1, 1, 0, 0, 6),
                                 datetime.datetime(2014, 1, 1, 0, 0, 8),
                                 datetime.datetime(2014, 1, 1, 0, 0, 10),
                                 datetime.datetime(2014, 1, 1, 0, 0, 12)], dtype=object)
    obstime_nonchrono = copy.deepcopy(obstime)
    obstime_nonchrono[1] = obstime[-1]
    obstime_nonchrono[-1] = obstime[1]
    obstime_notdatetime = copy.deepcopy(obstime)
    obstime_notdatetime[0] = 1
    temp_outofrange = Quantity([101, 11.0, 11.0, 11.0, 11.0, 11.0], unit="MK")
    # Ensure correct exceptions are raised.
    with pytest.raises(ValueError):
        rad_loss_test = goes._calc_rad_loss(temp_toolong, em, obstime)
    with pytest.raises(ValueError):
        rad_loss_test = goes._calc_rad_loss(temp_outofrange, em, obstime)
    with pytest.raises(IOError):
        rad_loss_test = goes._calc_rad_loss(temp, em, obstime_toolong)
    with pytest.raises(TypeError):
        lx_test = goes._calc_rad_loss(temp, em, obstime_notdatetime)
    with pytest.raises(ValueError):
        rad_loss_test = goes._calc_rad_loss(temp, em, obstime_nonchrono)
示例#2
0
def test_calc_rad_loss_obstime():
    # Define input variables
    temp = Quantity([11.0, 11.0, 11.0, 11.0, 11.0, 11.0], unit="MK")
    em = Quantity([4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48],
                  unit="1/cm**3")
    obstime = np.array([datetime.datetime(2014, 1, 1, 0, 0, 0),
                        datetime.datetime(2014, 1, 1, 0, 0, 2),
                        datetime.datetime(2014, 1, 1, 0, 0, 4),
                        datetime.datetime(2014, 1, 1, 0, 0, 6),
                        datetime.datetime(2014, 1, 1, 0, 0, 8),
                        datetime.datetime(2014, 1, 1, 0, 0, 10)], dtype=object)
    # Test output is correct when obstime and cumulative kwargs are set.
    rad_loss_test = goes._calc_rad_loss(temp, em, obstime)
    rad_loss_expected = {
        "rad_loss_rate": 3.01851392e+19 * Quantity(np.ones(6), unit="J/s"),
        "rad_loss_int": Quantity(3.01851392e+20, unit="J"),
        "rad_loss_cumul": Quantity([6.03702783e+19, 1.20740557e+20,
                                    1.81110835e+20, 2.41481113e+20,
                                    3.01851392e+20], unit="J")
        }
    assert sorted(rad_loss_test.keys()) == sorted(rad_loss_expected.keys())
    assert_quantity_allclose(rad_loss_test["rad_loss_rate"],
                             rad_loss_expected["rad_loss_rate"], rtol=0.0001)
    assert_quantity_allclose(rad_loss_test["rad_loss_int"],
                             rad_loss_expected["rad_loss_int"], rtol=0.0001)
    assert_quantity_allclose(rad_loss_test["rad_loss_cumul"],
                             rad_loss_expected["rad_loss_cumul"], rtol=0.0001)
示例#3
0
文件: test_goes.py 项目: zimmaz/sunpy
def test_calc_rad_loss_nokwags():
    # Define input variables
    temp = Quantity([11.0, 11.0, 11.0, 11.0, 11.0, 11.0], unit="MK")
    em = Quantity([4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48],
                  unit="1/cm**3")
    # Test output is correct when no kwags are set.
    rad_loss_test = goes._calc_rad_loss(temp[:2], em[:2])
    rad_loss_expected = {"rad_loss_rate":
                         3.01851392e+19 * Quantity(np.ones(2), unit="J/s")}
    assert sorted(rad_loss_test.keys()) == sorted(rad_loss_expected.keys())
    assert_quantity_allclose(rad_loss_test["rad_loss_rate"],
                             rad_loss_expected["rad_loss_rate"], rtol=0.01)
示例#4
0
def test_calc_rad_loss_nokwags():
    # Define input variables
    temp = Quantity([11.0, 11.0, 11.0, 11.0, 11.0, 11.0], unit="MK")
    em = Quantity([4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48],
                  unit="1/cm**3")
    obstime = np.array([datetime.datetime(2014, 1, 1, 0, 0, 0),
                        datetime.datetime(2014, 1, 1, 0, 0, 2),
                        datetime.datetime(2014, 1, 1, 0, 0, 4),
                        datetime.datetime(2014, 1, 1, 0, 0, 6),
                        datetime.datetime(2014, 1, 1, 0, 0, 8),
                        datetime.datetime(2014, 1, 1, 0, 0, 10)], dtype=object)
    # Test output is correct when no kwags are set.
    rad_loss_test = goes._calc_rad_loss(temp[:2], em[:2])
    rad_loss_expected = {"rad_loss_rate":
                         3.01851392e+19 * Quantity(np.ones(2), unit="J/s")}
    assert sorted(rad_loss_test.keys()) == sorted(rad_loss_expected.keys())
    assert_quantity_allclose(rad_loss_test["rad_loss_rate"],
                             rad_loss_expected["rad_loss_rate"], rtol=0.01)
示例#5
0
def test_calc_rad_loss_nokwags():
    # Define input variables
    temp = Quantity([11.0, 11.0, 11.0, 11.0, 11.0, 11.0], unit="MK")
    em = Quantity([4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48, 4.0e+48],
                  unit="1/cm**3")
    obstime = np.array([
        parse_time((2014, 1, 1, 0, 0, 0)),
        parse_time((2014, 1, 1, 0, 0, 2)),
        parse_time((2014, 1, 1, 0, 0, 4)),
        parse_time((2014, 1, 1, 0, 0, 6)),
        parse_time((2014, 1, 1, 0, 0, 8)),
        parse_time((2014, 1, 1, 0, 0, 10))
    ],
                       dtype=object)
    # Test output is correct when no kwags are set.
    rad_loss_test = goes._calc_rad_loss(temp[:2], em[:2])
    rad_loss_expected = {
        "rad_loss_rate": 3.01851392e+19 * Quantity(np.ones(2), unit="J/s")
    }
    assert sorted(rad_loss_test.keys()) == sorted(rad_loss_expected.keys())
    assert_quantity_allclose(rad_loss_test["rad_loss_rate"],
                             rad_loss_expected["rad_loss_rate"],
                             rtol=0.01)