python读取Himawari-8葵花8标准数据(HSD)

搬运自https://github.com/smft/Read_Himawari_binary_data,有改编,只测试了全云盘FLDK的数据
具体存放数据类型查看Himawari8 HSD User’s Guide
在这里插入图片描述
在这里插入图片描述
Band1-6和Band7-12的Block5存放内容是不同的
在这里插入图片描述
中间的Block8,9,10长度不是固定的,多做测试分配长度
在这里插入图片描述
代码测试数据是自行下载的Himawari8全云盘数据,测试过了几个FLDK的数据都可以用,如果后面读的不对,就需要查看BLOCK8,9,10的Block Length,调整BLOCK8,9,10的Spare占用长度
在这里插入图片描述

##########################
#************************#
"""author : qizhang NJU"""
#************************#
##########################
import numpy as np
from matplotlib import pyplot as plt
def read_Himawari(inputfile):
    resolution=int(inputfile[-12])
    if resolution==1:
        res=12100000
        nlin=1100
        ncol=11000
    elif resolution==2:
        res=3025000
        nlin=550
        ncol=5500
    else:
        res=48400000
        nlin=2200
        ncol=22000
    band=int(inputfile[-21:-19])
    if band < 7:
            formation = [('Block number1', 'i1', 1), \
                         ('Block length1', 'i2', 1), \
                         ('Total number of header blocks ', 'i2', 1), \
                         ('Byte order', 'i1', 1), \
                         ('Satellite name', 'S1', 16), \
                         ('Processing center name', 'S1', 16), \
                         ('Observation area', 'S1', 4), \
                         ('Other observation information', 'S1', 2), \
                         ('Observation timeline', 'i2', 1), \
                         ('Observation start time', 'float64', 1), \
                         ('Observation end time', 'float64', 1), \
                         ('File creation time', 'float64', 1), \
                         ('Total header length', 'i4', 1), \
                         ('Total data length', 'i4', 1), \
                         ('Quality flag 1', 'i1', 1), \
                         ('Quality flag 2 ', 'i1', 1), \
                         ('Quality flag 3', 'i1', 1), \
                         ('Quality flag 4', 'i1', 1), \
                         ('File format version', 'S1', 32), \
                         ('File name ', 'S1', 128), \
                         ('Spare1', 'S1', 40), \

                         ('Block number2', 'i1', 1), \
                         ('Block length2', 'i2', 1), \
                         ('Number of bits per pixel', 'i2', 1), \
                         ('Number of columns', 'i2', 1), \
                         ('Number of lines', 'i2', 1), \
                         ('Compression flag for data', 'i1', 1), \
                         ('Spare2', 'S1', 40), \

                         ('Block number3', 'i1', 1), \
                         ('Block length3', 'i2', 1), \
                         ('sub_lon', 'float64', 1), \
                         ('Column scaling factor', 'i4', 1), \
                         ('Line scaling factor', 'i4', 1), \
                         ('Column offset', 'float32', 1), \
                         ('Line offset', 'float32', 1), \
                         ('Distance from Earth’s center to virtual satellite', 'float64', 1), \
                         ('Earth’s equatorial radius', 'float64', 1), \
                         ('Earth’s polar radius', 'float64', 1), \
                         ('var1', 'float64', 1), \
                         ('var2', 'float64', 1), \
                         ('var3', 'float64', 1), \
                         ('Coefficient for sd', 'float64', 1), \
                         ('Resampling types', 'i2', 1), \
                         ('Resampling size', 'i2', 1), \
                         ('Spare3', 'S1', 40), \

                         ('Block number4', 'i1', 1), \
                         ('Block length4', 'i2', 1), \
                         ('Navigation information time', 'float64', 1), \
                         ('SSP longitude', 'float64', 1), \
                         ('SSP latitude', 'float64', 1), \
                         ('Distance from Earth’s center to Satellite', 'float64', 1), \
                         ('Nadir longitude', 'float64', 1), \
                         ('Nadir latitude', 'float64', 1), \
                         ('Sun’s position', 'float64', 3), \
                         ('Moon’s position', 'float64', 3), \
                         ('Spare4', 'S1', 40), \

                         ('Block number5', 'i1', 1), \
                         ('Block length5', 'i2', 1), \
                         ('Band number', 'i2', 1), \
                         ('Central wave length', 'float64', 1), \
                         ('Valid number of bits per pixel', 'i2', 1), \
                         ('Count value of error pixels', 'uint16', 1), \
                         ('Count value of pixels outside scan area', 'uint16', 1), \
                         ('Slope for count-radiance conversion equation ', 'float64', 1), \
                         ('Intercept for count-radiance conversion equation', 'float64', 1), \
                         ('Coefficient for transformation from radiance  to albedo', 'float64', 1), \
                         ('Update time of the values of the following No. 12 and No. 13', 'float64', 1), \
                         ('Calibrated Slope for count-radiance conversion equation_updated value of No. 8 of this block ', 'float64', 1),\
                         ('Calibrated Intercept for count-radiance conversion equation_updated value of No. 9 of this block ', 'float64', 1),\
                         ('Spare5', 'S1', 80), \

                         ('Block number6', 'i1', 1), \
                         ('Block length6', 'i2', 1), \
                         ('GSICS calibration coefficient_Intercept', 'float64', 1), \
                         ('GSICS calibration coefficient_Slope', 'float64', 1), \
                         ('GSICS calibration coefficient_Quadratic term', 'float64', 1), \
                         ('Radiance bias for standard scene', 'float64', 1), \
                         ('Uncertainty of radiance bias for standard scene', 'float64', 1), \
                         ('Radiance for standard scene', 'float64', 1), \
                         ('Start time of GSICS Correction validity period', 'float64', 1), \
                         ('End time of GSICS Correction validity period', 'float64', 1), \
                         ('Radiance validity range of GSICS calibration coefficients_upper limit', 'float32', 1), \
                         ('Radiance validity range of GSICS calibration coefficients_lower limit', 'float32', 1), \
                         ('File name of GSICS Correction', 'S1', 128), \
                         ('Spare6', 'S1', 56), \

                         ('Block number7', 'i1', 1), \
                         ('Block length7', 'i2', 1), \
                         ('Total number of segments', 'i1', 1), \
                         ('Segment sequence number', 'i1', 1), \
                         ('First line number of image segment', 'i2', 1), \
                         ('Spare7', 'S1', 40), \

                         ('Block number8', 'i1', 1), \
                         ('Block length8', 'i2', 1), \
                         ('Center column of rotation', 'float32', 1), \
                         ('Center line of rotation', 'float32', 1), \
                         ('Amount of rotational correction', 'float64', 1), \
                         ('Number of correction information data for column and line direction', 'i2', 1), \
                         ('Line number after rotation', 'i2', 1), \
                         ('Shift amount for column direction', 'float32', 1), \
                         ('Shift amount for line direction8', 'float32', 1), \
                         ('Spare8', 'S1', 50), \

                         ('Block number9', 'i1', 1), \
                         ('Block length9', 'i2', 1), \
                         ('Number of observation times9', 'i2', 1), \
                         ('Line number9', 'i2', 1), \
                         ('Observation time9', 'float64', 1), \
                         ('Spare9', 'S1', 70), \

                         ('Block number10', 'i1', 1), \
                         ('Block length10', 'i4', 1), \
                         ('Number of error information data', 'i2', 1), \
                         ('Line number10', 'i2', 1), \
                         ('Number of error pixels per line10', 'i2', 1), \
                         ('Spare10', 'S1', 36), \

                         ('Block number11', 'i1', 1), \
                         ('Block length11', 'i2', 1), \
                         ('Spare11', 'S1', 256), \

                         ('Count value of each pixel', 'i2', res)]
        else:
        formation=[('Block number1','i1',1),\
                    ('Block length1','i2',1),\
                    ('Total number of header blocks ','i2',1),\
                    ('Byte order','i1',1),\
                    ('Satellite name','S1',16),\
                    ('Processing center name','S1',16),\
                    ('Observation area','S1',4),\
                    ('Other observation information','S1',2),\
                    ('Observation timeline','i2',1),\
                    ('Observation start time','float64',1),\
                    ('Observation end time','float64',1),\
                    ('File creation time','float64',1),\
                    ('Total header length','i4',1),\
                    ('Total data length','i4',1),\
                    ('Quality flag 1','i1',1),\
                    ('Quality flag 2 ','i1',1),\
                    ('Quality flag 3','i1',1),\
                    ('Quality flag 4','i1',1),\
                    ('File format version','S1',32),\
                    ('File name ','S1',128),\
                    ('Spare1','S1',40),\

                    ('Block number2','i1',1),\
                    ('Block length2','i2',1),\
                    ('Number of bits per pixel','i2',1),\
                    ('Number of columns','i2',1),\
                    ('Number of lines','i2',1),\
                    ('Compression flag for data','i1',1),\
                    ('Spare2','S1',40),\

                    ('Block number3','i1',1),\
                    ('Block length3','i2',1),\
                    ('sub_lon','float64',1),\
                    ('Column scaling factor','i4',1),\
                    ('Line scaling factor','i4',1),\
                    ('Column offset','float32',1),\
                    ('Line offset','float32',1),\
                    ('Distance from Earth’s center to virtual satellite','float64',1),\
                    ('Earth’s equatorial radius','float64',1),\
                    ('Earth’s polar radius','float64',1),\
                    ('var1','float64',1),\
                    ('var2','float64',1),\
                    ('var3','float64',1),\
                    ('Coefficient for sd','float64',1),\
                    ('Resampling types','i2',1),\
                    ('Resampling size','i2',1),\
                    ('Spare3','S1',40),\

                    ('Block number4','i1',1),\
                    ('Block length4','i2',1),\
                    ('Navigation information time','float64',1),\
                    ('SSP longitude','float64',1),\
                    ('SSP latitude','float64',1),\
                    ('Distance from Earth’s center to Satellite','float64',1),\
                    ('Nadir longitude','float64',1),\
                    ('Nadir latitude','float64',1),\
                    ('Sun’s position','float64',3),\
                    ('Moon’s position','float64',3),\
                    ('Spare4','S1',40),\

                    ('Block number5','i1',1),\
                    ('Block length5','i2',1),\
                    ('Band number','i2',1),\
                    ('Central wave length','float64',1),\
                    ('Valid number of bits per pixel','i2',1),\
                    ('Count value of error pixels','i2',1),\
                    ('Count value of pixels outside scan area','i2',1),\
                    ('Slope for count-radiance conversion equation ','float64',1),\
                    ('Intercept for count-radiance conversion equation','float64',1),\
                    ('radiance to brightness temperature_c0','float64',1),\
                    ('radiance to brightness temperature_c1','float64',1),\
                    ('radiance to brightness temperature_c2','float64',1),\
                    ('brightness temperature to radiance_C0','float64',1),\
                    ('brightness temperature to radianceC1','float64',1),\
                    ('brightness temperature to radianceC2','float64',1),\
                    ('Speed of light','float64',1),\
                    ('Planck constant','float64',1),\
                    ('Boltzmann constant','float64',1),\
                    ('Spare5','S1',40), \

                   ('Block number6', 'i1', 1), \
                   ('Block length6', 'i2', 1), \
                   ('GSICS calibration coefficient_Intercept', 'float64', 1), \
                   ('GSICS calibration coefficient_Slope', 'float64', 1), \
                   ('GSICS calibration coefficient_Quadratic term', 'float64', 1), \
                   ('Radiance bias for standard scene', 'float64', 1), \
                   ('Uncertainty of radiance bias for standard scene', 'float64', 1), \
                   ('Radiance for standard scene', 'float64', 1), \
                   ('Start time of GSICS Correction validity period', 'float64', 1), \
                   ('End time of GSICS Correction validity period', 'float64', 1), \
                   ('Radiance validity range of GSICS calibration coefficients_upper limit', 'float32', 1), \
                   ('Radiance validity range of GSICS calibration coefficients_lower limit', 'float32', 1), \
                   ('File name of GSICS Correction', 'S1', 128), \
                   ('Spare6', 'S1', 56), \

                   ('Block number7', 'i1', 1), \
                   ('Block length7', 'i2', 1), \
                   ('Total number of segments', 'i1', 1), \
                   ('Segment sequence number', 'i1', 1), \
                   ('First line number of image segment', 'i2', 1), \
                   ('Spare7', 'S1', 40), \

                   ('Block number8', 'i1', 1), \
                   ('Block length8', 'i2', 1), \
                   ('Center column of rotation', 'float32', 1), \
                   ('Center line of rotation', 'float32', 1), \
                   ('Amount of rotational correction', 'float64', 1), \
                   ('Number of correction information data for column and line direction', 'i2', 1), \
                   ('Line number after rotation', 'i2', 1), \
                   ('Shift amount for column direction', 'float32', 1), \
                   ('Shift amount for line direction8', 'float32', 1), \
                   ('Spare8', 'S1', 50), \

                   ('Block number9', 'i1', 1), \
                   ('Block length9', 'i2', 1), \
                   ('Number of observation times9', 'i2', 1), \
                   ('Line number9', 'i2', 1), \
                   ('Observation time9', 'float64', 1), \
                   ('Spare9', 'S1', 70), \

                   ('Block number10', 'i1', 1), \
                   ('Block length10', 'i4', 1), \
                   ('Number of error information data', 'i2', 1), \
                   ('Line number10', 'i2', 1), \
                   ('Number of error pixels per line10', 'i2', 1), \
                   ('Spare10', 'S1', 36), \

                   ('Block number11', 'i1', 1), \
                   ('Block length11', 'i2', 1), \
                   ('Spare11', 'S1', 256), \


                   ('Count value of each pixel', 'i2', res)]
    data=np.fromfile(inputfile,dtype=formation)
    return data
    # data=np.fromfile(**.DAT',dtype=formation)['Count value of each pixel'].reshape(nlin,ncol)
    # return list(data)

