As we are at it,

Andre Gosselin (the guy who wrote pycdf) also wrote an interface to HDF4
(not 5) named pyhdf. I'm using that with numpy as well (patch attached),
but I haven't tested it much - little more than just running the examples,
really (which appear to be ok). Maybe it's useful...

In pyhdf, the author didn't support different array interfaces; so the
attached patch just modifes the existing source code and moves it over
to numpy. I've also attached a "install script" which makes use of the
particular lacotion of the HDF4 libraries (in $PREFIX/lib) and header
files (in $PREFIX/include/hdf), so it it almost certainly needs to be
adapted to the location of the actual HDF libraries and headers.

Regards,

  Christian.


On Fri, February 9, 2007 22:00, Christian Marquardt wrote:
> Dear list,
>
> attached is a patch for the original pycdf-0.6.2-rc1 distribution as
> available through sourceforge - and a little shell script illustrating
> how to install it. After applyng the patch, it should be configured for
> numpy. Note that the "installation" script uses an environment variable
> PREFIX to define where the pacjkage is installed; it also assumes that
> the netcdf libraries are installed in $PREFIX/lib.
>
> The orginal author already supported both numeric and numarray, so I just
> added a new subdirectory for numpy - which is simply the numeric version
> slightly changed. The patch is only that large because it replicates much
> of already existing code...
>
> I have been using this "port" for many weeks now without any problems or
> difficulties. I hope it's useful for others as well;-)
>
>   Christian.
>
>
>
> On Fri, February 9, 2007 15:31, Daran L. Rife wrote:
>> Hi Travis,
>>
>> If you're still offering NumPy "patches" to third party
>> packages that rely upon Numeric, I would really like for
>> pycdf to be ported to NumPy. This would allow me to
>> completely transition to NumPy.
>>
>> Thanks very much for considering my request.
>>
>>
>> Daran Rife
>>
>> _______________________________________________
>> Numpy-discussion mailing list
>> Numpy-discussion@scipy.org
>> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
diff -r -N -C 3 pyhdf-0.7-3/examples/hdfstruct/hdfstruct.py pyhdf-0.7-3-numpy/examples/hdfstruct/hdfstruct.py
*** pyhdf-0.7-3/examples/hdfstruct/hdfstruct.py	2004-11-03 15:41:12.000000000 +0100
--- pyhdf-0.7-3-numpy/examples/hdfstruct/hdfstruct.py	2007-01-20 21:08:53.000000000 +0100
***************
*** 2,8 ****
  
  import sys
  from pyhdf.SD import *
! from Numeric import *
  
  # Dictionnary used to convert from a numeric data type to its symbolic
  # representation
--- 2,8 ----
  
  import sys
  from pyhdf.SD import *
! from numpy import *
  
  # Dictionnary used to convert from a numeric data type to its symbolic
  # representation
diff -r -N -C 3 pyhdf-0.7-3/examples/szip/szip16.py pyhdf-0.7-3-numpy/examples/szip/szip16.py
*** pyhdf-0.7-3/examples/szip/szip16.py	2005-07-13 05:19:19.000000000 +0200
--- pyhdf-0.7-3-numpy/examples/szip/szip16.py	2007-01-20 21:04:14.000000000 +0100
***************
*** 1,7 ****
  #!/usr/bin/env python
  
  from pyhdf.SD import *
! import Numeric
  
  SZIP = True
  
--- 1,7 ----
  #!/usr/bin/env python
  
  from pyhdf.SD import *
! import numpy
  
  SZIP = True
  
***************
*** 12,18 ****
  WIDTH       = 100
  fill_value  = 0
  
! #data = Numeric.array(((100,100,200,200,300,400),
  #                      (100,100,200,200,300,400),
  #                      (100,100,200,200,300,400),
  #                      (300,300,  0,400,300,400),
--- 12,18 ----
  WIDTH       = 100
  fill_value  = 0
  
! #data = numpy.array(((100,100,200,200,300,400),
  #                      (100,100,200,200,300,400),
  #                      (100,100,200,200,300,400),
  #                      (300,300,  0,400,300,400),
***************
*** 20,28 ****
  #                      (300,300,  0,400,300,400),
  #                      (0,  0,600,600,300,400),
  #                      (500,500,600,600,300,400),
