Beispiel #1
0
    def post(self):
        """Serves requested file to the client."""
        # Retrieve specified MRS data from the database.
        mrs_data_id = self.request.get('mrs_data_id')
        db_entry = ds.fetch_mrs_data(ds.create_sqlite_connection(), mrs_data_id)

        # Set response headers.
        self.response.headers['Content-Type'] = 'application/octet-stream'
        self.response.headers['Content-Description'] = 'File Transfer'
        self.response.headers['Content-Transfer-Encoding'] = 'binary'
        self.response.headers['Content-Disposition'] = 'attachment; filename=\"%s\"' % db_entry[1]
        self.response.headers['Content-Length'] = sys.getsizeof(db_entry[2])
        # Set response content.
        self.response.out.write(db_entry[2])
Beispiel #2
0
    def prepare_mrs_data_set(self):
        """Retrieves all specified MRS data entries and processes each entry.

        Each MRS file is parsed and FFT is applied if specified.

        Returns:
            Tuple containing (list of sample inputs, list of sample outputs).
        """
        training_data_ids = self.request.get_all("training_data_ids")
        apply_fft = 'apply_fft' in self.request.POST
        LOGGER.debug('Processing MRS data: apply_fft=%s', apply_fft)
        # Retrieve specified training data from the database.
        conn = ds.create_sqlite_connection()
        db_entries = [ds.fetch_mrs_data(conn, data_id) for data_id in training_data_ids]
        # Separate each database entry into input and output.
        sample_inputs = []
        sample_outputs = []
        for entry in db_entries:
            # Parse data points from the file contents.
            mrs_data = dataparser.get_xy_data(str(entry[2]))
            # Apply FFT to the data points if specified by user.
            if apply_fft:
                mrs_data = fourier_transformer.get_fft(mrs_data)
            # Add input, output pair to separate lists.
            sample_inputs.append(mrs_data)
            sample_outputs.append(entry[3])

        # Format the data for classifier input.
        n_samples = len(sample_inputs)
        n_features = len(sample_inputs[0])
        sample_inputs = np.array(sample_inputs)  # convert before using as buffer
        sample_inputs = np.ndarray(
            shape=(n_samples, n_features), dtype=float, buffer=sample_inputs)
        # Labels for training.
        sample_outputs = np.array(sample_outputs)

        # Return processed MRS data.
        return (sample_inputs, sample_outputs)