예제 #1
0
def apply_iit(db_session,
              inst_combo_query,
              lbcc_image,
              use_indices,
              los_image,
              R0=1.01):
    ###### GET VARIABLE VALUES #####
    meth_name = "IIT"
    method_id_info = db_funcs.get_method_id(db_session,
                                            meth_name,
                                            meth_desc=None,
                                            var_names=None,
                                            var_descs=None,
                                            create=False)

    alpha_x_parameters = db_funcs.query_var_val(
        db_session,
        meth_name,
        date_obs=lbcc_image.date_obs,
        inst_combo_query=inst_combo_query)
    alpha, x = alpha_x_parameters

    ##### APPLY IIT TRANSFORMATION ######
    lbcc_data = lbcc_image.lbcc_data
    corrected_iit_data = np.copy(lbcc_data)
    corrected_iit_data[use_indices] = 10**(
        alpha * np.log10(lbcc_data[use_indices]) + x)
    # create IIT datatype
    iit_image = psi_d_types.create_iit_image(los_image, lbcc_image,
                                             corrected_iit_data,
                                             method_id_info[0])
    psi_d_types.LosImage.get_coordinates(iit_image, R0=R0)

    return lbcc_image, iit_image, use_indices, alpha, x
예제 #2
0
파일: dp_funcs.py 프로젝트: predsci/CHD
def gauss_chd(db_session,
              inst_list,
              los_image,
              iit_image,
              use_indices,
              iit_combo_query,
              thresh1=0.95,
              thresh2=1.35,
              nc=3,
              iters=1000,
              sigma=0.15):
    start = time.time()
    # reference alpha, x for threshold
    sta_ind = inst_list.index('EUVI-A')
    ref_alpha, ref_x = db_funcs.query_var_val(
        db_session,
        meth_name='IIT',
        date_obs=los_image.info['date_string'],
        inst_combo_query=iit_combo_query[sta_ind])

    # define chd parameters
    image_data = iit_image.iit_data
    use_chd = use_indices.astype(int)
    use_chd = np.where(use_chd == 1, use_chd, los_image.no_data_val)
    nx = iit_image.x.size
    ny = iit_image.y.size
    # calculate new threshold parameters based off reference (AIA) instrument
    t1 = thresh1 * ref_alpha + ref_x
    t2 = thresh2 * ref_alpha + ref_x
    # use gaussian varying for threshold
    gauss1 = gauss_func(mu=t1,
                        sigma=sigma * t1,
                        bottom=t1 - t1 * sigma,
                        top=t1 + t1 * sigma)
    gauss2 = gauss_func(mu=t2,
                        sigma=sigma * t2,
                        bottom=t2 - t2 * sigma,
                        top=t2 + t2 * sigma)

    # full width half max
    FWHM = 2 * np.sqrt(2 * np.log(2)) * sigma

    # fortran chd algorithm
    np.seterr(divide='ignore')
    ezseg_output, iters_used = ezsegwrapper.ezseg(np.log10(image_data),
                                                  use_chd, nx, ny, gauss1,
                                                  gauss2, nc, iters)
    chd_result = np.logical_and(ezseg_output == 0, use_chd == 1)
    chd_result = chd_result.astype(int)

    # create CHD image
    chd_image = datatypes.create_chd_image(los_image, chd_result)
    chd_image.get_coordinates()

    end = time.time()
    print("Coronal Hole Detection Algorithm has been applied to image",
          iit_image.data_id, "in", end - start, "seconds.")

    return chd_image, FWHM
예제 #3
0
    # query theoretic parameters
    theoretic_query = np.zeros((len(moving_avg_centers), 6))
    theoretic_query2 = np.empty((len(moving_avg_centers), 6))
    theoretic_query2.fill(np.nan)
    # query correct image combos
    combo_query = query_inst_combo(db_session, query_time_min, query_time_max,
                                   meth_name, instrument)
    plot_beta = np.zeros((sample_mu.__len__(), moving_avg_centers.__len__()))
    plot_beta2 = np.zeros((sample_mu.__len__(), moving_avg_centers.__len__()))
    plot_y = np.zeros((sample_mu.__len__(), moving_avg_centers.__len__()))
    plot_y2 = np.zeros((sample_mu.__len__(), moving_avg_centers.__len__()))
    for date_index, center_date in enumerate(moving_avg_centers):
        # query for variable value
        temp_vals = query_var_val(db_session,
                                  meth_name,
                                  date_obs=np.datetime64(center_date).astype(
                                      datetime.datetime),
                                  inst_combo_query=combo_query)
        theoretic_query[date_index, :] = temp_vals
        if (np.isnan(temp_vals).all()
                or center_date < combo_query.date_mean.min()
                or center_date > combo_query.date_mean.max()):
            plot_beta[:, date_index] = np.nan
            plot_y[:, date_index] = np.nan
        else:
            for mu_index, mu in enumerate(sample_mu):
                plot_beta[mu_index, date_index], plot_y[
                    mu_index, date_index] = lbcc.get_beta_y_theoretic_based(
                        theoretic_query[date_index, :], mu)

    #### BETA AND Y AS FUNCTION OF TIME ####
예제 #4
0
# sample mu colors
v_cmap = cm.get_cmap('viridis')
n_mu = len(sample_mu)
color_dist = np.linspace(0., 1., n_mu)

linestyles = ['solid', 'dashed', 'dashdot', 'None']
marker_types = ['None', 'None', 'None', 'x']

