Extract computed impedance data from `FeedbackResults` instance into
    `pandas.DataFrame`.
340675
def feedback_results_to_impedance_frame(feedback_result):
    '''
    
    '''
    index = pd.Index(feedback_result.time * 1e-3, name='seconds')
    df_feedback = pd.DataFrame(np.column_stack([feedback_result.V_actuation()
                                                .filled(np.NaN),
                                                feedback_result.capacitance()
                                                .filled(np.NaN),
                                                feedback_result.Z_device()
                                                .filled(np.NaN)]),
                               columns=['V_actuation', 'capacitance',
                                        'impedance'],
                               index=index)
    df_feedback.insert(0, 'frequency', feedback_result.frequency)
    df_feedback.insert(1, 'voltage', feedback_result.voltage)
    return df_feedback
651907
def to_dict(self):
        
        final_res = {
            "param": self._param,
            "unused_param": self.unused_param,
            "execution_time": self._exec_time,
            "output": {"accuracy": self.get_accuracy(),
                       "weights": self.get_weights(),
                       "splines": self._splines
                       }
        }
        return final_res
610137
def to_dataframe(self):
    

    data = []
    for target_index, target_row in enumerate(self._cm):
      for predicted_index, count in enumerate(target_row):
        data.append((self._labels[target_index], self._labels[predicted_index], count))

    return pd.DataFrame(data, columns=['target', 'predicted', 'count'])
453551
def to_pandas(self):
        """"""
        agedepthdf = pd.DataFrame(self.age, index=self.data.depth)
        agedepthdf.columns = list(range(self.n_members()))
        out = (agedepthdf.join(self.data.set_index('depth'))
               .reset_index()
               .melt(id_vars=self.data.columns.values, var_name='mciter', value_name='age'))
        out['mciter'] = pd.to_numeric(out.loc[:, 'mciter'])
        if self.n_members() == 1:
            out = out.drop('mciter', axis=1)
        return out
331984
def results(self):
        """"""

        # Add all saved samples (and ancillary quantities) to the results.
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            results = [('niter', self.it - 1),
                       ('ncall', np.array(self.saved_nc)),
                       ('eff', self.eff),
                       ('samples', np.array(self.saved_v)),
                       ('samples_id', np.array(self.saved_id)),
                       ('samples_batch', np.array(self.saved_batch,
                                                  dtype='int')),
                       ('samples_it', np.array(self.saved_it)),
                       ('samples_u', np.array(self.saved_u)),
                       ('samples_n', np.array(self.saved_n)),
                       ('logwt', np.array(self.saved_logwt)),
                       ('logl', np.array(self.saved_logl)),
                       ('logvol', np.array(self.saved_logvol)),
                       ('logz', np.array(self.saved_logz)),
                       ('logzerr', np.sqrt(np.array(self.saved_logzvar))),
                       ('information', np.array(self.saved_h)),
                       ('batch_nlive', np.array(self.saved_batch_nlive,
                                                dtype='int')),
                       ('batch_bounds', np.array(self.saved_batch_bounds))]

        # Add any saved bounds (and ancillary quantities) to the results.
        if self.sampler.save_bounds:
            results.append(('bound', copy.deepcopy(self.bound)))
            results.append(('bound_iter',
                            np.array(self.saved_bounditer, dtype='int')))
            results.append(('samples_bound',
                            np.array(self.saved_boundidx, dtype='int')))
            results.append(('scale', np.array(self.saved_scale)))

        return Results(results)
