示例#1
0
    def __init__(self,
                 prefix: str = 'RAScore',
                 model: str = 'ChEMBL',
                 n_jobs: int = 1,
                 **kwargs):
        """
        :param prefix: Prefix to identify scoring function instance
        :param model: Either 'ChEMBL', 'GDB', 'GDBMedChem' or specify a file path to a custom model
        :param n_jobs: Number of python.multiprocessing jobs for multiprocessing of fps
        :param kwargs:
        """
        self.prefix = prefix
        self.n_jobs = n_jobs

        if model == 'ChEMBL':
            with resources.open_binary(
                    'molscore.data.models.RAScore.XGB_chembl_ecfp_counts',
                    'model.pkl') as f:
                self.model = pkl.load(f)
        elif model == 'GDB':
            with resources.open_binary(
                    'molscore.data.models.RAScore.XGB_gdbchembl_ecfp_counts',
                    'model.pkl') as f:
                self.model = pkl.load(f)
        elif model == 'GDBMedChem':
            with resources.open_binary(
                    'molscore.data.models.RAScore.XGB_gdbmedechem_ecfp_counts',
                    'model.pkl') as f:
                self.model = pkl.load(f)
        else:
            with open(os.path.abspath(model), 'rb') as f:
                self.model = pkl.load(f)
    def __init__(self,
                 image_path,
                 is_train=True,
                 inp_res=256,
                 out_res=64,
                 sigma=1,
                 scale_factor=0.25,
                 rot_factor=30,
                 label_type='Gaussian'):
        self.img_folder = image_path  # root image folders
        self.is_train = is_train  # training set or test set
        self.inp_res = inp_res
        self.out_res = out_res
        self.sigma = sigma
        self.scale_factor = scale_factor
        self.rot_factor = rot_factor
        self.label_type = label_type

        # create train/val split

        with gzip.open(
                open_binary(stacked_hourglass.res,
                            'mpii_annotations.json.gz')) as f:
            self.anno = json.load(f)

        self.train_list, self.valid_list = [], []
        for idx, val in enumerate(self.anno):
            if val['isValidation'] == True:
                self.valid_list.append(idx)
            else:
                self.train_list.append(idx)
def test_hmmer_prof():
    buffer = pkg_resources.open_binary(hmmer_reader.data, "three-profs.hmm.gz")

    content = gzip.decompress(buffer.read()).decode()
    hmmfile = open_hmmer(StringIO(content))

    hmm = hmmfile.read_model()
    assert hmm.header == "HMMER3/f [3.1b2 | February 2015]"
    assert dict(hmm.metadata)["LENG"] == "40"
    assert hmm.M == 40
    assert hmm.alphabet == "ACDEFGHIKLMNPQRSTVWY"
    assert abs(hmm.match(2)["V"] - -2.72416) < 1e-6
    assert abs(hmm.insert(2)["V"] - -2.98518) < 1e-6
    assert abs(hmm.trans(3)["DD"] - -0.9551) < 1e-6
    assert abs(hmm.compo["N"] - -3.18565) < 1e-6

    output = str(hmm)
    assert "SM    hmmsearch -Z 45638612 -E 1000 --cpu 4 HMM pfamseq" in output

    hmm = hmmfile.read_model()
    assert dict(hmm.metadata)["LENG"] == "235"

    hmm = hmmfile.read_model()
    assert dict(hmm.metadata)["LENG"] == "449"

    buffer.close()
def test_hmmer_reader_fetch_metadata2(tmp_path: Path):
    buffer = pkg_resources.open_binary(hmmer_reader.data, "three-profs.hmm.gz")

    content = gzip.decompress(buffer.read()).decode()
    os.chdir(tmp_path)
    with open("db.hmm", "w") as file:
        file.write(content)

    df = fetch_metadata(tmp_path / "db.hmm")
    assert df.shape == (3, 4)

    assert df["NAME"].values[0] == "1-cysPrx_C"
    assert df["ACC"].values[0] == "PF10417.9"
    assert df["LENG"].values[0] == 40
    assert df["ALPH"].values[0] == "amino"

    assert df["NAME"].values[1] == "120_Rick_ant"
    assert df["ACC"].values[1] == "PF12574.8"
    assert df["LENG"].values[1] == 235
    assert df["ALPH"].values[1] == "amino"

    assert df["NAME"].values[2] == "12TM_1"
    assert df["ACC"].values[2] == "PF09847.9"
    assert df["LENG"].values[2] == 449
    assert df["ALPH"].values[2] == "amino"

    assert df["NAME"].dtype is dtype("O")
    assert df["ACC"].dtype is dtype("O")
    assert df["LENG"].dtype is dtype("int32")
    assert df["ALPH"].dtype is dtype("O")

    assert tuple(df.columns) == ("NAME", "ACC", "LENG", "ALPH")
示例#5
0
def evaluate_mpii_validation_accuracy(preds):
    threshold = 0.5
    SC_BIAS = 0.6

    dict = loadmat(open_binary(stacked_hourglass.res, 'detections_our_format.mat'))
    jnt_missing = dict['jnt_missing']
    pos_gt_src = dict['pos_gt_src']
    headboxes_src = dict['headboxes_src']

    preds = np.array(preds)
    assert preds.shape == (pos_gt_src.shape[2], pos_gt_src.shape[0], pos_gt_src.shape[1])
    pos_pred_src = np.transpose(preds, [1, 2, 0])

    jnt_visible = 1 - jnt_missing
    uv_error = pos_pred_src - pos_gt_src
    uv_err = np.linalg.norm(uv_error, axis=1)
    headsizes = headboxes_src[1, :, :] - headboxes_src[0, :, :]
    headsizes = np.linalg.norm(headsizes, axis=0)
    headsizes *= SC_BIAS
    scale = np.multiply(headsizes, np.ones((len(uv_err), 1)))
    scaled_uv_err = np.divide(uv_err, scale)
    scaled_uv_err = np.multiply(scaled_uv_err, jnt_visible)
    jnt_count = np.sum(jnt_visible, axis=1)
    less_than_threshold = np.multiply((scaled_uv_err < threshold), jnt_visible)
    PCKh = np.divide(100. * np.sum(less_than_threshold, axis=1), jnt_count)

    PCKh = np.ma.array(PCKh, mask=False)
    PCKh.mask[6:8] = True

    return PCKh
示例#6
0
 def open_binary(self, *args):
     bin_fd = open_binary(*args)
     if self.in_memory:
         mem_bin_fd = BytesIO(bin_fd.read())
         mem_bin_fd.seek(0)
         bin_fd.close()
         return mem_bin_fd
     else:
         return bin_fd
 def open_binary(self, *args):
     bin_fd = open_binary(*args)
     if self.in_memory:
         mem_bin_fd = BytesIO(bin_fd.read())
         mem_bin_fd.seek(0)
         bin_fd.close()
         return mem_bin_fd
     else:
         return bin_fd
def test_hmmer_reader_fetch_metadata_corrupted3(tmp_path: Path):
    buffer = pkg_resources.open_binary(hmmer_reader.data, "corrupted3.hmm.gz")

    content = gzip.decompress(buffer.read()).decode()
    os.chdir(tmp_path)
    with open("db.hmm", "w") as file:
        file.write(content)

    with pytest.raises(ParsingError):
        fetch_metadata(tmp_path / "db.hmm")
示例#9
0
    def setUp(self):
        with open_binary('tests.data', 'example02_image.jpg') as f:
            self.image: PIL.Image.Image = PIL.Image.open(f).copy()

        with open_text('tests.data', 'example02_camera.json') as f:
            camera_params = json.load(f)
            self.camera = CameraIntrinsics(
                torch.tensor(camera_params['intrinsic'])[:3])

        with open_text('tests.data', 'example02_univ_annot3.txt') as f:
            self.points = torch.as_tensor(np.loadtxt(f))
示例#10
0
def open_resource_binary(*path):
    """Return a file-like object opened for binary reading of the resource.

    If the resource does not already exist on its own on the file system,
    a temporary file will be created. If the file was created, it
    will be deleted upon exiting the context manager (no exception is
    raised if the directory was deleted prior to the context manager
    exiting).
    """
    if len(path) == 0:
        raise TypeError("must provide a path")
    file_name = path[-1]
    package = ".".join([RESOURCE_MODULE] + list(path[:-1]))
    return importlib_resources.open_binary(package, file_name)
示例#11
0
文件: app.py 项目: swatbotics/ursim
    def initialize_audio(self):

        snd = wave.open(open_binary('ursim.sounds', 'beep.wav'))
        params = snd.getparams()

        assert params.sampwidth == 2

        sdata = numpy.empty((params.nframes, params.nchannels),
                            dtype=numpy.int16)
        
        bytes_per_frame = params.nchannels * params.sampwidth
        blocksize = 1024
        
        cur_frame = 0

        while True:
            
            block_bytes = snd.readframes(blocksize)
            block_array = numpy.frombuffer(block_bytes, dtype=sdata.dtype)
            block_array = block_array.reshape(-1, params.nchannels)

            frames_read = len(block_array)

            sdata[cur_frame:cur_frame+frames_read] = block_array
            cur_frame += frames_read

            if frames_read < blocksize:
                break

        assert cur_frame == params.nframes

        self.snd_should_play = False
        self.snd_playback_frame = 0

        self.snd_data = sdata

        try:

            self.stream = sounddevice.OutputStream(samplerate=params.framerate,
                                                   channels=params.nchannels,
                                                   dtype='int16',
                                                   blocksize=1024,
                                                   callback=self.snd_callback)

            self.stream.start()

        except:

            self.stream = None
示例#12
0
def tmp_path_with_ui_fixture(
        tmp_path_factory: pytest.TempPathFactory) -> pathlib.Path:
    directory_path = tmp_path_factory.mktemp(
        basename="tmp_path_with_ui_fixture", numbered=True)

    name = "example.ui"

    ui_source_file = importlib_resources.open_binary(package=ssst._tests,
                                                     resource=name)
    ui_target_path = directory_path.joinpath(name)

    with ui_target_path.open("wb") as ui_target_file:
        shutil.copyfileobj(ui_source_file, ui_target_file)

    return directory_path
def test_cli_out_of_range():

    buffer = pkg_resources.open_binary(hmmer_reader.data, "PF02545.hmm.gz")
    text = gzip.decompress(buffer.read()).decode()

    runner = CliRunner()
    with runner.isolated_filesystem():

        def invoke(cmd):
            return runner.invoke(hmmer_reader.cli, cmd)

        with open("PF02545.hmm", "w") as f:
            f.write(text)

        r = invoke(["PF02545.hmm", "--match", "167"])
        assert r.exit_code == 1
示例#14
0
文件: qt.py 项目: hibtc/madgui
def load_ui(widget, package, filename):
    """
    Initialize widget from ``.uic`` file loaded from the given package.

    This function is for loading GUIs that were developed using the qt-designer
    rapid development tool which creates ``.uic`` description files. These can
    be saved in the same package alongside the corresponding python code. Now,
    in the class that implements the widget, use this function as follows::

        class MyWidget(QWidget):

            def __init__(self):
                super().__init__()
                load_ui(self, __package__, 'mywidget.uic')
    """
    with open_binary(package, filename) as f:
        uic.loadUi(f, widget)
示例#15
0
文件: qt.py 项目: CSRAccTeam/madgui
def load_ui(widget, package, filename):
    """
    Initialize widget from ``.uic`` file loaded from the given package.

    This function is for loading GUIs that were developed using the qt-designer
    rapid development tool which creates ``.uic`` description files. These can
    be saved in the same package alongside the corresponding python code. Now,
    in the class that implements the widget, use this function as follows::

        class MyWidget(QWidget):

            def __init__(self):
                super().__init__()
                load_ui(self, __package__, 'mywidget.uic')
    """
    with open_binary(package, filename) as f:
        uic.loadUi(f, widget)
示例#16
0
 def test_utf7_message_with_inline_ascii_sig(self):
     # The test message is bigger than 1K.  Set the threshold bigger to
     # avoid double processing in make_digest_messages.
     self._mlist.digest_size_threshold = 5
     # Subscribe some users receiving digests.
     anne = subscribe(self._mlist, 'Anne')
     anne.preferences.delivery_mode = DeliveryMode.mime_digests
     bart = subscribe(self._mlist, 'Bart')
     bart.preferences.delivery_mode = DeliveryMode.plaintext_digests
     with open_binary('mailman.runners.tests.data',
                      'ascii_in_utf7.eml') as fp:
         msg = message_from_binary_file(fp, Message)
     # Use any error logs as the error message if the test fails.
     error_log = LogFileMark('mailman.error')
     make_digest_messages(self._mlist, msg)
     # The runner will send the file to the shunt queue on exception.
     self.assertEqual(len(self._shuntq.files), 0, error_log.read())
     self._check_virgin_queue()
def configure_run(scanner, plate_type, plates, orientation, parse_dates):
    config = dict()
    config["parse_dates"] = parse_dates
    if parse_dates:
        config["index_name"] = "time"
    else:
        config["index_name"] = "source"
    if plates is None:
        config["plate_names"] = PLATES[scanner]
    else:
        allowed = frozenset(PLATES[scanner])
        for p in plates:
            if p not in allowed:
                raise ValueError(
                    "Specified tray '{}' does not exist or only on the other "
                    "scanner.".format(p))
        config["plate_names"] = plates

    plate_index = {p: i for i, p in enumerate(PLATES[scanner])}
    config["plate_indexes"] = [plate_index[p] for p in config["plate_names"]]

    with open_binary(gp_align.data, "plate_specs.json") as file_handle:
        plate_specs = json.load(file_handle)
    rows, columns = plate_specs["rows_and_columns"][str(plate_type)]
    config["rows"] = rows
    config["columns"] = columns
    LOGGER.debug("Plate type %d has %d rows and %d columns.", plate_type,
                 rows, columns)

    calibration_name_left = "calibration_type_{:d}_left".format(plate_type)
    with path(gp_align.data, calibration_name_left + ".png") as file_path:
        config["left_image"] = detect_edges(file_path)

    calibration_name_right = "calibration_type_{:d}_right".format(plate_type)
    with path(gp_align.data, calibration_name_right + ".png") as file_path:
        config["right_image"] = detect_edges(file_path)

    config["well_names"] = well_names(rows, columns, orientation)
    config["plate_size"] = plate_specs["plate_size"]
    config["left_positions"] = plate_specs[
        "plate_positions"][calibration_name_left]
    config["right_positions"] = plate_specs[
        "plate_positions"][calibration_name_right]
    return config
示例#18
0
def configure_run(scanner, plate_type, plates, orientation, parse_dates):
    config = dict()
    config["parse_dates"] = parse_dates
    if parse_dates:
        config["index_name"] = "time"
    else:
        config["index_name"] = "source"
    if plates is None:
        config["plate_names"] = PLATES[scanner]
    else:
        allowed = frozenset(PLATES[scanner])
        for p in plates:
            if p not in allowed:
                raise ValueError(
                    "Specified tray '{}' does not exist or only on the other "
                    "scanner.".format(p))
        config["plate_names"] = plates

    plate_index = {p: i for i, p in enumerate(PLATES[scanner])}
    config["plate_indexes"] = [plate_index[p] for p in config["plate_names"]]

    with open_binary(gp_align.data, "plate_specs.json") as file_handle:
        plate_specs = json.load(file_handle)
    rows, columns = plate_specs["rows_and_columns"][str(plate_type)]
    config["rows"] = rows
    config["columns"] = columns
    LOGGER.debug("Plate type %d has %d rows and %d columns.", plate_type, rows,
                 columns)

    calibration_name_left = "calibration_type_{:d}_left".format(plate_type)
    with path(gp_align.data, calibration_name_left + ".png") as file_path:
        config["left_image"] = detect_edges(file_path)

    calibration_name_right = "calibration_type_{:d}_right".format(plate_type)
    with path(gp_align.data, calibration_name_right + ".png") as file_path:
        config["right_image"] = detect_edges(file_path)

    config["well_names"] = well_names(rows, columns, orientation)
    config["plate_size"] = plate_specs["plate_size"]
    config["left_positions"] = plate_specs["plate_positions"][
        calibration_name_left]
    config["right_positions"] = plate_specs["plate_positions"][
        calibration_name_right]
    return config