完成后把data输出到txt中:1-7波段用注释掉的list,后面的波段用没注释掉的list

"""test!!!test"""
file=r'***\HS_H08_20170623_0250_B01_FLDK_R10_S0210.DAT'
# list=['Block number1'	,'Block length1'	,'Total number of header blocks '	,'Byte order'	,'Satellite name'	,'Processing center name'	,'Observation area'	,'Other observation information'	,'Observation timeline'	,'Observation start time'	,'Observation end time'	,'File creation time'	,'Total header length'	,'Total data length'	,'Quality flag 1'	,'Quality flag 2 '	,'Quality flag 3'	,'Quality flag 4'	,'File format version'	,'File name '	,'Spare1'	,'Block number2'	,'Block length2'	,'Number of bits per pixel'	,'Number of columns'	,'Number of lines'	,'Compression flag for data'	,'Spare2'	,'Block number3'	,'Block length3'	,'sub_lon'	,'Column scaling factor'	,'Line scaling factor'	,'Column offset'	,'Line offset'	,'Distance from Earth’s center to virtual satellite'	,'Earth’s equatorial radius'	,'Earth’s polar radius'	,'var1'	,'var2'	,'var3'	,'Coefficient for sd'	,'Resampling types'	,'Resampling size'	,'Spare3'	,'Block number4'	,'Block length4'	,'Navigation information time'	,'SSP longitude'	,'SSP latitude'	,'Distance from Earth’s center to Satellite'	,'Nadir longitude'	,'Nadir latitude'	,'Sun’s position'	,'Moon’s position'	,'Spare4'	,'Block number5'	,'Block length5'	,'Band number'	,'Central wave length'	,'Valid number of bits per pixel'	,'Count value of error pixels'	,'Count value of pixels outside scan area'	,'Slope for count-radiance conversion equation '	,'Intercept for count-radiance conversion equation'	,'Coefficient for transformation from radiance (I) to albedo'	,'Update time of the values of the following No. 12 and No. 13'	,'Calibrated Slope for count-radiance conversion equation_updated value of No. 8 of this block '	,'Calibrated Intercept for count-radiance conversion equation_updated value of No. 9 of this block '	,'Spare5'	,'Block number6'	,'Block length6'	,'GSICS calibration coefficient_Intercept'	,'GSICS calibration coefficient_Slope'	,'GSICS calibration coefficient_Quadratic term'	,'Radiance bias for standard scene'	,'Uncertainty of radiance bias for standard scene'	,'Radiance for standard scene'	,'Start time of GSICS Correction validity period'	,'End time of GSICS Correction validity period'	,'Radiance validity range of GSICS calibration coefficients_upper limit'	,'Radiance validity range of GSICS calibration coefficients_lower limit'	,'File name of GSICS Correction'	,'Spare6'	,'Block number7'	,'Block length7'	,'Total number of segments'	,'Segment sequence number'	,'First line number of image segment'	,'Spare7'	,'Block number8'	,'Block length8'	,'Center column of rotation'	,'Center line of rotation'	,'Amount of rotational correction'	,'Number of correction information data for column and line direction'	,'Line number after rotation'	,'Shift amount for column direction'	,'Shift amount for line direction8'	,'Spare8'	,'Block number9'	,'Block length9'	,'Number of observation times9'	,'Line number9'	,'Observation time9'	,'Spare9'	,'Block number10'	,'Block length10'	,'Number of error information data'	,'Line number10'	,'Number of error pixels per line10'	,'Spare10'	,'Block number11'	,'Block length11'	,'Spare11']
list=['Blocknumber1'	,'Blocklength1'	,'Totalnumberofheaderblocks'	,'Byteorder'	,'Satellitename'	,'Processingcentername'	,'Observationarea'	,'Otherobservationinformation'	,'Observationtimeline'	,'Observationstarttime'	,'Observationendtime'	,'Filecreationtime'	,'Totalheaderlength'	,'Totaldatalength'	,'Qualityflag1'	,'Qualityflag2'	,'Qualityflag3'	,'Qualityflag4'	,'Fileformatversion'	,'Filename'	,'Spare1'	,'Blocknumber2'	,'Blocklength2'	,'Numberofbitsperpixel'	,'Numberofcolumns'	,'Numberoflines'	,'Compressionflagfordata'	,'Spare2'	,'Blocknumber3'	,'Blocklength3'	,'sub_lon'	,'Columnscalingfactor'	,'Linescalingfactor'	,'Columnoffset'	,'Lineoffset'	,'DistancefromEarth’scentertovirtualsatellite'	,'Earth’sequatorialradius'	,'Earth’spolarradius'	,'var1'	,'var2'	,'var3'	,'Coefficientforsd'	,'Resamplingtypes'	,'Resamplingsize'	,'Spare3'	,'Blocknumber4'	,'Blocklength4'	,'Navigationinformationtime'	,'SSPlongitude'	,'SSPlatitude'	,'DistancefromEarth’scentertoSatellite'	,'Nadirlongitude'	,'Nadirlatitude'	,'Sun’sposition'	,'Moon’sposition'	,'Spare4'	,'Blocknumber5'	,'Blocklength5'	,'Bandnumber'	,'Centralwavelength'	,'Validnumberofbitsperpixel'	,'Countvalueoferrorpixels'	,'Countvalueofpixelsoutsidescanarea'	,'Slopeforcount-radianceconversionequation'	,'Interceptforcount-radianceconversionequation'	,'radiancetobrightnesstemperature_c0'	,'radiancetobrightnesstemperature_c1'	,'radiancetobrightnesstemperature_c2'	,'brightnesstemperaturetoradiance_C0'	,'brightnesstemperaturetoradianceC1'	,'brightnesstemperaturetoradianceC2'	,'Speedoflight'	,'Planckconstant'	,'Boltzmannconstant'	,'Spare5'	,'Blocknumber6'	,'Blocklength6'	,'GSICScalibrationcoefficient_Intercept'	,'GSICScalibrationcoefficient_Slope'	,'GSICScalibrationcoefficient_Quadraticterm'	,'Radiancebiasforstandardscene'	,'Uncertaintyofradiancebiasforstandardscene'	,'Radianceforstandardscene'	,'StarttimeofGSICSCorrectionvalidityperiod'	,'EndtimeofGSICSCorrectionvalidityperiod'	,'RadiancevalidityrangeofGSICScalibrationcoefficients_upperlimit'	,'RadiancevalidityrangeofGSICScalibrationcoefficients_lowerlimit'	,'FilenameofGSICSCorrection'	,'Spare6'	,'Blocknumber7'	,'Blocklength7'	,'Totalnumberofsegments'	,'Segmentsequencenumber'	,'Firstlinenumberofimagesegment'	,'Spare7'	,'Blocknumber8'	,'Blocklength8'	,'Centercolumnofrotation'	,'Centerlineofrotation'	,'Amountofrotationalcorrection'	,'Numberofcorrectioninformationdataforcolumnandlinedirection'	,'Linenumberafterrotation'	,'Shiftamountforcolumndirection'	,'Shiftamountforlinedirection8'	,'Spare8'	,'Blocknumber9'	,'Blocklength9'	,'Numberofobservationtimes9'	,'Linenumber9'	,'Observationtime9'	,'Spare9'	,'Blocknumber10'	,'Blocklength10'	,'Numberoferrorinformationdata'	,'Linenumber10'	,'Numberoferrorpixelsperline10'	,'Spare10'	,'Blocknumber11'	,'Blocklength11'	,'Spare11']
file=r'****\HS_H08_20190916_0300_B08_FLDK_R20_S0110.DAT'
data=read_Himawari(file)
f=open(r'****\HS_H08_20190916_0300_B08_FLDK_R20_S0110.txt','w')
for i in list:
        st=str(i)+':'+str(data[i])
        f.write(st+'\n')
f.close()

可以看一下txt内容:
band1:HS_H08_20170623_0250_B01_FLDK_R10_S0110.txt
在这里插入图片描述
Band8:HS_H08_20190916_0300_B08_FLDK_R20_S0110.txt

在这里插入图片描述

  • 7
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 20
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值