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 ...@@ -2,6 +2,7 @@ import os
from .lowlevel import * from .lowlevel import *
from numbers import Integral from numbers import Integral
from .crt import chinese_remainder, large_primes from .crt import chinese_remainder, large_primes
from .samples import download_synthesis as dsynth
def randfill(item, shape): def randfill(item, shape):
...@@ -691,6 +692,22 @@ class Pattern(object): ...@@ -691,6 +692,22 @@ class Pattern(object):
return self.owner.download_samples(self.apgcode, self.getrule(), **kwargs) 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
else:
synth = self.owner.load(tempfile)
try:
os.remove(tempfile)
except OSError:
pass
return synth
@property @property
def period(self): def period(self):
......
...@@ -68,6 +68,27 @@ class SampleSoupList(Sequence): ...@@ -68,6 +68,27 @@ class SampleSoupList(Sequence):
def __repr__(self): def __repr__(self):
return 'SampleSoupList(%r, %r, %r, %r)' % (self.lt, self.rule, self.symmetry, self.samples) return 'SampleSoupList(%r, %r, %r, %r)' % (self.lt, self.rule, self.symmetry, self.samples)
def download_synthesis(apgcode, rule, domain='https://gol.hatsya.co.uk', tempfile='tempfile'):
if ('_' in rule) and ('_' not in apgcode):
rule, apgcode = apgcode, rule
try:
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 = f.read()
if 'x' not in synthesis:
return None
else:
return synthesis
def download_samples(lt, apgcode, rule, domain='https://gol.hatsya.co.uk', tempfile='tempfile'): def download_samples(lt, apgcode, rule, domain='https://gol.hatsya.co.uk', tempfile='tempfile'):
if ('_' in rule) and ('_' not in apgcode): if ('_' in rule) and ('_' not in apgcode):
......
...@@ -62,6 +62,10 @@ $3b3o3b2o3b2o3bo2bo7bo2bo12b3o$3bo2bo2b2o3b2o2bo3bo7bob2o12bo2bo$3bo ...@@ -62,6 +62,10 @@ $3b3o3b2o3b2o3bo2bo7bo2bo12b3o$3bo2bo2b2o3b2o2bo3bo7bob2o12bo2bo$3bo
periods = [s[10000][-1000:1000, -1000:1000].period for s in samples['C2_2']] periods = [s[10000][-1000:1000, -1000:1000].period for s in samples['C2_2']]
self.assertEqual(periods[:20], [40]*20) self.assertEqual(periods[:20], [40]*20)
synth = pat.download_synthesis()
res = synth[1000]
self.assertEqual(res.period, 40)
def test_hashsoup(self): def test_hashsoup(self):
x = self.lt.hashsoup("b3s23", "C1", "n_GcpqZ62YqD3310086454") x = self.lt.hashsoup("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