! #                      (0,  0,600,600,300,400)), Numeric.Int16)
  
! data = Numeric.zeros((LENGTH, WIDTH), Numeric.Int16)
  for i in range(LENGTH):
      for j in range(WIDTH):
          data[i,j] = i+j
--- 20,28 ----
  #                      (300,300,  0,400,300,400),
  #                      (0,  0,600,600,300,400),
  #                      (500,500,600,600,300,400),
! #                      (0,  0,600,600,300,400)), numpy.int16)
  
! data = numpy.zeros((LENGTH, WIDTH), numpy.int16)
  for i in range(LENGTH):
      for j in range(WIDTH):
          data[i,j] = i+j
diff -r -N -C 3 pyhdf-0.7-3/examples/szip/szip32.py pyhdf-0.7-3-numpy/examples/szip/szip32.py
*** pyhdf-0.7-3/examples/szip/szip32.py	2005-07-13 22:51:18.000000000 +0200
--- pyhdf-0.7-3-numpy/examples/szip/szip32.py	2007-01-20 21:06:15.000000000 +0100
***************
*** 26,32 ****
  # 
  
  from pyhdf.SD import *
! import Numeric
  
  # Set SZIP to True to compress data using SZIP. Set to False to bypass compression.
  SZIP = True
--- 26,32 ----
  # 
  
  from pyhdf.SD import *
! import numpy
  
  # Set SZIP to True to compress data using SZIP. Set to False to bypass compression.
  SZIP = True
***************
*** 39,45 ****
  #LENGTH      = 9
  #WIDTH       = 6
  #
! #data = Numeric.array(((100,100,200,200,300,400),
  #                      (100,100,200,200,300,400),
  #                      (100,100,200,200,300,400),
  #                      (300,300,  0,400,300,400),
--- 39,45 ----
  #LENGTH      = 9
  #WIDTH       = 6
  #
! #data = numpy.array(((100,100,200,200,300,400),
  #                      (100,100,200,200,300,400),
  #                      (100,100,200,200,300,400),
  #                      (300,300,  0,400,300,400),
***************
*** 47,59 ****
  #                      (300,300,  0,400,300,400),
  #                      (0,  0,600,600,300,400),
  #                      (500,500,600,600,300,400),
! #                      (0,  0,600,600,300,400)), Numeric.Int32)
  
  # The above dataset is too small to show a significant size reduction after
  # compression. Try the following for a more realistic example.
  LENGTH      = 250
  WIDTH       = 100
! data = Numeric.zeros((LENGTH, WIDTH), Numeric.Int32)
  for i in range(LENGTH):
     for j in range(WIDTH):
          data[i,j] = (i+j)*(i-j)
--- 47,59 ----
  #                      (300,300,  0,400,300,400),
  #                      (0,  0,600,600,300,400),
  #                      (500,500,600,600,300,400),
! #                      (0,  0,600,600,300,400)), numpy.int32)
  
  # The above dataset is too small to show a significant size reduction after
  # compression. Try the following for a more realistic example.
  LENGTH      = 250
  WIDTH       = 100
! data = numpy.zeros((LENGTH, WIDTH), numpy.int32)
  for i in range(LENGTH):
     for j in range(WIDTH):
          data[i,j] = (i+j)*(i-j)
diff -r -N -C 3 pyhdf-0.7-3/examples/txttohdf/txttohdf.py pyhdf-0.7-3-numpy/examples/txttohdf/txttohdf.py
*** pyhdf-0.7-3/examples/txttohdf/txttohdf.py	2004-11-03 15:42:11.000000000 +0100
--- pyhdf-0.7-3-numpy/examples/txttohdf/txttohdf.py	2007-01-20 14:43:34.000000000 +0100
***************
*** 1,6 ****
  #!/usr/bin/env python
  
! from Numeric import *
  from pyhdf.SD import *
  
  import os
--- 1,6 ----
  #!/usr/bin/env python
  
! from numpy import *
  from pyhdf.SD import *
  
  import os
