Example #1
0
def test_goes_lx_errors():
    # Define input values of flux and time.
    longflux = 7e-6 * Quantity(np.ones(6), unit="W/m**2")
    shortflux = 7e-7 * Quantity(np.ones(6), unit="W/m**2")
    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)
    longflux_toolong = Quantity(np.append(longflux.value, 0),
                                unit=longflux.unit)
    obstime_nonchrono = copy.deepcopy(obstime)
    obstime_nonchrono[1] = obstime[-1]
    obstime_notdatetime = copy.deepcopy(obstime)
    obstime_notdatetime[0] = 1
    # Ensure correct exceptions are raised.
    with pytest.raises(ValueError):
        lx_test = goes._goes_lx(longflux_toolong, shortflux, obstime)
    with pytest.raises(TypeError):
        lx_test = goes._goes_lx(longflux, shortflux, obstime_notdatetime)
    with pytest.raises(ValueError):
        lx_test = goes._goes_lx(longflux, shortflux, obstime_nonchrono)
Example #2
0
def test_goes_lx_obstime():
    # Define input values of flux and time.
    longflux = Quantity([7e-6, 7e-6, 7e-6, 7e-6, 7e-6, 7e-6], unit="W/m**2")
    shortflux = Quantity([7e-7, 7e-7, 7e-7, 7e-7, 7e-7, 7e-7], unit="W/m**2")
    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 when obstime and cumulative kwargs are set.
    lx_test = goes._goes_lx(longflux, shortflux, obstime)
    lx_expected = {
        "longlum": 1.96860565e+18 * Quantity(np.ones(6), unit='W'),
        "shortlum": 1.96860565e+17 * Quantity(np.ones(6), unit='W'),
        "longlum_int": Quantity([1.96860565e+19], unit="J"),
        "shortlum_int": Quantity([1.96860565e+18], unit="J"),
        "longlum_cumul": Quantity([3.93721131e+18, 7.87442262e+18,
                                   1.18116339e+19, 1.57488452e+19,
                                   1.96860565e+19], unit="J"),
        "shortlum_cumul": Quantity([3.93721131e+17, 7.87442262e+17,
                                    1.18116339e+18, 1.57488452e+18,
                                    1.96860565e+18], unit="J")}
    assert sorted(lx_test.keys()) == sorted(lx_expected.keys())
    assert_quantity_allclose(lx_test["longlum"], lx_expected["longlum"], rtol=0.1)
    assert_quantity_allclose(lx_test["shortlum"], lx_expected["shortlum"],
                       rtol=0.1)
    assert_quantity_allclose(lx_test["longlum_int"], lx_expected["longlum_int"],
                       rtol=0.1)
    assert_quantity_allclose(lx_test["shortlum_int"], lx_expected["shortlum_int"],
                       rtol=0.1)
    assert_quantity_allclose(lx_test["longlum_cumul"], lx_expected["longlum_cumul"],
                       rtol=0.1)
    assert_quantity_allclose(lx_test["shortlum_cumul"],
                       lx_expected["shortlum_cumul"], rtol=0.1)
