Пример #1
0
def test_goes_chianti_tem_case3():
    # test case 3: satellite < 8 and != 6, abundances = coronal
    temp3, em3 = goes._goes_chianti_tem(LONGFLUX,
                                        SHORTFLUX,
                                        satellite=5,
                                        date=DATE,
                                        abundances="coronal")
    assert all(temp3 < Quantity([11.43], unit="MK")) and \
        all(temp3 > Quantity([11.42], unit="MK"))
    assert all(em3 < Quantity([3.85e+48], unit="1/cm**3")) and \
        all(em3 > Quantity([3.84e+48], unit="1/cm**3"))
Пример #2
0
def test_goes_chianti_tem_case8():
    # test case 8: satellite = 6, date > 1983-06-28, abundances = photospheric
    temp8, em8 = goes._goes_chianti_tem(LONGFLUX,
                                        SHORTFLUX,
                                        satellite=6,
                                        date=DATE,
                                        abundances="photospheric")
    assert all(temp8 < Quantity(10.36, unit="MK")) and \
        all(temp8 > Quantity(10.35, unit="MK"))
    assert all(em8 < Quantity(9.39e+48, unit="1/cm**3")) and \
        all(em8 > Quantity(9.38e+48, unit="1/cm**3"))
Пример #3
0
def test_goes_chianti_tem_case2():
    # test case 2: satellite > 7, abundances = photospheric
    temp2, em2 = goes._goes_chianti_tem(LONGFLUX,
                                        SHORTFLUX,
                                        satellite=15,
                                        date=DATE,
                                        abundances="photospheric")
    assert all(temp2 < Quantity([10.25], unit="MK")) and \
        all(temp2 > Quantity([10.24], unit="MK"))
    assert all(em2 < Quantity([1.12e+49], unit="1/cm**3")) and \
        all(em2 > Quantity([1.11e+49], unit="1/cm**3"))
Пример #4
0
def test_goes_chianti_tem_case7():
    # test case 7: satellite = 6, date > 1983-06-28, abundances = coronal
    temp7, em7 = goes._goes_chianti_tem(LONGFLUX,
                                        SHORTFLUX,
                                        satellite=6,
                                        date=DATE,
                                        abundances="coronal")
    assert all(temp7 < Quantity(11.34, unit="MK")) and \
        all(temp7 > Quantity(11.33, unit="MK"))
    assert all(em7 < Quantity(4.08e+48, unit="1/cm**3")) and \
        all(em7 > Quantity(4.07e+48, unit="1/cm**3"))
Пример #5
0
def test_goes_chianti_tem_case6():
    # test case 6: satellite = 6, date < 1983-06-28, abundances = photospheric
    temp6, em6 = goes._goes_chianti_tem(LONGFLUX,
                                        SHORTFLUX,
                                        satellite=6,
                                        date="1983-06-27",
                                        abundances="photospheric")
    assert all(temp6 < Quantity(11.44, unit="MK")) and \
        all(temp6 > Quantity(11.43, unit="MK"))
    assert all(em6 < Quantity(6.74e+48, unit="1/cm**3")) and \
        all(em6 > Quantity(6.73e+48, unit="1/cm**3"))
Пример #6
0
def test_goes_chianti_tem_case5():
    # test case 5: satellite = 6, date < 1983-06-28, abundances = coronal
    temp5, em5 = goes._goes_chianti_tem(LONGFLUX,
                                        SHORTFLUX,
                                        satellite=6,
                                        date="1983-06-27",
                                        abundances="coronal")
    assert all(temp5 < Quantity(12.30, unit="MK")) and \
        all(temp5 > Quantity(12.29, unit="MK"))
    assert all(em5 < Quantity(3.13e+48, unit="1/cm**3")) and \
        all(em5 > Quantity(3.12e+48, unit="1/cm**3"))
