Coder Social home page Coder Social logo

pleque's Introduction

PLEQUE - PLasma EQUilibrium Enjoyment module [pleɪɡ]

GitHub py3comp

PLEQUE is a Python module allowing simple visualisation and manipulation of tokamak plasma equilibria. For more information see the documentation at https://pleque.readthedocs.io.

Note: The work is still in the early development stage, so pleque probably contains bugs. You are very welcome to submit your wishes, encountered bugs or any other comments as an issue. Minor changes in the code structure may occur before the 0.1.0 release.

Getting Started

Prerequisites

The following packages are required to install pleque:

python>=3.5
numpy
scipy
shapely
scikit-image
xarray
pandas
h5py
omas

They should be automatically handled by pip further in the installation process.

Download the source code

First, pick where you wish to install the code:

 cd /desired/path/

There are two options how to get the code: from PyPI or by cloning the repository.

pip install --user pleque

Alternatively, you may use the unstable experimental release (probably with more fixed bugs):

 pip install --user -i https://test.pypi.org/simple/ pleque

Clone the github repository

git clone https://github.com/kripnerl/pleque.git
cd pleque
pip install --user .

Congratulations, you have just installed pleque!

Examples

The following example shows how to load an equilibrium saved in the eqdsk format. The equilibrium used here comes from a FIESTA simulation of the COMPASS-Upgrade tokamak.

from pleque.io import readers
import pkg_resources
import matplotlib as plt

#Locate a test equilibrium
filepath = pkg_resources.resource_filename('pleque', 'resources/baseline_eqdsk')

The heart of pleque is its Equilibrium class, which contains all the equilibrium information (and much more). Typically its instances are called eq.

# Create an instance of the `Equilibrium` class
eq = readers.read_geqdsk(filepath)

The Equilibrium class comes with tons of interesting functions and caveats.

# Plot a simple overview of the equilibrium
eq.plot_overview()

# Calculate the separatrix area
sep_area = eq.lcfs.area

# Get absolute magnetic field magnitude at given point
R = 0.7 #m
Z = 0.1 #m
B = eq.B_abs(R, Z)

Equilibria may be visualised in many different ways; they may be used for mapping or field line tracing; the possibilities are virtually endless. If there's a caveat you find missing from pleque, write to us! Further examples can be found as notebooks in the notebooks folder or in the examples directory.

Version

0.0.5

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related projects

  • FreeGS - free boundary Grad-Shafranov solver in Python.
  • OMFIT is an integrated modeling and experimental data analysis software for magnetically confined thermonuclear fusion experiments. The goal of OMFIT is to enhance existing scientific workflows and enable new integrated modeling capabilities. To achieve these goals OMFIT adopts a bottom-up collaborative development approach.
  • OMAS (Ordered Multidimensional Array Structure) is a Python library designed to simplify the interface of third-party codes with the ITER Integrated Modeling and Analysis Suite (IMAS) . ITER IMAS defines a data model, a data get/put API, and a data storage infrastructure used for manipulating ITER data.

References

pleque's People

Contributors

coobas avatar davidtskhakaya avatar evamac avatar jirakova avatar kripnerl avatar mateasek avatar ondrejfi avatar peterkamatej avatar seidlj avatar smartass101 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

nucg1gb louloufev

pleque's Issues

Set ".shot" attribute of Equilibrium when loading using io.compass.cdb()

Currently, Equilibrium object loaded via pleque.io.compass.cdb() has .shot=0. This then causes further minor inconveniences such as the loss of this metadata when writing the equilibrium into a file, e.g. to_geqdsk(). While I usually depend on the filename to store this metadata (shot number and time) I feel like it would be nice to have this additional backup given that this is already a feature of the eqdsk format.

Proposal for fix:

Probaly just add something like

# Accessing `sig_ref` instead of parameter `shot` should handle cases when user uses `shot=None`
eq.shot = sig_ref.record_number

added just below

eq = read_efithdf5(data_ref.full_path, time=time)

