Python处理envi导出的光谱曲线txt文件写入excel

import xlwt

with open('I:地物纹理曲线.txt', 'r') as f:
    i = 0
    data_list = []
    while True:
        line = f.readline()
        if i < 8:
            i += 1
            continue
        elif not line:
            break
        else:
            data_list.append(line)
    excel_table = xlwt.Workbook()
    sheet1 = excel_table.add_sheet(u'Sheet1', cell_overwrite_ok=True)
    sheet1.write(0, 0, 'Bands')
    sheet1.write(1, 0, '互花米草')
    sheet1.write(2, 0, '建筑')
    sheet1.write(3, 0, '泥沙水体')
    sheet1.write(4, 0, '普通水体')
    sheet1.write(5, 0, '互花米草(水)')
    sheet1.write(6, 0, '沙土植被')
    for index, item in enumerate(data_list):
        result = item.strip().split()
        '''with open('I:地物纹理曲线_new.txt', 'a+') as w:
            for j in result:
                w.write(j + '\n')
            w.write('\n')'''
        for j_index, j_item in enumerate(result):
            sheet1.write(j_index, index+1, float(j_item))
    excel_table.save('I:地物纹理曲线.xls')

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python可以使用多种方法来读取ENVI文件。一种常见的方法是使用Python的库,如gdal和spectral。引用提到了ENVI SPECTRAL LIBRARY文件ENVI自带的光谱文件,后缀(.sli)存储有各种实测的光谱数据。如果你想使用Python读取这种文件,可以考虑使用spectral库。spectral库是一个专门用于光谱分析的库,可以方便地处理ENVI文件。你可以通过导入spectral库并使用其envi模块中的open函数来读取ENVI文件。例如,你可以使用以下代码来读取ENVI文件并将其存储为一个pandas DataFrame对象: import spectral as spl import pandas as pd SpecLib = spl.envi.open('path_to_envi_file.sli') SpecLib_df = pd.DataFrame(index=SpecLib.names, data=SpecLib.spectra, columns=SpecLib.centers) 这样,你就可以使用SpecLib_df对象来进一步分析和处理ENVI文件中的光谱数据了。请注意,'path_to_envi_file.sli'应该替换为你自己的ENVI文件的路径。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [使用PythonENVI SPECTRAL LIBRARY(.sli)进行读取](https://blog.csdn.net/weixin_43581910/article/details/119458802)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值