def compute(self):
     citysim_xml = self.get_input('citysim')
     fmu_path = self.get_input('fmu_path').name
     cli_path = self.getInputFromPort('cli_path').name
     citysim_path = self.get_input('citysim_path').name
     tmp = tempfile.mkdtemp(
         prefix=datetime.datetime.now().strftime('%Y.%m.%d.%H.%M.%S')
         + "_RunCoSimulation_")
     root = citysim_xml.getroot()
     root.find('Climate').set('location', cli_path)
     building = root.find(".//Building[@Simulate='ep']")
     assert len(building), 'CitySimXml does not contain Simulate="ep"'
     building.set('fmu', fmu_path)
     building.set('tmp', tmp)
     citysim_xml_fd, citysim_xml_path = tempfile.mkstemp(
         suffix='.xml', dir=tmp)
     with os.fdopen(citysim_xml_fd, 'w') as citysim_xml_file:
         etree.ElementTree(root).write(citysim_xml_file)
     subprocess.check_call([citysim_path,
                            citysim_xml_path],
                           cwd=tmp)
     self.set_output('results_path', basic.PathObject(tmp))
     self.set_output('citysim_basename',
                     os.path.basename(citysim_xml_path)[:-4])
     self.set_output('eplus_basename',
                     os.path.join('Output_EPExport_RevitToCitySim',
                                  os.path.basename(fmu_path)[:-4]))
    def compute(self):
        import shutil
        idf = self.get_input('idf')
        idd_path = force_get_path(self, 'idd', find_idd())
        epw_path = self.get_input('epw').name
        energyplus_path = force_get_path(self, 'energyplus', find_energyplus())
        tmp = tempfile.mkdtemp(
            prefix=datetime.datetime.now().strftime('%Y.%m.%d.%H.%M.%S')
            + "_RunEnergyPlus_")
        idf_path = os.path.join(tmp, 'in.idf')
        with open(idf_path, 'w') as out:
            out.write(idf.idfstr())
        shutil.copy(idd_path, tmp)
        shutil.copyfile(epw_path, os.path.join(tmp, 'in.epw'))
        copy_list = self.force_get_input('copy_list', None)
        if copy_list:
            relnames = copy_list.split(';')
            from vistrails.core import application
            app = application.get_vistrails_application()
            wf_path = app.get_vistrail().locator.name
            wf_folder = os.path.dirname(wf_path)
            for relname in relnames:
                absolute_path = os.path.normpath(
                    os.path.join(wf_folder, relname))
                shutil.copy(absolute_path, tmp)

        subprocess.check_call([energyplus_path],
                              cwd=tmp)
        self.set_output('results', basic.PathObject(tmp))
 def compute(self):
     from vistrails.core import application
     app = application.get_vistrails_application()
     wf_path = app.get_vistrail().locator.name
     wf_folder = os.path.dirname(wf_path)
     relative_path = self.get_input('relative_path')
     relative_path = replace_vars(relative_path)
     absolute_path = os.path.normpath(
         os.path.join(wf_folder, relative_path))
     self.set_output('absolute_path', basic.PathObject(absolute_path))
Example #4
0
    def create_directory(self, suffix = '', prefix = 'vt_tmp'):
        """create_directory(suffix='', prefix='vt_tmp') -> PathObject.

        Returns a writable directory for use in modules. To avoid race
        conditions, this directory will already exist in the file system.

        """
        name = tempfile.mkdtemp(suffix=suffix,
                                      prefix=prefix,
                                      dir=self.directory)
        result = basic_modules.PathObject(name)
        self.files[name] = result
        return result
Example #5
0
    def create_file(self, suffix = '', prefix = 'vt_tmp'):
        """create_file(suffix='', prefix='vt_tmp') -> PathObject.

        Returns a File module representing a writable file for use in
        modules. To avoid race conditions, this file will already
        exist in the file system.

        """
        (fd, name) = tempfile.mkstemp(suffix=suffix,
                                      prefix=prefix,
                                      dir=self.directory)
        os.close(fd)
        result = basic_modules.PathObject(name)
        self.files[name] = result
        return result
Example #6
0
    def make_local_copy(self, src):
        """make_local_copy(src) -> PathObject

        Returns a file in the filePool that's either a link or a copy
        of the given file path. This ensures the file's longevity when
        necessary. Since it might use a hardlink for speed, modules
        should only use this method if the file is not going to be
        changed in the future.

        """
        (fd, name) = tempfile.mkstemp(suffix=self.guess_suffix(src),
                                      dir=self.directory)
        os.close(fd)
        # FIXME: Watch out for race conditions
        os.unlink(name)
        link_or_copy(src, name)
        result = basic_modules.PathObject(name)
        self.files[name] = result
        return result
 def compute(self):
     try:
         ep2fmu_path = self.get_input('EnergyPlusToFmu_path').name
         idd_path = self.get_input('idd_path').name
         idf = self.get_input('idf')
         epw_path = self.get_input('epw_path').name
         idf_fd, idf_path = tempfile.mkstemp(suffix='.idf')
         with os.fdopen(idf_fd, 'w') as idf_file:
             idf_file.write(idf.idfstr())
         cwd = tempfile.gettempdir()
         call_args = ['python', ep2fmu_path,
                      '-i', idd_path,
                      '-d', '-L',
                      '-w', epw_path,
                      idf_path]
         print call_args
         subprocess.check_call(call_args, cwd=cwd)
         self.set_output('fmu_path',
                         basic.PathObject(idf_path[:-4] + '.fmu'))
     except:
         raise
 def compute(self):
     citysim_xml = self.get_input('citysim_xml')
     cli_path = self.get_input('cli_path').name
     citysim_exe = self.get_input('citysim_exe').name
     tmp = tempfile.mkdtemp(
         prefix=datetime.datetime.now().strftime('%Y.%m.%d.%H.%M.%S')
         + "_RunCitySim_")
     root = citysim_xml.getroot()
     root.find('Climate').set('location', cli_path)
     # make sure we turn off co-simulation buildings:
     for building in root.findall(".//Building[@Simulate='ep']"):
         building.set('Simulate', 'true')
     citysim_xml_fd, citysim_xml_path = tempfile.mkstemp(
         suffix='.xml', dir=tmp)
     with os.fdopen(citysim_xml_fd, 'w') as citysim_xml_file:
         citysim_xml.write(citysim_xml_file)
     subprocess.check_call([citysim_exe,
                            citysim_xml_path],
                           cwd=tmp)
     self.set_output('results_path', basic.PathObject(tmp))
     self.set_output('citysim_basename',
                     os.path.basename(citysim_xml_path)[:-4])