Commit cf9a4967 authored by Adam P. Goucher's avatar Adam P. Goucher

Ability to download syntheses from Catagolue

parent 96ccb199
Pipeline #56599373 passed with stages
in 7 minutes and 41 seconds
......@@ -2,6 +2,7 @@ import os
from .lowlevel import *
from numbers import Integral
from .crt import chinese_remainder, large_primes
from .samples import download_synthesis as dsynth
def randfill(item, shape):
......@@ -691,6 +692,22 @@ class Pattern(object):
return self.owner.download_samples(self.apgcode, self.getrule(), **kwargs)
def download_synthesis(self, tempfile='tempfile.rle', **kwargs):
rle = dsynth(self.apgcode, self.getrule(), tempfile=tempfile, **kwargs)
if rle is None:
synth = None
synth = self.owner.load(tempfile)
except OSError:
return synth
def period(self):
......@@ -68,6 +68,27 @@ class SampleSoupList(Sequence):
def __repr__(self):
return 'SampleSoupList(%r, %r, %r, %r)' % (, self.rule, self.symmetry, self.samples)
def download_synthesis(apgcode, rule, domain='', tempfile='tempfile'):
if ('_' in rule) and ('_' not in apgcode):
rule, apgcode = apgcode, rule
from urllib import urlretrieve
except ImportError:
from urllib.request import urlretrieve
url = domain + '/textsamples/' + apgcode + '/' + rule + '/synthesis'
urlretrieve(url, tempfile)
with open(tempfile, 'r') as f:
synthesis =
if 'x' not in synthesis:
return None
return synthesis
def download_samples(lt, apgcode, rule, domain='', tempfile='tempfile'):
if ('_' in rule) and ('_' not in apgcode):
......@@ -62,6 +62,10 @@ $3b3o3b2o3b2o3bo2bo7bo2bo12b3o$3bo2bo2b2o3b2o2bo3bo7bob2o12bo2bo$3bo
periods = [s[10000][-1000:1000, -1000:1000].period for s in samples['C2_2']]
self.assertEqual(periods[:20], [40]*20)
synth = pat.download_synthesis()
res = synth[1000]
self.assertEqual(res.period, 40)
def test_hashsoup(self):
x ="b3s23", "C1", "n_GcpqZ62YqD3310086454")
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