示例#1
0
    def test_who_with_0dim_array(self):
        # ticket #1243
        import os
        import sys

        oldstdout = sys.stdout
        sys.stdout = open(os.devnull, 'w')
        try:
            try:
                np.who({'foo': np.array(1)})
            except Exception:
                raise AssertionError("ticket #1243")
        finally:
            sys.stdout.close()
            sys.stdout = oldstdout
示例#2
0
    def test_who_with_0dim_array(self):
        # ticket #1243
        import os
        import sys

        oldstdout = sys.stdout
        sys.stdout = open(os.devnull, 'w')
        try:
            try:
                np.who({'foo': np.array(1)})
            except Exception:
                raise AssertionError("ticket #1243")
        finally:
            sys.stdout.close()
            sys.stdout = oldstdout
示例#3
0
文件: grid.py 项目: cjgillot/cacolac
def main():
    A = Z = 1
    R0 = 900

    # Build grid
    rg = np.linspace(100, 150, 18)
    qq = 1.3 + 0 * np.linspace(0, 1, rg.size)**2

    theta = np.linspace(-np.pi, np.pi, 41)
    vpar = np.multiply.outer(np.linspace(.1, 4, 12), [1, -1])
    mu = np.linspace(0, 1, 8)

    grid = Grid(1, 1, 900, rg, qq, theta, vpar, mu)
    np.who(grid.__dict__)

    plt.figure()
    plt.plot(grid.radius.squeeze(), grid.psi.squeeze())
    plt.show()
    def test_who_with_0dim_array(self, level=rlevel) :
        """ticket #1243"""
        import os, sys

        sys.stdout = open(os.devnull, 'w')
        try :
            tmp = np.who({'foo' : np.array(1)})
            sys.stdout = sys.__stdout__
        except :
            sys.stdout = sys.__stdout__
            raise AssertionError("ticket #1243")
示例#5
0
    def test_who_with_0dim_array(self, level=rlevel):
        """ticket #1243"""
        import os, sys

        sys.stdout = open(os.devnull, 'w')
        try:
            tmp = np.who({'foo': np.array(1)})
            sys.stdout = sys.__stdout__
        except:
            sys.stdout = sys.__stdout__
            raise AssertionError("ticket #1243")
    def test_who_with_0dim_array(self, level=rlevel):
        """ticket #1243"""
        import os, sys

        oldstdout = sys.stdout
        sys.stdout = open(os.devnull, 'w')
        try:
            try:
                tmp = np.who({'foo': np.array(1)})
            except:
                raise AssertionError("ticket #1243")
        finally:
            sys.stdout.close()
            sys.stdout = oldstdout
    def test_who_with_0dim_array(self, level=rlevel) :
        """ticket #1243"""
        import os, sys

        oldstdout = sys.stdout
        sys.stdout = open(os.devnull, 'w')
        try:
            try:
                tmp = np.who({'foo' : np.array(1)})
            except:
                raise AssertionError("ticket #1243")
        finally:
            sys.stdout.close()
            sys.stdout = oldstdout
示例#8
0
from io import StringIO
from typing import Any, Dict

import numpy as np

AR: np.ndarray[Any, np.dtype[np.float64]]
AR_DICT: Dict[str, np.ndarray[Any, np.dtype[np.float64]]]
FILE: StringIO

def func(a: int) -> bool: ...

reveal_type(np.deprecate(func))  # E: def (a: builtins.int) -> builtins.bool
reveal_type(np.deprecate())  # E: _Deprecate

reveal_type(np.deprecate_with_doc("test"))  # E: _Deprecate
reveal_type(np.deprecate_with_doc(None))  # E: _Deprecate

reveal_type(np.byte_bounds(AR))  # E: Tuple[builtins.int, builtins.int]
reveal_type(np.byte_bounds(np.float64()))  # E: Tuple[builtins.int, builtins.int]

reveal_type(np.who(None))  # E: None
reveal_type(np.who(AR_DICT))  # E: None

reveal_type(np.info(1, output=FILE))  # E: None

reveal_type(np.source(np.interp, output=FILE))  # E: None

reveal_type(np.lookfor("binary representation", output=FILE))  # E: None

reveal_type(np.safe_eval("1 + 1"))  # E: Any
示例#9
0
def main():
    from grid import Grid

    # General parameters
    A = Z = 1
    R0 = 900

    # Build grid
    rg = np.linspace(100, 150, 18)
    qq = 1.3 + 0*np.linspace(0, 1, rg.size)**2

    theta = np.linspace(- np.pi, np.pi, 141)
    vpar = np.multiply.outer(np.linspace(.1, 4, 12), [1, -1])
    mu = np.linspace(0, 1, 8)

    grid = Grid(A, Z, R0, rg, qq, theta, vpar, mu)
    np.who(grid.__dict__)

    # Advect particles
    pot = np.zeros_like(rg)
    adv = ParticleAdvector(grid, pot)
    adv.compute_invariants()
    np.who(adv.__dict__)

    adv.compute_bounce_point()
    np.who(adv.__dict__)

    plt.figure()
    plt.suptitle('Banana tip')
    plt.subplot(121)
    plt.gca().set_title('psi')
    plt.plot(adv._banana_psi[:, 0])
    plt.xlabel('trapped index')
    plt.subplot(122)
    plt.gca().set_title('theta')
    plt.plot(adv._banana_theta[:, 0])
    plt.xlabel('trapped index')
    plt.show()

    adv.compute_trajectory()
    np.who(adv.__dict__)

    plt.figure()
    plt.suptitle('Trajectory')
    plt.subplot(121)
    plt.gca().set_title('psi')
    plt.plot(theta, adv.psi_path[:, 3].reshape(theta.size, -1))
    plt.subplot(122)
    plt.gca().set_title('vpar')
    plt.plot(theta, adv.vpar_path[:, 3].reshape(theta.size, -1))
    plt.show()

    # Compute trajectory timing
    adv.compute_displacement()
    adv.compute_precession()
    adv.compute_ballooning()
    np.who(adv.__dict__)

    living = np.where(
        adv.living_path(theta)[..., np.newaxis],
        1, np.nan
    )
    time = adv.time_path * living
    phi  = adv._trans  * living

    plt.figure()
    plt.suptitle('Displacement')
    plt.subplot(121)
    plt.gca().set_title('time')
    plt.plot(
        theta,
        time[:, 16].reshape(theta.size, -1),
    )
    plt.subplot(122)
    plt.gca().set_title('phi')
    plt.plot(
        theta,
        phi[:, 16].reshape(theta.size, -1),
    )
    plt.show()

    adv.compute_canon()
    np.who(adv.__dict__)

    idx = np.argsort(vpar.T.ravel())

    plt.figure()
    plt.subplot(121)
    plt.plot(
        vpar.T.ravel()[idx],
        adv._banana_momentum.T.reshape(vpar.size, -1)[idx],
    )
    plt.subplot(122)
    plt.plot(
        vpar.T.ravel()[idx],
        (
            adv._banana_momentum
            + grid.Z * (
                grid.qprofile * adv._ltor
                + rg[0]**2/2
            )
        ).T.reshape(vpar.size, -1)[idx],
    )
    plt.show()
示例#10
0
import numpy as np

np.deprecate(1)  # E: No overload variant

np.deprecate_with_doc(1)  # E: incompatible type

np.byte_bounds(1)  # E: incompatible type

np.who(1)  # E: incompatible type

np.lookfor(None)  # E: incompatible type

np.safe_eval(None)  # E: incompatible type
示例#11
0
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 11 12:59:39 2019

@author: Enes
"""
#dir(np) --> np kütüphanesinin fonksiyonlarını gösterir.

import numpy as np

a = np.arange(10)
b = np.ones(20)
np.who()

#np.tile([1,2],[3,4],3) --->Yan yana üç kere matrisleri kopyalar. 3,2 olsaydı 3 aşağıya 2 sağa kopyalar..
#np.triu(x)  --> Matrisi üst üçgen yapar.
#np.tril(x)  --> Matrisi alt üçgen yapar.
#np.var(x)   --> Varyansını alır.
#np.var(x,axix=0) --> Her sütunun ayrı ayrı varyansını alır. axix=1 ise de satırları yapar.
#sum --> toplama demek.
#np.sum(x) --> toplar.
#np.cumsum --> kümülatif toplama yapar. Verileri toplaya toplaya gider.
#pn.prod(x,axix=0) --> x değerlerinin düşey yönde çarpımlarını bulur. axix=1 de yatayda yapar.
#pn.cumprod(x,axix=0)
#np.hstack((a,b)) --> Yatay yönde a ve b matrislerini yan yana koyar.
#np.hstack((a,b)) --> Bu da dikey yönde yapar.
#np.stack((a,b),axix=0) --> Böyle kullaırsak da birleştirme yapmaz. Direkt boyut arttırır.

#-------------------#
#***Önemli, sınavda çıkabilir.***
#r=np.array([2,3,5])