本文整理汇总了Python中OCO_Matrix.OCO_Matrix.data[:,column_idx]方法的典型用法代码示例。如果您正苦于以下问题:Python OCO_Matrix.data[:,column_idx]方法的具体用法?Python OCO_Matrix.data[:,column_idx]怎么用?Python OCO_Matrix.data[:,column_idx]使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCO_Matrix.OCO_Matrix
的用法示例。
在下文中一共展示了OCO_Matrix.data[:,column_idx]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Process_File
# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data[:,column_idx] [as 别名]
def Process_File(source, destination, fileKeywords, moduleSections, valuesDict, mapDict):
logger = logging.getLogger(os.path.basename(__file__))
# Load existing file
matrix_obj = OCO_Matrix(source)
for realizeSect in moduleSections:
# Add ability to specify cols individually or using a * to goto end
covariance = Apply_Template(realizeSect.Get_Keyword_Value('covariance'), valuesDict, mapDict=mapDict)
column = Apply_Template(realizeSect.Get_Keyword_Value('column'), valuesDict, mapDict=mapDict)
if type(column) is ListType:
raise TypeError('Only one column can be modified per file')
if covariance == None or len(covariance) == 0:
raise IOError('covariance file is not specified')
if not os.path.exists(covariance):
raise IOError('covariance file does not exist: %s' % covariance)
cov_obj = OCO_Matrix(covariance)
rand_factors = [ random.normalvariate(0,1) for i in range(matrix_obj.dims[0]) ]
(eigen_val, eigen_vec) = linalg.eigh(cov_obj.data)
try:
column_idx = int(column)
except:
if column == None:
raise IOError('column named not defined for source file: %s' % (source))
elif not column.lower() in matrix_obj.labels_lower:
raise IOError('column named %s not found in source file: %s' % (column, source))
column_idx = matrix_obj.labels_lower.index(column.lower())
update_vals = dot(eigen_vec.transpose(), (rand_factors* sqrt(eigen_val)))
matrix_obj.data[:, column_idx] = matrix_obj.data[:, column_idx] + update_vals
matrix_obj.write(destination)
示例2: write_spectra_files
# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data[:,column_idx] [as 别名]
def write_spectra_files(output_dir, ids, data):
for curr_id, curr_data in zip(ids, data):
out_filename = '%s/%s.dat' % (output_dir, curr_id)
used_data = []
out_obj = OCO_Matrix()
out_obj.labels = FILE_LABELS
out_obj.units = FILE_UNITS
out_obj.file_id = FILE_ID_TMPL % (curr_id)
out_obj.data = numpy.zeros((curr_data['Num_Points'], len(FILE_LABELS)), dtype=float)
used_data.append('Num_Points')
for column_idx, column_name in enumerate(FILE_LABELS):
if curr_data.has_key(column_name):
out_obj.data[:, column_idx] = curr_data[column_name]
used_data.append(column_name)
header_dict = copy.copy(curr_data)
header_dict.update(HEADER_FILL_VALUES)
for data_name, data_values in header_dict.items():
if data_name in used_data:
continue
out_name = translate_header_name(data_name)
try:
if len(data_values.shape) == 0:
out_obj.header[out_name] = str(data_values)
else:
out_obj.header[out_name] = ' '.join([ str(item) for item in iter(data_values)])
except:
try:
out_obj.header[out_name] = str(data_values)
except:
print >>sys.stderr, 'Barfed on parsing %s with values: %s for header of file %s' % (data_name, data_values, out_filename)
print 'Writing: %s' % out_filename
out_obj.write(out_filename)