Пример #7
0
def test_goes_chianti_tem_case4():
    # test case 4: satellite < 8 and != 6, abundances = photospheric
    temp4, em4 = goes._goes_chianti_tem(LONGFLUX,
                                        SHORTFLUX,
                                        satellite=5,
                                        date=DATE,
                                        abundances="photospheric")
    assert all(temp4 < Quantity([10.42], unit="MK")) and \
        all(temp4 > Quantity([10.41], unit="MK"))
    assert all(em4 < Quantity(8.81e+48, unit="1/cm**3")) and \
        all(em4 > Quantity(8.80e+48, unit="1/cm**3"))
Пример #8
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")
    # 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)
Пример #9
0
def test_quantity_asanyarray():
    array_of_quantities = [Quantity(1), Quantity(2), Quantity(3)]
    quantity_array = quantity_asanyarray(array_of_quantities)
    assert isinstance(quantity_array, Quantity)
    assert np.issubdtype(quantity_array.dtype, np.inexact)

    array_of_integers = [1, 2, 3]
    np_array = quantity_asanyarray(array_of_integers)
    assert isinstance(np_array, np.ndarray)
    assert np.issubdtype(np_array.dtype, np.integer)

    np_array = quantity_asanyarray(array_of_integers, dtype=np.inexact)
    assert np.issubdtype(np_array.dtype, np.inexact)
Пример #10
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)
Пример #11
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)
Пример #12
0
    def __init__(self, rate, angle, ra0=None, dec0=None, t0=None):
        self.rate = rate
        self.angle = angle
        self.t0 = t0
        self.ra0 = Quantity(ra0)
        self.dec0 = Quantity(dec0)
        self.coordinate = None
        print("Combining frame at {} along angle {}".format(
            self.rate, self.angle))
        r = self.rate.to('arcsec/hour').value
        a = self.angle.to('degree').value
        self.name = "R{:06.1f}A{:05.1f}".format(r, a)

        logging.debug(
            "Computing for rate: {} and angle: {} centred at {} {}".format(
                self.rate, self.angle, self.ra0, self.dec0))
Пример #13
0
def lst_to_array(lst, mask=None):
    """ Simple method to convert a list to an array

    Allows for a list of Quantity objects

    Parameters
    ----------
    lst : list
      Should be number or Quantities
    mask : boolean array, optional

    Returns
    -------
    array or Quantity array

    """
    if mask is None:
        mask = np.array([True] * len(lst))
    if isinstance(lst[0], Quantity):
        return Quantity(lst)[mask]
    else:
        return np.array(lst)[mask]
        # Generate the Table
        tbl = Table(clms, names=attrib)
        # Return
        return tbl
Пример #14
0
    def RV_timeseries(self, ts, recalc=False):
        """
        Radial Velocity time series for star 1 at given times ts.

        :param ts:
            Times.  If not ``Quantity``, assumed to be in days.
        :type ts:
            array-like or ``Quantity``

        :param recalc: (optional)
            If ``False``, then if called with the exact same ``ts``
            as last call, it will return cached calculation.

        """
        if type(ts) != Quantity:
            ts *= u.day

        if not recalc and hasattr(self, 'RV_measurements'):
            if (ts == self.ts).all():
                return self._RV_measurements
            else:
                pass

        RVs = Quantity(np.zeros((len(ts), self.N)), unit='km/s')
        for i, t in enumerate(ts):
            RVs[i, :] = self.dRV(t, com=True)
        self._RV_measurements = RVs
        self.ts = ts
        return RVs
Пример #15
0
def test_gain_correct_quantity(ccd_data):
    init_data = ccd_data.data
    g = Quantity(3, u.electron / u.adu)
    ccd_data = gain_correct(ccd_data, gain=g)

    assert_array_equal(ccd_data.data, 3 * init_data)
    assert ccd_data.unit == u.electron
Пример #16
0
def test_goes_chianti_tem_errors():
    # Define input variables.
    ratio = SHORTFLUX / LONGFLUX
    shortflux_toomany = Quantity(np.append(SHORTFLUX.value,
                                           SHORTFLUX.value[0]),
                                 unit="W/m**2")
    shortflux_toosmall = copy.deepcopy(SHORTFLUX)
    shortflux_toosmall.value[0] = -1
    shortflux_toobig = copy.deepcopy(SHORTFLUX)
    shortflux_toobig.value[0] = 1
    temp_test = Quantity(np.zeros(len(LONGFLUX)) + 10, unit="MK")
    temp_test_toomany = Quantity(np.append(temp_test.value, 0), unit="MK")
    temp_test_toosmall = copy.deepcopy(temp_test)
    temp_test_toosmall.value[0] = -1
    temp_test_toobig = copy.deepcopy(temp_test)
    temp_test_toobig.value[0] = 101
    # First test correct exceptions are raised if incorrect inputs are
    # entered.
    with pytest.raises(ValueError):
        temp, em = goes._goes_chianti_tem(LONGFLUX, SHORTFLUX, satellite=-1)
    with pytest.raises(ValueError):
        temp, em = goes._goes_chianti_tem(LONGFLUX, shortflux_toomany)
    with pytest.raises(ValueError):
        temp = goes._goes_get_chianti_temp(ratio, satellite=-1)
    with pytest.raises(ValueError):
        temp, em = goes._goes_chianti_tem(LONGFLUX,
                                          SHORTFLUX,
                                          abundances="Neither")
    with pytest.raises(ValueError):
        temp = goes._goes_get_chianti_temp(ratio, abundances="Neither")
    with pytest.raises(ValueError):
        temp, em = goes._goes_chianti_tem(LONGFLUX, shortflux_toobig)
    with pytest.raises(ValueError):
        em = goes._goes_get_chianti_em(LONGFLUX, temp_test, satellite=-1)
    with pytest.raises(ValueError):
        em = goes._goes_get_chianti_em(LONGFLUX,
                                       temp_test,
                                       abundances="Neither")
    with pytest.raises(ValueError):
        em = goes._goes_get_chianti_em(LONGFLUX,
                                       temp_test,
                                       abundances="Neither")
    with pytest.raises(ValueError):
        em = goes._goes_get_chianti_em(LONGFLUX, temp_test_toosmall)
    with pytest.raises(ValueError):
        em = goes._goes_get_chianti_em(LONGFLUX, temp_test_toobig)
Пример #17
0
def test_valid_ellipse_ds9():

    reg_str1 = "image\nellipse (1, 2, 3, 4, 5)"
    reg_str2 = "fk5\nellipse (1, 2, 3, 4, 5)"
    reg_str3 = "image\nellipse (1, 2, 3, 4, 5, 6, 7)"  # Elliptical Annulus

    shape1 = DS9Parser(reg_str1, 'warn').shapes[0]
    shape2 = DS9Parser(reg_str2, 'warn').shapes[0]
    shape3 = DS9Parser(reg_str3, 'warn').shapes[0]

    assert_quantity_allclose(shape1.coord[:2], [0, 1])
    assert_quantity_allclose(
        shape2.coord[:2],
        [Quantity("1deg"), Quantity("2deg")])
    assert_quantity_allclose(shape3.coord[:2], [0, 1])

    assert_quantity_allclose(shape1.coord[2:-1], [6, 8])
    assert_quantity_allclose(
        shape2.coord[2:-1],
        [Quantity("6deg"), Quantity("8deg")])
    assert_quantity_allclose(shape3.coord[2:-1], [6, 8, 10, 12])

    assert_quantity_allclose(shape1.coord[-1], Quantity("5deg"))
    assert_quantity_allclose(shape2.coord[-1], Quantity("5deg"))
    assert_quantity_allclose(shape3.coord[-1], Quantity("7deg"))
Пример #18
0
 def x0(self):
     """X-axis coordinate of the first data point
     :type: `~astropy.units.Quantity` scalar
     """
     try:
         return self._x0
     except AttributeError:
         self._x0 = Quantity(0, self.xunit)
         return self._x0
Пример #19
0
def test_calculate_xray_luminosity():
    # Check correct exceptions are raised to incorrect inputs
    not_goeslc = []
    with pytest.raises(TypeError):
        goes_test = goes.calculate_xray_luminosity(not_goeslc)
    # Check function gives correct results.
    goeslc_input = lightcurve.GOESLightCurve.create("2014-01-01 00:00:00",
                                                    "2014-01-01 00:00:10")
    goeslc_test = goes.calculate_xray_luminosity(goeslc_input)
    goeslc_expected = copy.deepcopy(goeslc_input)
    goeslc_expected.data["luminosity_xrsa"] = \
      Quantity(np.array([2.49831950e+16, 2.49831950e+16, 2.49831950e+16,
                         2.52864004e+16, 2.49831950e+16], dtype="float32"),
                         unit="J/s")
    goeslc_expected.data["luminosity_xrsb"] = \
      Quantity(np.array([9.54399250e+17, 9.54399250e+17, 9.52985195e+17,
                         9.52985195e+17, 9.51571139e+17], dtype="float32"),
                         unit="J/s")
    assert_frame_equal(goeslc_test.data, goeslc_expected.data)
def test_simulate_hexitec_on_photon_list_1pixel():
    """Test simulate_masking_photon_list_1pixel()."""
    # Define a HexitecPileUp object.
    hpu = hexitec_simulation.HexitecSimulation(frame_rate=FRAME_RATE,
                                               detector_temperature=17 *
                                               u.deg_C,
                                               bias_voltage=-500 * u.V)
    # Define input photon list and waiting times.
    photon_energies = Quantity([1, 1, 2, 3, 5, 4, 6, 7, 8, 9, 10], unit=u.keV)
    photon_times = Quantity(np.array([
        0.25, 0.75, 1.25, 1.75, 2.25, 2.75, 4.5, 6., 7.5, 7.5,
        (hexitec_simulation.DATAFRAME_MAX_POINTS * hpu._sample_step /
         hpu.frame_duration).si.value + 0.5
    ]) * hpu.frame_duration,
                            unit=u.s)
    incident_photons = Table([photon_times, photon_energies],
                             names=("time", "energy"))
    # Define expected output photon list.
    f = hpu._voltage_pulse_shape[np.where(
        hpu._voltage_pulse_shape == max(hpu._voltage_pulse_shape))[0][0] - 1]
    expected_energies = Quantity([1, 3, 5, 6, 7 * f, 7, 17, 10], unit=u.keV)
    expected_times = np.array([
        0., 1., 2., 4., 5., 6., 7.,
        (hexitec_simulation.DATAFRAME_MAX_POINTS * hpu._sample_step /
         hpu.frame_duration).si.value
    ]) * hpu.frame_duration
    expected_next_frame_energy = Quantity([0., 0., 0., 0., 7., 0., 0., 0.],
                                          unit=u.keV)
    expected_photons = Table(
        [expected_times, expected_energies, expected_next_frame_energy],
        names=("time", "energy", "next frame first energy"))
    # Calculate test measured photon list by calling
    # simulate_hexitec_photon_list_1pixel().
    hpu.measured_photons = hpu.simulate_hexitec_on_photon_list_1pixel(
        incident_photons)
    # Assert test photon list is the same as expected photon list.
    np.testing.assert_allclose(hpu.measured_photons["time"],
                               expected_photons["time"],
                               atol=hpu.frame_duration.to(
                                   hpu.measured_photons["time"].unit).value)
    assert all(hpu.measured_photons["energy"] == expected_photons["energy"])
    assert all(hpu.measured_photons["next frame first energy"] == \
               expected_photons["next frame first energy"])
