Example #1
0
def setupEnv():
    global MODELS_VALUES
    global MODELS_DICT
    """
    Setup the necessary variables to speed up the genetic algorithm execution
    Reading all models

    :return:
    """
    for index, model_name in enumerate(os.listdir(config.MODELS_DATA_PATH)):
        if config.VERBOSE:
            print(f'[!] reading model {model_name}')
        file_path = os.path.join(config.MODELS_DATA_PATH, model_name)
        data_label_base, temp, lon, lat, lev = utils.read_data(file_path)
        temp, lon, lat, ilat, ilon = utils.get_zone_obs(temp,
                                                        lon,
                                                        lat,
                                                        size_reduction=CASE,
                                                        frlon=frlon,
                                                        tolon=tolon,
                                                        frlat=frlat,
                                                        tolat=tolat)

        MODELS_DICT[data_label_base] = index
        MODELS_VALUES.append(temp)

    MODELS_VALUES = np.array(MODELS_VALUES)
    if config.VERBOSE:
        print('\n [!] Genetic environment correctly configured.')
    # read the trained model file
    if CASE.upper() == 'ALL':
        obsSOM, true_labels = utils.loadSOM(
            save_dir=config.OUTPUT_TRAINED_MODELS_PATH,
            file_name=config.ZALL_SOM_3D_MODEL_NAME)
    elif CASE.upper() == 'SEL':
        obsSOM, true_labels = utils.loadSOM(
            save_dir=config.OUTPUT_TRAINED_MODELS_PATH,
            file_name=config.ZSEL_SOM_3D_MODEL_NAME)

    file_path = os.path.join(config.MODELS_DATA_PATH, MODEL_NAME)
    data_label_base, temp, lon, lat, lev = utils.read_data(file_path)
    temp, lon, lat, ilat, ilon = utils.get_zone_obs(temp,
                                                    lon,
                                                    lat,
                                                    size_reduction=CASE,
                                                    frlon=frlon,
                                                    tolon=tolon,
                                                    frlat=frlat,
                                                    tolat=tolat)

    agg_data = utils.aggregate_data(temp, case=CASE)

    all_model_data = agg_data.reshape(
        12, -1, order='A').T  # shape = 9900 (11*25*36), 12

    model_data = pd.DataFrame.from_records(all_model_data).dropna(axis=0)

    ocean_points_index = model_data.index.values  # ocean points index
    model_data = model_data.values  # train data

    model_labels = np.zeros(shape=(len(all_model_data)), dtype=int)