for inst_index, instrument in enumerate(instruments):

    # get variable values for each image combination
    for date_ind, center_date in enumerate(moving_avg_centers):
        cubic_query = query_var_val(db_session,
                                    n_mu_bins,
                                    n_intensity_bins,
                                    lat_band,
                                    center_date,
                                    moving_width,
                                    meth_name="LBCC Cubic",
                                    instrument=instrument)
        power_log_query = query_var_val(db_session,
                                        n_mu_bins,
                                        n_intensity_bins,
                                        lat_band,
                                        center_date,
                                        moving_width,
                                        meth_name="LBCC Power-Log",
                                        instrument=instrument)
        theoretic_query = query_var_val(db_session,
                                        n_mu_bins,
                                        n_intensity_bins,
                                        lat_band,
예제 #5
0
def apply_ipp(db_session, center_date, query_pd, inst_list, hdf_data_dir, lbc_combo_query,
              iit_combo_query, methods_list, n_intensity_bins=200, R0=1.01):
    """
    function to apply image pre-processing (limb-brightening, inter-instrument transformation) corrections
    to EUV images for creation of maps
    @param db_session: database session from which to query correction variable values
    @param center_date: date for querying
    @param query_pd: pandas dataframe of euv_images
    @param inst_list: instrument list
    @param hdf_data_dir: directory of hdf5 files
    @param lbc_combo_query: list (of length number of instruments) of lbc image combo queries
    @param iit_combo_query: list (of length number of instruments) of iit image combo queries
    @param methods_list: methods dataframe
    @param n_intensity_bins: number of intensity bins
    @param R0: radius
    @return: image dataframe, list of los images, list of iit images, indices used for correction, methods list,
             ref alpha, ref x
    """
    start = time.time()
    # create image lists
    image_pd = [None] * len(inst_list)
    los_list = [None] * len(inst_list)
    iit_list = [None] * len(inst_list)
    use_indices = [(2048, 2048)] * len(inst_list)
    # convert date to correct format
    print("\nStarting corrections for", center_date, "images:")
    date_time = np.datetime64(center_date).astype(datetime.datetime)
    # alpha, x for threshold
    sta_ind = inst_list.index('EUVI-A')
    ref_alpha, ref_x = db_funcs.query_var_val(db_session, meth_name='IIT', date_obs=date_time,
                                              inst_combo_query=iit_combo_query[sta_ind])
    # create dataframe for date
    hist_date = query_pd['date_obs']
    date_pd = query_pd[
        (hist_date >= np.datetime64(date_time - datetime.timedelta(minutes=10))) &
        (hist_date <= np.datetime64(date_time + datetime.timedelta(minutes=10)))]
    if len(date_pd) == 0:
        print("No Images to Process for this date.")
    else:
        for inst_ind, instrument in enumerate(inst_list):
            # get image row
            image_pd[inst_ind] = date_pd[date_pd['instrument'] == instrument]
            inst_image = date_pd[date_pd['instrument'] == instrument]
            if len(inst_image) == 0:
                print("No", instrument, "image to process for this date.")
            else:
                image_row = inst_image.iloc[0]
                index = np.where(date_pd['instrument'] == instrument)[0][0]
                print("Processing image number", image_row.data_id, "for LBC and IIT Corrections.")
                # apply LBC
                los_list[inst_ind], lbcc_image, mu_indices, use_ind, theoretic_query = lbcc_funcs.apply_lbc(db_session,
                                                                                                            hdf_data_dir,
                                                                                                            lbc_combo_query[
                                                                                                                inst_ind],
                                                                                                            image_row=image_row,
                                                                                                            n_intensity_bins=n_intensity_bins,
                                                                                                            R0=R0)
                # generate a record of the method and variable values used for LBC
                #  lbc_method = {'meth_name': ("LBCC", "LBCC", "LBCC", "LBCC", "LBCC", "LBCC"), 'meth_description':
                #                 ["LBCC Theoretic Fit Method"] * 6, 'var_name': ("TheoVar0", "TheoVar1", "TheoVar2", "TheoVar3", "TheoVar4", "TheoVar5"),
                #                           'var_description': ("Theoretic fit parameter at index 0", "Theoretic fit parameter at index 1", "Theoretic fit parameter at index 2",
                #                                               "Theoretic fit parameter at index 3", "Theoretic fit parameter at index 4", "Theoretic fit parameter at index 5"),
                #                           'var_val': (theoretic_query[0], theoretic_query[1], theoretic_query[2], theoretic_query[3],
                #                                       theoretic_query[4], theoretic_query[5])}
                # apply IIT
                lbcc_image, iit_list[inst_ind], use_indices[inst_ind], alpha, x = iit_funcs.apply_iit(db_session,
                                                                                                      iit_combo_query[
                                                                                                          inst_ind],
                                                                                                      lbcc_image,
                                                                                                      use_ind,
                                                                                                      los_list[
                                                                                                          inst_ind],
                                                                                                      R0=R0)
                # iit_method = {'meth_name': ("IIT", "IIT"), 'meth_description': ["IIT Fit Method"] * 2, 'var_name': (
                # "alpha", "x"), 'var_description': ("IIT correction coefficient: alpha", "IIT correction coefficient:
                # x"), 'var_val': (alpha, x)}
                # add methods to dataframe
                ipp_method = {'meth_name': ("LBCC", "IIT"), 'meth_description': ["LBCC Theoretic Fit Method",
                                                                                 "IIT Fit Method"],
                              'var_name': ("LBCC", "IIT"), 'var_description': (" ", " ")}
                methods_list[index] = methods_list[index].append(pd.DataFrame(data=ipp_method), sort=False)
                # methods_list[inst_ind] = pd.DataFrame(data=ipp_method)
        end = time.time()
        print("Image Pre-Processing Corrections (Limb-Brightening and Inter-Instrument Transformation) have been "
              "applied "
              " in", end - start, "seconds.")

    return date_pd, los_list, iit_list, use_indices, methods_list, ref_alpha, ref_x
예제 #6
0
    ###### GET LOS IMAGES COORDINATES (DATA) #####
    # apply LBC
    for index in range(n_images_plot):
        row = image_pd.iloc[index]
        print("Processing image number", row.data_id, ".")
        if row.fname_hdf == "":
            print("Warning: Image # " + str(row.data_id) +
                  " does not have an associated hdf file. Skipping")
            continue
        hdf_path = os.path.join(hdf_data_dir, row.fname_hdf)
        original_los = psi_d_types.read_los_image(hdf_path)
        original_los.get_coordinates(R0=R0)
        theoretic_query = query_var_val(
            db_session,
            meth_name,
            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,