def get_zscore_features(df_all, feature_names, out_file, REMOVE_OUTLIER=0,
                        zscore_threshold=ZSCORE_OUTLIER_THRESHOLD):  # if remove_outlier ==0 , just clip at threshold
    featureArray = df_all[feature_names].astype(float)
    featureArray.fillna(0,inplace=True)  ### might introduce some bias

    normalized = zscore(featureArray)
    # normalized = featureArray
    # normalized[~np.isnan(featureArray)] = zscore(featureArray[~np.isnan(featureArray)])

    num_outliers = np.count_nonzero(normalized < -zscore_threshold) + np.count_nonzero(
        normalized > zscore_threshold)
    print("Found %d  |z score| > %f in zscore matrix :" % (num_outliers, zscore_threshold) )

    df_all_modified = df_all
    df_outliers = pd.DataFrame()
    if num_outliers > 0:
        if not REMOVE_OUTLIER:  # just clip
            normalized[normalized < -zscore_threshold] = -zscore_threshold
            normalized[normalized > zscore_threshold] = zscore_threshold
        # else:
        #     outliers_l = np.nonzero(normalized < -zscore_threshold)
        #     outliers_h = np.nonzero(normalized > zscore_threshold)
        #     outlier_index = np.unique((np.append(outliers_l[0], outliers_h[0])))
        #
        #     # remove outlier rows
        #     df_all_modified = df_all_modified.drop(df_all_modified.index[outlier_index])
        #     normalized = np.delete(normalized, outlier_index, 0)
        #
        #     # re-zscoring and clipping
        #     # m_featureArray = df_all_modified[feature_names].astype(float)
        #     # normalized = zscore(m_featureArray)
        #     # normalized[normalized < -zscore_threshold] = -zscore_threshold
        #     # normalized[normalized > zscore_threshold] = zscore_threshold
        #
        #
        #     print("Removed %d outlier neurons" % len(outlier_index))
        #
        #     df_outliers = df_all.iloc[outlier_index]

    df_z = pd.DataFrame(normalized)
    df_z.columns = feature_names
    df_z.index = df_all['swc_file_name']

    if out_file:
        df_z.to_csv(out_file, index=True)
        print("save to " + out_file )

    if (df_z.shape[0] != df_all_modified.shape[0]):
        print ("error:  the sample size of the zscore and the original table does not match!")

    return df_z, df_all_modified, df_outliers