Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2e173c
commit 21ba0b0
Showing
43 changed files
with
275 additions
and
191 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,68 @@ | ||
"""Citation class for handling theory calculation citations""" | ||
# citations.py is based on code from the PyBaMM project | ||
# Inspired by pybamm.citations | ||
# https://github.com/pybamm-team/PyBaMM | ||
|
||
# Copyright (c) 2018-2020, the PyBaMM team. | ||
# All rights reserved. | ||
|
||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
from multiprocessing import Array | ||
import flavio | ||
import sys | ||
from itertools import compress | ||
import ctypes | ||
import yaml | ||
import pkgutil | ||
|
||
# * Redistributions of source code must retain the above copyright notice, this | ||
# list of conditions and the following disclaimer. | ||
|
||
# * Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
class CitationScope: | ||
|
||
# * Neither the name of the copyright holder nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
def __enter__(self): | ||
self._citations_global = flavio.citations | ||
flavio.citations = Citations() | ||
return flavio.citations | ||
|
||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import flavio | ||
def __exit__(self, type, value, traceback): | ||
flavio.citations = self._citations_global | ||
|
||
|
||
class Citations: | ||
|
||
"""Entry point to citations management. | ||
This object may be used to register a citation is relevant for a particular | ||
implementation. It can then also then print out a list of papers to be cited. | ||
Examples | ||
-------- | ||
>>> import flavio | ||
>>> flavio.sm_prediction("DeltaM_s") | ||
>>> print(flavio.default_citations) | ||
""" | ||
|
||
def __init__(self): | ||
self._reset() | ||
collect = CitationScope | ||
__all_citations = set(yaml.safe_load( | ||
pkgutil.get_data('flavio', 'data/citations.yml') | ||
)) | ||
|
||
def __init__(self, initial_citations=[]): | ||
self._initial_citations = set(initial_citations) | ||
self._all_citations = { | ||
k:i for i,k in | ||
enumerate(sorted(self.__all_citations | self._initial_citations)) | ||
} | ||
self._array = Array(ctypes.c_bool, len(self._all_citations)) | ||
for inspire_key in self._initial_citations: | ||
self.register(inspire_key) | ||
|
||
def __iter__(self): | ||
for citation in self._papers_to_cite: | ||
for citation in self.set: | ||
yield citation | ||
|
||
def __str__(self): | ||
return ",".join(self._papers_to_cite) | ||
|
||
def _reset(self): | ||
"Reset citations to empty" | ||
self._papers_to_cite = set() | ||
return ",".join(self.set) | ||
|
||
@property | ||
def tostring(self): | ||
return str(self) | ||
def set(self): | ||
return set(compress(sorted(self._all_citations.keys()), self._array)) | ||
|
||
@property | ||
def toset(self): | ||
return self._papers_to_cite | ||
|
||
def register(self, key): | ||
"""Register a paper to be cited. The intended use is that this method | ||
should be called only when the referenced functionality is actually being used. | ||
def string(self): | ||
return str(self) | ||
|
||
Parameters | ||
---------- | ||
key : str | ||
The INSPIRE texkey for the paper to be cited | ||
""" | ||
self._papers_to_cite.add(key) | ||
def register(self, inspire_key): | ||
self._array[self._all_citations[inspire_key]] = True | ||
|
||
def clear(self): | ||
self._array[:] = [False]*len(self._array) | ||
|
||
def reset(self): | ||
self.clear() | ||
for inspire_key in self._initial_citations: | ||
self.register(inspire_key) | ||
|
||
default_citations = Citations() | ||
# Register the flavio paper | ||
default_citations.register("Straub:2018kue") | ||
|
||
def register_citation(inspire_key): | ||
flavio.default_citations.register(inspire_key) | ||
sys.modules[__name__] = Citations(["Straub:2018kue"]) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
- Antonelli:2010yf | ||
- Asatrian:2003vq | ||
- Awramik:2003rn | ||
- Beneke:2001at | ||
- Beneke:2003az | ||
- Beneke:2004dp | ||
- Benson:2003kp | ||
- Bernard:2009zm | ||
- Bjorn:2016zlr | ||
- Bobeth:2013uxa | ||
- Boer:2014kda | ||
- Bourrely:2008za | ||
- Brignole:2004ah | ||
- Brivio:2017vri | ||
- Brod:2010hi | ||
- Buras:2006gb | ||
- Buras:2015yba | ||
- Caprini:1997mu | ||
- Chobanova:2017rkj | ||
- Cirigliano:2007ga | ||
- Descotes-Genon:2015hea | ||
- Falkowski:2019hvp | ||
- Freitas:2014hra | ||
- Gambino:2011cq | ||
- Gonzalez-Alonso:2018omy | ||
- Gorbahn:2006bm | ||
- Greub:2008cy | ||
- Guadagnoli:2016erb | ||
- Gubernari:2018wyi | ||
- Huber:2015sra | ||
- Inami:1980fz | ||
- Kitano:2002mt | ||
- Kozachuk:2017mdk | ||
- Kruger:2002gf | ||
- Kuno:1999jp | ||
- Melikhov:2004mk | ||
- Misiak:2006ab | ||
- Misiak:2015xwa | ||
- Pich:2013lsa | ||
- Seidel:2004jh | ||
- Straub:2015ica | ||
- fakename:2020abc |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#! /usr/bin/env python3 | ||
|
||
"""Standalone helper script to update the list of citations referenced in the | ||
flavio source code.""" | ||
|
||
import argparse | ||
import logging | ||
import sys | ||
import yaml | ||
import pkgutil | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
def main(argv): | ||
parser = argparse.ArgumentParser(description='Update the list of citations referenced in the flavio source code.') | ||
args = parser.parse_args() | ||
|
||
from flavio.util import get_datapath, extract_citations | ||
|
||
filename = get_datapath('flavio', 'data/citations.yml') | ||
with open(filename, 'w') as f: | ||
f.write(yaml.dump(sorted(extract_citations()))) | ||
logging.info(f"Saved updated citations to {filename}") | ||
|
||
if __name__ == '__main__': | ||
main(sys.argv) |
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
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
Oops, something went wrong.