示例#19
0
    def __init__(self):

        super().__init__()

        self.create_window('Hello World', 800, 600)

        gl.Enable(gl.CULL_FACE)
        gl.Enable(gl.FRAMEBUFFER_SRGB)

        self.framebuffer = gfx.Framebuffer(512, 512)

        self.texture = gfx.load_texture(
            open_binary('ursim.textures', 'monalisa.jpg'), 'RGB')

        self.fsquad = gfx.FullscreenQuad(self.texture)

        ballpos = gfx.translation_matrix(gfx.vec3(1.5, 0, 0))

        cylpos = gfx.translation_matrix(gfx.vec3(0, 1.5, 0))

        self.objects = [
            gfx.IndexedPrimitives.box(gfx.vec3(1, 1, 1),
                                      gfx.vec3(0.5, 0.75, 1.0),
                                      texture=None),
            gfx.IndexedPrimitives.sphere(0.5,
                                         32,
                                         24,
                                         gfx.vec3(1, 0, 0),
                                         model_pose=ballpos),
            gfx.IndexedPrimitives.cylinder(0.5,
                                           1,
                                           32,
                                           1,
                                           gfx.vec3(1, 0, 1),
                                           model_pose=cylpos)
        ]

        self.box = self.objects[0]

        self.mouse_pos = numpy.array(self.framebuffer_size / 2,
                                     dtype=numpy.float32)

        self.handle_mouse_rot()
def test_hmmer_reader():
    buffer = pkg_resources.open_binary(hmmer_reader.data, "PF02545.hmm.gz")

    content = gzip.decompress(buffer.read()).decode()
    hmmfile = open_hmmer(StringIO(content))

    hmm = hmmfile.read_model()
    assert hmm.header == "HMMER3/f [3.1b2 | February 2015]"
    assert dict(hmm.metadata)["LENG"] == "166"
    assert hmm.M == 166
    assert hmm.alphabet == "ACDEFGHIKLMNPQRSTVWY"
    assert abs(hmm.match(2)["V"] - -2.0152) < 1e-6
    assert abs(hmm.insert(2)["V"] - -2.98518) < 1e-6
    assert abs(hmm.trans(83)["DD"] - -0.94424) < 1e-6
    assert abs(hmm.compo["N"] + 3.21795) < 1e-6

    output = str(hmm)
    assert "SM    hmmsearch -Z 45638612 -E 1000 --cpu 4 HMM pfamseq" in output

    buffer.close()
def test_hmmer_reader_nt():
    buffer = pkg_resources.open_binary(hmmer_reader.data,
                                       "2OG-FeII_Oxy_3-nt.hmm.gz")

    content = gzip.decompress(buffer.read()).decode()
    hmmfile = open_hmmer(StringIO(content))

    hmm = hmmfile.read_model()
    assert hmm.header == "HMMER3/f [3.1b2 | February 2015]"
    assert dict(hmm.metadata)["LENG"] == "315"
    assert hmm.M == 315
    assert hmm.alphabet == "ACGT"
    assert abs(hmm.match(2)["A"] - -2.35771) < 1e-6
    assert abs(hmm.insert(2)["G"] - -1.38629) < 1e-6
    assert abs(hmm.trans(83)["DD"] - -0.40547) < 1e-6
    assert abs(hmm.compo["T"] - -1.50794) < 1e-6

    output = str(hmm)
    assert "DATE  Sun May 24 19:35:19 2015" in output

    buffer.close()
def test_hmmer_reader_fetch_metadata1(tmp_path: Path):
    buffer = pkg_resources.open_binary(hmmer_reader.data, "PF02545.hmm.gz")

    content = gzip.decompress(buffer.read()).decode()
    os.chdir(tmp_path)
    with open("db.hmm", "w") as file:
        file.write(content)

    df = fetch_metadata(tmp_path / "db.hmm")
    assert df.shape == (1, 4)
    assert df["NAME"].values[0] == "Maf"
    assert df["ACC"].values[0] == "PF02545.14"
    assert df["LENG"].values[0] == 166
    assert df["ALPH"].values[0] == "amino"

    assert df["NAME"].dtype is dtype("O")
    assert df["ACC"].dtype is dtype("O")
    assert df["LENG"].dtype is dtype("int32")
    assert df["ALPH"].dtype is dtype("O")

    assert tuple(df.columns) == ("NAME", "ACC", "LENG", "ALPH")
示例#23
0
    def __init__(self,
                 image_path,
                 is_train=True,
                 inp_res=256,
                 sigma=1,
                 scale_factor=0.25,
                 rot_factor=30,
                 label_type='Gaussian'):
        self.img_folder = image_path  # root image folders
        self.is_train = is_train  # training set or test set
        if not isinstance(inp_res,
                          (list, tuple)):  # Input res stored as (H, W)
            self.inp_res = [inp_res, inp_res]
        else:
            self.inp_res = inp_res
        self.out_res = [
            int(self.inp_res[0] / self.INPUT_OUTPUT_RATIO),
            int(self.inp_res[1] / self.INPUT_OUTPUT_RATIO)
        ]
        self.sigma = sigma
        self.scale_factor = scale_factor
        self.rot_factor = rot_factor
        self.label_type = label_type

        # create train/val split

        with gzip.open(
                open_binary(stacked_hourglass.res,
                            'mpii_annotations.json.gz')) as f:
            self.anno = json.load(f)

        self.train_list, self.valid_list = [], []
        for idx, val in enumerate(self.anno):
            if val['isValidation'] == True:
                self.valid_list.append(idx)
            else:
                self.train_list.append(idx)
示例#24
0
 def execute(self, package, path):
     with resources.open_binary(package, path):
         pass
示例#25
0
 def open(self):
     return pkg_resources.open_binary(self.module, str(self.rel_path))
示例#26
0
def dockerfile(file, binary=True):
    if binary:
        return pkg_resources.open_binary(dockerfiles, file)
    else:
        return pkg_resources.open_text(dockerfiles, file)
示例#27
0
def script(file, binary=True):
    if binary:
        return pkg_resources.open_binary(sh, file)
    else:
        return pkg_resources.open_text(sh, file)
def test_cli_frame():

    buffer = pkg_resources.open_binary(hmmer_reader.data, "PF02545.hmm.gz")
    text = gzip.decompress(buffer.read()).decode()

    runner = CliRunner()
    with runner.isolated_filesystem():

        def invoke(cmd):
            return runner.invoke(hmmer_reader.cli, cmd)

        with open("PF02545.hmm", "w") as f:
            f.write(text)

        r = invoke(["PF02545.hmm"])
        assert "STATS LOCAL MSV       -9.9559  0.70785" in r.stdout

        r = invoke(["PF02545.hmm", "--alphabet"])
        assert r.stdout.strip() == "ACDEFGHIKLMNPQRSTVWY"

        r = invoke(["PF02545.hmm", "--length"])
        assert r.stdout.strip() == "166"

        r = invoke(["PF02545.hmm", "--match", "0"])
        tbl = parse_table(r.stdout)
        assert tbl["A"] == 1.0
        assert tbl["C"] == 0.0

        r = invoke(["PF02545.hmm", "--match", "0"])
        tbl = parse_table(r.stdout)
        assert tbl["A"] == 1.0
        assert tbl["C"] == 0.0

        r = invoke(["PF02545.hmm", "--match", "1"])
        tbl = parse_table(r.stdout)
        assert abs(tbl["A"] - 0.063306327140559060) < 1e-7
        assert abs(tbl["C"] - 0.004970275538839500) < 1e-7

        r = invoke(["PF02545.hmm", "--match", "0", "--log"])
        tbl = parse_table(r.stdout)
        assert tbl["A"] == 0.0
        assert isinf(tbl["C"])

        r = invoke(["PF02545.hmm", "--match", "1", "--log"])
        tbl = parse_table(r.stdout)
        assert abs(tbl["A"] - log(0.063306327140559060)) < 1e-7
        assert abs(tbl["C"] - log(0.004970275538839500)) < 1e-7

        r = invoke(["PF02545.hmm", "--insert", "166"])
        tbl = parse_table(r.stdout)
        assert abs(tbl["M"] - 0.014308521644640306) < 1e-7
        assert abs(tbl["Y"] - 0.026916117721584094) < 1e-7

        r = invoke(["PF02545.hmm", "--insert", "166", "--log"])
        tbl = parse_table(r.stdout)
        assert abs(tbl["M"] - log(0.014308521644640306)) < 1e-7
        assert abs(tbl["Y"] - log(0.026916117721584094)) < 1e-7

        r = invoke(["PF02545.hmm", "--match", "5", "--sort"])
        assert "A 0.6014030" in r.stdout.strip().splitlines()[0].strip()
        assert "G 0.1542099" in r.stdout.strip().splitlines()[1].strip()
示例#29
0
 def test_open_binary(self):
     with resources.open_binary(self.data, 'utf-8.file') as fp:
         result = fp.read()
         self.assertEqual(result, b'Hello, UTF-8 world!\n')
    def __init__(self):
        # open all the files in binary reading mode
        # for more info on what is stored in which .bin file, please read the comments in file_converter.py
        self.poly_zone_ids = open_binary('timezonefinder', 'poly_zone_ids.bin')
        self.poly_coord_amount = open_binary('timezonefinder', 'poly_coord_amount.bin')
        self.poly_adr2data = open_binary('timezonefinder', 'poly_adr2data.bin')
        self.poly_data = open_binary('timezonefinder', 'poly_data.bin')
        self.poly_max_values = open_binary('timezonefinder', 'poly_max_values.bin')
        self.poly_nr2zone_id = open_binary('timezonefinder', 'poly_nr2zone_id.bin')

        self.hole_poly_ids = open_binary('timezonefinder', 'hole_poly_ids.bin')
        self.hole_coord_amount = open_binary('timezonefinder', 'hole_coord_amount.bin')
        self.hole_adr2data = open_binary('timezonefinder', 'hole_adr2data.bin')
        self.hole_data = open_binary('timezonefinder', 'hole_data.bin')

        self.shortcuts_entry_amount = open_binary('timezonefinder', 'shortcuts_entry_amount.bin')
        self.shortcuts_adr2data = open_binary('timezonefinder', 'shortcuts_adr2data.bin')
        self.shortcuts_data = open_binary('timezonefinder', 'shortcuts_data.bin')
        self.shortcuts_unique_id = open_binary('timezonefinder', 'shortcuts_unique_id.bin')

        # store for which polygons (how many) holes exits and the id of the first of those holes
        # since there are very few (+-22) it is feasible to keep them in the memory
        self.hole_registry = {}
        # read the polygon ids for all the holes
        for i, block in enumerate(iter(lambda: self.hole_poly_ids.read(2), b'')):
            poly_id = unpack(b'<H', block)[0]
            try:
                amount_of_holes, hole_id = self.hole_registry[poly_id]
                self.hole_registry.update({
                    poly_id: (amount_of_holes + 1, hole_id),
                })
            except KeyError:
                self.hole_registry.update({
                    poly_id: (1, i),
                })
示例#31
0
 def __call__(self, language_code=None):
     if language_code in ('en', None):
         return NullTranslations()
     mo_file = 'mailman-%s.mo' % language_code
     with open_binary('mailman.testing', mo_file) as fp:
         return GNUTranslations(fp)