Commit 03718e9e authored by liadomide's avatar liadomide

TVB-2598 Avoid read from H5 when only GID is necessary

parent b1fd6faa
......@@ -28,9 +28,9 @@
#
#
import numpy
from uuid import UUID
from tvb.analyzers.fft import FFT
from tvb.adapters.analyzers.fourier_adapter import FourierAdapter
from tvb.core.neocom import h5
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
......@@ -53,7 +53,6 @@ class TestFFT(TransactionalTestCase):
def test_fourier_adapter(self, tmpdir, session, operation_factory, time_series_index_factory):
# make file stored and indexed time series
ts_db = time_series_index_factory()
ts = h5.load_from_index(ts_db)
# we have the required data to start the adapter
# REVIEW THIS
......@@ -71,11 +70,11 @@ class TestFFT(TransactionalTestCase):
adapter = FourierAdapter()
adapter.storage_path = str(tmpdir)
view_model = adapter.get_view_model_class()()
view_model.time_series = ts.gid
view_model.time_series = UUID(ts_db.gid)
view_model.segment_length = 400
adapter.configure(view_model)
diskq = adapter.get_required_disk_size(ts_db)
memq = adapter.get_required_memory_size(ts_db)
diskq = adapter.get_required_disk_size(view_model)
memq = adapter.get_required_memory_size(view_model)
spectra_idx = adapter.launch(view_model)
assert spectra_idx.source_gid == ts_db.gid
......
......@@ -35,8 +35,8 @@
import os
import tvb_data
import json
from uuid import UUID
from tvb.adapters.datatypes.db.mapped_value import DatatypeMeasureIndex
from tvb.core.neocom import h5
from tvb.tests.framework.core.base_testcase import TransactionalTestCase
from tvb.config.init.introspector_registry import IntrospectionRegistry
from tvb.core.entities.model import model_operation
......@@ -77,28 +77,29 @@ class TestTimeSeriesMetricsAdapter(TransactionalTestCase):
algo = FlowService().get_algorithm_by_module_and_class(IntrospectionRegistry.SIMULATOR_MODULE,
IntrospectionRegistry.SIMULATOR_CLASS)
self.operation = model_operation.Operation(self.test_user.id, self.test_project.id, algo.id, json.dumps(''),
meta=json.dumps(meta), status=model_operation.STATUS_STARTED)
meta=json.dumps(meta), status=model_operation.STATUS_STARTED)
self.operation = dao.store_entity(self.operation)
# Get connectivity, region_mapping and a dummy time_series_region
connectivity = connectivity_factory()
region_mapping = region_mapping_factory()
dummy_time_series_index = time_series_region_index_factory(connectivity=connectivity, region_mapping=region_mapping)
dummy_time_series_index = time_series_region_index_factory(connectivity=connectivity,
region_mapping=region_mapping)
dummy_time_series_index.start_time = 0.0
dummy_time_series_index.sample_period = 1.0
dummy_time_series_index = dao.get_generic_entity(dummy_time_series_index.__class__, dummy_time_series_index.gid, 'gid')[0]
dummy_time_series = h5.load_from_index(dummy_time_series_index)
dummy_time_series_index = \
dao.get_generic_entity(dummy_time_series_index.__class__, dummy_time_series_index.gid, 'gid')[0]
ts_metric_adapter = TimeseriesMetricsAdapter()
form = TimeseriesMetricsAdapterForm()
view_model = form.get_view_model()()
view_model.time_series = dummy_time_series.gid
view_model.time_series = UUID(dummy_time_series_index.gid)
form.fill_trait(view_model)
ts_metric_adapter.submit_form(form)
resulted_metric = ts_metric_adapter.launch(view_model)
assert isinstance(resulted_metric, DatatypeMeasureIndex), "Result should be a datatype measure."
assert len(resulted_metric.metrics) >= len(list(ts_metric_adapter.get_form().algorithms.choices)),\
"At least a result should have been generated for every metric."
assert len(resulted_metric.metrics) >= len(list(ts_metric_adapter.get_form().algorithms.choices)), \
"At least a result should have been generated for every metric."
for metric_value in json.loads(resulted_metric.metrics).values():
assert isinstance(metric_value, (float, int))
......@@ -33,11 +33,11 @@ import os
import numpy
import tvb_data
import tvb_data.surfaceData
from uuid import UUID
from tvb.adapters.creators.stimulus_creator import RegionStimulusCreator, SurfaceStimulusCreator
from tvb.adapters.datatypes.db.connectivity import ConnectivityIndex
from tvb.adapters.datatypes.db.patterns import StimuliRegionIndex, StimuliSurfaceIndex
from tvb.core.entities.file.files_helper import FilesHelper
from tvb.core.neocom import h5
from tvb.core.services.flow_service import FlowService
from tvb.datatypes.equations import TemporalApplicableEquation, FiniteSupportEquation
from tvb.datatypes.surfaces import CORTICAL
......@@ -58,12 +58,10 @@ class TestStimulusCreator(TransactionalTestCase):
zip_path = os.path.join(os.path.dirname(tvb_data.__file__), 'connectivity', 'connectivity_66.zip')
TestFactory.import_zip_connectivity(self.test_user, self.test_project, zip_path)
connectivity_index = TestFactory.get_entity(self.test_project, ConnectivityIndex)
self.connectivity = h5.load_from_index(connectivity_index)
self.connectivity = TestFactory.get_entity(self.test_project, ConnectivityIndex)
cortex = os.path.join(os.path.dirname(tvb_data.surfaceData.__file__), 'cortex_16384.zip')
surface_index = TestFactory.import_surface_zip(self.test_user, self.test_project, cortex, CORTICAL)
self.surface = h5.load_from_index(surface_index)
self.surface = TestFactory.import_surface_zip(self.test_user, self.test_project, cortex, CORTICAL)
def transactional_teardown_method(self):
"""
......@@ -76,7 +74,7 @@ class TestStimulusCreator(TransactionalTestCase):
region_stimulus_creator = RegionStimulusCreator()
view_model = region_stimulus_creator.get_view_model_class()()
view_model.connectivity = self.connectivity.gid
view_model.connectivity = UUID(self.connectivity.gid)
view_model.weight = weight_array
view_model.temporal = TemporalApplicableEquation()
view_model.temporal.parameters['a'] = 1.0
......@@ -86,31 +84,32 @@ class TestStimulusCreator(TransactionalTestCase):
assert region_stimulus_index.temporal_equation == 'TemporalApplicableEquation'
assert json.loads(region_stimulus_index.temporal_parameters) == {'a': 1.0, 'b': 2.0}
assert region_stimulus_index.connectivity_gid == self.connectivity.gid.hex
assert region_stimulus_index.connectivity_gid == self.connectivity.gid
def test_create_stimulus_region_with_operation(self):
weight_array = numpy.zeros(self.connectivity.number_of_regions)
region_stimulus_creator = RegionStimulusCreator()
view_model = region_stimulus_creator.get_view_model_class()()
view_model.connectivity = self.connectivity.gid
view_model.connectivity = UUID(self.connectivity.gid)
view_model.weight = weight_array
view_model.temporal = TemporalApplicableEquation()
view_model.temporal.parameters['a'] = 1.0
view_model.temporal.parameters['b'] = 2.0
FlowService().fire_operation(region_stimulus_creator, self.test_user, self.test_project.id, view_model=view_model)
FlowService().fire_operation(region_stimulus_creator, self.test_user, self.test_project.id,
view_model=view_model)
region_stimulus_index = TestFactory.get_entity(self.test_project, StimuliRegionIndex)
assert region_stimulus_index.temporal_equation == 'TemporalApplicableEquation'
assert json.loads(region_stimulus_index.temporal_parameters) == {'a': 1.0, 'b': 2.0}
assert region_stimulus_index.connectivity_gid == self.connectivity.gid.hex
assert region_stimulus_index.connectivity_gid == self.connectivity.gid
def test_create_stimulus_surface(self):
surface_stimulus_creator = SurfaceStimulusCreator()
view_model = surface_stimulus_creator.get_view_model_class()()
view_model.surface = self.surface.gid
view_model.surface = UUID(self.surface.gid)
view_model.focal_points_triangles = numpy.array([1, 2, 3])
view_model.spatial = FiniteSupportEquation()
view_model.spatial_amp = 1.0
......@@ -124,13 +123,13 @@ class TestStimulusCreator(TransactionalTestCase):
assert surface_stimulus_index.spatial_equation == 'FiniteSupportEquation'
assert surface_stimulus_index.temporal_equation == 'TemporalApplicableEquation'
assert surface_stimulus_index.surface_gid == self.surface.gid.hex
assert surface_stimulus_index.surface_gid == self.surface.gid
def test_create_stimulus_surface_with_operation(self):
surface_stimulus_creator = SurfaceStimulusCreator()
view_model = surface_stimulus_creator.get_view_model_class()()
view_model.surface = self.surface.gid
view_model.surface = UUID(self.surface.gid)
view_model.focal_points_triangles = numpy.array([1, 2, 3])
view_model.spatial = FiniteSupportEquation()
view_model.spatial_amp = 1.0
......@@ -140,9 +139,10 @@ class TestStimulusCreator(TransactionalTestCase):
view_model.temporal.parameters['a'] = 1.0
view_model.temporal.parameters['b'] = 0.0
FlowService().fire_operation(surface_stimulus_creator, self.test_user, self.test_project.id, view_model=view_model)
FlowService().fire_operation(surface_stimulus_creator, self.test_user, self.test_project.id,
view_model=view_model)
surface_stimulus_index = TestFactory.get_entity(self.test_project, StimuliSurfaceIndex)
assert surface_stimulus_index.spatial_equation == 'FiniteSupportEquation'
assert surface_stimulus_index.temporal_equation == 'TemporalApplicableEquation'
assert surface_stimulus_index.surface_gid == self.surface.gid.hex
\ No newline at end of file
assert surface_stimulus_index.surface_gid == self.surface.gid
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment