Пример #1
0
    def get_morphology_features(self, dataframe=False, file_name=None):
        """
        Download morphology features for all cells with reconstructions in the database.

        Parameters
        ----------

        file_name: string
            File name to save/read the ephys features metadata as CSV.
            If file_name is None, the file_name will be pulled out of the
            manifest.  If caching is disabled, no file will be saved.
            Default is None.

        dataframe: boolean
            Return the output as a Pandas DataFrame.  If False, return
            a list of dictionaries.
        """

        file_name = self.get_cache_path(
            file_name, self.MORPHOLOGY_FEATURES_KEY)

        if self.cache:
            if dataframe:
                warnings.warn("dataframe argument is deprecated.")
                args = Cache.cache_csv_dataframe()
            else:
                args = Cache.cache_csv_json()
        else:
            args = Cache.nocache_json()

        args['strategy'] = 'lazy'
        args['path'] = file_name

        return self.api.get_morphology_features(**args)
Пример #2
0
    def get_morphology_features(self, dataframe=False, file_name=None):
        """
        Download morphology features for all cells with reconstructions in the database.

        Parameters
        ----------

        file_name: string
            File name to save/read the ephys features metadata as CSV.
            If file_name is None, the file_name will be pulled out of the
            manifest.  If caching is disabled, no file will be saved.
            Default is None.

        dataframe: boolean
            Return the output as a Pandas DataFrame.  If False, return
            a list of dictionaries.
        """

        file_name = self.get_cache_path(file_name,
                                        self.MORPHOLOGY_FEATURES_KEY)

        if self.cache:
            if dataframe:
                warnings.warn("dataframe argument is deprecated.")
                args = Cache.cache_csv_dataframe()
            else:
                args = Cache.cache_csv_json()
        else:
            args = Cache.nocache_json()

        args['strategy'] = 'lazy'
        args['path'] = file_name

        return self.api.get_morphology_features(**args)
Пример #3
0
def test_cacheable_csv_dataframe(from_csv, dictwriter, mock_json_utilities,
                                 mock_dataframe):
    @cacheable()
    def get_hemispheres():
        return RmaApi().model_query(model='Hemisphere')

    with patch('allensdk.config.manifest.Manifest.safe_mkdir') as mkdir:
        with patch(builtins.__name__ + '.open', mock_open(),
                   create=True) as open_mock:
            open_mock.return_value.write = MagicMock()
            df = get_hemispheres(path='/xyz/abc/example.txt',
                                 strategy='create',
                                 **Cache.cache_csv_dataframe())

    assert df.loc[:, 'whatever'][0]

    mock_json_utilities.read_url_get.assert_called_once_with(
        'http://api.brain-map.org/api/v2/data/query.json?q=model::Hemisphere')
    mock_dataframe.from_csv.assert_called_once_with('/xyz/abc/example.txt')
    assert not mock_json_utilities.write.called, 'write should not have been called'
    assert not mock_json_utilities.read.called, 'read should not have been called'
    mkdir.assert_called_once_with('/xyz/abc')
    open_mock.assert_called_once_with('/xyz/abc/example.txt', 'w')
Пример #4
0
def test_cacheable_csv_dataframe(read_csv, dictwriter, ju_read_url_get,
                                 ju_read, ju_write):
    @cacheable()
    def get_hemispheres():
        return RmaApi().model_query(model='Hemisphere')

    with patch('allensdk.config.manifest.Manifest.safe_mkdir') as mkdir:
        with patch(builtins.__name__ + '.open',
                   mock_open(),
                   create=True) as open_mock:
            open_mock.return_value.write = MagicMock()
            df = get_hemispheres(path='/xyz/abc/example.txt',
                                 strategy='create',
                                 **Cache.cache_csv_dataframe())

    assert df.loc[:, 'whatever'][0]

    ju_read_url_get.assert_called_once_with(
        'http://api.brain-map.org/api/v2/data/query.json?q=model::Hemisphere')
    read_csv.assert_called_once_with('/xyz/abc/example.txt', parse_dates=True)
    assert not ju_write.called, 'write should not have been called'
    assert not ju_read.called, 'read should not have been called'
    mkdir.assert_called_once_with('/xyz/abc')
    open_mock.assert_called_once_with('/xyz/abc/example.txt', 'w')