def ensure_dir_exists(cls, dir_location): """ Helper function that will make directories if they don't exist. Useful for temporary locations""" if dir_location and not os.path.exists(dir_location): from morphforge.core.mgrs.logmgr import LogMgr LogMgr.info('Creating FS Location - ' + dir_location) if not os.path.exists(dir_location): os.makedirs(dir_location) return cls.validate_exists(dir_location)
def Load(self, morphname, src, regionNames=None): regionNames = regionNames if regionNames else self.defaultxyzXYZRegionNames lines = [l.strip() for l in src.readlines()] lines = [l for l in lines if l and l[0] != '#' and l[0] != ':'] # Check the header: line1 = lines[0].translate(None, '\t ') assert line1 == 'n,T,x,y,z,X,Y,Z,P' line1 = lines[0].translate(None, '\t ') assert line1 == 'n,T,x,y,z,X,Y,Z,P' regionTypes = dict([(index, Region(name)) for index, name, in regionNames.iteritems()]) sections = [] for l in lines[1:]: toks = l.split(',') T = int(toks[1]) xyz = (float(toks[2]), float(toks[3]), float(toks[4])) XYZ = (float(toks[5]), float(toks[6]), float(toks[7])) centre = ((xyz[0] + XYZ[0]) / 2.0, (xyz[1] + XYZ[1]) / 2.0, (xyz[2] + XYZ[2]) / 2.0) rad = np.sqrt(sum([(xyz[i] - centre[i])**2.0 for i in [0, 1, 2]])) if rad < 0.3: rad = 0.3 if sections: LogMgr.info("Loading ID: %d" % int(toks[0])) newSect = sections[-1].create_distal_section( regions=[regionTypes[T]], x=centre[0], y=centre[1], z=centre[2], r=rad) else: newSect = Section(regions=[regionTypes[T]], x=centre[0], y=centre[1], z=centre[2], r=rad) sections.append(newSect) # Create the Cell c = MorphologyTree(name=morphname, root=sections[0], metadata={}) return c
def _run_spawn(self): LogMgr.info("_run_spawn() [Pickling Sim]") (bundle, resfilename) = MetaDataBundleBuilder.build_std_pickler(self) (_bundlefname, sim_cmd) = bundle.write_to_file_and_get_exec_string() # if Exists(resfilename): # os.unlink(resfilename) if not os.path.exists(resfilename): # Setup the LD_LIBRARY PATH: # It may be nessesary to add the following to .mfrc # ld_library_path_suffix = /home/michael/hw/morphforge/src/morphforgecontrib/neuron_gsl/cpp ld_path_additions = RCMgr.get("Neuron", "ld_library_path_suffix").split(":") old_ld_path = os.environ.get("LD_LIBRARY_PATH", "") os.environ["LD_LIBRARY_PATH"] = ":".join([old_ld_path] + ld_path_additions) LogMgr.info("_run_spawn() [Spawning subprocess]") ret_code = subprocess.call(sim_cmd, shell=True) if ret_code != 1: raise ValueError("Unable to simulate %s" % self.name) LogMgr.info("_run_spawn() [Finished spawning subprocess]") # Load back the results: LogMgr.info("_run_spawn() [Loading results]") print "_run_spawn() [Loading results from %s ]" % resfilename self.result = SimulationResult.load_from_file(resfilename) LogMgr.info("_run_spawn() [Finished loading results]") # We have to do this so that the simulation object # within the result is correct!! self.result.simulation = self # Save the simulation summary: do_summary = False if do_summary: fname = "~/Desktop/pdfs/%s.pdf" % (self._sim_desc_str().replace(" ", "")) summary = SimulationMRedoc.build(self) summary.to_pdf(fname) # And unlink the old files (so we don't go mad on disk space) os.unlink(resfilename) os.unlink(_bundlefname) return self.result
def _run_spawn(self): LogMgr.info('_run_spawn() [Pickling Sim]') (bundle, resfilename) = MetaDataBundleBuilder.build_std_pickler(self) (_bundlefname, sim_cmd) = bundle.write_to_file_and_get_exec_string() # if Exists(resfilename): # os.unlink(resfilename) if not os.path.exists(resfilename): # Setup the LD_LIBRARY PATH: # It may be nessesary to add the following to .mfrc # ld_library_path_suffix = /home/michael/hw/morphforge/src/morphforgecontrib/neuron_gsl/cpp ld_path_additions = RCMgr.get('Neuron', 'ld_library_path_suffix').split(':') old_ld_path = os.environ.get('LD_LIBRARY_PATH', '') os.environ['LD_LIBRARY_PATH'] = ':'.join([old_ld_path] + ld_path_additions) LogMgr.info('_run_spawn() [Spawning subprocess]') ret_code = subprocess.call(sim_cmd, shell=True) if ret_code != 1: raise ValueError('Unable to simulate %s' % self.name) LogMgr.info('_run_spawn() [Finished spawning subprocess]') # Load back the results: LogMgr.info('_run_spawn() [Loading results]') self.result = SimulationResult.load_from_file(resfilename) LogMgr.info('_run_spawn() [Finished loading results]') # We have to do this so that the simulation object # within the result is correct!! self.result.simulation = self # Save the simulation summary: do_summary = False if do_summary: fname = '~/Desktop/pdfs/%s.pdf' % (self._sim_desc_str().replace( ' ', '')) summary = SimulationMRedoc.build(self) summary.to_pdf(fname) return self.result
def Load(self, morphname, src, regionNames=None): assert False, 'Do not use this module ~ currently in development' regionNames = regionNames if regionNames else self.defaultxyzXYZRegionNames lines = [l.strip() for l in src.readlines()] lines = [l for l in lines if l and l[0] != '#' and l[0] != ':'] # Check the header: line1 = lines[0].translate(None, '\t ') assert line1 == 'n,T,x,y,z,X,Y,Z,P' line1 = lines[0].translate(None, '\t ') assert line1 == 'n,T,x,y,z,X,Y,Z,P' regionTypes = dict([(index, Region(name)) for index, name, in regionNames.iteritems() ]) sections = [] for l in lines[1:]: toks = l.split(',') T = int(toks[1]) xyz = (float(toks[2]), float(toks[3]), float(toks[4])) XYZ = (float(toks[5]), float(toks[6]), float(toks[7])) centre = ((xyz[0] + XYZ[0]) / 2.0, (xyz[1] + XYZ[1]) / 2.0, (xyz[2] + XYZ[2]) / 2.0) rad = np.sqrt(sum([(xyz[i] - centre[i]) ** 2.0 for i in [0, 1, 2]])) if rad < 0.3: rad = 0.3 if sections: LogMgr.info("Loading ID: %d" % int(toks[0])) newSect = sections[-1].create_distal_section(regions=[regionTypes[T]], x=centre[0], y=centre[1], z=centre[2], r=rad) else: newSect = Section (regions=[regionTypes[T]], x=centre[0], y=centre[1], z=centre[2], r=rad) sections.append(newSect) # Create the Cell c = MorphologyTree(name=morphname, root=sections[0], metadata={}) return c
def _RunSpawn(self): LogMgr.info("_RunSpawn() [Pickling Sim]") b, resfilename = MetaDataBundleBuilder.buildStdPickler(self) bundlefilename, simCmd = b.writeToFileAndGetExecString() #if Exists(resfilename): # os.unlink(resfilename) if not Exists(resfilename): # Setup the LD_LIBRARY PATH: # It may be nessesary to add the following to .mfrc # ld_library_path_suffix = /home/michael/hw/morphforge/src/morphforgecontrib/neuron_gsl/cpp ld_path_additions = RCMgr.get("Neuron","ld_library_path_suffix").split(":") old_ld_path = os.environ.get('LD_LIBRARY_PATH','') os.environ['LD_LIBRARY_PATH'] = ":".join( [old_ld_path] + ld_path_additions ) LogMgr.info("_RunSpawn() [Spawning subprocess]") retCode = ExecCommandGetRetCode(simCmd) if retCode != 1: raise ValueError("Unable to simulate %s" % self.name) LogMgr.info("_RunSpawn() [Finished spawning subprocess]") # Load back the results: LogMgr.info("_RunSpawn() [Loading results]") self.result = SimulationResult.loadFromFile(resfilename) LogMgr.info("_RunSpawn() [Finished loading results]") # We have to do this so that the simulation object # within the result is correct!! self.result.simulation = self return self.result