├── README.md ├── 读取高光谱数据到Excel表 ├── vegetation index ├── 4.求取植被指数平均值.ipynb ├── 2.植被指数.ipynb └── 1.高光谱数据转化.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # spectrum 2 | 和高光谱数据处理相关程序 3 | -------------------------------------------------------------------------------- /读取高光谱数据到Excel表: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import os 3 | datadir = './data-gaoguangpu/' 4 | 5 | files= os.listdir(datadir) #得到文件夹下的所有文件名称 6 | spectrum_columns = [] 7 | spectrum_columns.append('Asd') 8 | for i in range(325, 1076, 1): 9 | spectrum_columns.append(str(i)) 10 | result = pd.DataFrame(columns=spectrum_columns) 11 | k = 0 12 | for file in files: #遍历文件夹 13 | if file == '.DS_Store': 14 | continue 15 | print(file) 16 | if not os.path.isdir(file): #判断是否是文件夹,不是文件夹才打开 17 | df = pd.read_table(datadir + file, sep='\t') 18 | asd_columns = df.columns[1] 19 | asd = df.columns[1].split('.')[0] 20 | for i in range(325, 1076, 1): 21 | result.loc[k,'Asd'] = asd 22 | index = df[df['Wavelength'] == i].index.tolist() 23 | result.loc[k, str(i)] = df[asd_columns][index[0]] 24 | k = k + 1 25 | # if k ==3: 26 | # break 27 | 28 | 29 | result.to_excel('高光谱数据618.xlsx') 30 | -------------------------------------------------------------------------------- /vegetation index: -------------------------------------------------------------------------------- 1 | ##加载包 2 | import numpy as np 3 | import pandas as pd 4 | ##import os 5 | 6 | ##读取数据 7 | ##data_dir = r'D:\1博士2\2019试验数据\高光谱\825光谱数据' 8 | df=pd.read_excel(r'D:\1博士2\2019试验数据\高光谱\812光谱数据\高光谱数据812-python.xlsx') 9 | ##df[:5] 10 | 11 | ##提取波段参数,求植被指数 12 | nir=df['865'] 13 | red=df['650'] 14 | green=df['563'] 15 | blue=df['483'] 16 | 17 | ##归一化植被指数 18 | NDVI= (nir-red)/(nir+red) 19 | ##比值植被指数 20 | RVI=nir/red 21 | ##绿光比值植被指数 22 | GRVI=nir/green 23 | ##增强型植被指数1 24 | EVI1=2.5 * (nir-red) / (nir+6*red-7.5*blue) 25 | ##增强型植被指数2 26 | EVI2=2.5 * (nir-red) / (nir+2.4*red+1) 27 | ##土壤调整植被指数 28 | SAVI=1.5*(nir-red)/(nir+red+0.5) 29 | ##优化的土壤调整植被指数 30 | OSAVI=1.16*(nir-red)/(nir-red+0.16) 31 | 32 | ##df1.index=df.index 33 | ##df1['NDVI','RVI','GRVI','EVI1','EVI2','SAVI','OSAVI']=[NDVI,RVI,GRVI,EVI1,EVI2,SAVI,OSAVI] 34 | 35 | ##df['NDVI','RVI','GRVI','EVI1','EVI2','SAVI','OSAVI']=[NDVI,RVI,GRVI,EVI1,EVI2,SAVI,OSAVI] 36 | ##df1.index=[(0:204)] 37 | df['NDVI']= NDVI 38 | df['RVI']= RVI 39 | df['GRVI']= GRVI 40 | df['EVI1']= EVI1 41 | df['EVI2']= EVI2 42 | df['SAVI']= SAVI 43 | df['OSAVI']= OSAVI 44 | 45 | 46 | df.to_excel(r'D:\1博士2\2019试验数据\高光谱\812光谱数据\植被指数812.xlsx') 47 | -------------------------------------------------------------------------------- /4.求取植被指数平均值.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 4, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "##加载包\n", 10 | "import numpy as np\n", 11 | "import pandas as pd\n", 12 | "##import os\n", 13 | "\n", 14 | "##读取叶面积指数\n", 15 | "df=pd.read_excel(r'D:\\1博士2\\2019试验数据\\高光谱\\植被指数叶面积相关性-总不覆膜.xlsx')\n", 16 | "\n", 17 | "##求取平均值\n", 18 | "df2=[]\n", 19 | "df2=pd.pivot_table(df,index=['日期','处理'])\n", 20 | "df2.to_excel(r'D:\\1博士2\\2019试验数据\\高光谱\\植被指数叶面积相关性-平均值.xlsx')" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [] 29 | } 30 | ], 31 | "metadata": { 32 | "kernelspec": { 33 | "display_name": "Python 3", 34 | "language": "python", 35 | "name": "python3" 36 | }, 37 | "language_info": { 38 | "codemirror_mode": { 39 | "name": "ipython", 40 | "version": 3 41 | }, 42 | "file_extension": ".py", 43 | "mimetype": "text/x-python", 44 | "name": "python", 45 | "nbconvert_exporter": "python", 46 | "pygments_lexer": "ipython3", 47 | "version": "3.7.0" 48 | } 49 | }, 50 | "nbformat": 4, 51 | "nbformat_minor": 2 52 | } 53 | -------------------------------------------------------------------------------- /2.植被指数.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 求取植被指数" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 8, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "##加载包\n", 17 | "import numpy as np\n", 18 | "import pandas as pd\n", 19 | "##import os\n", 20 | "\n", 21 | "##读取数据\n", 22 | "##data_dir = r'D:\\1博士2\\2019试验数据\\高光谱\\825光谱数据'\n", 23 | "df=pd.read_excel(r'D:\\1博士2\\2019试验数据\\高光谱\\812光谱数据\\高光谱数据812-python.xlsx')\n", 24 | "##df[:5]\n", 25 | "\n", 26 | "##提取波段参数,求植被指数\n", 27 | "nir=df['865']\n", 28 | "red=df['650']\n", 29 | "green=df['563']\n", 30 | "blue=df['483']\n", 31 | "\n", 32 | "##归一化植被指数\n", 33 | "NDVI= (nir-red)/(nir+red)\n", 34 | "##比值植被指数\n", 35 | "RVI=nir/red\n", 36 | "##绿光比值植被指数\n", 37 | "GRVI=nir/green\n", 38 | "##增强型植被指数1\n", 39 | "EVI1=2.5 * (nir-red) / (nir+6*red-7.5*blue)\n", 40 | "##增强型植被指数2\n", 41 | "EVI2=2.5 * (nir-red) / (nir+2.4*red+1)\n", 42 | "##土壤调整植被指数\n", 43 | "SAVI=1.5*(nir-red)/(nir+red+0.5)\n", 44 | "##优化的土壤调整植被指数\n", 45 | "OSAVI=1.16*(nir-red)/(nir-red+0.16)\n", 46 | "\n", 47 | "##df1.index=df.index\n", 48 | "##df1['NDVI','RVI','GRVI','EVI1','EVI2','SAVI','OSAVI']=[NDVI,RVI,GRVI,EVI1,EVI2,SAVI,OSAVI]\n", 49 | "\n", 50 | "##df['NDVI','RVI','GRVI','EVI1','EVI2','SAVI','OSAVI']=[NDVI,RVI,GRVI,EVI1,EVI2,SAVI,OSAVI]\n", 51 | "##df1.index=[(0:204)]\n", 52 | "df['NDVI']= NDVI\n", 53 | "df['RVI']= RVI\n", 54 | "df['GRVI']= GRVI\n", 55 | "df['EVI1']= EVI1\n", 56 | "df['EVI2']= EVI2\n", 57 | "df['SAVI']= SAVI\n", 58 | "df['OSAVI']= OSAVI\n", 59 | "\n", 60 | "\n", 61 | "df.to_excel(r'D:\\1博士2\\2019试验数据\\高光谱\\812光谱数据\\植被指数812.xlsx')" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [] 70 | } 71 | ], 72 | "metadata": { 73 | "kernelspec": { 74 | "display_name": "Python 3", 75 | "language": "python", 76 | "name": "python3" 77 | }, 78 | "language_info": { 79 | "codemirror_mode": { 80 | "name": "ipython", 81 | "version": 3 82 | }, 83 | "file_extension": ".py", 84 | "mimetype": "text/x-python", 85 | "name": "python", 86 | "nbconvert_exporter": "python", 87 | "pygments_lexer": "ipython3", 88 | "version": "3.7.0" 89 | } 90 | }, 91 | "nbformat": 4, 92 | "nbformat_minor": 2 93 | } 94 | -------------------------------------------------------------------------------- /1.高光谱数据转化.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 高光谱数据的读取与转化" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 2, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "61800000.asd.txt\n", 20 | "61800001.asd.txt\n", 21 | "61800002.asd.txt\n", 22 | "61800003.asd.txt\n", 23 | "61800004.asd.txt\n", 24 | "61800005.asd.txt\n", 25 | "61800006.asd.txt\n", 26 | "61800007.asd.txt\n", 27 | "61800008.asd.txt\n", 28 | "61800009.asd.txt\n", 29 | "61800010.asd.txt\n", 30 | "61800011.asd.txt\n", 31 | "61800012.asd.txt\n", 32 | "61800013.asd.txt\n", 33 | "61800014.asd.txt\n", 34 | "61800015.asd.txt\n", 35 | "61800016.asd.txt\n", 36 | "61800017.asd.txt\n", 37 | "61800018.asd.txt\n", 38 | "61800019.asd.txt\n", 39 | "61800020.asd.txt\n", 40 | "61800021.asd.txt\n", 41 | "61800022.asd.txt\n", 42 | "61800023.asd.txt\n", 43 | "61800024.asd.txt\n", 44 | "61800025.asd.txt\n", 45 | "61800026.asd.txt\n", 46 | "61800027.asd.txt\n", 47 | "61800028.asd.txt\n", 48 | "61800029.asd.txt\n", 49 | "61800030.asd.txt\n", 50 | "61800031.asd.txt\n", 51 | "61800032.asd.txt\n", 52 | "61800033.asd.txt\n", 53 | "61800034.asd.txt\n", 54 | "61800035.asd.txt\n", 55 | "61800036.asd.txt\n", 56 | "61800037.asd.txt\n", 57 | "61800038.asd.txt\n", 58 | "61800039.asd.txt\n", 59 | "61800040.asd.txt\n", 60 | "61800041.asd.txt\n", 61 | "61800042.asd.txt\n", 62 | "61800043.asd.txt\n", 63 | "61800044.asd.txt\n", 64 | "61800045.asd.txt\n", 65 | "61800046.asd.txt\n", 66 | "61800047.asd.txt\n", 67 | "61800048.asd.txt\n", 68 | "61800049.asd.txt\n", 69 | "61800050.asd.txt\n", 70 | "61800051.asd.txt\n", 71 | "61800052.asd.txt\n", 72 | "61800053.asd.txt\n", 73 | "61800054.asd.txt\n", 74 | "61800055.asd.txt\n", 75 | "61800056.asd.txt\n", 76 | "61800057.asd.txt\n", 77 | "61800058.asd.txt\n", 78 | "61800059.asd.txt\n", 79 | "61800060.asd.txt\n", 80 | "61800061.asd.txt\n", 81 | "61800062.asd.txt\n", 82 | "61800063.asd.txt\n", 83 | "61800064.asd.txt\n", 84 | "61800065.asd.txt\n", 85 | "61800066.asd.txt\n", 86 | "61800067.asd.txt\n", 87 | "61800068.asd.txt\n", 88 | "61800069.asd.txt\n", 89 | "61800070.asd.txt\n", 90 | "61800071.asd.txt\n", 91 | "61800072.asd.txt\n", 92 | "61800073.asd.txt\n", 93 | "61800074.asd.txt\n", 94 | "61800075.asd.txt\n", 95 | "61800076.asd.txt\n", 96 | "61800077.asd.txt\n", 97 | "61800078.asd.txt\n", 98 | "61800079.asd.txt\n", 99 | "61800080.asd.txt\n", 100 | "61800081.asd.txt\n", 101 | "61800082.asd.txt\n", 102 | "61800083.asd.txt\n", 103 | "61800084.asd.txt\n", 104 | "61800085.asd.txt\n", 105 | "61800086.asd.txt\n", 106 | "61800087.asd.txt\n", 107 | "61800088.asd.txt\n", 108 | "61800089.asd.txt\n", 109 | "61800090.asd.txt\n", 110 | "61800091.asd.txt\n", 111 | "61800092.asd.txt\n", 112 | "61800093.asd.txt\n", 113 | "61800094.asd.txt\n", 114 | "61800095.asd.txt\n", 115 | "61800096.asd.txt\n", 116 | "61800097.asd.txt\n", 117 | "61800098.asd.txt\n", 118 | "61800099.asd.txt\n", 119 | "61800100.asd.txt\n", 120 | "61800101.asd.txt\n", 121 | "61800102.asd.txt\n", 122 | "61800103.asd.txt\n", 123 | "61800104.asd.txt\n", 124 | "61800105.asd.txt\n", 125 | "61800106.asd.txt\n", 126 | "61800107.asd.txt\n", 127 | "61800108.asd.txt\n", 128 | "61800109.asd.txt\n", 129 | "61800110.asd.txt\n", 130 | "61800111.asd.txt\n", 131 | "61800112.asd.txt\n", 132 | "61800113.asd.txt\n", 133 | "61800114.asd.txt\n", 134 | "61800115.asd.txt\n", 135 | "61800116.asd.txt\n", 136 | "61800117.asd.txt\n" 137 | ] 138 | } 139 | ], 140 | "source": [ 141 | "import pandas as pd\n", 142 | "import os\n", 143 | "datadir = './data-gaoguangpu/'\n", 144 | "\n", 145 | "files= os.listdir(datadir) #得到文件夹下的所有文件名称\n", 146 | "spectrum_columns = []\n", 147 | "spectrum_columns.append('Asd')\n", 148 | "for i in range(325, 1076, 1):\n", 149 | " spectrum_columns.append(str(i))\n", 150 | "result = pd.DataFrame(columns=spectrum_columns)\n", 151 | "k = 0\n", 152 | "for file in files: #遍历文件夹\n", 153 | " if file == '.DS_Store':\n", 154 | " continue\n", 155 | " print(file)\n", 156 | " if not os.path.isdir(file): #判断是否是文件夹,不是文件夹才打开\n", 157 | " df = pd.read_table(datadir + file, sep='\\t')\n", 158 | " asd_columns = df.columns[1]\n", 159 | " asd = df.columns[1].split('.')[0]\n", 160 | " for i in range(325, 1076, 1):\n", 161 | " result.loc[k,'Asd'] = asd\n", 162 | " index = df[df['Wavelength'] == i].index.tolist()\n", 163 | " result.loc[k, str(i)] = df[asd_columns][index[0]]\n", 164 | " k = k + 1\n", 165 | " # if k ==3:\n", 166 | " # break\n", 167 | "\n", 168 | "\n", 169 | "result.to_excel('高光谱数据618.xlsx')" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [] 178 | } 179 | ], 180 | "metadata": { 181 | "kernelspec": { 182 | "display_name": "Python 3", 183 | "language": "python", 184 | "name": "python3" 185 | }, 186 | "language_info": { 187 | "codemirror_mode": { 188 | "name": "ipython", 189 | "version": 3 190 | }, 191 | "file_extension": ".py", 192 | "mimetype": "text/x-python", 193 | "name": "python", 194 | "nbconvert_exporter": "python", 195 | "pygments_lexer": "ipython3", 196 | "version": "3.7.0" 197 | } 198 | }, 199 | "nbformat": 4, 200 | "nbformat_minor": 2 201 | } 202 | --------------------------------------------------------------------------------