def get_obs_list(self,init_yyyymmddhhmm,end_yyyymmddhhmm,hr): MISSING = self.MISSING str_init_yyyymmddhhmm = str(init_yyyymmddhhmm) str_end_yyyymmddhhmm = str(end_yyyymmddhhmm) times = 0 hhmm_list = dt().h_to_hm(hr) target_dtg = str_init_yyyymmddhhmm while True: if target_dtg == str_end_yyyymmddhhmm: break else: times += 1 target_dtg = dt().roll_hhmm(int(target_dtg),hhmm_list) target_dtg = str_init_yyyymmddhhmm if times != 0: obs_list = np.array([MISSING]*times) dtg_list = np.array([MISSING]*times) for k in range(times): dtg_list[k] = target_dtg target_dtg = dt().roll_hhmm( int(target_dtg),hhmm_list) for j in range(times): print(int(dtg_list[j])) obs_list[j] = self.find_obs_hhmm(int(dtg_list[j])) elif times == 0: obs_list = [] return obs_list
def act_mix_lc_TS(self,init_dtg,day,sec): act_list = [] for i in range(0,day+1): for k in range(1,sec+1): hkt = dt().roll_dtg(init_dtg,i) act_list.append(self.find_obs(hkt,k)) #hkt = dt().roll_dtg(init_dtg,day+1) #act_list.append(self.find_obs(hkt,1,Config().location)) #act_list.append(self.find_obs(hkt,2,Config().location)) #act_list.append(self.find_obs(hkt,3,Config().location)) return act_list
def get_dtg_list(self, dtg, I, t_scale=1): """ dtg = 201712121200 (starting point) I = [1.0,1.25,1.5,1.75.....10.0] <---1.0 hr ,1.25 hr ..... output = ['201712121300','201712121315',......] t_scale = 6 for LC normal section input: LC = LC_Reader(Config().loc_id).get_dtg_list(201701021200,[0,1.25,4,5,6,7,8],6) output: ['201701021200', '201701021930', '201701031200', '201701031800', '201701040000', '201701040600', '201701041200'] """ output = [] for k in I: time_list = dt().h_to_hm(t_scale * (k + 1)) output.append(dt().roll_hhmm(dtg, time_list)) return output
def find_obs_hhmm(self,yyyymmddhhmm): """ Argument: date = '20170713' hhmm = '0524' output: output is the float """ str_yyyymmddhhmm = str(yyyymmddhhmm) date = str(str_yyyymmddhhmm[0:8]) hhmm = str(str_yyyymmddhhmm[8:12]) output = self.MISSING loc = self.loc if type(date) is not str: date = str(date) if type(hhmm) is not str: hhmm = str(hhmm) if self.format == self.obs_format[0]: change = False if hhmm == '0000' and date[6:8] == '01': ## XXXXXX01 0000 in obs file is the day before XXXXXX01 and hhmm is 2400 (obs starting from 0001) date = dt().roll_dtg(yyyymmddhhmm,-1) change = True obs_content = self.readfile(yyyymmddhhmm) loop = 0 ##just for finding obs in OBS file ...may not be necessary if hhmm == '0000': if change == False: date = dt().roll_dtg(yyyymmddhhmm,-1) hhmm = '2400' else: hhmm = '2400' while obs_content: line = obs_content[loop] loop += 1 line = line.split() #print(line[1]) MMDD = line[0] HHMM = line[1] if date[0:8] == MMDD and hhmm == HHMM: data_list = [int(x.split()[2]) for x in obs_content[loop-self.sub2 /2:loop+self.sub2 /2]] ## may cause over list length in other language or python version output = self.find_max(data_list) self.max = self.MISSING break if output != self.MISSING: output = output/10.0 ##----------another source from observation data--------# elif self.format == self.obs_format[1] : # db has no minute obs_content = self.readfile(yyyymmddhhmm) loop = 0 req_date = date[0:8] + hhmm[0:2] while obs_content: line = obs_content[loop] line = line.strip() line = line.split(',') YYYYMMDDHH = line[0] #validtime value_str = line[1] if req_date == YYYYMMDDHH: output = float(value_str) break loop += 1 if loop > len(obs_content) - 1 : break if not output >= 0.0 and output <= 100.0: output = self.MISSING elif self.format == self.obs_format[2] : output = self.MISSING obs_content = self.readfile(yyyymmddhhmm) year = int(date[0:4]) month = int(date[4:6]) day = int(date[6:8]) hh = int(hhmm[0:2]) mm = int(hhmm[2:4]) DATE = datetime.datetime(year, month, day, hh, mm).strftime("%Y-%m-%d %H:%M") init_date = datetime.datetime(year, month, day, hh, mm) final_date = init_date find_index = True Target_dataf = obs_content.loc[obs_content['valid'] == DATE] index_list = Target_dataf.index.tolist() if len(index_list) != 0: find_index = False min_delta = 1 while find_index: final_date = final_date + datetime.timedelta(minutes = min_delta) Target_dataf = obs_content.loc[obs_content['valid'] == DATE] index_list = Target_dataf.index.tolist() min_delta += 1 if len(index_list) != 0 or min_delta >30: break if self.element == 'windspd': if len(index_list) != 0: output = float(Target_dataf.at[index_list[0],'sknt']) output = 0.514444444*output if not output >= 0.0 and output <= 100.0: output = self.MISSING return output
def set(self, data, sis_times=6, interval_hr=1.0, alpha=0.5, reliability=0.0): self.sis_times = sis_times self.interval_hr = interval_hr self.interval_hr = interval_hr self.set_times_hr(sis_times, interval_hr) date = self.init_dtg total_particles = self.total_P sigma = self.sigma location = self.loc element = self.element LC_interval = self.LC_interval start_section = LC_interval[0] end_section = LC_interval[1] - 1 diff_section = end_section - start_section EC_timeInterval = 6.0 interval_perday = 4 fcst_day = end_section / interval_perday + 1 section = end_section % interval_perday + 1 passed_hr_mm = dt().h_to_hm(float(sis_times) * float(interval_hr)) HKT_diff_UTC = 8 HKT_diff_init_dtg = int( EC_timeInterval ) + HKT_diff_UTC + start_section * int(EC_timeInterval) HKT_start = dt().roll_hhmm(date, [HKT_diff_init_dtg, 0]) HKT_end = dt().roll_hhmm(HKT_start, passed_hr_mm) SIS = SIS_up.SIS_up(alpha, total_particles, sigma) if data == 'RAW': SIS.set_option(date, location, element, LC_interval) SIS.process_data(self.hr) elif data == 'MBM': print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ) ReIndex = reliability GEN_MBM = gen_mem.gen_mem(date, ReIndex, element, location) ensemble_MBM = GEN_MBM.get_members(fcst_day, section) ensemble_MBM = ensemble_MBM[start_section:end_section + 1] #print(ensemble_MBM) sec_per_interval = int(EC_timeInterval / interval_hr) orignal_section_list = np.linspace(float(start_section), float(end_section), num=diff_section + 1, endpoint=True) split_section_list = np.linspace(float(start_section), float(end_section), num=sec_per_interval * (diff_section) + 1, endpoint=True) ensemble_MBM = TS.interpolation(orignal_section_list, ensemble_MBM, split_section_list, method="linear") OBS = obs_reader(location, element) obs_list = OBS.get_obs_list(HKT_start, HKT_end, interval_hr) SIS.InsertData(ensemble_MBM, obs_list) self.ens = SIS.y_list_sec self.new_particles = SIS.gen_particle(self.times)
return split_ens """ def gen_plume(self, name): loc = self.loc AXV = (self.sis_times - 1) * self.interval_hr plume = plot.plot_SIS(self.init_dtg, self.LC_interval, name, loc, self.element, vertical_line=AXV) plume.time_setting(self.day_gen, self.hr, self.times) plume.plot("plume") if __name__ == "__main__": for day in range(1): for i in range(20, 45): start = 201809141200 num = day x = i DD = dt().roll_dtg(start, num) SIS = SIS_main( DD, [0, 9], "wgl", 0.1, "windspd") ##0 stands for col 0, 6 stands for col 6(exclude) SIS.set('MBM', sis_times=i, interval_hr=1, alpha=0.5) SIS.gen_pdf(2) SIS.gen_plume("SIS")