FY4B_C_SPMS/utils.py

722 lines
29 KiB
Python

# -*- coding: utf-8 -*-
"""
Created on Thu Feb 28 15:16:57 2022
@author: zhangqiankun
"""
import os
import sys
import numpy as numpy
import datetime
import time
import glob
import numpy as np
from datetime import timedelta
import datetime
import h5py
import GRAPES
# def match_NWP(sattime, nwppath, delayed=12):
# delttime = 10800.0
# print(sattime)
# sattimest = datetime.datetime.strptime(sattime, '%Y%m%d%H%M')
# satday = datetime.datetime(sattimest.year, sattimest.month, sattimest.day)
# if sattimest.hour < 12:
# startfcsthour = 0
# else:
# startfcsthour = 12
# nwptime = satday - datetime.timedelta(hours=delayed)
# nwptimehour = nwptime + datetime.timedelta(hours=startfcsthour)
# fcsthour1 = int((sattimest - nwptimehour).total_seconds() / delttime) * int(delttime / 3600)
# fcsthour2 = fcsthour1 + int(delttime / 3600)
# fcsthour3 = fcsthour2 + int(delttime / 3600)
# nwptime = datetime.datetime.strftime(nwptimehour, '%Y%m%d%H')
# nwpttime1 = '%s%03d' % (nwptime, fcsthour1)
# nwpttime2 = '%s%03d' % (nwptime, fcsthour2)
# nwpttime3 = '%s%03d' % (nwptime, fcsthour3)
# _path_join = os.path.join
# nwppath = _path_join(nwppath, datetime.datetime.strftime(nwptimehour, '%Y'),
# datetime.datetime.strftime(nwptimehour, '%m'))
# nwpfile1 = _path_join(nwppath, 'gmf.gra.' + nwpttime1 + '.grb2')
# nwpfile2 = _path_join(nwppath, 'gmf.gra.' + nwpttime2 + '.grb2')
# nwpfile3 = _path_join(nwppath, 'gmf.gra.' + nwpttime3 + '.grb2')
# sfcfile1 = 'None'
# sfcfile2 = 'None'
# sfcfile3 = 'None'
# nwpt1 = nwptimehour + datetime.timedelta(hours=fcsthour1)
# nwpt2 = nwptimehour + datetime.timedelta(hours=fcsthour2)
# nwpt3 = nwptimehour + datetime.timedelta(hours=fcsthour3)
# nwptime1 = datetime.datetime.strftime(nwpt1, '%Y%m%d%H') + '00'
# nwptime2 = datetime.datetime.strftime(nwpt2, '%Y%m%d%H') + '00'
# nwptime3 = datetime.datetime.strftime(nwpt3, '%Y%m%d%H') + '00'
# print((nwptime1, nwptime2, nwptime3))
# print(nwpfile1, nwpfile2, nwpfile3)
# return (nwpfile1, nwpfile2, nwpfile3, sfcfile1, sfcfile2, sfcfile3), (nwptime1, nwptime2, nwptime3)
###makebt,ConvertHDF
VALID_RANGE = dict(
LandSeaMask=[0, 7],
clmnwp=[0, 1],
seaice=[0, 1],
qcmark=[0, 1],
SatAzimuth=[0, 36000],
SatZenith=[0, 18000],
SunAzimuth=[0, 36000],
SunZenith=[0, 18000],
lat=[-90, 90],
lon=[-180, 360.],
u10m=[-100, 100],
v10m=[-100, 100],
bt=[5000, 40000],
)
# 根据类型选择填充值
FV = dict(u2=0xFFFF, i2=0x8000, f4=-9999.9, f8=-9999.9, u1=0xFF, i1=0x80)
def headType(nlevel):
return [
('n', 'f4'),
('year', 'f4'),
('month', 'f4'),
('day', 'f4'),
('CO2', 'f4', nlevel),
('CH4', 'f4', nlevel),
('N2O', 'f4', nlevel),
('CO' , 'f4', nlevel),
('P', 'f4', nlevel),
('pix', 'f4'),
('line', 'f4'),
]
import io
def mwork(nlevel, nchannel, fileout, filein1, filein2):
nlevel = int(nlevel)
nchannel = int(nchannel)
print nlevel
print nchannel
print filein2
filein2.sort()
I2 = io.BytesIO()
for i in sorted(filein2,key=lambda x:int(x.split('/temp')[-1].split('_')[0])):
print i
with open(i,'rb') as f:
I2.write(f.read())
with open(filein1, 'rb') as I1:
_mwork(I1, I2, fileout, nlevel, nchannel)
def _mwork(I1, I2, fileout, nlevel, nchannel):
head, = numpy.fromfile(I1, dtype=headType(nlevel), count=1)
dataType = numpy.dtype([
('x', 'f4'),
('y', 'f4'),
('lat', 'f4'),
('lon', 'f4'),
('SatAzimuth', 'f4'),
('SatZenith', 'f4'),
('SunAzimuth', 'f4'),
('SunZenith', 'f4'),
('psfc', 'f4'),
('q2m', 'f4'),
('t2m', 'f4'),
('u10m', 'f4'),
('v10m', 'f4'),
('dem', 'f4'),
('seaice', 'f4'),
('LandSeaMask', 'f4'),
('ts', 'f4'),
('T', 'f4', nlevel),
('q', 'f4', nlevel),
('o3', 'f4', nlevel),
('qcmark', 'f4'),
('cloud', 'f4', (6,nlevel-1)),
('cfrac', 'f4', nlevel-1),
('obs', 'f4', nchannel),
('cloudmask', 'f4'),
('clmnwp', 'f4'),
('emissivity', 'f4', nchannel),
('time', 'f8'), ('11', 'f4',2)
])
print dataType.itemsize
n = int(head['n'])
print n
I1.seek(0,2)
n=I1.tell()/dataType.itemsize-1
l = int(head['line'])
p = int(head['pix'])
print n,l,p
I1.seek(dataType.itemsize, 0)
data = numpy.fromfile(I1, dtype=dataType, count=n) # pre
data2 = numpy.fromstring(I2.getvalue(), dtype=[('sim', 'f4', nchannel),('Qf', 'i4', nchannel)], count=n) # sim_result
# I2.close()
x = data['x'].astype('u4')-1
y = data['y'].astype('u4')-1
print fileout
with h5py.File(fileout, 'w') as f:
for i, j in ('LandSeaMask', 'u1'), ('clmnwp', 'u1'), ('seaice', 'u1'), ('qcmark','u1'), \
('SatAzimuth', 'u2'), ('SatZenith', 'u2'), ('SunAzimuth', 'u2'), ('SunZenith', 'u2'), \
('lat', 'f4'), ('lon', 'f4'), ('u10m', 'f4'), ('v10m', 'f4'):
d = numpy.full((l, p), fill_value=FV[j], dtype=j)
if j == 'u1':
tmp = data[i]
tmp[tmp<0] = 255
d[y, x] = tmp
elif j == 'u2':
tmp = data[i]
d[y, x] = tmp * 100
d[y, x][tmp<-998] = FV['u2']
else:
d[y, x] = data[i]
f.create_dataset(i, data=d, compression=9).attrs.update(
Slope=numpy.array(0.01,'f4') if j == 'u2' else numpy.array(1,'f4'),
valid_range=VALID_RANGE.get(i, [])
)
#bt_dype = 'f4'
#slope = numpy.array(1,'f4')
bt_dype = 'u2'
slope = numpy.array(0.01,'f4')
if nchannel ==1:
d = numpy.full((l, p), fill_value=FV[bt_dype], dtype=bt_dype)
else:
d = numpy.full((l, p, nchannel), fill_value=FV[bt_dype], dtype=bt_dype)
obs=data['obs']
#d[y, x] = obs
obs[obs<-999] = 655.35
print obs
d[y, x] = obs / slope
#d[y, x][obs<-998] = FV[bt_dype]
print(d)
f.create_dataset('BT_OBS', data=d, compression=9).attrs.update(
Slope=slope, valid_range=numpy.array(VALID_RANGE['bt'], dtype='i4'))
if nchannel == 1:
d = numpy.full((l, p), fill_value=FV[bt_dype], dtype=bt_dype)
else:
d = numpy.full((l, p, nchannel), fill_value=FV[bt_dype], dtype=bt_dype)
sim = data2['sim']
sim[sim<0] = 655.35
d[y, x] = sim / slope
f.create_dataset('BT_SIM', data=d, compression=9).attrs.update(
Slope=slope, valid_range=numpy.array(VALID_RANGE['bt'], dtype='i4')
)
d = numpy.full((l, p, nchannel), fill_value=255, dtype='u1')
obs = data2['Qf']
obs[obs<0] = 255
d[y, x] = obs
f.create_dataset('QC_rttov', data=d, dtype='u1',compression=9)
d = numpy.full((l,p), fill_value=-9999., dtype='f8')
tm = data['time']
# tf = tm>0
tm[tm<0]=-9999.
# d[y[tf],] = tm[tf]
d[y, x] = tm
f.create_dataset('timestamp', data=d, compression=9).attrs.update(
discription='seconds from 1970-01-01 00:00:00 UTC'
)
f.attrs.update(
G_TIME=time.strftime('%Y-%m-%d %H:%M:%S'),
MOUDLE='RTTOV 1.2',
BASEDATA='ERA5'
)
class dataset(object):
"""
Decorator that converts a method with a single self argument into a
property cached on the instance.
Optional ``name`` argument allows you to make cached dataset of other
methods. (e.g. url = dataset(get_absolute_url, name='url') )
"""
def __init__(self, func, name=None):
self.func = func
self.__doc__ = getattr(func, '__doc__')
self.name = name or func.__name__
def __get__(self, instance, cls=None):
if instance is None:
return self
res = instance.__dict__[self.name] = self.func(instance)
return res
class satfilebase(object):
"""Concrete satfile type.
Constructors:
Operators:
__new__()
Methods:
# fuzzyfile()
# generatepath()
Properties (readonly):
satname,instrument,regionaltype,datalevel,sattime,dataname,vesion
eg:/FY4A_DATA/FY4A/GIIRS/L1/IRD/REGX/2022/20220101/
FY4A-_GIIRS-_N_REGX_1047E_L1-_IRD-_MULT_NUL_20220101000000_20220101001044_016KM_001V3.HDF
"""
def __new__(cls,filename):
self = object.__new__(cls)
self._obspath = filename
self._basename = os.path.basename(filename)
print(self._basename)
_spiltname = self._basename.split('_')
self._satname = _spiltname[0].replace('-','')
self._instrument = _spiltname[1].replace('-','')
self._regionaltype = _spiltname[3]
self._subastralPoint = _spiltname[4]
self._datalevel = _spiltname[5].replace('-','')
self._datatype = _spiltname[6].replace('-','')
self._channelname = _spiltname[7]
self._projection = _spiltname[8]
self._startime = _spiltname[9]
self._endtime = _spiltname[10]
self._resolution = _spiltname[11]
self._vesion = _spiltname[12][:5]
return self
@property
def obspath(self):
return self._obspath
@property
def basename(self):
return self._basename
@property
def startime(self):
return self._startime
@property
def endtime(self):
return self._endtime
@property
def instrument(self):
return self._instrument
@property
def regionaltype(self):
return self._regionaltype
@property
def datalevel(self):
return self._datalevel
@property
def datatype(self):
return self._datatype
@property
def vesion(self):
return self._vesion
class bgbase(satfilebase):
def __new__(cls,filename,options):
# self = object.__new__(cls)
self = super(bgbase,cls).__new__(cls,filename)
settings = options['settings']
self._nwpname = settings['NWP']
self._nwpresolution = settings['NWP_resolution']
path = options['path']
self._configpath = path['configpath']
self._nwppath = path['NWPpath']
self._workpath = path['bgworkpath']
###
add ='/%s/%s/%s/%s/%s/'%(self._satname,self._instrument,self._nwpname,self._startime[0:4],self._startime[0:8])
self._outpath = path['bgoutpath']+add
if not os.path.exists(self._outpath):
os.makedirs(self._outpath)
print(self._startime)
if datetime.datetime.strptime(self._startime,'%Y%m%d%H%M%S')<datetime.datetime.strptime('202305220001','%Y%m%d%H%M'):
self._nwpresolution = 0.25
else:
self._nwpresolution = 0.125
staticfile=options['staticfile']
self._lsmfile = staticfile['lsmfile']
self._elefile = staticfile['elefile']
self._coeffile = staticfile['coeffile']
self._emispath = staticfile['emispath']
if self._instrument =='GIIRS':
###bg chan begin
if 'channelbegin' in settings.keys()and isinstance(settings['channelbegin'],dict):
if 'LW' in settings['channelbegin'].keys():
self._lwchannelbegin = settings['channelbegin']['LW']
else:
self._lwchannelbegin = 1
if 'MW' in settings['channelbegin'].keys():
self._mwchannelbegin = settings['channelbegin']['MW']
else:
self._mwchannelbegin = 1
else:
self._lwchannelbegin = 1
self._mwchannelbegin = 1
self._spectype='IR'
self._emispath=self._emispath+'/'+ self._spectype
if 'bgexepath' in staticfile.keys()and isinstance(staticfile['bgexepath'],dict):
if 'LW' in staticfile['bgexepath'].keys():
self._bglwexe = staticfile['bgexepath']['LW']
else:
self._bglwexe = '%s/produce_background_data_%s_%s_%s_LW.exe'%(self._workpath,self._nwpname,self._satname[2:],self._instrument)
if 'MW' in staticfile['bgexepath'].keys():
self._bgmwexe = staticfile['bgexepath']['MW']
else:
self._bgmwexe = '%s/produce_background_data_%s_%s_%s_MW.exe'%(self._workpath,self._nwpname,self._satname[2:],self._instrument)
else:
self._bglwexe = '%s/produce_background_data_%s_%s_%s_LW.exe'%(self._workpath,self._nwpname,self._satname[2:],self._instrument)
self._bgmwexe = '%s/produce_background_data_%s_%s_%s_MW.exe'%(self._workpath,self._nwpname,self._satname[2:],self._instrument)
self._bgexe={'LW':self._bglwexe,'MW':self._bgmwexe}
lwoutfile = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_clear_sea_profiles_LW.dat'
lwoutcloudy = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_cloudy_profiles_LW.dat'
lwoutland = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_clear_land_profiles_LW.dat'
mwoutfile = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_clear_sea_profiles_MW.dat'
mwoutcloudy = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_cloudy_profiles_MW.dat'
mwoutland = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_clear_land_profiles_MW.dat'
self._outfile = {'LW':lwoutfile,'MW':mwoutfile}
self._outcloudy = {'LW':lwoutcloudy,'MW':mwoutcloudy}
self._outland = {'LW':lwoutland,'MW':mwoutland}
elif self._instrument =='AGRI':
self._spectype='IR'
self._emispath=self._emispath+'/'+ self._spectype
self._bgexe = '%s/produce_background_data_%s_%s_%s.exe'%(self._workpath,self._nwpname,self._satname[2:],self._instrument)
self._outfile = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_clear_sea_profiles.dat'
self._outcloudy = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_cloudy_profiles.dat'
self._outland = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_clear_land_profiles.dat'
self._configfile = None
return self
def match_nwp(self):
A = GRAPES.GRAPESMETA()
nwpfile,nwptime,_ = A.match(self._startime[0:12],nums=3,delttime=10800,delayed=6,fcschoice=12,fcssame = True)
self._nwpfile = nwpfile
self._nwptime = nwptime
if (os.path.exists(nwpfile[0]))&(os.path.exists(nwpfile[1]))&(os.path.exists(nwpfile[2])):
return True
else:
return False
def make_config(self,wmtype='',obsfile='None',geofile='None'):
if self._instrument == 'GIIRS' and (not wmtype in ("MW","LW") ):
print('giirs need input wmtype')
exit()
if self._instrument == 'AGRI':
print(obsfile)
if obsfile!='None':
obsfile = obsfile
else:
dirname = os.path.dirname(self._obspath)
obsfile = dirname.replace('GEO','4000M')+'/'+self._basename.replace('GEO','FDI')
if geofile!="None":
geofile = geofile
else:
geofile = '/fy4_ads_data/FY4B/data/1330E/FY4B_OBI_4000M_NOM_LATLON.HDF' #default
# /FY4B_DATA/AGRI/L1/FDI/DISK/GEO/2022/20220415/FY4B-_AGRI--_N_DISK_1330E_L1-_GEO-_MULT_NOM_20220415040000_20220415041459_4000M_V0001.HDF
# /FY4B_DATA/AGRI/L1/FDI/DISK/4000M/2022/20220415/FY4B-_AGRI--_N_DISK_1330E_L1-_FDI-_MULT_NOM_20220415031500_20220415032959_4000M_V0001.HDF
self._configfile = self._configpath+'/configure_bg_%s_%s_%s.txt'%(self._nwpname,self._basename[0:11],self._startime)
print('*****',self._configfile)
elif self._instrument == 'GHI':
if not obsfile=='None':
obsfile = obsfile
else:
dirname = os.path.dirname(self._obspath)
obsfile = dirname.replace('GEO','2000M')+'/'+self._basename.replace('GEO','FDI')
# /FY4B_DATA/AGRI/L1/FDI/DISK/GEO/2022/20220415/FY4B-_AGRI--_N_DISK_1330E_L1-_GEO-_MULT_NOM_20220415040000_20220415041459_4000M_V0001.HDF
# /FY4B_DATA/AGRI/L1/FDI/DISK/4000M/2022/20220415/FY4B-_AGRI--_N_DISK_1330E_L1-_FDI-_MULT_NOM_20220415031500_20220415032959_4000M_V0001.HDF
self._configfile = self._configpath+'/configure_bg_%s_%s_%s.txt'%(self._nwpname,self._basename[0:11],self._startime)
elif self._instrument == 'GIIRS':
obsfile='None'
geofile = 'None'
######conf
self._configfile = self._configpath+'/configure_bg_%s_%s_%s_%s.txt'%(self._nwpname,self._basename[0:11],self._startime,wmtype)
print self._configfile
# configfile = self._configpath+'/configure_%s_%s_%s_%s.txt'%(self.nwpname,self._basename[0:11]+self._startime,giirstype)
if not os.path.exists(self._configpath):
os.makedirs(self._configpath)
polar = 0
clmfile ='None'
delttime = 10800.0
with open(self._configfile,'w')as f:
f.write('&L1info\n')
f.write('satfilename=\'%s\'' % self._obspath +',\n')
f.write('obsfilename=\'%s\'' % obsfile +',\n')
f.write('clmfilename=\'%s\'' % clmfile +',\n')
f.write('coeffile=\'%s\'' % self._coeffile +',\n')
f.write('emispath=\'%s\'' % self._emispath +',\n')
f.write('spectype=\'%s\'' % self._spectype +',\n')
f.write('sattype=%s' % polar +',\n')
f.write('year=%s' % self._startime[0:4] +',\n')
f.write('month=%s' % self._startime[4:6] +',\n')
f.write('day=%s' % self._startime[6:8] +',\n')
if self._instrument == 'GIIRS'and wmtype=='MW':
f.write('channelbegin=%s' % self._mwchannelbegin +',\n')
f.write('/\n')
f.write('&nwpfileinfo\n')
f.write('nwpfilename1=\'%s\'' % self._nwpfile[0] +',\n')
f.write('nwpfilename2=\'%s\'' % self._nwpfile[1] +',\n')
f.write('nwpfilename3=\'%s\'' % self._nwpfile[2] +',\n')
f.write('sfcfilename1=\'%s\'' % self._nwpfile[3] +',\n')
f.write('sfcfilename2=\'%s\'' % self._nwpfile[4] +',\n')
f.write('sfcfilename3=\'%s\'' % self._nwpfile[5] +',\n')
f.write('lsmfilename=\'%s\'' % self._lsmfile +',\n')
f.write('elefilename=\'%s\'' % self._elefile +',\n')
f.write('geofilename=\'%s\'' % geofile +',\n')
f.write('time1=%s' % self._nwptime[0] +',\n')
f.write('time2=%s' % self._nwptime[1] +',\n')
f.write('time3=%s' % self._nwptime[2] +',\n')
f.write('delttime=%s' % delttime +',\n')
f.write('NWP_resolution=%s' % self._nwpresolution +',\n')
f.write('/\n')
f.write('&output\n')
if self._instrument == 'GIIRS':
f.write('outfilename=\'%s\'' % self._outfile[wmtype] +',\n')
f.write('outcloudy=\'%s\'' % self._outcloudy[wmtype] +',\n')
f.write('outland=\'%s\'' % self._outland[wmtype] +',\n')
else:
f.write('outfilename=\'%s\'' % self._outfile +',\n')
f.write('outcloudy=\'%s\'' % self._outcloudy +',\n')
f.write('outland=\'%s\'' % self._outland +',\n')
f.write('/\n')
return self._configfile
@property
def config(self):
return self._configfile
def del_config(self):
if os.path.exists(self._configfile):
os.remove(self._configfile)
print('del %s'% self._configfile)
def run(self,wmtype='None'):
if self._configfile is None:
print('config is not exist,please make config file!')
else:
if self._instrument=='GIIRS' and wmtype =='LW':
os.system('time %s %s' % ( self._bglwexe,self._configfile))
print('time %s %s' % (self._bglwexe,self._configfile))
#
os.system('rm -f /fy4_ads_data/stss_v2.0/FILE_GRAPES_inv/FY4B-_GIIRS*%s*'%(self._satname[0:10]))
elif self._instrument=='GIIRS' and wmtype =='MW':
os.system('time %s %s' % (self._bgmwexe,self._configfile))
print('time %s %s' % (self._bgmwexe,self._configfile))
os.system('rm -f /fy4_ads_data/stss_v2.0/FILE_GRAPES_inv/FY4B-_GIIRS*%s*'%(self._satname[0:10]))
else:
print('time %s %s' % ( self._bgexe,self._configfile))
os.system('time %s %s' % ( self._bgexe,self._configfile))
def del_bgfile(self,wmtype='None'):
if self._instrument=='GIIRS':
if os.path.exists(self._outfile[wmtype]):
os.remove(self._outfile[wmtype])
print('del %s'% self._outfile[wmtype])
if os.path.exists(self._outcloudy[wmtype]):
os.remove(self.outcloudy[wmtype])
print('del %s'% self.outcloudy[wmtype])
if os.path.exists(self._outland[wmtype]):
os.remove(self._outland[wmtype])
print('del %s'% self._outland[wmtype])
else:
if os.path.exists(self._outfile):
os.remove(self._outfile)
print('del %s'% self._outfile)
if os.path.exists(self._outcloudy):
os.remove(self.outcloudy)
print('del %s'% self.outcloudy)
if os.path.exists(self._outland):
os.remove(self._outland)
print('del %s'% self._outland)
class simbase(satfilebase):
def __new__(cls,filename,options):
# self = object.__new__(cls)
self = super(simbase,cls).__new__(cls,filename)
settings = options['settings']
self._nwpname = settings['NWP']
self._nwplevel = settings['NWP_level']
if self._instrument=="GIIRS":
self._nchannels = {'LW':settings['channels']['LW'],
'MW':settings['channels']['MW']}
else:
self._nchannels = settings['channels']
# self._IP = settings['IP']
self._numexe = settings['numexe']
path = options['path']
self._configpath = path['configpath']
self._bgfilepath = path['bgoutpath']
self._temppath = path['temppath']
self._outpath = path['simpath']
staticfile=options['staticfile']
self._coeffile = staticfile['coeffile']
self._emispath = staticfile['emispath']
self._simexe = staticfile['simexe']
self._spectype='IR'
self._emispath=self._emispath+'/'+ self._spectype
add ='/%s/%s/%s/%s/%s/'%(self._satname,self._instrument,self._nwpname,self._startime[0:4],self._startime[0:8])
self._temppath = self._temppath+add
self._outpath = self._outpath+add
return self
def make_config(self,wmtype='None'):
if not os.path.exists(self._temppath):
os.makedirs(self._temppath)
print(self._outpath)
if not os.path.exists(self._outpath):
os.makedirs(self._outpath)
if not os.path.exists(self._configpath):
os.makedirs(self._configpath)
add ='/%s/%s/%s/%s/%s/'%(self._satname,self._instrument,self._nwpname,self._startime[0:4],self._startime[0:8])
self._bgfilepath +=add
# self._self._outfile = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_clear_sea_profiles.dat'
if self._instrument=='GIIRS':
self._configfile = self._configpath+'/configure_sim_%s_%s_%s_%s.txt'%(self._nwpname,self._basename[0:11],self._startime,wmtype)
self._outcloudy = self._bgfilepath+self._basename[0:44]+self._startime+'_'+self._resolution+'_cloudy_profiles_%s.dat'%(wmtype)
self._outbasename = self._basename[0:44]+self._startime+'_'+self._resolution+'_%s_BT.dat'%(wmtype)
self._outfile = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_%s_BT.HDF'%(wmtype)
nchannels = self._nchannels[wmtype]
if wmtype == "MW":
chanannelbegine = 722
else:
chanannelbegine = 1
else:
self._configfile = self._configpath+'/configure_sim_%s_%s_%s.txt'%(self._nwpname,self._basename[0:11],self._startime)
self._outcloudy = self._bgfilepath+self._basename[0:44]+self._startime+'_'+self._resolution+'_cloudy_profiles.dat'
# lwoutcloudy = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_cloudy_profiles_LW.dat'
self._outbasename = self._basename[0:44]+self._startime+'_'+self._resolution+'_BT.dat'
self._outfile = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_BT.HDF'
nchannels = self._nchannels
chanannelbegine = 1
#####
#wenjian
#####
# self._configfile = configfile
# if self._instrument == 'MERSI':
# obsfile = self.obspath.replace(self._datatype,self._datatype[3]+'000M')
# else:
# obsfile='None'
######config
# self._nvar=(20 + 3 * self._nwplevel + 7 * ((self._nwplevel-1)) +self._nchannels + self._nchannels + 4)
with open(self._configfile,'w')as f:
f.write('&L1info\n')
f.write('nchannels=%s' % nchannels +',\n')
f.write('channelbegin=%s' %chanannelbegine +',\n')
f.write('platformid=%s' % '1' +',\n')
f.write('satid=%s' % '23' +',\n')
f.write('insid=%s' % '1' +',\n')
f.write('coefffile=\'%s\'' % self._coeffile +',\n')
f.write('scattcoef_file=\'%s\'' % 'None' +',\n')
f.write('emisfilepath=\'%s\'' % self._emispath +',\n')
f.write('zeemancoef_file=\'%s\'' % 'None' +',\n')
f.write('/\n')
f.write('&nwpfileinfo\n')
f.write('spectype=%s' % self._spectype +',\n')
f.write('bkgfile=\'%s\'' % self._outcloudy +',\n')
f.write('nprofile=%s' % '5793312' +',\n')
f.write('nlevel=%s' % self._nwplevel +',\n')
f.write('/\n')
f.write('&output\n')
f.write('temppath=\'%s\'' % self._temppath +',\n')
f.write('outpath=\'%s\'' % self._outpath +',\n')
f.write('outfilename=\'%s\'' % self._outbasename +',\n')
f.write('/\n')
return self._configfile
# @property
def config(self,wmtype='None'):
if self._instrument=='GIIRS':
self._configfile = self._configpath+'/configure_sim_%s_%s_%s_%s.txt'%(self._nwpname,self._basename[0:11],self._startime,wmtype)
else:
self._configfile = self._configpath+'/configure_sim_%s_%s_%s.txt'%(self._nwpname,self._basename[0:11],self._startime)
return self._configfile
# @property
def outfile(self,wmtype='None'):
if self._instrument=='GIIRS':
self._outfile = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_%s_BT.HDF'%(wmtype)
else:
self._outfile = self._outpath+self._basename[0:44]+self._startime+'_'+self._resolution+'_BT.HDF'
return self._outfile
def del_config(self):
if os.path.exists(self._configfile):
os.remove(self._configfile)
print('del %s'% self._configfile)
def run(self,wmtype='None'):
if self._configfile is None:
print('config is not exist,please make config file!')
if self._instrument=='GIIRS':
self._tempfilename = self._temppath+'temp*_'+self._basename[0:44]+self._startime+'_'+self._resolution+'_%s_BT.dat'%(wmtype)
nchannels = self._nchannels[wmtype]
else:
self._tempfilename = self._temppath+'temp*_'+self._basename[0:44]+self._startime+'_'+self._resolution+'_BT.dat'
nchannels = self._nchannels
os.system('time mpirun -n %s %s %s'%(self._numexe,self._simexe,self._configfile))
self._tempfiles= glob.glob(self._tempfilename)
mwork(self._nwplevel,nchannels,self._outfile,self._outcloudy,self._tempfiles)
def run_nonrunexe(self,wmtype='None'):
# if self._configfile is None:
# print('config is not exist,please make config file!')
if self._instrument=='GIIRS':
self._tempfilename = self._temppath+'temp*_'+self._basename[0:44]+self._startime+'_'+self._resolution+'_%s_BT.dat'%(wmtype)
nchannels = self._nchannels[wmtype]
else:
self._tempfilename = self._temppath+'temp*_'+self._basename[0:44]+self._startime+'_'+self._resolution+'_BT.dat'
nchannels = self._nchannels
# os.system('time mpirun -n %s %s %s'%(self._numexe,self._simexe,self._configfile))
self._tempfiles= glob.glob(self._tempfilename)
# print(self._nwplevel,nchannels,self._outfile,self._outcloudy,self._tempfiles)
mwork(self._nwplevel,nchannels,self._outfile,self._outcloudy,self._tempfiles)
def del_temp(self):
if self._tempfiles:
os.system('rm -f '+self._tempfilename)
print('del %s'% self._tempfiles)
def del_bgfile(self):
if os.path.exists(self._outcloudy):
os.remove(self._outcloudy)
print('del %s'% self._outcloudy)