Refact, remove some property from CableSum. Refact. fill_q_vector and get_layers function

This commit is contained in:
Maria Marchwicka 2020-11-05 19:18:01 +01:00
parent 96b4860d2e
commit 84a4c2a082
3 changed files with 26 additions and 87 deletions

View File

@ -18,8 +18,9 @@ class CableSummand():
def __init__(self, knot_as_k_values): def __init__(self, knot_as_k_values):
self.knot_as_k_values = knot_as_k_values self.knot_as_k_values = knot_as_k_values
self._knot_description = self.get_summand_descrption(knot_as_k_values) self.knot_description = self.get_summand_descrption(knot_as_k_values)
self._signature_as_function_of_theta = None self.signature_as_function_of_theta = \
self.get_summand_signature_as_theta_function()
@staticmethod @staticmethod
@ -32,18 +33,6 @@ class CableSummand():
description += "2, " + str(2 * abs(k) + 1) + "; " description += "2, " + str(2 * abs(k) + 1) + "; "
return description[:-2] + ")" return description[:-2] + ")"
@property
def knot_description(self):
return self._knot_description
@property
def signature_as_function_of_theta(self):
if self._signature_as_function_of_theta is None:
self._signature_as_function_of_theta = \
self.get_summand_signature_as_theta_function()
return self._signature_as_function_of_theta
@classmethod @classmethod
def get_blanchfield_for_pattern(cls, k_n, theta=0): def get_blanchfield_for_pattern(cls, k_n, theta=0):
@ -137,7 +126,6 @@ class CableSummand():
for a in range(k + 1, q)})) for a in range(k + 1, q)}))
return SignatureFunction(counter=counter) return SignatureFunction(counter=counter)
def get_summand_signature_as_theta_function(self): def get_summand_signature_as_theta_function(self):
knot_as_k_values = self.knot_as_k_values knot_as_k_values = self.knot_as_k_values
def get_summand_signture_function(theta): def get_summand_signture_function(theta):
@ -167,7 +155,6 @@ class CableSummand():
name += "_theta_" + str(theta) name += "_theta_" + str(theta)
return name return name
def plot_summand_for_theta(self, theta, save_path=None): def plot_summand_for_theta(self, theta, save_path=None):
pp, sp = self.signature_as_function_of_theta(theta) pp, sp = self.signature_as_function_of_theta(theta)
title = self.knot_description + ", theta = " + str(theta) title = self.knot_description + ", theta = " + str(theta)
@ -176,15 +163,25 @@ class CableSummand():
save_path = os.path.join(save_path, file_name) save_path = os.path.join(save_path, file_name)
pp.plot_sum_with_other(sp, title=title, save_path=save_path) pp.plot_sum_with_other(sp, title=title, save_path=save_path)
def plot_summand(self): def plot_summand(self):
range_limit = min(self.knot_as_k_values[-1] + 1, 3) range_limit = min(self.knot_as_k_values[-1] + 1, 3)
for theta in range(range_limit): for theta in range(range_limit):
self.plot_summand_for_theta(theta) self.plot_summand_for_theta(theta)
class CableSum(): class CableSum():
def __init__(self, knot_sum): def __init__(self, knot_sum):
self.knot_sum_as_k_valus = knot_sum self.knot_sum_as_k_valus = knot_sum
self.knot_description = self.get_knot_descrption(knot_sum)
self.patt_k_list = [abs(i[-1]) for i in knot_sum]
self.patt_q_list = [2 * i + 1 for i in self.patt_k_list]
if any(n not in Primes() for n in self.patt_q_list):
msg = "Incorrect k- or q-vector. This implementation assumes that"\
+ " all last q values are prime numbers.\n" + \
str(self.patt_q_list)
raise ValueError(msg)
self.q_order = LCM_list(self.patt_q_list)
self.knot_summands = [CableSummand(k) for k in knot_sum] self.knot_summands = [CableSummand(k) for k in knot_sum]
self.signature_as_function_of_theta = \ self.signature_as_function_of_theta = \
self.get_signature_as_function_of_theta() self.get_signature_as_function_of_theta()
@ -253,43 +250,6 @@ class CableSum():
knot.plot_summand() knot.plot_summand()
@property
def knot_description(self):
return self._knot_description
@property
def patt_k_list(self):
return self._patt_k_list
@property
def patt_q_list(self):
return self._patt_q_list
# q_order is LCM of all q values for pattern knots
@property
def q_order(self):
return self._q_order
@q_order.setter
def q_order(self, val):
self._q_order = val
@property
def knot_sum_as_k_valus(self):
return self._knot_sum_as_k_valus
@knot_sum_as_k_valus.setter
def knot_sum_as_k_valus(self, knot_sum):
self._knot_sum_as_k_valus = knot_sum
self._knot_description = self.get_knot_descrption(knot_sum)
self._patt_k_list = [abs(i[-1]) for i in knot_sum]
self._patt_q_list = [2 * i + 1 for i in self._patt_k_list]
if any(n not in Primes() for n in self._patt_q_list):
msg = "Incorrect q-vector. This implementation assumes that" + \
" all last q values are prime numbers.\n" + \
str(self._patt_q_list)
raise ValueError(msg)
self.q_order = LCM_list(self._patt_q_list)
def parse_thetas(self, *thetas): def parse_thetas(self, *thetas):
summands_num = len(self.knot_sum_as_k_valus) summands_num = len(self.knot_sum_as_k_valus)
if not thetas: if not thetas:
@ -441,9 +401,7 @@ class CableTemplate():
return self._cable return self._cable
def fill_q_vector(self, q_vector=None, slice=True): def fill_q_vector(self, q_vector=None, slice=True):
if q_vector is None: self.q_vector = q_vector or self.get_q_vector(self.knot_formula, slice)
q_vector = self.get_q_vector(self.knot_formula)
self.q_vector = q_vector
@property @property
def knot_formula(self): def knot_formula(self):
@ -499,10 +457,7 @@ class CableTemplate():
number_of_layers = max(len(lst) for lst in k_indices) number_of_layers = max(len(lst) for lst in k_indices)
layers = [] layers = []
for i in range(1, number_of_layers + 1): for i in range(1, number_of_layers + 1):
layer = set() layer = [lst[-i] for lst in k_indices if len(lst)>= i]
for lst in k_indices:
if len(lst) >= i:
layer.add(lst[-i])
layers.append(layer) layers.append(layer)
return layers return layers
@ -514,12 +469,8 @@ class CableTemplate():
def __add__(self, other): def __add__(self, other):
s_formula = self.knot_formula knot_formula = self.knot_formula[:-1] + ",\n" + other.knot_formula[1:]
o_formula = other.knot_formula return CableTemplate(knot_formula)
knot_formula = s_formula[:-1] + ",\n" + o_formula[1:]
cable_template = CableTemplate(knot_formula)
return cable_template
def mod_one(n): def mod_one(n):

