(train_sites, settings)
return features
Load the labelled data from the different training sites

    KV WRL 2019

    Arguments:
    -----------
    train_sites: list of str
        sites to be loaded
    settings: dict with the following keys
        'labels': dict
            list of label names (key) and label numbers (value) for each class
        'filepath_train': str
            directory in which to save the labelled data
                
    Returns:
    -----------
    features: dict
        contains the features for each labelled pixel
Load the labelled data from the different training sites
Load the labelled data from the different training sites
def load_labels(train_sites, settings):
    """
    Load the labelled data from the different training sites

    KV WRL 2019

    Arguments:
    -----------
    train_sites: list of str
        sites to be loaded
    settings: dict with the following keys
        'labels': dict
            list of label names (key) and label numbers (value) for each class
        'filepath_train': str
            directory in which to save the labelled data
                
    Returns:
    -----------
    features: dict
        contains the features for each labelled pixel
    
    """    
    
    filepath_train = settings['filepath_train']
    # initialize the features dict
    features = dict([])
    n_features = 20
    first_row = np.nan*np.ones((1,n_features))
    for key in settings['labels'].keys():
        features[key] = first_row
    # loop through each site 
    for site in train_sites:
        sitename = site[:site.find('.')] 
        filepath = os.path.join(filepath_train,sitename)
        if os.path.exists(filepath):
            list_files = os.listdir(filepath)
        else:
            continue
        # make a new list with only the .pkl files (no .jpg)
        list_files_pkl = []
        for file in list_files:
            if '.pkl' in file:
                list_files_pkl.append(file)
        # load and append the training data to the features dict
        for file in list_files_pkl:
            # read file
            with open(os.path.join(filepath, file), 'rb') as f:
                labelled_data = pickle.load(f) 
            for key in labelled_data['features'].keys():
                if len(labelled_data['features'][key])>0: # check that is not empty
                    # append rows
                    features[key] = np.append(features[key],
                                labelled_data['features'][key], axis=0)  
    # remove the first row (initialized with nans) and print how many pixels
    print('Number of pixels per class in training data:')
    for key in features.keys(): 
        features[key] = features[key][1:,:]
        print('%s : %d pixels'%(key,len(features[key])))
    
    return features
def load_labels ( train_sites , settings ) : filepath_train = settings [ 'filepath_train' ] # initialize the features dict features = dict ( [ ] ) n_features = 20 first_row = np . nan * np . ones ( ( 1 , n_features ) ) for key in settings [ 'labels' ] . keys ( ) : features [ key ] = first_row # loop through each site  for site in train_sites : sitename = site [ : site . find ( '.' ) ] filepath = os . path . join ( filepath_train , sitename ) if os . path . exists ( filepath ) : list_files = os . listdir ( filepath ) else : continue # make a new list with only the .pkl files (no .jpg) list_files_pkl = [ ] for file in list_files : if '.pkl' in file : list_files_pkl . append ( file ) # load and append the training data to the features dict for file in list_files_pkl : # read file with open ( os . path . join ( filepath , file ) , 'rb' ) as f : labelled_data = pickle . load ( f ) for key in labelled_data [ 'features' ] . keys ( ) : if len ( labelled_data [ 'features' ] [ key ] ) > 0 : # check that is not empty # append rows features [ key ] = np . append ( features [ key ] , labelled_data [ 'features' ] [ key ] , axis = 0 ) # remove the first row (initialized with nans) and print how many pixels print ( 'Number of pixels per class in training data:' ) for key in features . keys ( ) : features [ key ] = features [ key ] [ 1 : , : ] print ( '%s : %d pixels' % ( key , len ( features [ key ] ) ) ) return features