def yearly_cummulative_image(year): """ create cumulative image fits files for the given year input: year --- the year you want to create the image fits files output: lev1, lev2, and inst map for the given year """ # #--- hrc i 115 case # hdir = 'hrc_i_115' run_map_fucntion(hdir, year) # #--- hrc s 125 hi res case # hdir = 'hrc_s_125_hi' run_map_fucntion(hdir, year) # #--- hrc s 125 case: 3 sections # hdir = 'hrc_s_125' for sec in range(1, 4): run_map_fucntion(hdir, year, sec) # #--- create histograms and maps of image files # hpm.plot_hrc_map(year)
def create_cumulative_image(): """ create normalized combined image fits files input: none but read from each directory output: combine image fits files, e.g. hrc_i_115_total_norm.fits.gz it also create png files """ for hdir in ['Hrc_i_115', 'Hrc_s_125_hi', 'Hrc_s_125']: head = hdir.lower() # #--- hrc_s_125 has three parts # if hdir == 'Hrc_s_125': p_list = ['1', '2', '3'] else: p_list = [''] for part in p_list: # #--- lev 1 image # cmd = 'ls ' + data_dir + hdir + '/' + head + '*_norm' + part cmd = cmd + '.fits.gz > ' + zspace os.system(cmd) # #--- exclude the previous combined image file (with "_total_") and instmant (with "_instmap_") # tlist = mcf.read_data_file(zspace, remove=1) slist = [x for x in tlist if 'total' not in x] flist = [x for x in slist if 'instmap' not in x] add_image_fits_data(flist, part) # #--- lev 2 image # cmd = 'ls ' + data_dir + hdir + '/' + head + '_lev2*_norm' cmd = cmd + part + '.fits.gz > ' + zspace os.system(cmd) tlist = mcf.read_data_file(zspace, remove=1) flist = [x for x in tlist if 'total' not in x] add_image_fits_data(flist, part) # #--- create map png files and histogram png files # hpm.plot_hrc_map('total')
def run_hrc_stowed_background_monthly_update(lyear='', lmonth=''): """ run monthly update for the hrc stowed background data input: lyear, lmonth --- the year and month of the data to be processed if they are not given, the last month of year and year will be used output: newly proccessed data: <data_dir>/<yyyy><mmm>/* if it is jan or jul, cummulative maps for the year (and the entire period) are created """ # #--- clean up exc dir # cmd = 'rm -rf ' + exc_dir + 'Temp_dir/* 2> /dev/null' os.system(cmd) cmd = 'rm -rf ' + exc_dir + 'param 2> /dev/null' os.system(cmd) cmd = 'mkdir ' + exc_dir + 'param 2> /dev/null' os.system(cmd) # #--- if date (year/month) to be processed is not given, find the last month's year, month # if lyear == '': ctime = time.gmtime() #--- today's date information lyear = ctime.tm_year lmonth = ctime.tm_mon - 1 if lmonth < 1: lyear -= 1 lmonth = 12 # #--- check whether the data was already processed; if not, run the process # smonth = tcnv.changeMonthFormat(lmonth) cdir = data_dir + str(lyear) + smonth.upper() smail = 0 if not os.path.isdir(cdir): try: hsb.hrc_stowed_background(lyear, lmonth, lyear, lmonth) # #--- if the processed month is june or december, update maps and html pages # if (lmonth == 12) or (lmonth == 6): # #--- update total event number tables # get_yearly_evt_count() chif.yearly_cummulative_image(lyear) hpm.plot_hrc_map(lyear) hpm.plot_hrc_map('total') #---- creating cumulative maps hpm.plot_hrc_map( 'total', 1) #---- creating cumulative histogram for the front page hpr.plot_hrc_trend_data() #---- creating trending plots uhhp.create_html_pages(lyear) #---- updating all html pages create_cumulative_image() if test_data_creation(lyear, lmonth): smail = 1 else: smail = 3 except: smail = 2 else: smail = 0 # #--- remove the temp file if it is still around # cmd = 'rm /tmp/zspace*hrc* 2> /dev/null' os.system(cmd) cmd = 'rm -rf ' + exc_dir + 'Temp_dir/* 2> /dev/null' os.system(cmd) # #--- sending mail # if smail == 1: message = 'hrc stowed proccess ran normally for the period: ' + str( lyear) + ' : ' + str(lmonth) + '\n' header = '"Subject: HRC Stowed Data Process Complated"' elif smail == 2: message = 'hrc stowed proccess ran into problems with the data for the period: ' + str( lyear) + ' : ' + str(lmonth) + '\n' header = '"Subject: HRC Stowed Data Process Failed"' elif smail == 3: message = 'hrc stowed proccess did not find any data for the period: ' + str( lyear) + ' : ' + str(lmonth) + '\n' header = '"Subject: HRC Stowed Data Process: No Data Found"' if smail > 0: send_email(message, header)