#######################################################################
#
# $Id: XYData.py,v 1.2 2008-02-07 05:45:25 lorenz Exp $
# 
# Copyright (C) 2004-2008 Petr Lorenz
# All rights reserved.
# 
# ##### BEGIN LICENSE BLOCK #####
#
# Version: MPL 1.1 / GPL 2.0 / LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
# 
# The Original Code is Petr Lorenz emGine Graphical User Interface (GUI).
# 
# The Initial Developer of the Original Code is Petr Lorenz.
# Portions created by the Initial Developer are Copyright (C) 2004-2008.
# All Rights Reserved.
# 
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the  "GPL"), or the
# GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
# case the provisions of the GPL or the LGPL are applicable instead of those
# above.  If you wish to allow use of your version of this file only under the
# terms of either the GPL or the LGPL and not to allow others to use your
# version of this file under the MPL, indicate your decision by deleting the
# provisions above and replace them with the notice and other provisions
# required by the GPL or LGPL.  If you do not delete the provisions above, a
# recipient may use your version of this file under the terms of any one of the
# MPL License, the GPL or the LGPL.
#
# ##### END LICENSE BLOCK #####
#
#######################################################################
# 
# $Log: XYData.py,v $
# Revision 1.2  2008-02-07 05:45:25  lorenz
# * Fixed 'Simulation Boundary View' check problem
#   when closing a project.
#
# * Fixed Bounding Box problems when moving/editing a geometry.
#
# Revision 1.1.1.1  2008-01-28 06:15:35  lorenz
# Import emGine GUI v. 0.7.1
#
# Revision 1.3  2007-07-02 06:37:18  lorenz
# Clean up of old code.
#
# Revision 1.2  2007-05-14 04:53:51  lorenz
# New code for multiport time-domain signals and S-parameters
#
# Revision 1.1.1.1  2007-05-08 06:22:35  lorenz
# Initial Import
#
#######################################################################

#
# June 2006 - May 2007
#
# XYData Object
#
import numpy
import FFTData

#
# The data values are internaly stored as NumPy arrays
#
class XYData:
  def __init__(self):
    self.xvalues = None
    self.yvalues = list()
    self.fft_OP = FFTData.FFTData()	# fft OPerator

  def set_xvalues(self, data):
    self.xvalues = numpy.array(data)

  def set_yvalues(self, data, elem = None):
    print len(self.yvalues)
    if (elem != None):
      self.yvalues[elem] = numpy.array(data)
    else:
      self.yvalues = list()
      self.add_yvalues(data)

  def add_yvalues(self, data):
    self.yvalues.append(numpy.array(data))

  def get_ylen(self):
    return len(self.yvalues)

  def get_xlist(self):
    return self.xvalues.tolist()

  def get_ylist(self, elem = 0):
    return self.yvalues[elem].tolist()

  def get_ylist_abs(self, elem = 0):
    return numpy.absolute(self.yvalues[elem]).tolist()

  def get_real_ylist(self, elem = 0):
    return numpy.real(self.yvalues[elem]).tolist()

  def get_imag_ylist(self, elem = 0):
    return numpy.imag(self.yvalues[elem]).tolist()

  def get_abs_ylist(self, elem = 0):
    return numpy.absolute(self.yvalues[elem]).tolist()

  def get_10abs_dB_ylist(self, elem = 0):
    return (10*numpy.log10(numpy.absolute(self.yvalues[elem]))).tolist()

  def get_20abs_dB_ylist(self, elem = 0):
    return (20*numpy.log10(numpy.absolute(self.yvalues[elem]))).tolist()

  def get_xarray(self):
    return self.xvalues

  def get_yarray(self, elem = 0):
    return self.yvalues[elem]

  def get_real_yarray(self, elem = 0):
    return numpy.real(self.yvalues[elem])

  def get_imag_yarray(self, elem = 0):
    return numpy.imag(self.yvalues[elem])

  def get_abs_yarray(self, elem = 0):
    return numpy.absolute(self.yvalues[elem])

  def get_10abs_dB_yarray(self, elem = 0):
    return 10*numpy.log10(numpy.absolute(self.yvalues[elem]))

  def get_20abs_dB_yarray(self, elem = 0):
    return 20*numpy.log10(numpy.absolute(self.yvalues[elem]))

  def fft(self, Npoints = None, elem = 0):
    self.yvalues[elem] = self.fft_OP.array_to_array(self.yvalues[elem], Npoints)

  def fft_all(self, Npoints = None):
    for i in range(len(self.yvalues)):
      self.fft(Npoints, i)


