# Path: pyfusion/data/tests.py
# def get_multimode_test_data(channels = get_n_channels(DEFAULT_N_CHANNELS),
#                             timebase = DEFAULT_TIMEBASE,
#                             modes = [mode_1, mode_2], noise = DEFAULT_NOISE):
#     """Generate synthetic multi-channel data for testing."""
#     n_channels = len(channels)
#     data_size = (n_channels, timebase.size)
#     data_array = noise*2*(np.random.random(data_size)-0.5)
#     timebase_matrix = np.resize(timebase, data_size)
#     angle_matrix = np.resize(np.array([i.coords.cylindrical[1] for i in channels]),
#                           data_size[::-1]).T
#     for m in modes:
#         data_array += m['amp']*np.cos(2*np.pi*m['freq']*timebase_matrix +
#                                    m['mode_number']*angle_matrix + m['phase'])
#     output = TimeseriesData(timebase=timebase, signal=Signal(data_array),
#                             channels=channels)
#     return output
# 
# def get_n_channels(n_ch):
#     """Return a list of n_ch channels."""
#     poloidal_coords = 2*np.pi*np.arange(n_ch)/n_ch
#     channel_gen = (Channel('ch_%02d' %i, Coords('cylindrical', (1.0,i,0.0)))
#                    for i in poloidal_coords)
#     return ChannelList(*channel_gen)
# 
# Path: pyfusion/data/timeseries.py
# class Timebase(np.ndarray):
#     """Timebase vector with parameterised internal representation.
# 
#     see doc/subclassing.py in numpy code for details on subclassing ndarray
#     """
#     def __new__(cls, input_array):
#         # should this follow the example in doc/subclassing.py?... (it doesn't)
#         obj = np.asarray(input_array).view(cls).copy()
#         obj.sample_freq = 1.0/(obj[1]-obj[0])
#         obj.meta = PfMetaData()
#         return obj
# 
#     def is_contiguous(self):
#         return max(((self[1:]-self[:-1])-1.0/self.sample_freq)**2) < (0.1/self.sample_freq)**2
# 
#     def normalise_freq(self, input_freq):
#         """Normalise input frequencies to [0,1] where 1 is pi*sample_freq"""
#         try:
#             return input_freq/(0.5*self.sample_freq)
#         except:
#             # sample_freq should maybe be self.sample_freq? i don't remember
#             return [i/(0.5*self.sample_freq) for i in sample_freq]
# 
#     def __array_finalize__(self, obj):
#         # ``self`` is a new object resulting from
#         # ndarray.__new__(InfoArray, ...), therefore it only has
#         # attributes that the ndarray.__new__ constructor gave it -
#         # i.e. those of a standard ndarray.
#         #
#         # We could have got to the ndarray.__new__ call in 3 ways:
#         # From an explicit constructor - e.g. InfoArray():
#         #    obj is None
#         #    (we're in the middle of the InfoArray.__new__
#         #    constructor, and self.info will be set when we return to
#         #    InfoArray.__new__)
#         if obj is None: return
#         # From view casting - e.g arr.view(InfoArray):
#         #    obj is arr
#         #    (type(obj) can be InfoArray)
#         # From new-from-template - e.g infoarr[:3]
#         #    type(obj) is InfoArray
#         #
#         # Note that it is here, rather than in the __new__ method,
#         # that we set the default value for 'info', because this
#         # method sees all creation of default objects - with the
#         # InfoArray.__new__ constructor, but also with
#         # arr.view(InfoArray).
#         self.sample_freq = getattr(obj, 'sample_freq', None)
#         self.meta = getattr(obj, 'meta', None)
#         # We do not need to return anything


import numpy as np
import cProfile, pstats, os
from pyfusion.data.tests import get_multimode_test_data, get_n_channels
from pyfusion.data.timeseries import Timebase
"""
generate flucstrucs for benchmarking
"""

THIS_DIR = os.path.dirname(__file__)

stats_file = os.path.join(THIS_DIR, "stats", "fs")

n_ch = 30
n_samples = 1024*100

# Path: pyfusion/data/tests.py
# def get_multimode_test_data(channels = get_n_channels(DEFAULT_N_CHANNELS),
#                             timebase = DEFAULT_TIMEBASE,
#                             modes = [mode_1, mode_2], noise = DEFAULT_NOISE):
#     """Generate synthetic multi-channel data for testing."""
#     n_channels = len(channels)
#     data_size = (n_channels, timebase.size)
#     data_array = noise*2*(np.random.random(data_size)-0.5)
#     timebase_matrix = np.resize(timebase, data_size)
#     angle_matrix = np.resize(np.array([i.coords.cylindrical[1] for i in channels]),
#                           data_size[::-1]).T
#     for m in modes:
#         data_array += m['amp']*np.cos(2*np.pi*m['freq']*timebase_matrix +
#                                    m['mode_number']*angle_matrix + m['phase'])
#     output = TimeseriesData(timebase=timebase, signal=Signal(data_array),
#                             channels=channels)
#     return output
# 
# def get_n_channels(n_ch):
#     """Return a list of n_ch channels."""
#     poloidal_coords = 2*np.pi*np.arange(n_ch)/n_ch
#     channel_gen = (Channel('ch_%02d' %i, Coords('cylindrical', (1.0,i,0.0)))
#                    for i in poloidal_coords)
#     return ChannelList(*channel_gen)
# 
# Path: pyfusion/data/timeseries.py
# class Timebase(np.ndarray):
#     """Timebase vector with parameterised internal representation.
# 
#     see doc/subclassing.py in numpy code for details on subclassing ndarray
#     """
#     def __new__(cls, input_array):
#         # should this follow the example in doc/subclassing.py?... (it doesn't)
#         obj = np.asarray(input_array).view(cls).copy()
#         obj.sample_freq = 1.0/(obj[1]-obj[0])
#         obj.meta = PfMetaData()
#         return obj
# 
#     def is_contiguous(self):
#         return max(((self[1:]-self[:-1])-1.0/self.sample_freq)**2) < (0.1/self.sample_freq)**2
# 
#     def normalise_freq(self, input_freq):
#         """Normalise input frequencies to [0,1] where 1 is pi*sample_freq"""
#         try:
#             return input_freq/(0.5*self.sample_freq)
#         except:
#             # sample_freq should maybe be self.sample_freq? i don't remember
#             return [i/(0.5*self.sample_freq) for i in sample_freq]
# 
#     def __array_finalize__(self, obj):
#         # ``self`` is a new object resulting from
#         # ndarray.__new__(InfoArray, ...), therefore it only has
#         # attributes that the ndarray.__new__ constructor gave it -
#         # i.e. those of a standard ndarray.
#         #
#         # We could have got to the ndarray.__new__ call in 3 ways:
#         # From an explicit constructor - e.g. InfoArray():
#         #    obj is None
#         #    (we're in the middle of the InfoArray.__new__
#         #    constructor, and self.info will be set when we return to
#         #    InfoArray.__new__)
#         if obj is None: return
#         # From view casting - e.g arr.view(InfoArray):
#         #    obj is arr
#         #    (type(obj) can be InfoArray)
#         # From new-from-template - e.g infoarr[:3]
#         #    type(obj) is InfoArray
#         #
#         # Note that it is here, rather than in the __new__ method,
#         # that we set the default value for 'info', because this
#         # method sees all creation of default objects - with the
#         # InfoArray.__new__ constructor, but also with
#         # arr.view(InfoArray).
#         self.sample_freq = getattr(obj, 'sample_freq', None)
#         self.meta = getattr(obj, 'meta', None)
#         # We do not need to return anything


# Path: pyfusion/test/benchmarks/gen_flucstrucs.py
import numpy as np
import cProfile, pstats, os
from pyfusion.data.tests import get_multimode_test_data, get_n_channels
from pyfusion.data.timeseries import Timebase

"""
generate flucstrucs for benchmarking
"""

THIS_DIR = os.path.dirname(__file__)

stats_file = os.path.join(THIS_DIR, "stats", "fs")

n_ch = 30
n_samples = 1024*100

data = get_multimode_test_data(channels=get_n_channels(n_ch),