Example #3
0
def test_goes_lx_obstime():
    # Define input values of flux and time.
    longflux = Quantity([7e-6, 7e-6, 7e-6, 7e-6, 7e-6, 7e-6], unit="W/m**2")
    shortflux = Quantity([7e-7, 7e-7, 7e-7, 7e-7, 7e-7, 7e-7], unit="W/m**2")
    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 when obstime and cumulative kwargs are set.
    lx_test = goes._goes_lx(longflux, shortflux, obstime)
    lx_expected = {
        "longlum": 1.91013779e+18 * Quantity(np.ones(6), unit='W'),
        "shortlum": 1.91013779e+17 * Quantity(np.ones(6), unit='W'),
        "longlum_int": Quantity([1.9101360630079373e+19], unit="J"),
        "shortlum_int": Quantity([1.9101360630079373e+18], unit="J"),
        "longlum_cumul": Quantity([3.82027213e+18, 7.64054425e+18,
                                  1.14608164e+19, 1.52810885e+19,
                                  1.91013606e+19], unit="J"),
        "shortlum_cumul": Quantity([3.82027213e+17, 7.64054425e+17,
                                    1.14608164e+18, 1.52810885e+18,
                                    1.91013606e+18], unit="J")}
    assert sorted(lx_test.keys()) == sorted(lx_expected.keys())
    assert np.allclose(lx_test["longlum"], lx_expected["longlum"], rtol=0.01)
    assert np.allclose(lx_test["shortlum"], lx_expected["shortlum"],
                       rtol=0.01)
    assert np.allclose(lx_test["longlum_int"], lx_expected["longlum_int"],
                       rtol=0.01)
    assert np.allclose(lx_test["shortlum_int"], lx_expected["shortlum_int"],
                       rtol=0.01)
    assert np.allclose(lx_test["longlum_cumul"], lx_expected["longlum_cumul"],
                       rtol=0.01)
    assert np.allclose(lx_test["shortlum_cumul"],
                       lx_expected["shortlum_cumul"], rtol=0.01)
Example #4
0
def test_goes_lx_errors():
    # Define input values of flux and time.
    longflux = 7e-6 * Quantity(np.ones(6), unit="W/m**2")
    shortflux = 7e-7 * Quantity(np.ones(6), unit="W/m**2")
    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)
    longflux_toolong = Quantity(np.append(longflux.value, 0), unit=longflux.unit)
    obstime_nonchrono = copy.deepcopy(obstime)
    obstime_nonchrono[1] = obstime[-1]
    obstime_notdatetime = copy.deepcopy(obstime)
    obstime_notdatetime[0] = 1
    # Ensure correct exceptions are raised.
    with pytest.raises(ValueError):
        lx_test = goes._goes_lx(longflux_toolong, shortflux, obstime)
    with pytest.raises(TypeError):
        lx_test = goes._goes_lx(longflux, shortflux, obstime_notdatetime)
    with pytest.raises(ValueError):
        lx_test = goes._goes_lx(longflux, shortflux, obstime_nonchrono)
Example #5
0
def test_goes_lx_date():
    # Define input values of flux and time.
    longflux = Quantity([7e-6, 7e-6, 7e-6, 7e-6, 7e-6, 7e-6], unit="W/m**2")
    shortflux = Quantity([7e-7, 7e-7, 7e-7, 7e-7, 7e-7, 7e-7], unit="W/m**2")
    # Test output when date kwarg is set.
    lx_test = goes._goes_lx(longflux[:2], shortflux[:2], date="2014-04-21")
    lx_expected = {"longlum": Quantity([1.98649103e+18, 1.98649103e+18],
                                       unit="W"),
                   "shortlum": Quantity([1.98649103e+17, 1.98649103e+17],
                                        unit="W")}
    assert sorted(lx_test.keys()) == sorted(lx_expected.keys())
    assert_quantity_allclose(lx_test["longlum"], lx_expected["longlum"], rtol=0.001)
    assert_quantity_allclose(lx_test["shortlum"], lx_expected["shortlum"],
                       rtol=0.001)
Example #6
0
def test_goes_lx_nokwargs():
    # Define input values of flux and time.
    longflux = Quantity([7e-6, 7e-6, 7e-6, 7e-6, 7e-6, 7e-6], unit="W/m**2")
    shortflux = Quantity([7e-7, 7e-7, 7e-7, 7e-7, 7e-7, 7e-7], unit="W/m**2")
    # Test output when no kwargs are set.
    lx_test = goes._goes_lx(longflux[:2], shortflux[:2])
    lx_expected = {"longlum": Quantity([1.91013779e+18, 1.91013779e+18],
                                       unit="W"),
                   "shortlum": Quantity([1.91013779e+17, 1.91013779e+17],
                                       unit="W")}
    assert sorted(lx_test.keys()) == sorted(lx_expected.keys())
    assert np.allclose(lx_test["longlum"], lx_expected["longlum"], rtol=0.01)
    assert np.allclose(lx_test["shortlum"], lx_expected["shortlum"],
                       rtol=0.01)