def stime_to_ddate2(stime): """ change data in second from 1998.1.1 to yyyymmdd format input: stime --- time in seconds from 1998.1.1 output: dtime --- date in the form of yyyymmdd (e.g. 20150819) """ tlist = tcnv.axTimeMTA(stime) atemp = re.split(':', tlist) year = int(float(atemp[0])) lyear = str(atemp[0]) ydate = int(float(atemp[1])) [mon, date] = tcnv.changeYdateToMonDate(year, ydate) smon = str(mon) if mon < 10: smon = '0' + smon sday = str(date) if date < 10: sday = '0' + sday dtime = lyear + smon + sday return dtime
def stime_to_ddate(stime): """ change data in second from 1998.1.1 to mm/dd/yy format input: stime --- time in seconds from 1998.1.1 output: dtime --- date in the form of mm/dd/yy (e.g. 08/19/15) """ tlist = tcnv.axTimeMTA(stime) atemp = re.split(':', tlist) year = int(float(atemp[0])) ydate = int(float(atemp[1])) [mon, date] = tcnv.changeYdateToMonDate(year, ydate) lyear = str(atemp[0]) syr = lyear[2] + lyear[3] smon = str(mon) if mon < 10: smon = '0' + smon sday = str(date) if date < 10: sday = '0' + sday dtime = smon + '/' + sday + '/' + syr return dtime
def start_stop_period(year, yday): """ convert year and yday to the mm/dd/yy, 00:00:00 format input: year --- year yday --- yday output: [start, stop] --- in the format of mm/dd/yy, 00:00:00 """ lyear = str(year) syear = lyear[2] + lyear[3] [mon, mday] = tcnv.changeYdateToMonDate(year, yday) smon = str(mon) if mon < 10: smon = '0' + smon sday = str(mday) if mday < 10: sday = '0' + sday start = smon + '/' + sday + '/' + syear stop = start start = start + ',00:00:00' stop = stop + ',23:59:59' return [start, stop]
def get_data_period(): """ set start and stop time of the data period input: none output: [start, stop] --- in format of mm/dd/yy """ # #--- find the last date of the data update # maxt = 0 for dname in ('I2cp.dat', 'I3cp.dat', 'S2cp.dat', 'S3cp.dat'): file = web_dir + dname f = open(file, 'r') data = [line.strip() for line in f.readlines()] f.close() atemp = re.split('\s+', data[-1]) val = float(atemp[0]) if val > maxt: maxt = int(val) atemp = tcnv.axTimeMTA(str(maxt)) ttemp = re.split(':', atemp) year = int(float(ttemp[0])) ydate = int(float(ttemp[1])) (month, mdate) = tcnv.changeYdateToMonDate(year, ydate) smon = str(month) if month < 10: smon = '0' + smon sday = str(mdate) if mdate < 10: sday = '0' + sday start = smon + '/' + sday + '/' + ttemp[0][2] + ttemp[0][3] # #--- find today's date; it will be the last date of the period # ctime = datetime.datetime.now() syear = str(ctime.year) month = ctime.month cmon = str(month) if month < 10: cmon = '0' + cmon date = ctime.day cday = str(date) if date < 10: cday = '0' + cday stop = cmon + '/' + cday + '/' + syear[2] + syear[3] return [start, stop]
def make_data_list(year, mon, day, tail): """ make a data list from the last entry date to the most current data input: year --- the year of the last entry mon --- the month of the last entry day --- the day of month of the last entry tail --- the suffix of the data file output dlist --- a list of data names """ # #--- convert the date into seconds from 1998.1.1 # dst = tcnv.convertDateToTime2(year, mon, day) # #--- find today's time # today = tcnv.currentTime() cyear = today[0] cmon = today[1] cday = today[2] cdst = tcnv.convertDateToTime2(cyear, cmon, cday) dlist = [] # #--- check the current date is larger than the date indicated #--- if so find how many days between and retrieve data for each day # if cdst > dst: step = int(( cdst - dst)/86400) if step >= 1: head = make_header(year, mon, day) name = head + tail dlist.append(name) for i in range(2, step): sdate = int(cdst - 86400.0 * i) out = tcnv.axTimeMTA(sdate) atemp = re.split(':', out) year = int(atemp[0]) ydate = int(atemp[1]) [mon, day] = tcnv.changeYdateToMonDate(year, ydate) head = make_header(year, mon, day) name = head + tail dlist.append(name) return dlist
def find_starting_date(): """ set starting and stopping time from the last entry of a fits file input: none but read from hvpsstat_data.fits output: start --- starting time <yyyy>-<mm>-<dd>T00:00:00 stop --- stoping time <yyyy>-<mm>-<dd>T23:59:59 """ test = dpath + 'hvpsstat_data.fits' ltime = ecf.find_the_last_entry_time(test) # #--- convert time from sec from 1998.1.1 to year and ydate # out = Chandra.Time.DateTime(ltime).date atemp = re.split(':', out) year = int(float(atemp[0])) yday = int(float(atemp[1])) yday += 1 # #--- check whether the date crosses the year end # if tcnv.isLeapYear(year) == 1: if yday > 366: yday = 1 year += 1 else: if yday > 365: yday = 1 year += 1 # #--- convert to month and mday # [mon, day] = tcnv.changeYdateToMonDate(year, yday) lmon = str(mon) if mon < 10: lmon = '0' + lmon lday = str(day) if day < 10: lday = '0' + lday start = str(year) + '-' + lmon + '-' + lday + 'T00:00:00' stop = str(year) + '-' + lmon + '-' + lday + 'T23:59:59' return [start, stop]
def create_display_data_table(): """ create a readable data table for html page Input: none, but read from <data_dir>/ccd<ccd>_<node> Output: <web_dir>/ccd<ccd>_<node> """ for ccd in range(0, 10): for node in range(0, 4): file = 'ccd' + str(ccd) + '_' + str(node) infile = data_dir + file outfile = web_dir + 'Data/' + file f = open(infile, 'r') data = [line.strip() for line in f.readlines()] f.close() fo = open(outfile, 'w') # #--- adding heading # line = "#\n#Date Mn K alpha Al K alpha Ti K alpha Slope Sigma Int Sigma\n#\n" fo.write(line) for ent in data: atemp = re.split('\s+', ent) stime = int(atemp[0]) # #--- converting the date into <mon> <year> form (e.g. May 2013) # ltime = tcnv.axTimeMTA(stime) btemp = re.split(':', ltime) year = btemp[0] [mon, mdate] = tcnv.changeYdateToMonDate(int(year), int(btemp[1])) lmon = tcnv.changeMonthFormat(mon) line = lmon + ' ' + year for j in range(1, len(atemp)): line = line + '\t' + atemp[j] line = line + '\n' fo.write(line) fo.close()
def plot_data(start, stop, mag_plot=1): """ create a configulation display panel for a give time period input: start --- starting time in sec from 1998.1.1 stop --- stopping time in sec from 1998.1.1 """ # #---- set a few parameters # if mag_plot == 0: pnum = 5 else: pnum = 6 mpl.rcParams['font.size'] = 11 mpl.rcParams['font.weight'] = 'strong' props = font_manager.FontProperties(size=6) plt.subplots_adjust(hspace=0.05) plt.subplots_adjust(wspace=0.12) # #--- set a few others # xpos = stime_to_ydate(stop) + 0.1 ystep = 0.2 # #--- read sim information # [acis_i_start, acis_i_stop, acis_s_start, \ acis_s_stop, hrc_i_start, hrc_i_stop, \ hrc_s_start, hrc_s_stop, hetg_start, \ hetg_stop, letg_start, letg_stop, \ radmon_start, radmon_stop, fmt, time] = erd.find_sim_position(start, stop) # #--- hetg /letg information plot # start_set = [hetg_start, letg_start] stop_set = [hetg_stop, letg_stop] ax1 = plt.subplot(pnum, 1, 1) plot_strip_box(ax1,start, stop, start_set, stop_set, color1) plt.text(xpos, 0.8, "HETG", color=color1[0]) plt.text(xpos, 0.6, "LETG", color=color1[1]) # #--- acis /hrc information plot # start_set = [acis_i_start, acis_s_start, hrc_i_start, hrc_s_start] stop_set = [acis_i_stop, acis_s_stop, hrc_i_stop, hrc_s_stop] ax2 = plt.subplot(pnum, 1, 2) plot_strip_box(ax2,start, stop, start_set, stop_set, color1) plt.text(xpos, 0.9, "ACIS I ", color=color1[0]) plt.text(xpos, 0.7, "ACIS S ", color=color1[1]) plt.text(xpos, 0.5, "HRC I ", color=color1[2]) plt.text(xpos, 0.3, "HRC S ", color=color1[3]) # #--- cti information plot # [cti_start, cti_stop] = erd.read_ccd_data(start, stop) start_set = [cti_start] stop_set = [cti_stop] ax3 = plt.subplot(pnum, 1, 3) plot_strip_box(ax3, start, stop, start_set, stop_set, color1) # #--- altitude information plot # [atime, alt, magx, magy, magz, crm] = erd.read_orbit_data(start, stop) plot_line(ax3, start, stop, atime, alt) plt.text(xpos, 0.8, "CTI ", color=color1[0]) plt.text(xpos, 0.7, "Check ", color=color1[0]) plt.text(xpos, 0.4, "Altitude ", color="green") # #--- radmon information plot # start_set = [radmon_start] stop_set = [radmon_stop] ax4 = plt.subplot(pnum, 1, 4) plot_strip_box(ax4, start, stop, start_set, stop_set, color1) # #--- hrc sheild rate plot # [htime, rate] = erd.read_hrc_data(start, stop) plot_line(ax4, start, stop, htime, rate) # #--- goes p3 rate plot # # [gtime, p1, p2, p3] = erd.read_goes_data(start, stop) # plot_points(ax4, start, stop, gtime, p3, color='lime', pts=0.5,lw=0) plt.text(xpos, 0.8, "Radmon", color=color1[0]) plt.text(xpos, 0.6, "HRC", color="green") plt.text(xpos, 0.5, "Shield", color="green") plt.text(xpos, 0.4, "Rate", color="green") # plt.text(xpos, 0.2, "GOES P3", color="green") # #--- magnetsphere plot # if mag_plot != 0: [start_set, stop_set] = find_mag_region(start, stop) axm = plt.subplot(6, 1, 5) plot_strip_box(axm, start, stop, start_set, stop_set, color1) # plt.text(xpos, 0.9, "Solar", color=color1[0]) # plt.text(xpos, 0.8, "Wind", color=color1[0]) plt.text(xpos, 0.6, "Magneto-", color=color1[1]) plt.text(xpos, 0.5, "sheath", color=color1[1]) plt.text(xpos, 0.3, "Magneto-", color=color1[2]) plt.text(xpos, 0.2, "sphere", color=color1[2]) # #--- often the data are not available; so make a note on the plot # # diff1 = stop - start # tlast = time[len(time)-1] # diff2 = tlast - start # ratio = diff2 / diff1 # if ratio < 0.7: # xnote = 0.5 * (stop - tlast) # plt.text(xnote, 0.5, "No Data", color='maroon') # #--- FMT format information plot # [start_set, stop_set] = find_fmt_region(start, stop, fmt, time) ax5 = plt.subplot(pnum, 1, pnum) plot_strip_box(ax5, start, stop, start_set, stop_set,color4) plt.text(xpos, 0.9, "FMT1", color=color4[0]) plt.text(xpos, 0.7, "FMT2", color=color4[1]) plt.text(xpos, 0.5, "FMT3", color=color4[2]) plt.text(xpos, 0.3, "FMT4", color=color4[3]) plt.text(xpos, 0.1, "FMT5", color=color4[4]) # #--- plot x axis tick label only at the bottom ones # if mag_plot == 0: ax_list = [ax1, ax2, ax3, ax4, ax5] else: ax_list = [ax1, ax2, ax3, ax4, ax5, axm] for ax in ax_list: for label in ax.get_yticklabels(): label.set_visible(False) if ax != ax5: for label in ax.get_xticklabels(): label.set_visible(False) else: pass # #--- x axis label # mid = int(0.5 * (start + stop)) ltime = tcnv.axTimeMTA(mid) atemp = re.split(':', ltime) year = int(atemp[0]) ydate = int(atemp[1]) [mon, day] = tcnv.changeYdateToMonDate(year,ydate) xlabel = "Time (DOY) " + str(atemp[0]) ax5.set_xlabel(xlabel) # #--- set the size of the plotting area in inch (width: 10.0in, height 5.0in) # fig = matplotlib.pyplot.gcf() fig.set_size_inches(12.0, 10.0) # #--- save the plot in png format # syear = str(year) smon = tcnv.changeMonthFormat(mon) smon = smon.lower() outname = 'rad_use_' + smon + syear[2] + syear[3] + '.png' plt.savefig(outname, format='png', dpi=100) plt.close('all')
def run_script(): for year in range(1999,2015): leap = tcnv.isLeapYear(year) if leap == 1: dend = 367 else: dend = 366 syear = str(year) lyear = syear[2] + syear[3] for yday in range(1,dend): if year == 1999 and yday < 239: continue if year == 2014 and yday > 316: break print "Year: " + str(year) + ' Ydate: ' + str(yday) [month, date] =tcnv.changeYdateToMonDate(year, yday) smonth = str(month) if month < 10: smonth = '0' + smonth sdate = str(date) if date < 10: sdate = '0' + sdate start = smonth + '/' + sdate + '/' + lyear + ',00:00:00' stop = smonth + '/' + sdate + '/' + lyear + ',23:59:59' line = 'operation = retrieve\n' line = line + 'dataset = flight\n' line = line + 'detector = telem\n' line = line + 'level = raw\n' line = line + 'tstart = ' + start + '\n' line = line + 'tstop = ' + stop + '\n' line = line + 'go\n' fo = open(zspace, 'w') fo.write(line) fo.close() cmd1 = "/usr/bin/env PERL5LIB=" cmd2 = ' echo ' + hakama + ' |arc4gl -U' + dare + ' -Sarcocc -i' + zspace cmd = cmd1 + cmd2 bash(cmd, env=ascdsenv0) mcf.rm_file(zspace) cmd = 'ls * > ' + zspace os.system(cmd) test = open(zspace, 'r').read() mc = re.search('sto', test) if mc is not None: os.system('rm *log*') os.system('gzip -fd *gz') os.system('ls *.sto > xtmpnew') os.system('nice ./filters_ccdm') esd.extract_sim_data() os.system('rm -rf *.sto *.tl')
def run_script(): for year in range(1999, 2015): leap = tcnv.isLeapYear(year) if leap == 1: dend = 367 else: dend = 366 syear = str(year) lyear = syear[2] + syear[3] for yday in range(1, dend): if year == 1999 and yday < 239: continue if year == 2014 and yday > 316: break print "Year: " + str(year) + ' Ydate: ' + str(yday) [month, date] = tcnv.changeYdateToMonDate(year, yday) smonth = str(month) if month < 10: smonth = '0' + smonth sdate = str(date) if date < 10: sdate = '0' + sdate start = smonth + '/' + sdate + '/' + lyear + ',00:00:00' stop = smonth + '/' + sdate + '/' + lyear + ',23:59:59' line = 'operation = retrieve\n' line = line + 'dataset = flight\n' line = line + 'detector = telem\n' line = line + 'level = raw\n' line = line + 'tstart = ' + start + '\n' line = line + 'tstop = ' + stop + '\n' line = line + 'go\n' fo = open(zspace, 'w') fo.write(line) fo.close() cmd1 = "/usr/bin/env PERL5LIB=" cmd2 = ' echo ' + hakama + ' |arc4gl -U' + dare + ' -Sarcocc -i' + zspace cmd = cmd1 + cmd2 bash(cmd, env=ascdsenv0) mcf.rm_file(zspace) cmd = 'ls * > ' + zspace os.system(cmd) test = open(zspace, 'r').read() mc = re.search('sto', test) if mc is not None: os.system('rm *log*') os.system('gzip -fd *gz') os.system('ls *.sto > xtmpnew') os.system('nice ./filters_ccdm') esd.extract_sim_data() os.system('rm -rf *.sto *.tl')