Support for the log.TAG files

class magic.MagicSetup(datadir='.', nml='input.nml', quiet=False)[source]

This class allows to read the input namelist or the log file of a current job and creates an object that contains all the parameters found in the namelist/log file.

>>> stp = MagicSetup(nml='log.test', quiet=True)
>>> print(stp.ra) # print the Rayleigh number
>>> print(stp.n_r_max) # print n_r_max
__init__(datadir='.', nml='input.nml', quiet=False)[source]
Parameters
  • datadir (str) – the working directory

  • nml (str) – name of the input namelist/ log file

  • quiet (bool) – when set to True, makes the output silent (default False)

__weakref__

list of weak references to the object (if defined)

Support for the time series

class magic.MagicTs(datadir='.', field='e_kin', iplot=True, all=False, tag=None)[source]

This python class is used to read and plot the different time series written by the code:

Here are a couple of examples of how to use this function.

>>> # plot the most recent e_kin.TAG file found in the directoy
>>> MagicTs(field='e_kin')
>>>
>>> # stack **all** the power.TAG file found in the directory
>>> ts = MagicTs(field='power', all=True)
>>> print(ts.time, ts.buoPower) # print time and buoyancy power
>>>
>>> # If you only want to read the file ``heat.N0m2z``
>>> ts = MagicTs(field='heat', tag='N0m2z', iplot=False)
__init__(datadir='.', field='e_kin', iplot=True, all=False, tag=None)[source]
Parameters
  • datadir (str) – working directory

  • field (str) – the file you want to plot

  • iplot (bool) – when set to True, display the plots (default True)

  • all (bool) – when set to True, the complete time series is reconstructed by stacking all the corresponding files from the working directory (default False)

  • tag (str) – read the time series that exactly corresponds to the specified tag

plot()[source]

Plotting subroutines. Only called if ‘iplot=True’

Averaging the time series

class magic.AvgField(tag=None, tstart=None, model='/home/gastine/magic/python/magic/model.json', datadir='.', std=False, write=True)[source]

This class computes the time-average properties from time series, spectra and radial profiles. It will store the input starting time in a small file named tInitAvg, such that the next time you use it you don’t need to provide tstart again. By default, the outputs are stored in a fully documented JSON file named avg.json: this is split into several categories, namely numerical parameters, physical parameters, time averaged scalar quantities, time averaged spectra and time-averaged radial profiles. The quantities stored in the JSON file are entirely controlled by an input model file wich enlists the different quantities of interest. A default example file named model.json is provided in $MAGIC_HOME/python/magic, and an example of how to build a dedicated one is provided below.

>>> # Average from t=2.11
>>> a = AvgField(tstart=2.11)
>>> # Average only the files that match the pattern N0m2[a-c]
>>> a = AvgField(tstart=2.11, tag='N0m2[a-c]')
>>> print(a) # print the formatted output
>>> # Custom JSON model to select averages
>>> json_model = { 'phys_params': ['ek'],
                   'time_series': { 'heat': ['topnuss', 'botnuss'],
                                    'e_kin': ['ekin_pol', 'ekin_tor'],
                                    'par': ['rm'] },
                   'spectra': {},
                   'radial_profiles': {'powerR': ['viscDiss', 'buoPower']}
                 }
>>> # Compute the selected averages in the dirctory mydir
>>> a = AvgField(datadir='mydir', model=json_model)
__init__(tag=None, tstart=None, model='/home/gastine/magic/python/magic/model.json', datadir='.', std=False, write=True)[source]
Parameters
  • tag (str) – if you specify an input tag (generic regExp pattern), the averaging process will only happen on the time series that match this input pattern

  • tstart (float) – the starting time for averaging

  • datadir (str) – working directory

  • std (bool) – compute the standard deviation when set to True

  • write (bool) – write the outputs in a JSON file

  • model (str) – this is the path of a JSON file which defines which fields will be handled in the time-averaging process. This can be any python attributes wich is defined in MagicTs, MagicSpectrum or MagicRadial.

__str__()[source]

Formatted output

__weakref__

list of weak references to the object (if defined)

get_tags(tstart)[source]

This routine returns a list of tags which have been generated after tstart

Parameters

tstart (float) – starting averaging time

Returns

a list of tags

Return type

list

write_header()[source]

Write header in case an ascii output is requested

write_json(datadir='.')[source]

This function writes the averages as a simple JSON file stored in the directory ‘avg.json’

Parameters

datadir (str) – working directory

Some resolution/convergence checks

magic.checker.MagicCheck(tstart=None)[source]

This function is used to compute several sanity checks that can be evaluated if the power.TAG and some spectra have been produced in the current directory. If in addition the tInitAvg file is also there in the directory it averages only from this starting time.

>>> MagicCheck(tstart=10.)