本文整理汇总了Python中pyhdf.SD.SD.create方法的典型用法代码示例。如果您正苦于以下问题:Python SD.create方法的具体用法?Python SD.create怎么用?Python SD.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyhdf.SD.SD
的用法示例。
在下文中一共展示了SD.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_interpolated
# 需要导入模块: from pyhdf.SD import SD [as 别名]
# 或者: from pyhdf.SD.SD import create [as 别名]
def write_interpolated(filename, f0, f1, fact, datasets):
'''
interpolate two hdf files f0 and f1 using factor fact, and
write the result to filename
'''
hdf = SD(filename, SDC.WRITE|SDC.CREATE)
for dataset in datasets:
try:
info = SD(f0).select(dataset).info()
except:
print >> stderr, 'Error loading %s in %s' % (dataset, f0)
raise
typ = info[3]
shp = info[2]
met0 = SD(f0).select(dataset).get()
met1 = SD(f1).select(dataset).get()
interp = (1-fact)*met0 + fact*met1
interp = interp.astype({
SDC.INT16: 'int16',
SDC.FLOAT32: 'float32',
SDC.FLOAT64: 'float64',
}[typ])
# write
sds = hdf.create(dataset, typ, shp)
sds[:] = interp[:]
sds.endaccess()
hdf.end()
示例2: setUp
# 需要导入模块: from pyhdf.SD import SD [as 别名]
# 或者: from pyhdf.SD.SD import create [as 别名]
def setUp(self):
"""Create a test HDF4 file"""
from pyhdf.SD import SD, SDC
h = SD('test.hdf', SDC.WRITE | SDC.CREATE | SDC.TRUNC)
data = np.arange(10. * 100, dtype=np.float32).reshape((10, 100))
v1 = h.create('ds1_f', SDC.FLOAT32, (10, 100))
v1[:] = data
v2 = h.create('ds1_i', SDC.INT16, (10, 100))
v2[:] = data.astype(np.int16)
# Add attributes
h.test_attr_str = 'test_string'
h.test_attr_int = 0
h.test_attr_float = 1.2
# h.test_attr_str_arr = np.array(b"test_string2")
for d in [v1, v2]:
d.test_attr_str = 'test_string'
d.test_attr_int = 0
d.test_attr_float = 1.2
h.end()
示例3: write_hdf
# 需要导入模块: from pyhdf.SD import SD [as 别名]
# 或者: from pyhdf.SD.SD import create [as 别名]
def write_hdf(filename, dataset, data):
'''
write a dataset in hdf file
'''
hdf = SD(filename, SDC.WRITE|SDC.CREATE)
typ = {
'int16' : SDC.INT16,
'float32' : SDC.FLOAT32,
'float64' : SDC.FLOAT64,
}[data.dtype.name]
sds = hdf.create(dataset, typ, data.shape)
sds[:] = data[:]
sds.endaccess()
hdf.end()
示例4: write_interpolated
# 需要导入模块: from pyhdf.SD import SD [as 别名]
# 或者: from pyhdf.SD.SD import create [as 别名]
def write_interpolated(filename, f0, f1, fact, datasetNames):
'''
interpolate two hdf files f0 and f1 using factor fact, and
write the result to filename
'''
hdf = SD(filename, SDC.WRITE|SDC.CREATE)
for datasetName in datasetNames:
try:
info = SD(f0).select(datasetName).info()
except:
print >> stderr, 'Error loading %s in %s' % (datasetName, f0)
raise
typ = info[3]
shp = info[2]
sds_in1 = SD(f0).select(datasetName)
met0 = sds_in1.get()
met1 = SD(f1).select(datasetName).get()
interp = (1-fact)*met0 + fact*met1
interp = interp.astype({
SDC.INT16: 'int16',
SDC.FLOAT32: 'float32',
SDC.FLOAT64: 'float64',
}[typ])
# write
sds = hdf.create(datasetName, typ, shp)
sds[:] = interp[:]
# copy attributes
attr = sds_in1.attributes()
if len(attr) > 0:
for name in attr.keys():
setattr(sds, name, attr[name])
sds.endaccess()
hdf.end()
示例5: SD
# 需要导入模块: from pyhdf.SD import SD [as 别名]
# 或者: from pyhdf.SD.SD import create [as 别名]
dl_data[(rad_sol <= -1)] = day1
day2 = rad_sol[(rad_sol < 1) & (rad_sol > -1)]
day2 = 24.0 * np.arccos(day2)/np.pi
dl_data[(rad_sol < 1) & (rad_sol > -1)] = day2
day3 = rad_sol[(rad_sol >= 1)]
day3 = 0.0
dl_data[(rad_sol >= 1)] = day3
dl_data = dl_data.reshape(1080,2160)
print "day length complete"
####################################################################
# Calculates NPP for each pixel by multiplying values for that #
# pixel from pbopt, zeu, tot_chl, par and dl together. #
# Produces output hdf file containing NPP data. #
####################################################################
NPP_data = np.zeros_like(dl_data)
NPP_data = pbopt_data * zeu_data * chl_data * par_data * dl_data
OUTPUT1 = "C:\Anaconda\envs\sat_data\NPP_3.hdf"
NPP = SD(OUTPUT1, SDC.WRITE | SDC.CREATE)
sds = NPP.create("sds1", SDC.FLOAT64,(1080,2160))
sds.setfillvalue(0)
sds[:] = NPP_data
sds.endaccess()
NPP.end()
示例6: createhdf
# 需要导入模块: from pyhdf.SD import SD [as 别名]
# 或者: from pyhdf.SD.SD import create [as 别名]
def createhdf(filename, table=[]):
hdf = SD(filename, SDC.CREATE | SDC.WRITE)
for i in table:
hdf.create(i, SDC.FLOAT32, 0)
hdf.end()
return True