예제 #1
0
# Establish connection to database
db_session = db_funcs.init_db_conn(db_type,
                                   db_class.Base,
                                   db_loc,
                                   db_name=mysql_db_name,
                                   user=user,
                                   password=password,
                                   cred_dir=cred_dir)

# SAMPLE QUERY
# use database session to query available pre-processed images
query_time_min = datetime.datetime(2011, 2, 1, 0, 0, 0)
query_time_max = datetime.datetime(2011, 2, 1, 12, 0, 0)

image_pd = db_funcs.query_euv_images(db_session,
                                     time_min=query_time_min,
                                     time_max=query_time_max)

# view a snapshot of the results
image_pd.loc[:, ['date_obs', 'instrument', 'fname_hdf']]

# open the first image
image_path = os.path.join(hdf_data_dir, image_pd.fname_hdf[0])
psi_image = psi_dtypes.read_los_image(image_path)

# plot deconvolved image
psi_plots.PlotImage(psi_image)

# CLOSE CONNECTION
db_session.close()
예제 #2
0
            date_obs=original_los.info['date_string'],
            inst_combo_query=combo_query)

        ###### DETERMINE LBC CORRECTION (for valid mu values) ######
        beta1d, y1d, mu_indices, use_indices = lbcc.get_beta_y_theoretic_continuous_1d_indices(
            theoretic_query, los_image=original_los)

        ###### APPLY LBC CORRECTION (log10 space) ######
        corrected_lbc_data = np.copy(original_los.data)
        corrected_lbc_data[use_indices] = 10**(
            beta1d * np.log10(original_los.data[use_indices]) + y1d)

        ##### PLOTTING ######
        if plot:
            Plotting.PlotImage(original_los,
                               nfig=100 + inst_index * 10 + index,
                               title="Original LOS Image for " + instrument)
            Plotting.PlotCorrectedImage(corrected_data=corrected_lbc_data,
                                        los_image=original_los,
                                        nfig=200 + inst_index * 10 + index,
                                        title="Corrected LBCC Image for " +
                                        instrument)
            Plotting.PlotCorrectedImage(
                corrected_data=original_los.data - corrected_lbc_data,
                los_image=original_los,
                nfig=300 + inst_index * 10 + index,
                title="Difference Plot for " + instrument)
# end time
end_time_tot = time.time()
print("LBC has been applied and specified images plotted.")
print("Total elapsed time to apply correction and plot: " +
예제 #3
0
map_nycoord = sum(abs(test_los.y) < R0)
del_y = (y_range[1] - y_range[0]) / (map_nycoord - 1)
map_nxcoord = (np.floor((x_range[1] - x_range[0]) / del_y) + 1).astype(int)

# generate map x,y grids. y grid centered on equator, x referenced from lon=0
map_y = np.linspace(y_range[0], y_range[1], map_nycoord.astype(int))
map_x = np.linspace(x_range[0], x_range[1], map_nxcoord.astype(int))

# test LosImage function interp_to_map()
test_map = test_los.interp_to_map(R0=R0,
                                  map_x=map_x,
                                  map_y=map_y,
                                  image_num=selected_image.data_id)

# compare test image to test map
EasyPlot.PlotImage(test_los, nfig=9)
EasyPlot.PlotMap(test_map, nfig=10)

# # determine number of pixels in map y-grid
# map_nycoord = sum(abs(test_los.y) < R0)
# del_y = (y_range[1] - y_range[0])/(map_nycoord-1)
# map_nxcoord = (np.floor((x_range[1] - x_range[0])/del_y) + 1).astype(int)
#
# # generate map x,y grids
# map_y = np.linspace(y_range[0], y_range[1], map_nycoord.astype(int))
# map_x = np.linspace(x_range[0], x_range[1], map_nxcoord.astype(int))
#
# # initialize grid to receive interpolation with values of -1
# interp_result = np.full((map_nycoord, map_nxcoord), np.nan)
#
# # generate as row and column vectors
예제 #4
0
        query_pd = pd.read_sql(
            db_session.query(db_class.EUV_Images, db_class.Data_Files).filter(
                db_class.EUV_Images.data_id.in_(bad_image_lists[inst_index]),
                db_class.Data_Files.data_id ==
                db_class.EUV_Images.data_id).order_by(
                    db_class.EUV_Images.date_obs).statement, db_session.bind)
        # remove duplicate columns
        query_pd = query_pd.loc[:, ~query_pd.columns.duplicated()]

        n_images = bad_image_lists[inst_index].__len__()
        for im_num, row in query_pd.iterrows():
            full_path = os.path.join(hdf_data_dir, row.fname_hdf)
            print("Plotting", instrument, im_num + 1, "of", n_images, "-",
                  row.date_obs)
            bad_im = psi_d_types.read_los_image(full_path)
            EasyPlot.PlotImage(bad_im, nfig=0)
            plt.waitforbuttonpress()
            plt.close(0)

# loop through flag_bad and change flag in database
for inst_index, instrument in enumerate(inst_list):
    # query images
    query_pd = pd.read_sql(
        db_session.query(db_class.EUV_Images, db_class.Data_Files).filter(
            db_class.EUV_Images.data_id.in_(bad_image_lists[inst_index]),
            db_class.Data_Files.data_id ==
            db_class.EUV_Images.data_id).order_by(
                db_class.EUV_Images.date_obs).statement, db_session.bind)
    # remove duplicate columns
    query_pd = query_pd.loc[:, ~query_pd.columns.duplicated()]
    for index, row in query_pd.iterrows():
예제 #5
0
defs_columns = []
for column in db_class.Var_Defs.__table__.columns:
    defs_columns.append(column.key)
df_cols = set().union(meth_columns, defs_columns, ("var_val", ))
methods_template = pd.DataFrame(data=None, columns=df_cols)
# generate a list of methods dataframes
methods_list = [methods_template] * query_pd.__len__()

# read hdf file(s) to a list of LOS objects
los_list = [None] * query_pd.__len__()
image_plot_list = [None] * query_pd.__len__()
for index, row in query_pd.iterrows():
    hdf_path = os.path.join(hdf_data_dir, row.fname_hdf)
    los_list[index] = psi_d_types.read_los_image(hdf_path)
    EasyPlot.PlotImage(los_list[index],
                       nfig=index,
                       title="Image " + str(index))

# --- 2. Limb-brightening correction ------------------------------------------

for ii in range(len(los_list)):
    # call function to de-limb los_list[ii]
    # los_list[ii] = limb_correct(los_list[ii])
    # generate a record of the method and variable values used for LBC
    new_method = {
        'meth_name': ("lbcc_v1", "lbcc_v1"),
        'meth_description': [
            "Limb Brightening Correction from "
            "linear-log space model. Version 1"
        ] * 2,
        'var_name': ("Beta", "y"),