Proposal for further investigation:

  • Might be worth to look into the other io options (such as cudb) and how they handle the shot attribute, potentially fix them as well

Nine or zero?

I suppose there should be 9 instead of 0

attrs_pos = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17]

instead of

attrs_pos = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 10, 11, 13, 15, 17]

attrs_pos = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 10, 11, 13, 15, 17]

Pleque Structure

While preparing export of FluxFunction objects to omas I realised this is one way how to get equilibrium data from a coordinate object is for example this:

coords._eq.tor_flux(coords)

I am not sure if the possibility or need to do this is a good Idea. I am also afraid it could lead to growing ambiguity, cyclic referencing and confusion in the module and it's using as it grows.

Please correct me if I'm wrong.

Equilibriumclass functions work with coordinates objects, e.g.:

code

The equilibrium object has to be passed to the coordinates upon creation and is saved as a property :
code

Isn't this kind of a cycle which could in future fire back? Another disadvantage is (as I've already mentioned) is that the user has to be either keeping both equilibrium and coordinates objects to get
some equilibrium value for the coordinates (although the equilibrium is saved in coordinates), e.g.:

equi = Equilibrium(...)
coords = equi.coordinates(...)
equi.tor_flux(coords)
`
or keep using this:

equi = Equilibrium(...)
coords = equi.coordinates(...)
coords._equi.tor_flux(coords)
`

I might be wrong disliking this and maybe this way is the correct way. But I think the structure of the whole module should be changed to avoid this. One possibility to solve this could could be by using inheritance by making the coordinates class child class of the equilibrium. What do you think?

Test failures on master

Hello, I just cloned master and ran:

python3 -m venv testvenv
source testvenv/bin/activate
pip install -U pip
pip install -e .
pip install pytest
pytest

and got the following test failures/errors:

===================================================================================================================================================== warnings summary ======================================================================================================================================================
pleque/core/equilibrium.py:215: 5 tests with warnings
tests/compu_test.py: 1 test with warning
tests/test_2Dinterpolation.py: 6 tests with warnings
tests/test_cocos.py: 48 tests with warnings
tests/test_coordinates.py: 6 tests with warnings
tests/test_equilibria.py: 12 tests with warnings
tests/test_gfile.py: 12 tests with warnings
tests/test_io.py: 6 tests with warnings
tests/test_surface_param.py: 1 test with warning
  /home/peter/Codes/pleque/pleque/core/equilibrium.py:215: DeprecationWarning: np.asscalar(a) is deprecated since NumPy v1.16, use a.item() instead

pleque/core/coordinates.py:463
  /home/peter/Codes/pleque/pleque/core/coordinates.py:463: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working

pleque/io/metis.py:37
  /home/peter/Codes/pleque/pleque/io/metis.py:37: PendingDeprecationWarning: dropping variables using `drop` will be deprecated; using drop_vars is encouraged.

testvenv/lib64/python3.7/site-packages/numpy/lib/type_check.py:277
  /home/peter/Codes/pleque/testvenv/lib64/python3.7/site-packages/numpy/lib/type_check.py:277: FutureWarning: elementwise == comparison failed and returning scalar instead; this will raise an error or perform elementwise comparison in the future.

testvenv/lib64/python3.7/site-packages/omas/omas_setup.py:16
  /home/peter/Codes/pleque/testvenv/lib64/python3.7/site-packages/omas/omas_setup.py:16: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working

testvenv/lib64/python3.7/site-packages/omas/omas_hdc.py:9
  /home/peter/Codes/pleque/testvenv/lib64/python3.7/site-packages/omas/omas_hdc.py:9: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working