822266
def validate_table(the_con, dtype, verbose=False, output_dir="."):
    
    print("-I- Validating {}".format(dtype))
    # grab dataframe
    current_df = the_con.tables[dtype].df
    # grab data model
    current_dm = the_con.tables[dtype].data_model.dm[dtype]
    # run all validations (will add columns to current_df)
    current_df = validate_df(current_df, current_dm, the_con)
    # get names of the added columns
    value_col_names, present_col_names, type_col_names, missing_groups, validation_col_names = get_validation_col_names(current_df)
    # print out failure messages
    ofile = os.path.join(output_dir, "{}_errors.txt".format(dtype))
    failing_items = get_row_failures(current_df, value_col_names,
                                     type_col_names, verbose, outfile=ofile)
    bad_rows, bad_cols, missing_cols = get_bad_rows_and_cols(current_df, validation_col_names,
                                                             value_col_names, type_col_names,
                                                             verbose=True)
    # delete all validation rows
    current_df.drop(validation_col_names, axis=1, inplace=True)
    current_df.drop(missing_groups, axis=1, inplace=True)
    if len(failing_items):
        print("-I- Complete list of row errors can be found in {}".format(ofile))
        return dtype, bad_rows, bad_cols, missing_cols, missing_groups, failing_items
    elif len(missing_cols) or len(missing_groups):
        print("-I- You are missing some required headers")
        if len(missing_cols):
            print("-I- You are missing these required headers: {}".format(", ".join(missing_cols)))
        if len(missing_groups):
            formatted_groups = [group[11:] for group in missing_groups]
            print('-I- You need at least one header from these groups: {}'.format(", ".join(formatted_groups)))
        else:
            formatted_groups = []
        return dtype, bad_rows, bad_cols, missing_cols, formatted_groups, failing_items
    else:
        print("-I- No row errors found!")
        return False
1241673
def get_bad_rows_and_cols(df, validation_names, type_col_names,
                          value_col_names, verbose=False):
    
    df["num"] = list(range(len(df)))
    problems = df[validation_names.union(["num"])]
    all_problems = problems.dropna(how='all', axis=0, subset=validation_names)
    value_problems = problems.dropna(how='all', axis=0, subset=type_col_names.union(value_col_names))
    all_problems = all_problems.dropna(how='all', axis=1)
    value_problems = value_problems.dropna(how='all', axis=1)
    if not len(problems):
        return None, None, None
    #
    bad_cols = all_problems.columns
    prefixes = ["value_pass_", "type_pass_"]
    missing_prefix = "presence_pass_"
    problem_cols = []
    missing_cols = []
    long_missing_cols = []
    problem_rows = []
    for col in bad_cols:
        pre, stripped_col = extract_col_name(col)
        for prefix in prefixes:
            if col.startswith(prefix):
                problem_cols.append(stripped_col)
                continue
        if col.startswith(missing_prefix):
            missing_cols.append(stripped_col)
            long_missing_cols.append(col)
    if len(value_problems):
        bad_rows = list(zip(list(value_problems["num"]), list(value_problems.index)))
    else:
        bad_rows = []
    if verbose:
        if bad_rows:
            formatted_rows = ["row: {}, name: {}".format(row[0], row[1]) for row in bad_rows]
            if len(bad_rows) > 5:
                print("-W- these rows have problems:\n", "\n".join(formatted_rows[:5]), " ...")
                print("(for full error output see error file)")
            else:
                print("-W- these rows have problems:", "\n".join(formatted_rows))
        if problem_cols:
            print("-W- these columns contain bad values:", ", ".join(set(problem_cols)))
        if missing_cols:
            print("-W- these required columns are missing:", ", ".join(missing_cols))
    return bad_rows, problem_cols, missing_cols
390017
def input_dataset_from_dataframe(df, delays=(1, 2, 3), inputs=(1, 2, -1), outputs=None, normalize=True, verbosity=1):
    
    return dataset_from_dataframe(df=df, delays=delays, inputs=inputs, outputs=outputs,
                                  normalize=normalize, verbosity=verbosity)
1000538
def process_prediction_results(results, show_image):
  """"""

  import pandas as pd

  if (is_in_IPython() and show_image is True):
    import IPython
    for image_url, image, label_and_score in results:
      IPython.display.display_html('<p style="font-size:28px">%s(%.5f)</p>' % label_and_score,
                                   raw=True)
      IPython.display.display(IPython.display.Image(data=image))
  result_dict = [{'image_url': url, 'label': r[0], 'score': r[1]} for url, _, r in results]
  return pd.DataFrame(result_dict)
572938
def make_dataframe(result):
    
    import pandas as pd
    ret = {}
    if isinstance(result,dict):
        if 'timeseries' in result:
            result = result['timeseries']
    for uuid, data in result.items():
        df = pd.DataFrame(data)
        if len(df.columns) == 5: # statistical data
            df.columns = ['time','min','mean','max','count']
        else:
            df.columns = ['time','value']
        df['time'] = pd.to_datetime(df['time'],unit='ns')
        df = df.set_index(df.pop('time'))
        ret[uuid] = df
    return ret
