Settings

Settings for the whole analysis are defined in the brainscopypaste.settings module, and should be accessed through the brainscopypaste.conf module as explained below.

Accessing settings: brainscopypaste.conf

Manage settings from the settings module, allowing overriding of some values.

Use the settings class instance from this module to access settings from any other module: from brainscopypaste.conf import settings. Note that only uppercase variables from the settings module are taken into account, the rest is ignored.

class brainscopypaste.conf.Settings[source]

Bases: object

Hold all settings for the analysis, managing and proxying access to the settings module.

Only uppercase variables from the settings module are taken into account, the rest is ignored. This class also lets you override values with a context manager to make testing easier. See the override() and file_override() methods for more details.

Use the settings instance of this class to access a singleton version of the settings for the whole analysis. Overridden values then appear overridden to all other modules (i.e. for all accesses) until the context manager is closed.

_override(name, value)[source]

Override name with value, after some checks.

The method checks that name is an uppercase string, and that it exists in the known settings. Use this when writing a context manager that wraps the operation in try/finally blocks, then restores the default behaviour.

Parameters:

name : str

Uppercase string denoting a known setting to be overridden.

value : object

Value to replace the setting with.

Raises:

ValueError

If name is not an uppercase string or is not a known setting name.

_setup()[source]

Set uppercase variables from the settings module as attributes on this instance.

file_override(*names)[source]

Context manager that overrides a file setting by pointing it to an empty temporary file for the duration of the context.

Some values in the settings module are file paths, and you might want to easily override the contents of that file for a block of code. This method lets you do just that: it will create a temporary file for a setting you wish to override, point that setting to the new empty file, and clean up once the context closes. This is a shortcut for override() when working on files whose contents you want to override.

Parameters:

names : list of str

List of setting names you want to override with temporary files.

Raises:

ValueError

If any member of names is not an uppercase string or is not a known setting name.

See also

override

Examples

Override the Age-of-Acquisition source file to e.g. test code that imports it as a word feature:

>>> from brainscopypaste.conf import settings
>>> with settings.file_override('AOA'):
...    with open(settings.AOA, 'w') as aoa:
...        # Write test content to the temporary AOA file.
...    # Test your code on the temporary AOA content.
>>> # `settings.AOA` is back to default here.
override(*names_values)[source]

Context manager that overrides setting values for the duration of the context.

Use this method to override one or several setting values for a block of code, then have those settings go back to their default value. Very useful when writing tests.

Parameters:

names_values : list of tuples

List of (name, value) tuples defining which settings to override with what value. Setting names must already exist (you can’t use this to create a new entry).

Raises:

ValueError

If any of the name values in names_values is not an uppercase string or is not a known setting name.

See also

file_override

Examples

Override MemeTracker filter settings for the duration of a test:

>>> from brainscopypaste.conf import settings
>>> with settings.override(('MT_FILTER_MIN_TOKENS', 2),
...                        ('MT_FILTER_MAX_DAYS, 50)):
...     # Here: some test code using the overridden settings.
>>> # `settings` is back to default here.
brainscopypaste.conf.settings = <brainscopypaste.conf.Settings object>

Instance of the Settings class that should be used to access settings. See that class’s documentation for more information.

Defining settings: brainscopypaste.settings

Definition of the overall settings for the analysis.

Edit this module to permanently change settings for the analysis. Do NOT directly import this module if you want to access these settings from inside some other code; to do so see conf.settings (which also lets you temporarily override settings).

All uppercase variables defined in this module are considered settings, the rest is ignored.

See Also

brainscopypaste.conf.Settings

brainscopypaste.settings.AOA = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/AoA/Kuperman-BRM-data-2012.csv'

Path to the file containing word age of acquisition data.

brainscopypaste.settings.BETWEENNESS = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/betweenness.pickle'

Path to the pickle file containing word betweeness centrality values.

brainscopypaste.settings.CLEARPOND = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/clearpond/englishCPdatabase2.txt'

Path to the file containing word neighbourhood density data.

brainscopypaste.settings.CLUSTERING = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/clustering.pickle'

Path to the pickle file containing word clustering coefficient values.

brainscopypaste.settings.DB_NAME = 'brainscopypaste'

Name of the PostgreSQL database used to store analysis data.

brainscopypaste.settings.DB_NAME_TEST = 'brainscopypaste_test'

Name of the PostgreSQL database used to store test data.

brainscopypaste.settings.DB_PASSWORD = ''

PostgreSQL connection user password.

brainscopypaste.settings.DB_USER = 'brainscopypaste'

PostgreSQL connection user name.

brainscopypaste.settings.DEGREE = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/degree.pickle'

Path to the pickle file containing word degree centrality values.

brainscopypaste.settings.FA_SOURCES = ['/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/Cue_Target_Pairs.A-B', '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/Cue_Target_Pairs.C', '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/Cue_Target_Pairs.D-F', '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/Cue_Target_Pairs.G-K', '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/Cue_Target_Pairs.L-O', '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/Cue_Target_Pairs.P-R', '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/Cue_Target_Pairs.S', '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/Cue_Target_Pairs.T-Z']

List of files making up the Free Association data.

brainscopypaste.settings.FIGURE = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/figures/{}.png'

Template for the file path to a figure from the main analysis that is to be saved.

brainscopypaste.settings.FIGURE_VARIANTS = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/figures/{notebook}/{model}'

Template for the folder containing all the figures of a notebook variant with a specific substitution-detection model.

brainscopypaste.settings.FREQUENCY = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/MemeTracker/frequency.pickle'

Path to the pickle file containing word frequency values.

brainscopypaste.settings.MT_FILTER_MAX_DAYS = 80

Maximum number of days a quote or a cluster can span to be kept by the MemeTracker filter.

brainscopypaste.settings.MT_FILTER_MIN_TOKENS = 5

Minimum number of tokens a quote must have to be kept by the MemeTracker filter.

brainscopypaste.settings.MT_LENGTH = 8357595

Number of lines in the MT_SOURCE file (pre-computed with wc -l <memetracker-file>); used by MemeTrackerParser.

brainscopypaste.settings.MT_SOURCE = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/MemeTracker/clust-qt08080902w3mfq5.txt'

Path to the source MemeTracker data set.

brainscopypaste.settings.NOTEBOOK = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/notebooks/{model} - {notebook}'

Template for the file path to a notebook variant with a specific substitution-detection model.

brainscopypaste.settings.PAGERANK = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/FreeAssociation/pagerank.pickle'

Path to the pickle file containing word pagerank centrality values.

brainscopypaste.settings.STOPWORDS = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/stopwords.txt'

Path to the file containing the list of stopwords.

brainscopypaste.settings.TOKENS = '/home/docs/checkouts/readthedocs.org/user_builds/brainscopypaste/checkouts/latest/docs/data/MemeTracker/tokens.pickle'

Path to the pickle file containing the list of known tokens.

brainscopypaste.settings.TREETAGGER_TAGDIR = 'treetagger'

TreeTagger library folder.