-- Docs: https://docs.pytest.org/en/latest/warnings.html
================================================================================================================================================== short test summary info ==================================================================================================================================================
FAILED tests/compu_test.py::test_compu - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/surfaces_test.py::test_surfs - assert array([], shape=(1, 0), dtype=float64) is None
FAILED tests/test_cocos.py::test_directions[5-1] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_directions[5-2] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_directions[5-3] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_directions[5-4] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_coordinates_transforms[5-1] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_coordinates_transforms[5-2] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_coordinates_transforms[5-3] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_coordinates_transforms[5-4] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_coordinates_transforms[5-5] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_coordinates_transforms[5-6] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_coordinates_transforms[5-7] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_coordinates_transforms[5-8] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_cocos_consistency[5-1] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_cocos_consistency[5-2] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_cocos_consistency[5-3] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_cocos_consistency[5-4] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_cocos_consistency[5-5] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_cocos_consistency[5-6] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_cocos_consistency[5-7] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_cocos.py::test_cocos_consistency[5-8] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_equilibria.py::test_equilibria[4] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 2 has size 2
FAILED tests/test_equilibria.py::test_equilibria[5] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_gfile.py::test_calculated_profiles[5] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
FAILED tests/test_surface_param.py::test_q_profiles - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
ERROR tests/test_2Dinterpolation.py::test_surfacefunction[4-data0-coord10-coord20-3-1] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 2 has size 2
ERROR tests/test_2Dinterpolation.py::test_surfacefunction[4-data1-coord11-coord21-3-0] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 2 has size 2
ERROR tests/test_2Dinterpolation.py::test_surfacefunction[5-data0-coord10-coord20-3-1] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
ERROR tests/test_2Dinterpolation.py::test_surfacefunction[5-data1-coord11-coord21-3-0] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
ERROR tests/test_coordinates.py::test_coordinates[4] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 2 has size 2
ERROR tests/test_coordinates.py::test_coordinates[5] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
ERROR tests/test_equilibria.py::test_critical[4] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 2 has size 2
ERROR tests/test_equilibria.py::test_eq_properties[4] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 2 has size 2
ERROR tests/test_equilibria.py::test_critical[5] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
ERROR tests/test_equilibria.py::test_eq_properties[5] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
ERROR tests/test_gfile.py::test_from_to_gfile[4] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 2 has size 2
ERROR tests/test_gfile.py::test_from_to_gfile[5] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
ERROR tests/test_io.py::test_dict2xarray[4] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 2 has size 2
ERROR tests/test_io.py::test_dict2xarray[5] - ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 2
======================================================================================================================= 26 failed, 56 passed, 1 skipped, 102 warnings, 14 errors in 226.26s (0:03:46) =======================================================================================================================

Happy to attach the full failure log if that would be helpful!

io.compass - Use last revision by default

Function pleque.io.compass.cdb() uses revision=1 as a default parameter value. I would propose a change to revision=-1, i.e. the most recent revision.

Arguments:

  • On the one hand, the original behaviour enforces some degree of reproducibility of the returned value on subsequent calls. On the other hand, there are cases where the revision=1 data in CDB are broken (cause exception when you attempt to load them) but a fixed version of the data are available in revision=2. As a result, the original behaviour ensures that that particular discharge will always throw error, possibly misleading the user into thinking that no "fixed data" exist.
  • A second argument for the change is the fact that the pyCDB client loads the most recent revision by default. A user then might logically expect the same behaviour from pleque as well, since this feels as the defining property/philosophy of the CDB database itself (i.e. "last revision is always/eventually the best revision which everyone should use").

FluxSurface class

  • implement into class Equilibrium as
def flux_surface(*coordinates, psi_n=None, coord_type=('psi_n'), resolution = 100, **coords):
    """
    :param resolution: number of points used for generation of FluxSurface
    :return FluxSurface or list of FluSurfaces generated on given coordinates. 
    """
    grid = False
    ...
  • add test file to test all implemented functions
  • FluxSurface should accept instance of Coordinates on input
  • implement (r, theta) coordinates into Coordinates class
  • implement as_array into Coordinates
  • all functions returning some set of points should return instance of Coordinates

copy object to itself

@smartass101 @coobas
Is it possible to simply satisfy something like this:

class A:
  def __init__(self, name):
    if isinstance(name, str):
      self.name = name
    elif isinstance(name, A):
      self = name

a = A('foo')
b = A(a)

Where I intend to a and b be the same objects/or copies of one object.
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.