830304
def impute_data(self,x):
        """"""
        imp = Imputer(missing_values='NaN', strategy='mean', axis=0)
        return imp.fit_transform(x)
1367232
def show_results(self, ds_type=DatasetType.Valid, rows:int=5, max_len:int=20):
        from IPython.display import display, HTML
        ""
        ds = self.dl(ds_type).dataset
        x,y = self.data.one_batch(ds_type, detach=False, denorm=False)
        preds = self.pred_batch(batch=(x,y))
        y = y.view(*x.size())
        z = preds.view(*x.size(),-1).argmax(dim=2)
        xs = [ds.x.reconstruct(grab_idx(x, i)) for i in range(rows)]
        ys = [ds.x.reconstruct(grab_idx(y, i)) for i in range(rows)]
        zs = [ds.x.reconstruct(grab_idx(z, i)) for i in range(rows)]
        items,names = [],['text', 'target', 'pred']
        for i, (x,y,z) in enumerate(zip(xs,ys,zs)):
            txt_x = ' '.join(x.text.split(' ')[:max_len])
            txt_y = ' '.join(y.text.split(' ')[max_len-1:2*max_len-1])
            txt_z = ' '.join(z.text.split(' ')[max_len-1:2*max_len-1])
            items.append([txt_x, txt_y, txt_z])
        items = np.array(items)
        df = pd.DataFrame({n:items[:,i] for i,n in enumerate(names)}, columns=names)
        with pd.option_context('display.max_colwidth', -1):
            display(HTML(df.to_html(index=False)))
187639
def load_feedback():
    
    result = {}
    if os.path.exists(_feedback_file):
        f = open(_feedback_file, 'r')
        cont = f.read()
        f.close()
    else:
        cont = '{}'

    try:
        result = json.loads(cont) if cont else {}
    except ValueError as e:
        result = {"result":"crash", "text":"Feedback file has been modified by user !"}
    return result
1081186
def _conv(self, data):
        """"""
        if isinstance(data, pd.Series):
            if data.name is None:
                data = data.to_frame(name='')
            else:
                data = data.to_frame()
        data = data.fillna('NaN')
        return data
155570
def v_posts_from_dataframe(df,N=1e4,alpha=0.23,l0=20,sigl=20):
    
    vsini_posts = []
    veq_posts = []
    if 'ep_R' in df:
        for R,dR_p,dR_m,P,dP,v,dv in zip(df['R'],df['ep_R'],df['em_R'],
                                  df['Prot'],df['e_Prot'],
                                  df['vsini'],df['e_vsini']):
            vsini_posts.append(stats.norm(v,dv))
            if dR_p==dR_m:
                veq_posts.append(Veq_Posterior(R,dR_p,P,dP))
            else:
                R_dist = dists.fit_doublegauss(R,dR_m,dR_p)
                Prot_dist = stats.norm(P,dP)
                veq_posts.append(Veq_Posterior_General(R_dist,Prot_dist,N=N,
                                                       l0=l0,sigl=sigl))
    else:
        for R,dR,P,dP,v,dv in zip(df['R'],df['e_R'],
                                  df['Prot'],df['e_Prot'],
                                  df['vsini'],df['e_vsini']):
            vsini_posts.append(stats.norm(v,dv))
            veq_posts.append(Veq_Posterior(R,dR,P,dP))
        
    return vsini_posts,veq_posts
1016937
def to_df(self, method: str = 'MEMORY', **kwargs) -> 'pd.DataFrame':
        
        ll = self._is_valid()
        if ll:
            print(ll['LOG'])
            return None
        else:
            return self.sas.sasdata2dataframe(self.table, self.libref, self.dsopts, method, **kwargs)
507719
def _series_feedback(series, out_port, in_port):
    """"""
    series_s = series.series_inverse().series_inverse()
    if series_s == series:
        raise CannotSimplify()
    return series_s.feedback(out_port=out_port, in_port=in_port)