diff -r -N -C 3 pyhdf-0.7-3/pyhdf/hdfext_wrap.c pyhdf-0.7-3-numpy/pyhdf/hdfext_wrap.c
*** pyhdf-0.7-3/pyhdf/hdfext_wrap.c	2005-07-14 00:04:21.000000000 +0200
--- pyhdf-0.7-3-numpy/pyhdf/hdfext_wrap.c	2007-01-20 13:07:23.000000000 +0100
***************
*** 904,910 ****
  
  #include "hdfi.h"     /* declares int32, float32, etc */
  
! #include "Numeric/arrayobject.h"
  
  #define DFNT_FLOAT32     5
  #define DFNT_FLOAT       5  /* For backward compat; don't use */
--- 904,910 ----
  
  #include "hdfi.h"     /* declares int32, float32, etc */
  
! #include "numpy/oldnumeric.h"
  
  #define DFNT_FLOAT32     5
  #define DFNT_FLOAT       5  /* For backward compat; don't use */
diff -r -N -C 3 pyhdf-0.7-3/pyhdf/SD.py pyhdf-0.7-3-numpy/pyhdf/SD.py
*** pyhdf-0.7-3/pyhdf/SD.py	2005-07-14 03:36:41.000000000 +0200
--- pyhdf-0.7-3-numpy/pyhdf/SD.py	2007-01-20 13:07:09.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+ ## Automatically adapted for numpy.oldnumeric Jan 20, 2007 by 
+ 
  # $Id: SD.py,v 1.7 2005/07/14 01:36:41 gosselin_a Exp $
  # $Log: SD.py,v $
  # Revision 1.7  2005/07/14 01:36:41  gosselin_a
***************
*** 997,1003 ****
  __all__ = ['SD', 'SDAttr', 'SDC', 'SDS', 'SDim', 'HDF4Error']
  
  try:
!     import Numeric as _toto
      del _toto
  except ImportError:
      raise HDF4Error, "Numeric package required but not installed"
--- 999,1005 ----
  __all__ = ['SD', 'SDAttr', 'SDC', 'SDS', 'SDim', 'HDF4Error']
  
  try:
!     import numpy.oldnumeric as _toto
      del _toto
  except ImportError:
      raise HDF4Error, "Numeric package required but not installed"
***************
*** 1093,1101 ****
                           INT32,
                           CHAR8, UCHAR8]
      try:
!         from Numeric import UInt16 as _bozo
          equivNumericTypes.append(UINT16)
!         from Numeric import UInt32 as _bozo
          equivNumericTypes.append(UINT32)
          del _bozo
      except ImportError:
--- 1095,1103 ----
                           INT32,
                           CHAR8, UCHAR8]
      try:
!         from numpy.oldnumeric import UInt16 as _bozo
          equivNumericTypes.append(UINT16)
!         from numpy.oldnumeric import UInt32 as _bozo
          equivNumericTypes.append(UINT32)
          del _bozo
      except ImportError:
***************
*** 1973,1979 ****
                                 "number of dimensions")
          else:   # Convert single index to sequence
              elem = [elem]
!         if type(shape) == types.IntType:
              shape = [shape]
  
          start = []
--- 1975,1981 ----
                                 "number of dimensions")
          else:   # Convert single index to sequence
              elem = [elem]
!         if isinstance(shape, types.IntType):
              shape = [shape]
  
          start = []
***************
*** 1986,1992 ****
              # See if the dimension is unlimited (always at index 0)
              unlim = n == 0 and unlimited
              # Simple index
!             if type(e) == types.IntType:
                  slice = 0
                  if e < 0 :
                      e += shape[n]
--- 1988,1994 ----
              # See if the dimension is unlimited (always at index 0)
              unlim = n == 0 and unlimited
              # Simple index
!             if isinstance(e, types.IntType):
                  slice = 0
                  if e < 0 :
                      e += shape[n]
***************
*** 2727,2733 ****
  
          # Get the number of dimensions and their lengths.
          nDims, dimLen = self.info()[1:3]
!         if type(dimLen) == types.IntType:    # need a sequence
              dimLen = [dimLen]
          # Check if the dataset is appendable.
          unlim = self.isrecord()
--- 2729,2735 ----
  
          # Get the number of dimensions and their lengths.
          nDims, dimLen = self.info()[1:3]
!         if isinstance(dimLen, types.IntType):    # need a sequence
              dimLen = [dimLen]
          # Check if the dataset is appendable.
          unlim = self.isrecord()
