def plot_data(fnames, column, savefig=None): if niutils.check_iter(fnames): df = merge_tables(fnames) tab_for_format = fnames[0] ntab = len(fnames) else: df = read_table(fnames) tab_for_format = fname ntab = 1 if column is None: raise ValueError("Column can not be None") df = add_datetime_col(df) fig, ax = plt.subplots(1, 1, figsize=(12*ntab, 6)) ax = niutils.plotparams(ax) if not niutils.check_iter(column): column = [column] mask = [ np.where(df[column[i]] != -9999.9)[0] for i in range(len(column)) ] colors = niutils.get_colors()['br_colors'] colors = [colors[0], colors[2]] ax.plot(df['datetime'][mask[0]], df[column[0]][mask[0]], color=colors[0], label=column[0]) ax.set_xlabel("Date", fontsize=20) ax.set_ylabel(format_ace_column(column[0], table=tab_for_format), fontsize=20) if len(column) > 1: ax, ax1 = niutils.DoubleY(ax, colors=(colors[0], colors[1])) ax1.plot(df['datetime'][mask[1]], df[column[1]][mask[1]], color=colors[1], label=column[1]) ax1.set_ylabel(format_ace_column(column[1], table=tab_for_format), fontsize=20) if max(df['day']) > 180: ax.xaxis.set_minor_locator(MonthLocator()) else: ax.xaxis.set_major_locator(MonthLocator()) ax.xaxis.set_minor_locator(MonthLocator(bymonthday=15)) myfmt = DateFormatter('%Y-%m') ax.xaxis.set_major_formatter(myfmt) if savefig is None: plt.show() else: fig.savefig(savefig)
def plot_data_split(fnames, column, savefig=None): if niutils.check_iter(fnames): df_list = [read_table(f) for f in fnames] else: raise ValueError("Must input multiple filenames") if column is None: raise ValueError("Column can not be None") df_list = [add_datetime_col(df) for df in df_list] fig, ax = plt.subplots(len(df_list), 1, figsize=(12, 5.2*len(df_list))) plt.subplots_adjust(top=.98, bottom=.07) for a in ax: a = niutils.plotparams(a) if not niutils.check_iter(column): column = [column] colors = niutils.get_colors()['br_colors'] colors = [colors[0], colors[2]] for i in range(len(df_list)): df = df_list[i] mask = [ np.where(df[column[i]] != -9999.9)[0] for i in range(len(column)) ] ax[i].plot(df['datetime'][mask[0]], df[column[0]][mask[0]], color=colors[0], label=column[0]) ax[i].set_xlabel("Date", fontsize=20) ax[i].set_ylabel(format_ace_column(column[0], table=fnames[0]), fontsize=20) if len(column) > 1: ax[i], ax1 = niutils.DoubleY(ax[i], colors=(colors[0], colors[1])) ax1.plot(df['datetime'][mask[1]], df[column[1]][mask[1]], color=colors[1], label=column[1]) ax1.set_ylabel(format_ace_column(column[1], table=fnames[0]), fontsize=20) if max(df['day']) > 180: ax[i].xaxis.set_minor_locator(MonthLocator()) else: ax[i].xaxis.set_major_locator(MonthLocator()) ax[i].xaxis.set_minor_locator(MonthLocator(bymonthday=15)) myfmt = DateFormatter('%Y-%m') ax[i].xaxis.set_major_formatter(myfmt) if savefig is None: plt.show() else: fig.savefig(savefig)
def main(mail_file, jobs_to_check): if not niutils.check_iter(jobs_to_check): jobs_to_check = [jobs_to_check] #Get all cron log output job_groups = np.array(read_log(mail_file)) job_names = np.array([identify_job(g) for g in job_groups]) idx_to_check = [] #For each job we're interested in for job in jobs_to_check: #Find which cron lines match idx = [i for i in range(len(job_names)) if job in job_names[i]] if len(idx) == 0: log.warning("No cron jobs found matching {0}".format(job)) #only want to do error search on most recent idx_to_check.append(idx[-1]) bad_lines = [check_errors(job_groups[i]) for i in idx_to_check] for i, j in zip(idx_to_check, jobs_to_check): log.info("Errors/Warnings for {}".format(j)) bad_lines = check_errors(job_groups[i]) for l in bad_lines: print(l.strip('\n'))
def get_exposure(sources, user, passwd): df = print_nicer_segment(username=user, password=passwd) if not niutils.check_iter(sources): sources = [sources] else: pass exp_list = [] n_obsIDs = [] for s in sources: df_selection = df[df['Target Name'] == s] n_obsIDs.append(len(df_selection)) exp_list.append(np.sum(df_selection['Good Expo[s]'])) return exp_list, n_obsIDs
def check_split(evt, fnames): if not os.path.isfile(evt): raise FileNotFoundError("Event file not found") if not niutils.check_iter(fnames): raise TypeError("fnames must be iterable") for f in fnames: if not os.path.isfile(f): raise FileNotFoundError("{0} not found".format(f)) full_tab = Table.read(evt, hdu=1) total_length = len(full_tab) summed = 0 for split_evt in fnames: tab = Table.read(split_evt, hdu=1) summed += len(tab) return summed == total_length
def run_datadownload(sourcename, heasarc_user, heasarc_pwd, outdir, decryptkey, clobber=False, obsIDs=None, silent_curl=False): if outdir == "./": if not os.getcwd().endswith(sourcename): if not outdircheck(sourcename): return 0 else: if not (outdir.endswith(sourcename or sourcename + "/")): if not outdircheck(soucename): return 0 cmd = [ 'custom_data_download.py', sourcename, heasarc_user, heasarc_pwd, '--outdir', outdir, '--decryptkey', decryptkey, '--unzip' ] if clobber: cmd.append('--clobber') if obsIDs is not None: if not niutils.check_iter(obsIDs): obsIDs = [obsIDs] cmd.append('--obsIDs') cmd.extend(obsIDs) if silent_curl: cmd.append("--silent_curl") subprocess.call(cmd)