Esempio n. 1
0
    def __init__(self, target_filename=None, output_columns=None, header=0):

        if target_filename is None:
            msg = (
                f"target_filename must be set for SimpleCSV. This should be"
                f"the name of the output file this decoder acts on."
            )
            logging.error(msg)
            raise RuntimeError(msg)

        if output_columns is None:
            msg = (
                f"output_columns must be specified for SimpleCSV. This should"
                f"be the names of the output columns this decoder extracts"
                f"from the target csv file."
            )
            logging.error(msg)
            raise RuntimeError(msg)

        if len(output_columns) == 0:
            msg = "output_columns cannot be empty."
            logger.error(msg)
            raise RuntimeError(msg)

        self.target_filename = target_filename
        self.output_columns = output_columns
        self.header = header

        self.output_type = OutputType('sample')
Esempio n. 2
0
    def __init__(self, target_filename=None, output_columns=None):

        if target_filename is None:
            msg = (
                f"target_filename must be set for JSONDecoder. This should be"
                f"the name of the output file this decoder acts on.")
            logging.error(msg)
            raise RuntimeError(msg)

        if output_columns is None:
            msg = (
                f"output_columns must be specified for JSONDecoder. This should"
                f"be the names of the output fields this decoder extracts"
                f"from the target json file. For nested values use arrays"
                f"e.g. ['root', 'node', 'field'] where field is the leaf"
                f"that contains the value you need.")
            logging.error(msg)
            raise RuntimeError(msg)

        if len(output_columns) == 0:
            msg = "output_columns cannot be empty."
            logger.error(msg)
            raise RuntimeError(msg)

        self.target_filename = target_filename
        self.output_columns = output_columns

        self.output_type = OutputType('sample')
Esempio n. 3
0
    def __init__(self, target_filename, cpo_name, output_columns):

        if target_filename is None:
            msg = (f"target_filename must be set for CPODecoder. This should be"
                   f"the name of the output file this decoder acts on.")
            logging.error(msg)
            raise Exception(msg)

        if output_columns is None:
            msg = (f"output_columns must be specified for CPODecoder.")
            logging.error(msg)
            raise Exception(msg)

        if cpo_name is None:
            msg = (f"cpo_name must be specified for CPODecoder.")
            logging.error(msg)
            raise Exception(msg)

        if len(output_columns) == 0:
            msg = "output_columns cannot be empty."
            logger.error(msg)
            raise Exception(msg)

        self.target_filename = target_filename
        self.cpo_name = cpo_name
        self.output_columns = output_columns

        self.output_type = OutputType('sample')
Esempio n. 4
0
 def __init__(self, target_filename, output_columns):
     if len(output_columns) == 0:
         msg = "output_columns cannot be empty."
         logger.error(msg)
         raise RuntimeError(msg)
     self.target_filename = target_filename
     self.output_columns = output_columns
     self.output_type = OutputType('sample')
Esempio n. 5
0
    def __init__(self, target_filename=None):

        if target_filename is None:
            msg = (f"target_filename must be set for SimpleCSV. This should be"
                   f"the name of the output file this decoder acts on.")
            logging.error(msg)
            raise Exception(msg)

        self.output_type = OutputType('sample')
        self.target_filename = target_filename
Esempio n. 6
0
def aggregate_samples(campaign, average=False, *args, **kwargs):
    """
    Aggregate the results of all completed simulations described by the
    Campaign.

    Parameters
    ----------
    campaign:   `easyvvuq.Campaign`
        Campaign from which to get simulation output to aggregate.
    average:
        Should the values read in be averaged (mean).

    Returns
    -------
    `pd.DataFrame`:
        Aggregated data from all completed runs referenced in the input Campaign.

    """

    decoder = campaign.decoder

    if decoder.output_type != OutputType.SAMPLE:
        raise RuntimeError('Can only aggregate sample type data')

    runs = campaign.runs

    full_data = pd.DataFrame()

    for run_id, run_info in runs.items():

        if decoder.sim_complete(run_info=run_info, *args, **kwargs):

            runs[run_id]['completed'] = True

            run_data = decoder.parse_sim_output(run_info=run_info,
                                                *args,
                                                **kwargs)

            if average:

                run_data = pd.DataFrame(run_data.mean()).transpose()

            column_list = list(run_info.keys()) + run_data.columns.tolist()

            for param, value in run_info.items():

                run_data[param] = value

            # Reorder columns
            run_data = run_data[column_list]

            run_data['run_id'] = run_id

            full_data = full_data.append(run_data, ignore_index=True)

    data_dir = os.path.join(campaign.campaign_dir, 'data')

    out_dir = tempfile.mkdtemp(dir=data_dir)
    out_file = os.path.join(out_dir, 'aggregate_sample.tsv')

    full_data.to_csv(out_file, sep='\t', index=False)

    state_file = os.path.join(out_dir, 'state_snapshot.json')
    campaign.save_state(state_file)

    campaign.data = {
        'files': [out_file],
        'type': OutputType('summary').value,
        'output_columns': decoder.output_columns,
        'state': state_file
    }

    return full_data
Esempio n. 7
0
    def __init__(self, *args, **kwargs):

        # Handles creation of `self.app_info` attribute (dicts)
        super().__init__(*args, **kwargs)

        self.output_type = OutputType('sample')
Esempio n. 8
0
    def __init__(self, *args, **kwargs):

        self.output_type = OutputType('sample')
        self.output_columns = []