SDDS Python Demo Fails

Moderators: cyao, michael_borland

Post Reply
JoelFrederico
Posts: 60
Joined: 05 Aug 2010, 11:32
Location: SLAC National Accelerator Laboratory

SDDS Python Demo Fails

Post by JoelFrederico » 01 Nov 2012, 16:55

Hey all,

I can't seem to get the SDDS Python Demo function to work. I'm diving into the source, but I'm new to the Python C API, so it's slow. So far I've traced the problem to sddsdata.SetParameter(x.index,page,value) where value is a string. Whenever I ask that function to return a value it gives me this error. E.g., if I'm storing the result to a variable, or if I'm comparing it as the Python does in the sdds.save function from "import sdds". I copied the demo and save functions into my own script. When it gets to the sddsdata.SetParameter part, it errors out. I'm running iPython. So it returns and leaves things as it was when it was running. If I try to execute just the sddsdata.SetParameter command, it seems to work. Ipython shows a "1L" as the result. But if I say test=sddsdata.SetParameter(..., same error. If I compare it, same error. If I print it, same error. I have no idea what's going on, but it seems to have an issue with returning a value...

Maybe I just don't try to set parameters that have text instead of values... But it's weird that your demo function doesn't even work, you guys might want to fix that...

Joel

Code: Select all

In [1]: import sdds

In [2]: sdds.dem
sdds.demo   sdds.demo2  

In [2]: sdds.demo('output.sdds')
/u/pl/joelfred/opt/lib/python2.7/site-packages/sdds/sdds.py:170: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
  if sddsdata.SetParameter(self.index, i, self.parameterData[i][page]) != 1:
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/afs/slac.stanford.edu/u/pl/joelfred/SDDSTOOLS/<ipython-input-2-9501aeffffb1> in <module>()
----> 1 sdds.demo('output.sdds')

/u/pl/joelfred/opt/lib/python2.7/site-packages/sdds/sdds.pyc in demo(output)
    311                               ["","","","",x.SDDS_STRING,0],
    312                               ["","","","",x.SDDS_CHARACTER,0]]
--> 313      x.save(output)
    314      del x
    315 

/u/pl/joelfred/opt/lib/python2.7/site-packages/sdds/sdds.pyc in save(self, output)
    168                          sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
    169                     for i in range(numberOfParameters):
--> 170                          if sddsdata.SetParameter(self.index, i, self.parameterData[i][page]) != 1:
    171                               sddsdata.PrintErrors(self.SDDS_EXIT_PrintErrors)
    172                     for i in range(numberOfColumns):

TypeError: an integer is required

JoelFrederico
Posts: 60
Joined: 05 Aug 2010, 11:32
Location: SLAC National Accelerator Laboratory

Re: SDDS Python Demo Fails

Post by JoelFrederico » 01 Nov 2012, 17:09

It seems to have the same problem with characters in columns. The save functionality just seems to be really broken. Is this true? Or is it just me?

soliday
Posts: 408
Joined: 28 May 2008, 09:15

Re: SDDS Python Demo Fails

Post by soliday » 02 Nov 2012, 09:28

I just tested the demo script by running:

import sdds
sdds.demo('out.sdds')

and it worked without any problems. I ran this on CentOS 6.3 with Python 2.6 with our SDDSPython-2.6.6-1.x86_64.rpm package. We don't have a package built for your Python 2.7 version which might be the source of the problem. I will look into getting a copy of Python 2.7 and building a version of SDDSPython for it.

soliday
Posts: 408
Joined: 28 May 2008, 09:15

Re: SDDS Python Demo Fails

Post by soliday » 02 Nov 2012, 10:18

Try the version I just compiled using python2.7. You can get it from:
www.aps.anl.gov/asd/oag/downloads/sddspython2.7.tar
Unpack the tar file in your /u/pl/joelfred/opt/lib/python2.7/site-packages/sdds/ to overwrite your sddsdatamodule.so, sdds.py and sdds.pyc files. I was able to run the sdds.demo() function with this without any problems. Let me know if it works.

JoelFrederico
Posts: 60
Joined: 05 Aug 2010, 11:32
Location: SLAC National Accelerator Laboratory

Re: SDDS Python Demo Fails

Post by JoelFrederico » 02 Nov 2012, 13:49

It's better... no errors, but the file is written incorrectly. I'm running on RedHat:

Code: Select all

===============================================================================
RHEL Workstation 6.3 (Santiago) 2.6.32-279.5.2.el6.x86_64 (4x2992MHz OptiPlex 960)
===============================================================================
joelfred@ar-frederico ~$ sddsprintout -par=* -col=* test.sdds 
Printout for SDDS file test.sdds

ShortP =                 1  LongP =                  2  FloatP =      3.300000e+00  DoubleP =     4.400000e+00
StringP =             five  CharacterP =              a

 ShortC     LongC        FloatC        DoubleC          StringC      CharacterC 
--------------------------------------------------------------------------------
      1           1   1.000000e+00   1.000000e+00             row 1           x 
      2           0   2.000000e+00   2.000000e+00             row 2           y 
      3           2   3.000000e+00   3.000000e+00             row 3           z 
ShortP =                 6  LongP =                  7  FloatP =      8.800000e+00  DoubleP =     9.800000e+00
StringP =              ten  CharacterP =              b

 ShortC     LongC        FloatC        DoubleC          StringC      CharacterC 
--------------------------------------------------------------------------------
     -1          -1  -1.000000e+00  -1.000000e+00             row 1           i 
     -2          -1  -2.000000e+00  -2.000000e+00             row 2           j 
     -3          -2  -3.600000e+00  -3.600000e+00             row 3           k 
     -4          -1  -4.400000e+00  -4.400000e+00             row 4           l 
The LongC column data is wrong - it shows up as 1 0 2 not 1 2 3, and -1 -1 -2 -1 not -1 -2 -3 -4. Everything else makes sense though.

This is the code for the demo function:
Screenshot.png

soliday
Posts: 408
Joined: 28 May 2008, 09:15

Re: SDDS Python Demo Fails

Post by soliday » 02 Nov 2012, 14:32

Okay, I didn't notice that problem before. If you redownload the link I posted you will get a fix for this problem. The problem stems from running this on a 64bit computer. I believe I fixed it for both reading and writing.

JoelFrederico
Posts: 60
Joined: 05 Aug 2010, 11:32
Location: SLAC National Accelerator Laboratory

Re: SDDS Python Demo Fails

Post by JoelFrederico » 02 Nov 2012, 14:39

That looks great! Thanks for helping.

Post Reply