Skip to content
Snippets Groups Projects
Commit c69e3d77 authored by Adam Morris's avatar Adam Morris
Browse files

Packaging, entrypoints and licence

parent cc2ec33a
No related branches found
No related tags found
1 merge request!1Packaging, entrypoints and licence
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
\ No newline at end of file
###############################################################################
# (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
image: python:latest image: python:latest
# Change pip's cache directory to be inside the project directory since we can pre-commit:
# only cache local items. stage: build
variables: before_script:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" - pip install pre-commit
script:
- pre-commit run --all-files
variables:
PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit
cache:
paths:
- ${PRE_COMMIT_HOME}
# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/topics/caching/
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
paths:
- .cache/pip
- venv/
build-env: .setup_environment:
stage: build before_script:
script:
- python --version ; pip --version # For debugging - python --version ; pip --version # For debugging
- pip install virtualenv - pip install virtualenv
- virtualenv venv - virtualenv venv
- source venv/bin/activate - source venv/bin/activate
- pip install numpy - pip install .
extract-and-convert-table-2018-050: extract-and-convert-table-2018-050:
extends: .setup_environment
stage: test stage: test
script: script:
- source venv/bin/activate - gethepdata extract_tables -f "TestAnalyses/LHCb-PAPER-2018-050/bfrac-13.tex"
- python extract_tables_from_source.py -f "TestAnalyses/LHCb-PAPER-2018-050/bfrac-13.tex" - gethepdata extract_tables -f "TestAnalyses/LHCb-PAPER-2018-050/Supplementary.tex"
- python extract_tables_from_source.py -f "TestAnalyses/LHCb-PAPER-2018-050/Supplementary.tex" - gethepdata tex_to_yaml --file "ptB.tex" --format "i d stat sys d stat sys"
- python tex_to_yaml.py --file "ptB.tex" --format "i d stat sys d stat sys"
- ls *.yaml | grep "ptB.yaml" - ls *.yaml | grep "ptB.yaml"
needs: ["build-env"]
artifacts: artifacts:
when: always when: always
extract-and-convert-table-2020-018: extract-and-convert-table-2020-018:
extends: .setup_environment
stage: test stage: test
needs: ["build-env"]
script: script:
- source venv/bin/activate - gethepdata extract_tables -f "TestAnalyses/LHCb-PAPER-2020-018/main.tex"
- python extract_tables_from_source.py -f "TestAnalyses/LHCb-PAPER-2020-018/main.tex" - gethepdata tex_to_yaml --file eta_results.tex --format "i d e d e d e"
- python tex_to_yaml.py --file eta_results.tex --format "i d e d e d e"
- ls *.yaml | grep "eta_results.yaml" - ls *.yaml | grep "eta_results.yaml"
artifacts: artifacts:
when: always when: always
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: no-commit-to-branch
args: [--branch, main]
- repo: https://gitlab.cern.ch/lhcb-core/LbDevTools
rev: 2.0.40
hooks:
- id: lb-add-copyright
COPYING 0 → 100644
This diff is collapsed.
# HepDataExtractor # HepDataExtractor
Simple python scripts to extract tables from LaTeX papers and convert them to HepData entries Simple python tool to extract tables from LaTeX papers and convert them to HepData entries
## Helping to Develop ## Helping to Develop
...@@ -12,37 +12,37 @@ Spotted an error? Need something special you think is useable by others? Create ...@@ -12,37 +12,37 @@ Spotted an error? Need something special you think is useable by others? Create
### I have a LaTeX file with just the tables I want to process ### I have a LaTeX file with just the tables I want to process
In some ways this is the easiest way to do things! You can simply pass the file to `tex_to_yaml.py` via the command line, e.g. In some ways this is the easiest way to do things! You can simply pass the file to `tex_to_yaml` via the command line, e.g.
``` ```
python tex_to_yaml.py --file myfile.tex --format "i d stat syst d stat syst" gethepdata tex_to_yaml --file myfile.tex --format "i d stat syst d stat syst"
``` ```
if you need help with the command line documents, type if you need help with the command line documents, type
``` ```
python tex_to_yaml.py --help gethepdata tex_to_yaml --help
``` ```
### I have a document which I want to process the tables for ### I have a document which I want to process the tables for
Not a problem! The script `extract_tables_from_source.py` extracts all the tables from a document (including recursively by passing only the `main.tex` file). You can call from the command line using Not a problem! The command `extract_tables` extracts all the tables from a document (including recursively by passing only the `main.tex` file). You can call from the command line using
``` ```
python extract_tables_from_source.py --file /path/to/main.tex gethepdata extract_tables --file /path/to/main.tex
``` ```
which will then use the `\label` argument to determine the tex file name. which will then use the `\label` argument to determine the `.tex` file name.
### My submission is ready! Create the `submission.yaml` file ### My submission is ready! Create the `submission.yaml` file
Once you have all tables in the `.yaml` format, you can run the script `make_submission_yaml_file.py` to create the relevant file suitable for hepdata submission Once you have all tables in the `.yaml` format, you can run the command `prepare_submission` to create the relevant file suitable for HepData submission
``` ```
python make_submission_yaml_file.py --files *.yaml gethepdata prepare_submission --files *.yaml
``` ```
This will create the `submission.yaml` based on the *.yaml files produced by the `tex_to_yaml.py` step. This will create the `submission.yaml` based on the output of the `tex_to_yaml` step.
Original Author: Harvey Turner, Manchester, supervised by Adam Davis and Will Barter. Updated 11 August 2023 by Adam Davis Original Author: Harvey Turner, Manchester, supervised by Adam Davis and Will Barter. Updated 11 August 2023 by Adam Davis
\ No newline at end of file
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
[project]
name = "HepDataExtractor"
dependencies = [
"pyyaml",
"numpy"
]
dynamic = ["version"]
description = "Simple python tool to extract tables from LaTeX papers and convert them to HepData entries"
authors = [
{name = "Adam Davis"},
{name = "Harvey Turner"},
{name = "Will Barter"}
]
maintainers = [
{name = "LHCb Simulation"}
]
readme = "README.md"
classifiers = [
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 3"
]
[project.urls]
Repository = "https://gitlab.cern.ch/lhcb-simulation/hepdataextractor"
"Bug Tracker" = "https://gitlab.cern.ch/lhcb-simulation/hepdataextractor/-/issues"
[project.scripts]
gethepdata = "HepDataExtractor.__main__:parse_args"
###############################################################################
# (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
###############################################################################
# (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
import argparse
from .extract_tables_from_source import main as etfs
from .make_submission_yaml_file import main as msyf
from .tex_to_yaml import main as tty
def parse_args():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="action", required=True)
# extract_tables_from_source
etfs_parser = subparsers.add_parser("extract_tables")
etfs_parser.add_argument('-f','--file',type=str,required=True,help='input file to parse')
etfs_parser.add_argument('--no_output',action="store_true",help='skip output')
etfs_parser.set_defaults(func=etfs)
# tex_to_yaml
tty_parser = subparsers.add_parser("tex_to_yaml")
tty_parser.add_argument("--file", type=str,required=True,help='file contains name of data file')
tty_parser.add_argument("--format", type=str, required=False,help='''format contains string of data format (not necessary for covariance)
A guide: i -- independent variable,
d -- dependent variable,
stat -- statistical error,
sys -- systematic error''')
tty_parser.add_argument("--covariance", action="store_true", default=False,help='Flag to say whether the data is a covariance matrix or not') #
tty_parser.add_argument("--correlation", action="store_true", default=False,help='Same as covariance, but for a correlation matrix') #
tty_parser.add_argument("--qualifiers", type=str, default="None",help='qualifiers contains name of qualifiers file, defaults to "None"')
tty_parser.add_argument("--remove", nargs='+', help="list of terms to remove from table")
tty_parser.set_defaults(func=tty)
# make_submission_yaml_file
msyf_parser = subparsers.add_parser("prepare_submission",
description="Preparation of submission.yaml file for HepData submission. "
"Requires the data yaml files produced from tex_to_yaml to be provided")
msyf_parser.add_argument('-f','--files',type=str,nargs='+',required=True,help='input yaml file(s) to parse. Note, can pass *.yaml')
msyf_parser.set_defaults(func=msyf)
args = parser.parse_args()
args.func(args)
###############################################################################
# (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
import sys,os import sys,os
def extract_tables(sourcefile): def extract_tables(sourcefile):
...@@ -14,42 +24,36 @@ def extract_tables(sourcefile): ...@@ -14,42 +24,36 @@ def extract_tables(sourcefile):
return tables_in_paper return tables_in_paper
with open(sourcefile) as f: with open(sourcefile) as f:
lines = f.readlines() lines = f.readlines()
for i in range(len(lines)): for i in range(len(lines)):
if 'begin{table}' in lines[i] or 'begin{sidewaystable}' in lines[i]: if 'begin{table}' in lines[i] or 'begin{sidewaystable}' in lines[i]:
# print('starting table') # print('starting table')
temptable = [] temptable = []
j=0 j=0
while not "\end" in lines[i+j]: while not r"\end" in lines[i+j]:
if "\label" in lines[i+j]: if r"\label" in lines[i+j]:
temptablename = lines[i+j].split("\label{")[1].split("}")[0].replace("tab:","") temptablename = lines[i+j].split(r"\label{")[1].split("}")[0].replace("tab:","")
if not 'begin{' in lines[i+j]: if not 'begin{' in lines[i+j]:
temptable.append(lines[i+j]) temptable.append(lines[i+j])
j+=1 j+=1
tables_in_paper[temptablename]=temptable tables_in_paper[temptablename]=temptable
if '\input' in lines[i]: if r'\input' in lines[i]:
#skip commented inputs #skip commented inputs
if "%" in lines[i]: continue if "%" in lines[i]: continue
extended_file = lines[i].split("\input{")[1].split("}")[0]+".tex" extended_file = lines[i].split(r"\input{")[1].split("}")[0]+".tex"
#pathological case where people also include .tex in input command #pathological case where people also include .tex in input command
if ".tex.tex" in extended_file: if ".tex.tex" in extended_file:
extended_file = extended_file.replace(".tex.tex",".tex") extended_file = extended_file.replace(".tex.tex",".tex")
path_to_included_file = os.path.join(full_path_to_sourcefile,extended_file) path_to_included_file = os.path.join(full_path_to_sourcefile,extended_file)
extended_dict = extract_tables(path_to_included_file) extended_dict = extract_tables(path_to_included_file)
tables_in_paper = tables_in_paper | extended_dict tables_in_paper = tables_in_paper | extended_dict
return tables_in_paper return tables_in_paper
if '__main__'==__name__: def main(args):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-f','--file',type=str,required=True,help='input file to parse')
parser.add_argument('--no_output',action="store_true",help='skip output')
args = parser.parse_args()
print('now parsing',args.file) print('now parsing',args.file)
tables_in_paper = extract_tables(args.file) tables_in_paper = extract_tables(args.file)
...@@ -62,4 +66,4 @@ if '__main__'==__name__: ...@@ -62,4 +66,4 @@ if '__main__'==__name__:
f.close() f.close()
else: else:
print('here is the output of the tables') print('here is the output of the tables')
print(tables_in_paper) print(tables_in_paper)
\ No newline at end of file
###############################################################################
# (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
import sys,os import sys,os
import argparse import argparse
...@@ -12,7 +22,7 @@ import yaml ...@@ -12,7 +22,7 @@ import yaml
def get_metadata_info_for_yaml(input_yaml): def get_metadata_info_for_yaml(input_yaml):
""" """
Simple wrapper to get the metadata information necessary for the submission.yaml file. Simple wrapper to get the metadata information necessary for the submission.yaml file.
Uses safe_substitute on the template in the Templates directory to ensure return even Uses safe_substitute on the template in the Templates directory to ensure return even
in the case of error. in the case of error.
""" """
conf = yaml.safe_load(open(input_yaml,'r')) conf = yaml.safe_load(open(input_yaml,'r'))
...@@ -33,7 +43,7 @@ def get_metadata_info_for_yaml(input_yaml): ...@@ -33,7 +43,7 @@ def get_metadata_info_for_yaml(input_yaml):
if 'Covariance' in thing['header']['name'] or 'Correlation' in thing['header']['name']: if 'Covariance' in thing['header']['name'] or 'Correlation' in thing['header']['name']:
# print('skipping observables addition for correlation/covariance') # print('skipping observables addition for correlation/covariance')
the_dict['special']=str(thing['header']['name']) the_dict['special']=str(thing['header']['name'])
else: else:
observables.append(thing['header']['name']) observables.append(thing['header']['name'])
for thing in conf['independent_variables']: for thing in conf['independent_variables']:
# print('now appending independent variables',thing['header']['name']) # print('now appending independent variables',thing['header']['name'])
...@@ -45,18 +55,13 @@ def get_metadata_info_for_yaml(input_yaml): ...@@ -45,18 +55,13 @@ def get_metadata_info_for_yaml(input_yaml):
else: else:
vars_sorted = list(OrderedDict.fromkeys(independent_vars)) vars_sorted = list(OrderedDict.fromkeys(independent_vars))
# the_dict['description'] = the_dict['special'] + ' for ' +', '.join(vars_sorted) # the_dict['description'] = the_dict['special'] + ' for ' +', '.join(vars_sorted)
the_template = Template(open(os.path.dirname(os.path.abspath(__file__))+"/Templates/submission_template.yaml",'r').read()) the_template = Template(open(os.path.dirname(os.path.abspath(__file__))+"/Templates/submission_template.yaml",'r').read())
return the_template.safe_substitute(the_dict) return the_template.safe_substitute(the_dict)
if '__main__'==__name__: def main(args):
parser = argparse.ArgumentParser(description="Preparation of submission.yaml script for hepdata submission.\
Requires the data yaml files produced from tex_to_yaml.py to be provided")
parser.add_argument('-f','--files',type=str,nargs='+',required=True,help='input yaml file(s) to parse. Note, can pass *.yaml')
args = parser.parse_args()
for f in args.files: for f in args.files:
if not '.yaml' in f: if not '.yaml' in f:
print("You haven't passed valid yaml files! Please try again") print("You haven't passed valid yaml files! Please try again")
...@@ -89,7 +94,7 @@ if '__main__'==__name__: ...@@ -89,7 +94,7 @@ if '__main__'==__name__:
submission_file.write('\n') submission_file.write('\n')
submission_file.write("---\n") submission_file.write("---\n")
submission_file.write('\n') submission_file.write('\n')
submission_file.close() submission_file.close()
print('Done!') print('Done!')
\ No newline at end of file
###############################################################################
# (c) Copyright 2024 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
import argparse import argparse
import numpy as np import numpy as np
import re import re
...@@ -59,7 +69,7 @@ class value: ...@@ -59,7 +69,7 @@ class value:
else: else:
output = " - value: " + str(self.x) + "\n" output = " - value: " + str(self.x) + "\n"
return output return output
class variable: class variable:
""" """
Variable class to contain the column header and each value the variable takes, with uncertainties Variable class to contain the column header and each value the variable takes, with uncertainties
...@@ -90,7 +100,7 @@ def discard(line): ...@@ -90,7 +100,7 @@ def discard(line):
line = line.strip(" \n\t~{}") line = line.strip(" \n\t~{}")
if line == "": if line == "":
return True return True
elif line.startswith("\multicolumn"): elif line.startswith(r"\multicolumn"):
return False return False
elif line[0] == "%" or line[0] == "\\": elif line[0] == "%" or line[0] == "\\":
return True return True
...@@ -101,7 +111,7 @@ def extract_header(string): ...@@ -101,7 +111,7 @@ def extract_header(string):
""" """
Extracts the name and units (if any) from the header of a column and returns a string suitable for yaml Extracts the name and units (if any) from the header of a column and returns a string suitable for yaml
""" """
string = string.replace("\\xspace", "").replace("\\kern", "").replace("\\,", "").replace("\\!", "").replace("-0.1em", "").strip(" \n\t~\\") string = string.replace(r"\xspace", "").replace(r"\kern", "").replace(r"\,", "").replace(r"\!", "").replace("-0.1em", "").strip(" \n\t~\\")
if string.startswith("multicolumn"): #Removes leading multicolumn expression from header if string.startswith("multicolumn"): #Removes leading multicolumn expression from header
string = string[string.find("}")+1:] string = string[string.find("}")+1:]
string = string[string.find("}")+1:] string = string[string.find("}")+1:]
...@@ -122,16 +132,16 @@ def extract_description(string): ...@@ -122,16 +132,16 @@ def extract_description(string):
Extract the description field from the caption listed in paper Extract the description field from the caption listed in paper
""" """
temp_string = string.replace("\\n","").replace("\\xspace","").replace("\\","").rstrip().strip() temp_string = string.replace("\\n","").replace("\\xspace","").replace("\\","").rstrip().strip()
if 'label' in temp_string: if 'label' in temp_string:
to_rep = re.findall("label\{[tab:]*[a-zA-Z_]*\}",temp_string) to_rep = re.findall(r"label{[tab:]*[a-zA-Z_]*}",temp_string)
for rep in to_rep: for rep in to_rep:
temp_string = temp_string.replace(rep,"") temp_string = temp_string.replace(rep,"")
temp_string = temp_string.replace('caption{',"").replace("}","") temp_string = temp_string.replace('caption{',"").replace("}","")
return temp_string return temp_string
def split_format(string): def split_format(string):
""" """
Splits format string so that each variable is its own string in a list Splits format string so that each variable is its own string in a list
""" """
...@@ -143,7 +153,7 @@ def split_format(string): ...@@ -143,7 +153,7 @@ def split_format(string):
temp_list[-1].append(i) temp_list[-1].append(i)
return temp_list return temp_list
def format_value(string): def format_value(string):
""" """
Takes string with errors separated by commas and returns value object Takes string with errors separated by commas and returns value object
""" """
...@@ -161,7 +171,7 @@ def format_value(string): ...@@ -161,7 +171,7 @@ def format_value(string):
return the_val return the_val
def write_variables(variable_list, file): def write_variables(variable_list, file):
""" """
Writes variable objects in list to a yaml file Writes variable objects in list to a yaml file
""" """
...@@ -173,7 +183,7 @@ def write_variables(variable_list, file): ...@@ -173,7 +183,7 @@ def write_variables(variable_list, file):
for i in variable_list: for i in variable_list:
if i.is_indep == False: if i.is_indep == False:
file.write(repr(i)) file.write(repr(i))
def write_description(description,file): def write_description(description,file):
""" """
...@@ -185,11 +195,11 @@ def remove_phantoms(string): # ...@@ -185,11 +195,11 @@ def remove_phantoms(string): #
""" """
Removes \\phantom{...} from string Removes \\phantom{...} from string
""" """
while "\phantom" in string: while r"\phantom" in string:
x = string.find("\phantom") x = string.find(r"\phantom")
while string[x] != "}": while string[x] != "}":
x += 1 x += 1
string = string[:string.find("\phantom")] + string[x+1:] string = string[:string.find(r"\phantom")] + string[x+1:]
return string return string
def asym_unc(string): def asym_unc(string):
...@@ -201,20 +211,7 @@ def asym_unc(string): ...@@ -201,20 +211,7 @@ def asym_unc(string):
if '__main__'==__name__: def main(args):
parser = argparse.ArgumentParser()
parser.add_argument("--file", type=str,required=True,help='file contains name of data file')
parser.add_argument("--format", type=str, required=False,help='format contains string of data format (not necessary for covariance)\n\
A guide: i -- independent variable,\
d -- dependent variable, \
stat -- statistical error,\
sys -- systematic error')
parser.add_argument("--covariance", action="store_true", default=False,help='Flag to say whether the data is a covariance matrix or not') #
parser.add_argument("--correlation", action="store_true", default=False,help='Same as covariance, but for a correlation matrix') #
parser.add_argument("--qualifiers", type=str, default="None",help='qualifiers contains name of qualifiers file, defaults to "None"')
parser.add_argument("--remove", nargs='+', help="list of terms to remove from table")
args = parser.parse_args()
description = None description = None
if args.covariance==False and args.correlation == False and args.format ==None: if args.covariance==False and args.correlation == False and args.format ==None:
print('Must pass format if not passing a correlation or covariance matrix!') print('Must pass format if not passing a correlation or covariance matrix!')
...@@ -234,20 +231,20 @@ if '__main__'==__name__: ...@@ -234,20 +231,20 @@ if '__main__'==__name__:
for i in lines: for i in lines:
if discard(i) == False: #Only valid lines if discard(i) == False: #Only valid lines
if args.covariance == True or args.correlation == True: if args.covariance == True or args.correlation == True:
data_array.append(remove_phantoms(i).replace("\\hline", "").strip(" \n\t~\\").split("&")) #Splits into array by & data_array.append(remove_phantoms(i).replace(r"\hline", "").strip(" \n\t~\\").split("&")) #Splits into array by &
else: else:
if len(data_array) == 0: #Does not take convert the first line to values, as this contains headers if len(data_array) == 0: #Does not take convert the first line to values, as this contains headers
data_array.append(remove_phantoms(i).replace("\\hline", "").strip(" \n\t~\\").split("&")) data_array.append(remove_phantoms(i).replace(r"\hline", "").strip(" \n\t~\\").split("&"))
else: else:
line_split = remove_phantoms(i).replace("\\hline", "").strip(" \n\t~\\$").split("&") line_split = remove_phantoms(i).replace(r"\hline", "").strip(" \n\t~\\$").split("&")
if "\pm" in line_split: #Removes items that are just \pm if r"\pm" in line_split: #Removes items that are just \pm
line_split.remove("\pm") line_split.remove(r"\pm")
if " \pm " in line_split: if r" \pm " in line_split:
line_split.remove(" \pm ") line_split.remove(r" \pm ")
count = 0 #Count iterates in the format string to determine whether each number is a indep value, dep value, sys uncertainty, etc. count = 0 #Count iterates in the format string to determine whether each number is a indep value, dep value, sys uncertainty, etc.
value_list = [] #List of values extracted from this line value_list = [] #List of values extracted from this line
for j in line_split: #For item in line split by "&" for j in line_split: #For item in line split by "&"
temp = j.split("\pm") temp = j.split(r"\pm")
temp = [x.strip(" \n\t~\\$") for x in temp] temp = [x.strip(" \n\t~\\$") for x in temp]
if len(temp) > 1: #Removes blank characters from temp if len(temp) > 1: #Removes blank characters from temp
if "" in temp: if "" in temp:
...@@ -296,7 +293,7 @@ if '__main__'==__name__: ...@@ -296,7 +293,7 @@ if '__main__'==__name__:
else: else:
variables.append(variable(True, indep_header, "None")) variables.append(variable(True, indep_header, "None"))
variables.append(variable(True, indep_header, "None")) variables.append(variable(True, indep_header, "None"))
if args.covariance == True: if args.covariance == True:
variables.append(variable(False, "name: Covariance", args.qualifiers)) variables.append(variable(False, "name: Covariance", args.qualifiers))
else: else:
variables.append(variable(False, "name: Correlation", args.qualifiers)) variables.append(variable(False, "name: Correlation", args.qualifiers))
...@@ -341,14 +338,14 @@ if '__main__'==__name__: ...@@ -341,14 +338,14 @@ if '__main__'==__name__:
for i in range(1,len(data_array)): for i in range(1,len(data_array)):
for j in range(len(data_array[i,:])): for j in range(len(data_array[i,:])):
variables[j].append(data_array[i,j]) variables[j].append(data_array[i,j])
output_file = open(args.file.replace(".tex", ".yaml"), "w") #Creates file with same name, but .yaml instead of .tex output_file = open(args.file.replace(".tex", ".yaml"), "w") #Creates file with same name, but .yaml instead of .tex
write_variables(variables, output_file) #Writes contents of variables list to file write_variables(variables, output_file) #Writes contents of variables list to file
output_file.close() output_file.close()
#write extra file for description #write extra file for description
if description is not None: if description is not None:
output_description_file = open(args.file.replace('.tex','_description_file.txt'),'w') output_description_file = open(args.file.replace('.tex','_description_file.txt'),'w')
write_description(description, output_description_file) write_description(description, output_description_file)
output_description_file.close() output_description_file.close()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment