Esempio n. 1
0
def test_invalid_instrument(instrument, pulse):
    """Test an exception is raised when try to read data for an instrument
    that doesn't exist."""
    assume(instrument.lower() not in AVAILABLE_INSTRUMENTS)
    with open(filepath, "r", encoding="latin-1") as f:
        data = f.read()
    assume(
        not re.search(rf"^\*.*{re.escape(instrument)}.*$", data, re.MULTILINE))
    with pytest.raises(surf_los.SURFException):
        surf_los.read_surf_los(filepath, pulse, instrument)
Esempio n. 2
0
def test_read_kk3_los_2(pulse, upper_case):
    rstart, rend, zstart, zend, Tstart, Tend = surf_los.read_surf_los(
        filepath, pulse, change_case("kk3", upper_case))
    assert (len(rstart) == len(rend) == len(zstart) == len(zend) == len(Tstart)
            == len(Tend) == 1)
    assert rstart[0] == pytest.approx(5.37)
    assert rend[0] == pytest.approx(1.563)
    assert zstart[0] == pytest.approx(0.248)
    assert zend[0] == pytest.approx(0.248)
    assert np.all(Tstart == pytest.approx(0.0))
    assert np.all(Tend == pytest.approx(0.0))
Esempio n. 3
0
def test_read_kk3_los_1(pulse, upper_case):
    """Test reading the lines of sight for KK3."""
    rstart, rend, zstart, zend, Tstart, Tend = surf_los.read_surf_los(
        filepath, pulse, change_case("kk3", upper_case))
    assert (len(rstart) == len(rend) == len(zstart) == len(zend) == len(Tstart)
            == len(Tend) == 1)
    assert rstart[0] == pytest.approx(5.37)
    assert rend[0] == pytest.approx(1.563)
    assert zstart[0] == pytest.approx(0.133)
    assert zend[0] == pytest.approx(0.133)
    assert np.all(Tstart == pytest.approx(0.0))
    assert np.all(Tend == pytest.approx(0.0))
Esempio n. 4
0
def test_read_bolo_v_los_3(pulse, upper_case):
    """Test reading lines of sight for bolometric camera H."""
    rstart, rend, zstart, zend, Tstart, Tend = surf_los.read_surf_los(
        filepath, pulse, change_case("bolo/kb5v", upper_case))
    assert (len(rstart) == len(rend) == len(zstart) == len(zend) == len(Tstart)
            == len(Tend) == 32)
    assert rstart[0] == pytest.approx(3.2311)
    assert rend[0] == pytest.approx(3.8678)
    assert zstart[0] == pytest.approx(2.3932)
    assert zend[0] == pytest.approx(0.6155)
    assert rstart[10] == pytest.approx(3.1708)
    assert rend[10] == pytest.approx(2.734)
    assert zstart[10] == pytest.approx(2.3894)
    assert zend[10] == pytest.approx(-1.6615)
    assert np.all(Tstart == pytest.approx(0.0))
    assert np.all(Tend == pytest.approx(0.0))
Esempio n. 5
0
def test_read_bolo_h_los_3(pulse, upper_case):
    """Test reading lines of sight for bolometric camera H."""
    rstart, rend, zstart, zend, Tstart, Tend = surf_los.read_surf_los(
        filepath, pulse, change_case("bolo/kb5h", upper_case))
    assert (len(rstart) == len(rend) == len(zstart) == len(zend) == len(Tstart)
            == len(Tend) == 24)
    assert rstart[0] == pytest.approx(5.0301)
    assert rend[0] == pytest.approx(2.3929)
    assert zstart[0] == pytest.approx(0.4052)
    assert zend[0] == pytest.approx(-1.7272)
    assert rstart[10] == pytest.approx(5.0513)
    assert rend[10] == pytest.approx(1.9325)
    assert zstart[10] == pytest.approx(0.3538)
    assert zend[10] == pytest.approx(-0.5836)
    assert np.all(Tstart == pytest.approx(0.0))
    assert np.all(Tend == pytest.approx(0.0))
Esempio n. 6
0
def test_read_sxr_h_los(pulse, upper_case):
    """Test reading of lines of sight for SXR camera h"""
    rstart, rend, zstart, zend, Tstart, Tend = surf_los.read_surf_los(
        filepath, pulse, change_case("sxr/h", upper_case))
    assert (len(rstart) == len(rend) == len(zstart) == len(zend) == len(Tstart)
            == len(Tend) == 17)
    assert np.all(rstart == pytest.approx(5.917))
    assert np.all(zstart[:8] == pytest.approx(0.414))
    assert np.all(zstart[8:] == pytest.approx(-0.408))
    assert np.all(Tstart == pytest.approx(0.0))
    assert rend[0] == pytest.approx(0.429873)
    assert zend[0] == pytest.approx(-2.66607)
    assert Tend[0] == pytest.approx(1.53583)
    assert rend[10] == pytest.approx(0.429705)
    assert zend[10] == pytest.approx(1.02936)
    assert Tend[10] == pytest.approx(1.53555)
Esempio n. 7
0
    def _get_cyclotron_emissions(
        self,
        uid: str,
        instrument: str,
        revision: RevisionLike,
        quantities: Set[str],
    ) -> Dict[str, Any]:
        """Fetch raw data for electron cyclotron emissin diagnostics."""
        _, _, zstart, zend, _, _ = surf_los.read_surf_los(
            SURF_PATH, self.pulse, instrument.lower()
        )
        assert zstart[0] == zend[0]

        # gen contains accquisition parameters
        # e.g. which channels are valid (gen[0,:] > 0)
        gen, gen_path = self._get_signal(uid, instrument, "gen", revision)
        channels = np.argwhere(gen.data[0, :] > 0)[:, 0]
        freq = gen.data[15, channels] * 1e9
        nharm = gen.data[11, channels]
        results: Dict[str, Any] = {
            "machine_dims": self.MACHINE_DIMS,
            "z": zstart[0],
            "length": len(channels),
            "Btot": 2 * np.pi * freq * sc.m_e / (sc.e * nharm),
        }
        bad_channels = np.argwhere(
            np.logical_or(gen.data[18, channels] == 0.0, gen.data[19, channels] == 0.0)
        )
        results["bad_channels"] = results["Btot"][bad_channels]
        for q in quantities:
            records = [SURF_PATH.name, gen_path]
            data = []
            for i in channels:
                qval, q_path = self._get_signal(
                    uid, instrument, f"{q}{i + 1:02d}", revision
                )
                records.append(q_path)
                data.append(qval.data)
                if "times" not in results:
                    results["times"] = qval.dimensions[0].data
            results[q] = np.array(data).T
            results[q + "_error"] = self._default_error * results[q]
            results[q + "_records"] = records

        results["revision"] = self._get_revision(uid, instrument, revision)
        return results
Esempio n. 8
0
def test_read_sxr_t_los_3(pulse, upper_case):
    """Test reading of lines of sight for SXR camera T"""
    rstart, rend, zstart, zend, Tstart, Tend = surf_los.read_surf_los(
        filepath, pulse, change_case("sxr/t", upper_case))
    assert (len(rstart) == len(rend) == len(zstart) == len(zend) == len(Tstart)
            == len(Tend) == 35)
    angle = np.radians(5.0)
    f = 0.03531
    assert np.all(rstart == pytest.approx(2.848))
    assert np.all(zstart == pytest.approx(2.182))
    assert np.all(Tstart == pytest.approx(0.0))
    assert np.all(Tend == pytest.approx(0.0))
    theta = np.arctan2(rstart[0] - rend[0], zstart[0] - zend[0])
    assert theta == pytest.approx(
        np.arctan2(
            -17 * PIXEL * np.cos(angle) - f * np.tan(angle),
            -17 * PIXEL * np.sin(angle) + f,
        ))
    theta = np.arctan2(rstart[10] - rend[10], zstart[10] - zend[10])
    assert theta == pytest.approx(
        np.arctan2(
            -7 * PIXEL * np.cos(angle) - f * np.tan(angle),
            -7 * PIXEL * np.sin(angle) + f,
        ))
Esempio n. 9
0
def test_invalid_pulse(instrument_pulse):
    """Test an exception is raised when try to read data for a pulse which is
    not available."""
    instrument, pulse = instrument_pulse
    with pytest.raises(surf_los.SURFException):
        surf_los.read_surf_los(filepath, pulse, instrument)
Esempio n. 10
0
    def _get_radiation(
        self,
        uid: str,
        instrument: str,
        revision: RevisionLike,
        quantities: Set[str],
    ) -> Dict[str, Any]:
        """Fetch raw data for radiation quantities such as SXR and bolometric
        fluxes..

        """
        results: Dict[str, Any] = {
            "length": {},
            "machine_dims": self.MACHINE_DIMS,
        }
        for q in quantities:
            qtime = q + "_times"
            records = [SURF_PATH.name]
            if instrument == "bolo":
                qval, qpath = self._get_signal(uid, instrument, q, revision)
                records.append(qpath)
                results["length"][q] = qval.dimensions[1].length
                results[qtime] = qval.dimensions[0].data
                results[q] = qval.data
                channels: Union[List[int], slice] = slice(None, None)
            else:
                luminosities = []
                channels = []
                for i in range(1, self._RADIATION_RANGES[instrument + "/" + q] + 1):
                    try:
                        qval, q_path = self._get_signal(
                            uid, instrument, f"{q}{i:02d}", revision
                        )
                    except NodeNotFound:
                        continue
                    records.append(q_path)
                    luminosities.append(qval.data)
                    channels.append(i - 1)
                    if qtime not in results:
                        results[qtime] = qval.dimensions[0].data
                if len(channels) == 0:
                    # TODO: Try getting information on the INSTRUMENT (DDA in JET),
                    #  to determine if the failure is actually due to requesting
                    #  an invalid INSTRUMENT (DDA in JET) or revision
                    self._client.list(
                        f"/pulse/{self.pulse:d}/ppf/signal/{uid}/{instrument}:"
                        f"{revision:d}"
                    )
                    raise PPFError(f"No channels available for {instrument}/{q}.")
                results["length"][q] = len(channels)
                results[q] = np.array(luminosities).T
            results[q + "_error"] = self._default_error * results[q]
            results[q + "_records"] = records
            xstart, xend, zstart, zend, ystart, yend = surf_los.read_surf_los(
                SURF_PATH, self.pulse, instrument.lower() + "/" + q.lower()
            )
            results[q + "_xstart"] = xstart[channels]
            results[q + "_xstop"] = xend[channels]
            results[q + "_zstart"] = zstart[channels]
            results[q + "_zstop"] = zend[channels]
            results[q + "_ystart"] = ystart[channels]
            results[q + "_ystop"] = yend[channels]

        results["revision"] = self._get_revision(uid, instrument, revision)
        return results