コード例 #1
0
def demo():
    '''Examples of how to use find_cut_plane'''
    neuron_slice = load_neuron('../test_data/valid_set/Neuron_slice.h5')

    result = find_cut_plane(neuron_slice, bin_width=1)
    print('Cut plane found using a bin width of 1 (which is too low): {0}'.
          format(result['cut_plane']))
    print('Status: {0}'.format(result['status']))

    result = find_cut_plane(neuron_slice)
    print('\nCut plane found using default parameter: {0}'.format(
        result['cut_plane']))
    print('Status: {0}'.format(result['status']))
    print('Number of leaves to repair: {0}'.format(len(result['cut_leaves'])))
    print('More details can be found under details:\n{0}'.format(
        result['details']))

    try:
        print('\nNow displaying the plots using the display=True option...')
        import matplotlib.pyplot as plt
        result = find_cut_plane(neuron_slice, display=True)
        for name, (fig, _) in result['figures'].items():
            print('Saving figure {}.png'.format(name))
            fig.savefig(name)
        print(
            "\nRemember:"
            " it's up to the user to call matplotlib.pyplot.show() to display the plots"
        )
        plt.show()
    except ImportError:
        L.warning(
            "It appears that matplotlib is not installed. Can't display plots."
        )
コード例 #2
0
def test_cut_neuron():
    result = find_cut_plane(load_neuron('test_data/valid_set/Neuron_slice.h5'))
    nt.assert_equal(result['status'], 'ok')

    cut_axis, position = result['cut_plane']
    nt.assert_equal(cut_axis, 'Z')
    nt.assert_true(abs(position - 48) < 2)
コード例 #3
0
def test_display():
    result = find_cut_plane(load_neuron('test_data/valid_set/Neuron_slice.h5'),
                            display=True)
    for fig, ax in result['figures'].values():
        nt.assert_true(fig)
        nt.assert_true(ax)
    nt.assert_equal(set(result['figures'].keys()),
                    set(['distrib_1d', 'xy', 'xz', 'yz']))
コード例 #4
0
def test_repaired_neuron():
    result = find_cut_plane(load_neuron('test_data/h5/v1/bio_neuron-000.h5'))
    nt.assert_not_equal(result['status'], 'ok')
コード例 #5
0
def test_empty_neuron():
    result = find_cut_plane(Neuron())
    nt.assert_equal(result['status'], 'Empty neuron')
コード例 #6
0
    def generate_prediction(self, model, verbose=False):
        """Implementation of sciunit.Test.generate_prediction."""
        self.model_version = model.model_version
        self.path_test_output = os.path.join(
            self.base_directory, 'validation_results',
            'neuroM_morph_hardChecks', self.model_version,
            datetime.now().strftime("%Y%m%d-%H%M%S"))
        if not os.path.exists(self.path_test_output):
            os.makedirs(self.path_test_output)

        # note: observation here is either the contents of the config file or a local path
        # if local path load contents
        if not isinstance(self.observation, dict):
            with open(self.observation) as f:
                self.observation = json.load(f)
        # save morph_check config as local file
        morph_check_config_file = os.path.join(self.path_test_output,
                                               "morph_check_config.json")
        with open(morph_check_config_file, 'w') as f:
            json.dump(self.observation["morph_check"], f, indent=4)
        cut_plane_config = self.observation["cut_plane"]

        morhpcheck_output_file = os.path.join(self.path_test_output,
                                              "morph_check_output.json")
        call(
            shlex.split(
                f"morph_check -C {morph_check_config_file} -o {morhpcheck_output_file} {model.morph_path}"
            ))
        with open(morhpcheck_output_file) as json_data:
            prediction = json.load(json_data)

        cut_plane_output_json = find_cut_plane(
            load_neuron(model.morph_path),
            bin_width=cut_plane_config["bin_width"],
            display=True)
        cut_plane_figure_list = []
        for key in cut_plane_output_json["figures"].keys():
            cut_plane_figure_list.append(
                cut_plane_output_json["figures"][key][0])
        cutplane_output_pdf = os.path.join(self.path_test_output,
                                           "cut_plane_figures.pdf")
        cut_plane_pdf = matplotlib.backends.backend_pdf.PdfPages(
            cutplane_output_pdf)
        for fig in range(1, len(cut_plane_figure_list) + 1):
            cut_plane_pdf.savefig(fig)
        cut_plane_pdf.close()
        cutplane_output_file = os.path.join(self.path_test_output,
                                            "cut_plane_output.json")
        cut_plane_output_json.pop("figures")
        cut_plane_output_json["cut_leaves"] = cut_plane_output_json[
            "cut_leaves"].tolist()

        def convert(o):
            if isinstance(o, numpy.int64): return int(o)
            raise TypeError

        with open(cutplane_output_file, "w") as outfile:
            json.dump(cut_plane_output_json,
                      outfile,
                      indent=4,
                      default=convert)

        self.figures.append(morhpcheck_output_file)
        self.figures.append(cutplane_output_file)
        self.figures.append(cutplane_output_pdf)
        return prediction