boutpy.boututils
– useful tools¶Table of Contents
calculus
– Derivatives and Integralscompare_inp
– parse & compare BOUT.inpdatafile
– Netcdf File I/Ofileio
– data I/O methodsfunctions
– useful functionspfile
– Osborne pfiles I/Oshell
– Run shell commandcalculus
– Derivatives and Integrals¶deriv (*args, **kwargs) |
Take derivative of 1D array. |
integrate (var[, periodic]) |
Integrate a 1D array |
Derivatives and integrals of periodic and non-periodic functions
B.Dudson, University of York, Nov 2009
compare_inp
– parse & compare BOUT.inp¶parser_config (configfile[, level1, header, …]) |
Parser config files. |
dict_to_level1 (Dict[, sep]) |
Convert a dict to a one level dict. |
compare_inp (*configfiles, **kwargs) |
Comparison of configfiles, return & print details of differences. |
Parser config files
boutpy.boututils.compare_inp.
str_to_num
(x)[source]¶Convert str ‘x’ to int or float if possible, otherwise return itself.
boutpy.boututils.compare_inp.
parser_config
(configfile, level1=False, header=None, dataframe=False)[source]¶Parser config files.
Return a dict contains all options information in the config files.
Parameters: |
|
---|---|
Returns: |
|
Examples
>>> result = parser_config('/path/to/BOUT.inp')
# ConfigObj({'NOUT': '250', 'TIMESTEP': '1.e0',
# ...
# 'kappa': {'bndry_core': 'neumann', 'bndry_sol': 'neumann'}})
>>> result = parser_config('[header]\noption1=1', header='main')
# ConfigObj({'header': {'option1': '1'}})
>>> result = parser_config('#comments\noptions=1')
# ConfigObj({'options': '1'})
>>> result = parser_config('#comments\noptions=1', header='main')
# ConfigObj({'main': {'options': '1'}})
boutpy.boututils.compare_inp.
dict_to_level1
(Dict, sep=u'.')[source]¶Convert a dict to a one level dict.
Parameters: |
|
---|---|
Returns: |
|
Examples
>>> test1 = {'A': {'a': 1,'b': 2}, 'B': 3}
>>> dict_to_level1(test1)
# {'A.a': 1, 'A.b': 2, 'B': 3}
>>> test2 = {'A':{'a': 1, 'b': 2}, 'a': 3}
>>> dict_to_level1(test2)
# {'A.a': 1, 'A.b': 2, 'a': 3}
boutpy.boututils.compare_inp.
multi_index
(boutinp, header=u'global', column=u'Value')[source]¶Return a panda.DataFrame with [‘Sec’, ‘Opt’] as multi-index.
Parameters: |
|
---|---|
Returns: |
|
boutpy.boututils.compare_inp.
compare_inp
(*configfiles, **kwargs)[source]¶Comparison of configfiles, return & print details of differences.
Parameters: |
|
---|---|
Returns: |
|
Examples
>>> import glob
>>> cases, table = compare_inp(glob.glob("*/BOUT.inp"), grid=False)
datafile
– Netcdf File I/O¶boutpy.boututils.datafile.
DataFile
(filename=None, write=False, create=False, format='NETCDF3_CLASSIC')[source]¶NETCDF file I/O class.
Methods
open(filename, write=False, create=False, format=’NETCDF3_CLASSIC’) | Open NETCDF file |
close() | Close netcdf file |
read(name, range=None) | Read variable from file. |
fileio
– data I/O methods¶save2nc (filename, mode, *args, **kwargs) |
Save variables to NetCDF file. |
readsav (filename[, idict, python_dict, …]) |
Read an IDL .sav file. |
file_import (filename) |
Import an NetCDF file. |
file_list (filename[, ncol, sep]) |
Return a sorted list of names of all variables in NetCDF file. |
This module is for data I/O
Requirements
boutpy.boututils.fileio.
save2nc
(filename, mode, *args, **kwargs)[source]¶Save variables to NetCDF file.
ONLY for numeric type variables.
Parameters: |
|
---|---|
Returns: |
|
See also
numpy.savez
numpy.load
Notes
Any bug reports and suggestion are gladly welcome. Email: cjgls@pku.edu.cn
boutpy.boututils.fileio.
readsav
(filename, idict=None, python_dict=False, uncompressed_file_name=None, verbose=False, reverse=True)[source]¶Read an IDL .sav file.
Parameters: |
|
---|---|
Returns: |
|
boutpy.boututils.fileio.
file_import
(filename)[source]¶Import an NetCDF file.
Parameters: |
|
---|---|
Returns: |
|
boutpy.boututils.fileio.
file_list
(filename, ncol=None, sep=u' ')[source]¶Return a sorted list of names of all variables in NetCDF file.
Parameters: |
|
---|---|
Returns: |
|
functions
– useful functions¶get_yesno ([prompt, default, timeout]) |
Get yes/no from input, return Ture/False correspondingly. |
get_nth (n_th, end[, start, pad]) |
Get the nth value in closed interval [start, end] |
get_limits (array) |
Get the minium and maxium value of array |
get_input ([prompt, timeout]) |
Get input from stdin with timer |
nearest (array, target[, value]) |
Find the element in array which is closest to target |
pycommand ([default, lvars, gvars]) |
Run python command |
nrange (start, stop, step[, endpoint]) |
Return evenly spaced numbers over a specified interval except endpoint: interval [start, start`+`step, …, stop] |
sort_nicely (l) |
Sort the given list in the way that humans expect. |
Common Funtions.
boutpy.boututils.functions.
get_yesno
(prompt=u'Yes?[y/N]: ', default=False, timeout=5)[source]¶Get yes/no from input, return Ture/False correspondingly.
Parameters: |
|
---|---|
Returns: |
|
boutpy.boututils.functions.
get_nth
(n_th, end, start=0, pad=u'const')[source]¶Get the nth value in closed interval [start, end]
Parameters: |
|
---|---|
Returns: |
|
boutpy.boututils.functions.
get_limits
(array)[source]¶Get the minium and maxium value of array
Parameters: |
|
---|---|
Returns: |
|
boutpy.boututils.functions.
get_input
(prompt=u'input', timeout=5)[source]¶Get input from stdin with timer
Parameters: |
|
---|---|
Returns: |
|
boutpy.boututils.functions.
nearest
(array, target, value=False)[source]¶Find the element in array which is closest to target
Parameters: |
|
---|---|
Returns: |
|
boutpy.boututils.functions.
pycommand
(default=None, lvars=None, gvars=None)[source]¶Run python command
Parameters: |
|
---|---|
Returns: |
|
boutpy.boututils.functions.
sort_nicely
(l)[source]¶Sort the given list in the way that humans expect.
Parameters: |
|
---|---|
Returns: |
|
Examples
>>> a=['z20', 'z2', 'z10']
>>> sort_nicely(a)
['z2', 'z10', 'z20']
>>> a.sort()
['z10', 'z2', 'z20']
boutpy.boututils.functions.
nrange
(start, stop, step, endpoint=True)[source]¶Return evenly spaced numbers over a specified interval except endpoint: interval [start, start`+`step, …, stop]
The endpoint stop of the the interval can optionally be excluded.
Parameters: |
|
---|---|
Returns: |
|
pfile
– Osborne pfiles I/O¶A class object used to interface with Osborne pfiles.
boutpy.boututils.pfile.
pfile
(filename)[source]¶A class object used to interface with Osborne pfiles.
This class is inheritated from collections.OrderedDict. Each variable are loaded as an dict item, its value is an dict object including keys ‘data’, ‘description’, ‘units’, ‘psinorm’, ‘derivative’.
Notes
This class is modified from omfit_osborne.py in the OMFIT project.
Attributes: |
|
---|
Methods
load() | load pfile data, called at the initiation stage. |
save(filename=None) | save pfile data to filename if it is given. Otherwise overwrite the original file. |
plot() | plot profiles in the pfile. |
interpolate() | interpolate the profiles to the same psinorm. Return all profiles and psin . |
interpolate
(npoints=500, psin=None, output=False)[source]¶Interpolate profiles to same psin array.
Parameters: |
|
---|---|
Returns: |
|
shell
– Run shell command¶shell (command[, pipe]) |
Return the status and output of a shell command. |
jobinfo (jobid) |
Return a dict containing all information of the slurm job. |
Run a shell command.
boutpy.boututils.shell.
shell
(command, pipe=False)[source]¶Return the status and output of a shell command.
Parameters: |
|
---|---|
Returns: |
|