Пример #1
0
def set_time_interval(from_day: float, to_day: float):
    """
    Sets start time and stop time to param.in file.
    :param from_day:
    :param to_day:
    :return:
    """
    def _edit_file(filepath: str, callback: Callable[[Iterable[str], TextIO],
                                                     None]):
        with open(filepath) as f:
            out_fname = filepath + ".tmp"
            out = open(out_fname, "w")
            callback(f, out)
            out.close()
            os.rename(out_fname, filepath)

    def _update_params(infile: Iterable[str], outfile: TextIO):
        startday_pattern = ' start time (days)= '
        stopday_pattern = ' stop time (days) = '
        for line in infile:
            if line.startswith(startday_pattern):
                line = '%s%f\n' % (startday_pattern, from_day)
            if line.startswith(stopday_pattern):
                line = '%s%f\n' % (stopday_pattern, to_day)
            outfile.write(line)

    integrator_path = opjoin(Config.get_project_dir(),
                             CONFIG['integrator']['dir'])
    param_in_filepath = opjoin(integrator_path,
                               CONFIG.INTEGRATOR_PARAM_FILENAME)

    _edit_file(param_in_filepath, _update_params)
Пример #2
0
import glob
import logging
import os
import shutil
import subprocess
from os.path import join as opjoin

from resonances.integrator import element6
from resonances.integrator import simple_clean
from resonances.settings import Config

CONFIG = Config.get_params()
PROJECT_DIR = Config.get_project_dir()
BODIES_COUNTER = int(CONFIG['integrator']['number_of_bodies'])
EXPORT_BASE_DIR = opjoin(PROJECT_DIR, CONFIG['export']['base_dir'])


class ExtractError(Exception):
    pass


def extract(start: int, elements: bool = False, do_copy_aei: bool = False) -> bool:
    """Extract resonance file from archive to directory in export folder
    start — first object number for extracting (start + number of bodies)
    elements — should mercury6 create aei files for all objects?

    :param int start:
    :param bool elements:
    :param bool do_copy_aei:
    :rtype bool:
    :raises FileNotFoundError: if archive not found.
Пример #3
0
    @event.listens_for(Engine, "before_cursor_execute")
    def before_cursor_execute(conn, cursor, statement, parameters, context,
                              executemany):
        conn.info.setdefault('query_start_time', []).append(time.time())
        logger.debug("Start Query: %s", statement % parameters)

    @event.listens_for(Engine, "after_cursor_execute")
    def after_cursor_execute(conn, cursor, statement, parameters, context,
                             executemany):
        total = time.time() - conn.info['query_start_time'].pop(-1)
        logger.debug("Query Complete!")
        logger.debug("Total Time: %f", total)


_config = AlembicConfig(
    os.path.join(Config.get_project_dir(),
                 Config.get_params()['db_path']))


@as_declarative()
class Base(object):
    def __init__(self, **kwargs):
        super(Base, self).__init__(**kwargs)

    id = Column(Integer, primary_key=True)


engine = create_engine('postgres://%s:%s@%s/%s' %
                       (_USER, _PASSWORD, _HOST, _DB),
                       implicit_returning=False)
_Session = sessionmaker()