View File

@ -68,7 +68,6 @@ def main(arg=None):
# knot_formula = config.knot_formula # knot_formula = config.knot_formula
# q_vector = (3, 5, 7, 13) # q_vector = (3, 5, 7, 13)
# q_vector = (3, 5, 7, 11) # q_vector = (3, 5, 7, 11)
return
formula_1 = "[[k[0], k[5], k[3]], " + \ formula_1 = "[[k[0], k[5], k[3]], " + \
"[-k[1], -k[3]], " + \ "[-k[1], -k[3]], " + \
@ -89,33 +88,23 @@ def main(arg=None):
cable_with_shift = cable_template_1.add_with_shift(cable_template_2) cable_with_shift = cable_template_1.add_with_shift(cable_template_2)
print(cable_with_shift.knot_formula) print(cable_with_shift.knot_formula)
cable_template.fill_q_vector() cable_template.fill_q_vector()
print(cable_template.q_vector)
print(cable_template.knot_formula)
cable = cable_template.cable cable = cable_template.cable
sf = cable(4,4,4,4,0,0,0,0) sf = cable(4,4,4,4,0,0,0,0)
writer = SignatureWriter(sf)
writer.plot(title="hoho")
sf = cable_template.cable.signature_as_function_of_theta(4,1,1,4,0,0,0,0) sf = cable_template.cable.signature_as_function_of_theta(4,1,1,4,0,0,0,0)
writer = SignatureWriter(sf)
writer.plot(title="hoho", color='red')
cable_template.cable.is_signature_big_for_all_metabolizers() # cable_template.cable.is_signature_big_for_all_metabolizers()
cable_template_1 = CableTemplate(knot_formula=formula_1) cable_template_1 = CableTemplate(knot_formula=formula_1)
cable_template_2 = CableTemplate(knot_formula=formula_2) cable_template_2 = CableTemplate(knot_formula=formula_2)
cable_template = cable_template_1 + cable_template_2 cable_template = cable_template_1 + cable_template_2
cable_template.cable.is_signature_big_for_all_metabolizers() # cable_template.cable.is_signature_big_for_all_metabolizers()
sf = cable_template.cable.signature_as_function_of_theta(4,4,4,4,0,0,0,0) # sf = cable_template.cable.signature_as_function_of_theta(4,4,4,4,0,0,0,0)
writer = SignatureWriter(sf)
writer.plot(title="hoho")

View File

@ -145,8 +145,7 @@ class SignatureFunction():
fig.suptitle(title) fig.suptitle(title)
plt.tight_layout() plt.tight_layout()
if save_path is None: save_path = save_path or os.path.join(os.getcwd(),"tmp.png")
save_path = os.path.join(os.getcwd(),"tmp.png")
save_path = Path(save_path) save_path = Path(save_path)
save_path = save_path.with_suffix('.png') save_path = save_path.with_suffix('.png')
@ -197,8 +196,8 @@ class SignatureFunction():
fig.suptitle(title) fig.suptitle(title)
plt.tight_layout() plt.tight_layout()
if save_path is None:
save_path = os.path.join(os.getcwd(),"tmp.png") save_path = save_path or os.path.join(os.getcwd(),"tmp.png")
save_path = Path(save_path) save_path = Path(save_path)
save_path = save_path.with_suffix('.png') save_path = save_path.with_suffix('.png')