Python SDF阅读器故障

时间:2019-03-04 10:10:16

标签: python sdf

我想运行这个python脚本。我在主目录中通过以下命令在Linux中安装了SDF阅读器

python -m pip install --upgrade sdf

,它似乎已成功安装。 python脚本如下

import sdf
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import numpy as np
import os
from numpy import ma
from matplotlib import colors, ticker, cm
from matplotlib.mlab import bivariate_normal
from matplotlib.colors import ListedColormap


if __name__ == "__main__":
  print ('This is main of module "test2d.py"')
  ######## Constant defined here ########
  pi        =     3.1415926535897932384626
  q0        =     1.602176565e-19 # C
  m0        =     9.10938291e-31  # kg
  v0        =     2.99792458e8    # m/s^2
  kb        =     1.3806488e-23   # J/K
  mu0       =     4.0e-7*pi       # N/A^2
  epsilon0  =     8.8541878176203899e-12 # F/m
  h_planck  =     6.62606957e-34  # J s
  wavelength=     1.0e-6
  frequency =     v0*2*pi/wavelength

  exunit    =     m0*v0*frequency/q0
  bxunit    =     m0*frequency/q0
  denunit    =     frequency**2*epsilon0*m0/q0**2
  print 'electric field unit: '+str(exunit)
  print 'magnetic field unit: '+str(bxunit)
  print 'density unit nc: '+str(denunit)

  font = {'family' : 'helvetica',  
          'color'  : 'black',  
          'weight' : 'normal',  
          'size'   : 20,  
          }  



  n=47
  data = sdf.read("./"+str(n).zfill(4)+".sdf",dict=True)
  header=data['Header']
  time=header['time']
  x  = data['Grid/Grid_mid'].data[0]/1.0e-6
  y  = data['Grid/Grid_mid'].data[1]/1.0e-6
  y  = y[600:1799]
  X, Y = np.meshgrid(x, y)

它给我以下错误:

Traceback (most recent call last):
  File "epochvis.py", line 45, in <module>
    data = sdf.read("./"+str(n).zfill(4)+".sdf",dict=True)
AttributeError: 'module' object has no attribute 'read'

有什么想法吗?预先谢谢你。

1 个答案:

答案 0 :(得分:0)

sdf没有读取功能。

尝试在python shell中键入以下内容

import sdf
help(sdf)

您将看到

FUNCTIONS
    load(filename, objectname='/', unit=None, scale_units=None)
        Load a dataset or group from an SDF file

    save(filename, group)
        Save an SDF group to a file

    validate(obj)
        Validate an sdf.Group or sdf.Dataset