Пример #21
0
def test_tagged_object_array(tmpdir):
    # See https://github.com/spacetelescope/asdf/issues/383 for feature
    # request
    astropy = pytest.importorskip('astropy')
    from astropy.units.quantity import Quantity

    objdata = np.empty((3, 3), dtype=object)
    for i, _ in enumerate(objdata.flat):
        objdata.flat[i] = Quantity(i, 'angstrom')

    helpers.assert_roundtrip_tree({'bizbaz': objdata}, tmpdir)
Пример #22
0
 def x0(self, value):
     if value is None:
         del self.x0
         return
     if not isinstance(value, Quantity):
         try:
             value = Quantity(value, self.xunit)
         except TypeError:
             value = Quantity(float(value), self.xunit)
     # if setting new x0, delete xindex
     '''
     try:
         x0 = self._x0
     except AttributeError:
         del self.xindex
     else:
         if value is None or self.x0 is None or value != x0:
             del self.xindex
     '''
     self._x0 = value
Пример #23
0
def _enter_column_into_table_as_quantity(header_property_name, header,
                                         header_colnames, data, unit):
    """Used in initiation of IRISSpectrograph to convert auxiliary data to Quantities."""
    index = np.where(np.array(header_colnames) == header_property_name)[0]
    if len(index) == 1:
        index = index[0]
    else:
        raise ValueError("Multiple property names equal to {0}".format(
            header_property_name))
    pop_colname = header_colnames.pop(index)
    return Quantity(data[:, header[pop_colname]], unit=unit)
Пример #24
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)
Пример #25
0
 def _make_quantity(parameters: Dict[str, Any]):
     parsed = {}
     for name, value in parameters.items():
         if value == {}:
             pass
         elif name.isupper():
             parsed[name] = value
         elif name.islower():
             parsed[name] = Quantity(value)
         else:
             parsed[name] = Angle(value)
     return parsed
Пример #26
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)
Пример #27
0
 def __new__(cls, value, vunit=None, # Quantity attrs
             dx=None, x0=None, xunit=None, name=None, # Series attrs
             dtype=None, copy=True, order=None, # ndarray attrs
             subok=True, ndmin=0): # ndarray attrs
     new = super(Series, cls).__new__(cls, value, unit=vunit, dtype=dtype,
                                      copy=copy, order=order, subok=subok,
                                      ndmin=ndmin)        
     if copy:
         new = new.copy()
         
     if name is not None:
         new.name = name
         
     if dx is not None:
         new.dx = Quantity(dx,unit=xunit)
         
     if x0 is not None:
         new.x0 = x0
         
     new.nlen = len(value)        
     new._series = Quantity(np.arange(new.nlen)*dx,unit=xunit)        
     return new
Пример #28
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)
Пример #29
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)
Пример #30
0
def test_shape_crtf():

    reg_str = "circle[[18h12m24s, -23d11m00s], 2.3arcsec], linewidth=2, coord=J2000, symsize=2"

    parser = CRTFParser(reg_str)
    shape1 = parser.shapes[0]
    region = parser.shapes.to_regions()
    shape2 = to_shape_list(region, 'CRTF', 'fk5')[0]

    assert shape1.format_type == shape2.format_type
    assert shape1.coordsys == shape2.coordsys
    assert shape1.region_type == shape2.region_type
    assert shape1.include == shape2.include
    assert_quantity_allclose(shape1.coord, shape2.coord)
    # assert dict(shape1.meta) == dict(shape2.meta)
    assert shape1.composite == shape2.composite

    # Pixel origin is assumed to be 0 origin. Needs to be checked though.
    reg_str = "circle[[1pix, 2pix], 3pix], linewidth=2, coord=image, symsize=2"

    parser = CRTFParser(reg_str)
    shape = parser.shapes[0]
    assert_quantity_allclose(shape.coord, [Quantity("1"), Quantity("2"), Quantity("3")])