diff -r -N -C 3 pyhdf-0.7-3/pyhdf/VS.py pyhdf-0.7-3-numpy/pyhdf/VS.py
*** pyhdf-0.7-3/pyhdf/VS.py	2005-07-14 03:36:41.000000000 +0200
--- pyhdf-0.7-3-numpy/pyhdf/VS.py	2007-01-20 13:07:10.000000000 +0100
***************
*** 1,3 ****
--- 1,5 ----
+ ## Automatically adapted for numpy.oldnumeric Jan 20, 2007 by 
+ 
  # $Id: VS.py,v 1.4 2005/07/14 01:36:41 gosselin_a Exp $
  # $Log: VS.py,v $
  # Revision 1.4  2005/07/14 01:36:41  gosselin_a
***************
*** 2016,2022 ****
          for e in elem:
              n += 1
              # Simple index
!             if type(e) == types.IntType:
                  slice = 0
                  if e < 0:
                      e += shape[n]
--- 2018,2024 ----
          for e in elem:
              n += 1
              # Simple index
!             if isinstance(e, types.IntType):
                  slice = 0
                  if e < 0:
                      e += shape[n]
diff -r -N -C 3 pyhdf-0.7-3/setup.py pyhdf-0.7-3-numpy/setup.py
*** pyhdf-0.7-3/setup.py	2005-07-14 03:36:41.000000000 +0200
--- pyhdf-0.7-3-numpy/setup.py	2007-01-20 21:28:55.000000000 +0100
***************
*** 28,39 ****
  # Date: July 13 2005
  
  from distutils.core import setup, Extension
! HDF_include  = "/usr/local/hdf-4.2r1/include"
! HDF_lib      = "/usr/local/hdf-4.2r1/lib"
  
  _hdfext =    Extension('pyhdf._hdfext', 
!                        sources   = ["pyhdf/hdfext_wrap.c"],
! 		       include_dirs=[HDF_include],
  
  		       # Define NOUINT if your version of Numeric does not support
  		       # unsigned shorts or unsigned ints. Only versions 22 and above
--- 28,40 ----
  # Date: July 13 2005
  
  from distutils.core import setup, Extension
! from numpy.distutils.misc_util import get_numpy_include_dirs
! 
! include_dirs = get_numpy_include_dirs()
  
  _hdfext =    Extension('pyhdf._hdfext', 
!                        sources      = ["pyhdf/hdfext_wrap.c"],
! 		       include_dirs = include_dirs,
  
  		       # Define NOUINT if your version of Numeric does not support
  		       # unsigned shorts or unsigned ints. Only versions 22 and above
***************
*** 42,49 ****
  		       # support.
  		       #extra_compile_args=["-DNOUINT"],
  		       #extra_compile_args=["-DNOSZIP"],
! 
! 		       library_dirs=[HDF_lib],
  		       #extra_link_args=["extra stuff passed to the linker"],
  
  		       # 'libraries' is set to the list of libraries to link
--- 43,50 ----
  		       # support.
  		       #extra_compile_args=["-DNOUINT"],
  		       #extra_compile_args=["-DNOSZIP"],
!                        
! 		       #library_dirs=["extra libraries required"],
  		       #extra_link_args=["extra stuff passed to the linker"],
  
  		       # 'libraries' is set to the list of libraries to link
***************
*** 66,72 ****
        author       = 'Andre Gosselin',
        author_email = '[EMAIL PROTECTED]',
        description  = 'Python interface to the NCSA HDF4 library',
!       keywords     = ['hdf', 'netcdf', 'Numeric', 'python'],
        license      = 'public',
        long_description = 'The pyhdf package wraps the functionality\n '
                           'of the NCSA HDF version 4 library inside a Python OOP\n '
--- 67,73 ----
        author       = 'Andre Gosselin',
        author_email = '[EMAIL PROTECTED]',
        description  = 'Python interface to the NCSA HDF4 library',
!       keywords     = ['hdf', 'netcdf', 'numpy', 'python'],
        license      = 'public',
        long_description = 'The pyhdf package wraps the functionality\n '
                           'of the NCSA HDF version 4 library inside a Python OOP\n '

Attachment: build_pyhdf-0.7-3-numpy-linux.sh
Description: application/shellscript

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to