Last active
March 11, 2024 11:42
-
-
Save giorgiopizz/5fa647b8de400bb984ce6935cb049ac3 to your computer and use it in GitHub Desktop.
Simple script to edit a MG restrict card and save it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import subprocess | |
class block: | |
def __init__(self, restrict, name='SMEFT'): | |
start = restrict.index(list(filter(lambda k: k == 'Block ' + name, restrict))[0]) + 1 | |
stop = restrict[start:].index('###################################') | |
stop = start + stop | |
smeft = list(map(lambda k: list(filter(lambda j: j != '', k.split(' '))), restrict[start: stop])) | |
self.smeft = list(filter(lambda k: len(k) == 4, smeft)) | |
self.start = start | |
self.stop = stop | |
self.ops = list(map(lambda k: k[-1], self.smeft)) | |
self.activate(ops=self.ops, val='0') | |
def activate(self, ops=[], val='9.999999e-01'): | |
for op in ops: | |
op_index = self.ops.index(op) | |
self.smeft[op_index][1] = val | |
def info(self): | |
return self.__dict__#{'start': self.start, 'stop': self.stop, 'smeft': self.smeft} | |
def format(self): | |
smeft_fmt = list(map(lambda k: ' ' + ' '.join(k), self.smeft)) | |
return smeft_fmt | |
#return {'start': self.start, 'stop': self.stop, 'smeft': self.smeft} | |
a = requests.get('https://raw.githubusercontent.com/GiuliaLavizzari/perGiacomo/67f5eec9fbfc7dad01ec17fb9a311d63b0d78e90/mySSWW/restrict_ssww_topU3l_noQ_nocHB_firsttry.dat') | |
restrict = a.text.split('\n') | |
a = block(restrict, 'SMEFT') | |
del restrict[a.start: a.stop] | |
restrict = restrict[:a.start] + a.format() + restrict[a.start:] | |
a = block(restrict, 'SMEFTcpv') | |
del restrict[a.start: a.stop] | |
cp_odd_ops = a.ops | |
restrict = restrict[:a.start] + a.format() + restrict[a.start:] | |
proc = subprocess.Popen('mkdir -p restrict_cards', shell=True) | |
proc.wait() | |
with open('restrict_cards/restrict_ssww_topU3l_noQ_nocHB_original.dat', 'w') as file: | |
file.write('\n'.join(restrict)) | |
for cp_odd_op in cp_odd_ops: | |
with open('restrict_cards/restrict_ssww_topU3l_noQ_nocHB_original.dat') as file: | |
restrict = file.read().split('\n') | |
a = block(restrict, 'SMEFTcpv') | |
del restrict[a.start: a.stop] | |
a.activate([cp_odd_op]) | |
restrict = restrict[:a.start] + a.format() + restrict[a.start:] | |
with open(f'restrict_cards/restrict_ssww_topU3l_noQ_nocHB_{cp_odd_op}.dat', 'w') as file: | |
file.write('\n'.join(restrict)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment