repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
ecordell/pymacaroons
pymacaroons/serializers/json_serializer.py
JsonSerializer._serialize_v1
def _serialize_v1(self, macaroon): '''Serialize the macaroon in JSON format v1. @param macaroon the macaroon to serialize. @return JSON macaroon. ''' serialized = { 'identifier': utils.convert_to_string(macaroon.identifier), 'signature': macaroon.signatur...
python
def _serialize_v1(self, macaroon): '''Serialize the macaroon in JSON format v1. @param macaroon the macaroon to serialize. @return JSON macaroon. ''' serialized = { 'identifier': utils.convert_to_string(macaroon.identifier), 'signature': macaroon.signatur...
[ "def", "_serialize_v1", "(", "self", ",", "macaroon", ")", ":", "serialized", "=", "{", "'identifier'", ":", "utils", ".", "convert_to_string", "(", "macaroon", ".", "identifier", ")", ",", "'signature'", ":", "macaroon", ".", "signature", ",", "}", "if", ...
Serialize the macaroon in JSON format v1. @param macaroon the macaroon to serialize. @return JSON macaroon.
[ "Serialize", "the", "macaroon", "in", "JSON", "format", "v1", "." ]
train
https://github.com/ecordell/pymacaroons/blob/c941614df15fe732ea432a62788e45410bcb868d/pymacaroons/serializers/json_serializer.py#L20-L36
ecordell/pymacaroons
pymacaroons/serializers/json_serializer.py
JsonSerializer._serialize_v2
def _serialize_v2(self, macaroon): '''Serialize the macaroon in JSON format v2. @param macaroon the macaroon to serialize. @return JSON macaroon in v2 format. ''' serialized = {} _add_json_binary_field(macaroon.identifier_bytes, serialized, 'i') _add_json_binary_...
python
def _serialize_v2(self, macaroon): '''Serialize the macaroon in JSON format v2. @param macaroon the macaroon to serialize. @return JSON macaroon in v2 format. ''' serialized = {} _add_json_binary_field(macaroon.identifier_bytes, serialized, 'i') _add_json_binary_...
[ "def", "_serialize_v2", "(", "self", ",", "macaroon", ")", ":", "serialized", "=", "{", "}", "_add_json_binary_field", "(", "macaroon", ".", "identifier_bytes", ",", "serialized", ",", "'i'", ")", "_add_json_binary_field", "(", "binascii", ".", "unhexlify", "(",...
Serialize the macaroon in JSON format v2. @param macaroon the macaroon to serialize. @return JSON macaroon in v2 format.
[ "Serialize", "the", "macaroon", "in", "JSON", "format", "v2", "." ]
train
https://github.com/ecordell/pymacaroons/blob/c941614df15fe732ea432a62788e45410bcb868d/pymacaroons/serializers/json_serializer.py#L38-L55
ecordell/pymacaroons
pymacaroons/serializers/json_serializer.py
JsonSerializer.deserialize
def deserialize(self, serialized): '''Deserialize a JSON macaroon depending on the format. @param serialized the macaroon in JSON format. @return the macaroon object. ''' deserialized = json.loads(serialized) if deserialized.get('identifier') is None: return ...
python
def deserialize(self, serialized): '''Deserialize a JSON macaroon depending on the format. @param serialized the macaroon in JSON format. @return the macaroon object. ''' deserialized = json.loads(serialized) if deserialized.get('identifier') is None: return ...
[ "def", "deserialize", "(", "self", ",", "serialized", ")", ":", "deserialized", "=", "json", ".", "loads", "(", "serialized", ")", "if", "deserialized", ".", "get", "(", "'identifier'", ")", "is", "None", ":", "return", "self", ".", "_deserialize_v2", "(",...
Deserialize a JSON macaroon depending on the format. @param serialized the macaroon in JSON format. @return the macaroon object.
[ "Deserialize", "a", "JSON", "macaroon", "depending", "on", "the", "format", "." ]
train
https://github.com/ecordell/pymacaroons/blob/c941614df15fe732ea432a62788e45410bcb868d/pymacaroons/serializers/json_serializer.py#L57-L67
ecordell/pymacaroons
pymacaroons/serializers/json_serializer.py
JsonSerializer._deserialize_v1
def _deserialize_v1(self, deserialized): '''Deserialize a JSON macaroon in v1 format. @param serialized the macaroon in v1 JSON format. @return the macaroon object. ''' from pymacaroons.macaroon import Macaroon, MACAROON_V1 from pymacaroons.caveat import Caveat ...
python
def _deserialize_v1(self, deserialized): '''Deserialize a JSON macaroon in v1 format. @param serialized the macaroon in v1 JSON format. @return the macaroon object. ''' from pymacaroons.macaroon import Macaroon, MACAROON_V1 from pymacaroons.caveat import Caveat ...
[ "def", "_deserialize_v1", "(", "self", ",", "deserialized", ")", ":", "from", "pymacaroons", ".", "macaroon", "import", "Macaroon", ",", "MACAROON_V1", "from", "pymacaroons", ".", "caveat", "import", "Caveat", "caveats", "=", "[", "]", "for", "c", "in", "des...
Deserialize a JSON macaroon in v1 format. @param serialized the macaroon in v1 JSON format. @return the macaroon object.
[ "Deserialize", "a", "JSON", "macaroon", "in", "v1", "format", "." ]
train
https://github.com/ecordell/pymacaroons/blob/c941614df15fe732ea432a62788e45410bcb868d/pymacaroons/serializers/json_serializer.py#L69-L99
ecordell/pymacaroons
pymacaroons/serializers/json_serializer.py
JsonSerializer._deserialize_v2
def _deserialize_v2(self, deserialized): '''Deserialize a JSON macaroon v2. @param serialized the macaroon in JSON format v2. @return the macaroon object. ''' from pymacaroons.macaroon import Macaroon, MACAROON_V2 from pymacaroons.caveat import Caveat caveats = [...
python
def _deserialize_v2(self, deserialized): '''Deserialize a JSON macaroon v2. @param serialized the macaroon in JSON format v2. @return the macaroon object. ''' from pymacaroons.macaroon import Macaroon, MACAROON_V2 from pymacaroons.caveat import Caveat caveats = [...
[ "def", "_deserialize_v2", "(", "self", ",", "deserialized", ")", ":", "from", "pymacaroons", ".", "macaroon", "import", "Macaroon", ",", "MACAROON_V2", "from", "pymacaroons", ".", "caveat", "import", "Caveat", "caveats", "=", "[", "]", "for", "c", "in", "des...
Deserialize a JSON macaroon v2. @param serialized the macaroon in JSON format v2. @return the macaroon object.
[ "Deserialize", "a", "JSON", "macaroon", "v2", "." ]
train
https://github.com/ecordell/pymacaroons/blob/c941614df15fe732ea432a62788e45410bcb868d/pymacaroons/serializers/json_serializer.py#L101-L125
zooniverse/panoptes-python-client
panoptes_client/project_preferences.py
ProjectPreferences.find
def find(cls, id='', user=None, project=None): """ Like :py:meth:`.PanoptesObject.find` but can also query by user and project. - **user** and **project** can be either a :py:class:`.User` and :py:class:`.Project` instance respectively, or they can be given as IDs. I...
python
def find(cls, id='', user=None, project=None): """ Like :py:meth:`.PanoptesObject.find` but can also query by user and project. - **user** and **project** can be either a :py:class:`.User` and :py:class:`.Project` instance respectively, or they can be given as IDs. I...
[ "def", "find", "(", "cls", ",", "id", "=", "''", ",", "user", "=", "None", ",", "project", "=", "None", ")", ":", "if", "not", "id", ":", "if", "not", "(", "user", "and", "project", ")", ":", "raise", "ValueError", "(", "'Both user and project requir...
Like :py:meth:`.PanoptesObject.find` but can also query by user and project. - **user** and **project** can be either a :py:class:`.User` and :py:class:`.Project` instance respectively, or they can be given as IDs. If either argument is given, the other is also required.
[ "Like", ":", "py", ":", "meth", ":", ".", "PanoptesObject", ".", "find", "but", "can", "also", "query", "by", "user", "and", "project", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/project_preferences.py#L21-L49
zooniverse/panoptes-python-client
panoptes_client/project_preferences.py
ProjectPreferences.save_settings
def save_settings(cls, project=None, user=None, settings=None): """ Save settings for a user without first fetching their preferences. - **user** and **project** can be either a :py:class:`.User` and :py:class:`.Project` instance respectively, or they can be given as IDs. If...
python
def save_settings(cls, project=None, user=None, settings=None): """ Save settings for a user without first fetching their preferences. - **user** and **project** can be either a :py:class:`.User` and :py:class:`.Project` instance respectively, or they can be given as IDs. If...
[ "def", "save_settings", "(", "cls", ",", "project", "=", "None", ",", "user", "=", "None", ",", "settings", "=", "None", ")", ":", "if", "(", "isinstance", "(", "settings", ",", "dict", ")", ")", ":", "_to_update", "=", "settings", "if", "(", "isinst...
Save settings for a user without first fetching their preferences. - **user** and **project** can be either a :py:class:`.User` and :py:class:`.Project` instance respectively, or they can be given as IDs. If either argument is given, the other is also required. - **settings** is a :...
[ "Save", "settings", "for", "a", "user", "without", "first", "fetching", "their", "preferences", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/project_preferences.py#L52-L90
zooniverse/panoptes-python-client
panoptes_client/subject.py
Subject.async_saves
def async_saves(cls): """ Returns a context manager to allow asynchronously creating subjects. Using this context manager will create a pool of threads which will create multiple subjects at once and upload any local files simultaneously. The recommended way to use this ...
python
def async_saves(cls): """ Returns a context manager to allow asynchronously creating subjects. Using this context manager will create a pool of threads which will create multiple subjects at once and upload any local files simultaneously. The recommended way to use this ...
[ "def", "async_saves", "(", "cls", ")", ":", "cls", ".", "_local", ".", "save_exec", "=", "ThreadPoolExecutor", "(", "max_workers", "=", "ASYNC_SAVE_THREADS", ")", "return", "cls", ".", "_local", ".", "save_exec" ]
Returns a context manager to allow asynchronously creating subjects. Using this context manager will create a pool of threads which will create multiple subjects at once and upload any local files simultaneously. The recommended way to use this is with the `with` statement:: ...
[ "Returns", "a", "context", "manager", "to", "allow", "asynchronously", "creating", "subjects", ".", "Using", "this", "context", "manager", "will", "create", "a", "pool", "of", "threads", "which", "will", "create", "multiple", "subjects", "at", "once", "and", "...
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/subject.py#L63-L96
zooniverse/panoptes-python-client
panoptes_client/subject.py
Subject.save
def save(self, client=None): """ Like :py:meth:`.PanoptesObject.save`, but also uploads any local files which have previosly been added to the subject with :py:meth:`add_location`. Automatically retries uploads on error. If multiple local files are to be uploaded, several files ...
python
def save(self, client=None): """ Like :py:meth:`.PanoptesObject.save`, but also uploads any local files which have previosly been added to the subject with :py:meth:`add_location`. Automatically retries uploads on error. If multiple local files are to be uploaded, several files ...
[ "def", "save", "(", "self", ",", "client", "=", "None", ")", ":", "if", "not", "client", ":", "client", "=", "Panoptes", ".", "client", "(", ")", "async_save", "=", "hasattr", "(", "self", ".", "_local", ",", "'save_exec'", ")", "with", "client", ":"...
Like :py:meth:`.PanoptesObject.save`, but also uploads any local files which have previosly been added to the subject with :py:meth:`add_location`. Automatically retries uploads on error. If multiple local files are to be uploaded, several files will be uploaded simultaneously to save t...
[ "Like", ":", "py", ":", "meth", ":", ".", "PanoptesObject", ".", "save", "but", "also", "uploads", "any", "local", "files", "which", "have", "previosly", "been", "added", "to", "the", "subject", "with", ":", "py", ":", "meth", ":", "add_location", ".", ...
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/subject.py#L107-L178
zooniverse/panoptes-python-client
panoptes_client/subject.py
Subject.async_save_result
def async_save_result(self): """ Retrieves the result of this subject's asynchronous save. - Returns `True` if the subject was saved successfully. - Raises `concurrent.futures.CancelledError` if the save was cancelled. - If the save failed, raises the relevant exception. ...
python
def async_save_result(self): """ Retrieves the result of this subject's asynchronous save. - Returns `True` if the subject was saved successfully. - Raises `concurrent.futures.CancelledError` if the save was cancelled. - If the save failed, raises the relevant exception. ...
[ "def", "async_save_result", "(", "self", ")", ":", "if", "hasattr", "(", "self", ",", "\"_async_future\"", ")", "and", "self", ".", "_async_future", ".", "done", "(", ")", ":", "self", ".", "_async_future", ".", "result", "(", ")", "return", "True", "els...
Retrieves the result of this subject's asynchronous save. - Returns `True` if the subject was saved successfully. - Raises `concurrent.futures.CancelledError` if the save was cancelled. - If the save failed, raises the relevant exception. - Returns `False` if the subject hasn't finished...
[ "Retrieves", "the", "result", "of", "this", "subject", "s", "asynchronous", "save", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/subject.py#L192-L206
zooniverse/panoptes-python-client
panoptes_client/subject.py
Subject.add_location
def add_location(self, location): """ Add a media location to this subject. - **location** can be an open :py:class:`file` object, a path to a local file, or a :py:class:`dict` containing MIME types and URLs for remote media. Examples:: subject.add_loca...
python
def add_location(self, location): """ Add a media location to this subject. - **location** can be an open :py:class:`file` object, a path to a local file, or a :py:class:`dict` containing MIME types and URLs for remote media. Examples:: subject.add_loca...
[ "def", "add_location", "(", "self", ",", "location", ")", ":", "if", "type", "(", "location", ")", "is", "dict", ":", "self", ".", "locations", ".", "append", "(", "location", ")", "self", ".", "_media_files", ".", "append", "(", "None", ")", "return",...
Add a media location to this subject. - **location** can be an open :py:class:`file` object, a path to a local file, or a :py:class:`dict` containing MIME types and URLs for remote media. Examples:: subject.add_location(my_file) subject.add_location('/data/...
[ "Add", "a", "media", "location", "to", "this", "subject", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/subject.py#L215-L255
zooniverse/panoptes-python-client
panoptes_client/exportable.py
Exportable.get_export
def get_export( self, export_type, generate=False, wait=False, wait_timeout=None, ): """ Downloads a data export over HTTP. Returns a `Requests Response <http://docs.python-requests.org/en/master/api/#requests.Response>`_ object containing the ...
python
def get_export( self, export_type, generate=False, wait=False, wait_timeout=None, ): """ Downloads a data export over HTTP. Returns a `Requests Response <http://docs.python-requests.org/en/master/api/#requests.Response>`_ object containing the ...
[ "def", "get_export", "(", "self", ",", "export_type", ",", "generate", "=", "False", ",", "wait", "=", "False", ",", "wait_timeout", "=", "None", ",", ")", ":", "if", "generate", ":", "self", ".", "generate_export", "(", "export_type", ")", "if", "genera...
Downloads a data export over HTTP. Returns a `Requests Response <http://docs.python-requests.org/en/master/api/#requests.Response>`_ object containing the content of the export. - **export_type** is a string specifying which type of export should be downloaded. - **generate** ...
[ "Downloads", "a", "data", "export", "over", "HTTP", ".", "Returns", "a", "Requests", "Response", "<http", ":", "//", "docs", ".", "python", "-", "requests", ".", "org", "/", "en", "/", "master", "/", "api", "/", "#requests", ".", "Response", ">", "_", ...
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/exportable.py#L30-L92
zooniverse/panoptes-python-client
panoptes_client/exportable.py
Exportable.wait_export
def wait_export( self, export_type, timeout=None, ): """ Blocks until an in-progress export is ready. - **export_type** is a string specifying which type of export to wait for. - **timeout** is the maximum number of seconds to wait. If ``ti...
python
def wait_export( self, export_type, timeout=None, ): """ Blocks until an in-progress export is ready. - **export_type** is a string specifying which type of export to wait for. - **timeout** is the maximum number of seconds to wait. If ``ti...
[ "def", "wait_export", "(", "self", ",", "export_type", ",", "timeout", "=", "None", ",", ")", ":", "success", "=", "False", "if", "timeout", ":", "end_time", "=", "datetime", ".", "datetime", ".", "now", "(", ")", "+", "datetime", ".", "timedelta", "("...
Blocks until an in-progress export is ready. - **export_type** is a string specifying which type of export to wait for. - **timeout** is the maximum number of seconds to wait. If ``timeout`` is given and the export is not ready by the time limit, :py:class:`.PanoptesAPIExcept...
[ "Blocks", "until", "an", "in", "-", "progress", "export", "is", "ready", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/exportable.py#L94-L140
zooniverse/panoptes-python-client
panoptes_client/exportable.py
Exportable.generate_export
def generate_export(self, export_type): """ Start a new export. - **export_type** is a string specifying which type of export to start. Returns a :py:class:`dict` containing metadata for the new export. """ if export_type in TALK_EXPORT_TYPES: return talk.p...
python
def generate_export(self, export_type): """ Start a new export. - **export_type** is a string specifying which type of export to start. Returns a :py:class:`dict` containing metadata for the new export. """ if export_type in TALK_EXPORT_TYPES: return talk.p...
[ "def", "generate_export", "(", "self", ",", "export_type", ")", ":", "if", "export_type", "in", "TALK_EXPORT_TYPES", ":", "return", "talk", ".", "post_data_request", "(", "'project-{}'", ".", "format", "(", "self", ".", "id", ")", ",", "export_type", ".", "r...
Start a new export. - **export_type** is a string specifying which type of export to start. Returns a :py:class:`dict` containing metadata for the new export.
[ "Start", "a", "new", "export", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/exportable.py#L142-L160
zooniverse/panoptes-python-client
panoptes_client/exportable.py
Exportable.describe_export
def describe_export(self, export_type): """ Fetch metadata for an export. - **export_type** is a string specifying which type of export to look up. Returns a :py:class:`dict` containing metadata for the export. """ if export_type in TALK_EXPORT_TYPES: ...
python
def describe_export(self, export_type): """ Fetch metadata for an export. - **export_type** is a string specifying which type of export to look up. Returns a :py:class:`dict` containing metadata for the export. """ if export_type in TALK_EXPORT_TYPES: ...
[ "def", "describe_export", "(", "self", ",", "export_type", ")", ":", "if", "export_type", "in", "TALK_EXPORT_TYPES", ":", "return", "talk", ".", "get_data_request", "(", "'project-{}'", ".", "format", "(", "self", ".", "id", ")", ",", "export_type", ".", "re...
Fetch metadata for an export. - **export_type** is a string specifying which type of export to look up. Returns a :py:class:`dict` containing metadata for the export.
[ "Fetch", "metadata", "for", "an", "export", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/exportable.py#L162-L179
zooniverse/panoptes-python-client
panoptes_client/classification.py
Classification.where
def where(cls, **kwargs): """ where(scope=None, **kwargs) Like :py:meth:`.PanoptesObject.where`, but also allows setting the query scope. - **scope** can be any of the values given in the `Classification Collection API documentation <http://docs.panoptes.apiary.io/#re...
python
def where(cls, **kwargs): """ where(scope=None, **kwargs) Like :py:meth:`.PanoptesObject.where`, but also allows setting the query scope. - **scope** can be any of the values given in the `Classification Collection API documentation <http://docs.panoptes.apiary.io/#re...
[ "def", "where", "(", "cls", ",", "*", "*", "kwargs", ")", ":", "scope", "=", "kwargs", ".", "pop", "(", "'scope'", ",", "None", ")", "if", "not", "scope", ":", "return", "super", "(", "Classification", ",", "cls", ")", ".", "where", "(", "*", "*"...
where(scope=None, **kwargs) Like :py:meth:`.PanoptesObject.where`, but also allows setting the query scope. - **scope** can be any of the values given in the `Classification Collection API documentation <http://docs.panoptes.apiary.io/#reference/classification/classification/list-all...
[ "where", "(", "scope", "=", "None", "**", "kwargs", ")" ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/classification.py#L12-L37
zooniverse/panoptes-python-client
panoptes_client/collection.py
Collection.find
def find(cls, id='', slug=None): """ Similar to :py:meth:`.PanoptesObject.find`, but allows lookup by slug as well as ID. Examples:: collection_1234 = Collection.find(1234) my_collection = Collection.find(slug="example/my-collection") """ if not...
python
def find(cls, id='', slug=None): """ Similar to :py:meth:`.PanoptesObject.find`, but allows lookup by slug as well as ID. Examples:: collection_1234 = Collection.find(1234) my_collection = Collection.find(slug="example/my-collection") """ if not...
[ "def", "find", "(", "cls", ",", "id", "=", "''", ",", "slug", "=", "None", ")", ":", "if", "not", "id", "and", "not", "slug", ":", "return", "None", "try", ":", "return", "cls", ".", "where", "(", "id", "=", "id", ",", "slug", "=", "slug", ")...
Similar to :py:meth:`.PanoptesObject.find`, but allows lookup by slug as well as ID. Examples:: collection_1234 = Collection.find(1234) my_collection = Collection.find(slug="example/my-collection")
[ "Similar", "to", ":", "py", ":", "meth", ":", ".", "PanoptesObject", ".", "find", "but", "allows", "lookup", "by", "slug", "as", "well", "as", "ID", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/collection.py#L28-L46
zooniverse/panoptes-python-client
panoptes_client/collection.py
Collection.set_default_subject
def set_default_subject(self, subject): """ Sets the subject's location media URL as a link. It displays as the default subject on PFE. - **subject** can be a single :py:class:`.Subject` instance or a single subject ID. Examples:: collection.set_default_s...
python
def set_default_subject(self, subject): """ Sets the subject's location media URL as a link. It displays as the default subject on PFE. - **subject** can be a single :py:class:`.Subject` instance or a single subject ID. Examples:: collection.set_default_s...
[ "def", "set_default_subject", "(", "self", ",", "subject", ")", ":", "if", "not", "(", "isinstance", "(", "subject", ",", "Subject", ")", "or", "isinstance", "(", "subject", ",", "(", "int", ",", "str", ",", ")", ")", ")", ":", "raise", "TypeError", ...
Sets the subject's location media URL as a link. It displays as the default subject on PFE. - **subject** can be a single :py:class:`.Subject` instance or a single subject ID. Examples:: collection.set_default_subject(1234) collection.set_default_subject(Subj...
[ "Sets", "the", "subject", "s", "location", "media", "URL", "as", "a", "link", ".", "It", "displays", "as", "the", "default", "subject", "on", "PFE", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/collection.py#L74-L100
zooniverse/panoptes-python-client
panoptes_client/subject_set.py
SubjectSet.subjects
def subjects(self): """ A generator which yields :py:class:`.Subject` objects which are in this subject set. Examples:: for subject in subject_set.subjects: print(subject.id) """ for sms in SetMemberSubject.where(subject_set_id=self.id): ...
python
def subjects(self): """ A generator which yields :py:class:`.Subject` objects which are in this subject set. Examples:: for subject in subject_set.subjects: print(subject.id) """ for sms in SetMemberSubject.where(subject_set_id=self.id): ...
[ "def", "subjects", "(", "self", ")", ":", "for", "sms", "in", "SetMemberSubject", ".", "where", "(", "subject_set_id", "=", "self", ".", "id", ")", ":", "yield", "sms", ".", "links", ".", "subject" ]
A generator which yields :py:class:`.Subject` objects which are in this subject set. Examples:: for subject in subject_set.subjects: print(subject.id)
[ "A", "generator", "which", "yields", ":", "py", ":", "class", ":", ".", "Subject", "objects", "which", "are", "in", "this", "subject", "set", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/subject_set.py#L69-L82
zooniverse/panoptes-python-client
panoptes_client/workflow.py
Workflow.retire_subjects
def retire_subjects(self, subjects, reason='other'): """ Retires subjects in this workflow. - **subjects** can be a list of :py:class:`Subject` instances, a list of subject IDs, a single :py:class:`Subject` instance, or a single subject ID. - **reason** gives the rea...
python
def retire_subjects(self, subjects, reason='other'): """ Retires subjects in this workflow. - **subjects** can be a list of :py:class:`Subject` instances, a list of subject IDs, a single :py:class:`Subject` instance, or a single subject ID. - **reason** gives the rea...
[ "def", "retire_subjects", "(", "self", ",", "subjects", ",", "reason", "=", "'other'", ")", ":", "subjects", "=", "[", "s", ".", "id", "if", "isinstance", "(", "s", ",", "Subject", ")", "else", "s", "for", "s", "in", "subjects", "]", "return", "Workf...
Retires subjects in this workflow. - **subjects** can be a list of :py:class:`Subject` instances, a list of subject IDs, a single :py:class:`Subject` instance, or a single subject ID. - **reason** gives the reason the :py:class:`Subject` has been retired. Defaults to **oth...
[ "Retires", "subjects", "in", "this", "workflow", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/workflow.py#L31-L57
zooniverse/panoptes-python-client
panoptes_client/project.py
Project.collaborators
def collaborators(self, *roles): """ Returns a list of :py:class:`.User` who are collaborators on this project. Zero or more role arguments can be passed as strings to narrow down the results. If any roles are given, users who possess at least one of the given roles are ...
python
def collaborators(self, *roles): """ Returns a list of :py:class:`.User` who are collaborators on this project. Zero or more role arguments can be passed as strings to narrow down the results. If any roles are given, users who possess at least one of the given roles are ...
[ "def", "collaborators", "(", "self", ",", "*", "roles", ")", ":", "return", "[", "r", ".", "links", ".", "owner", "for", "r", "in", "ProjectRole", ".", "where", "(", "project_id", "=", "self", ".", "id", ")", "if", "len", "(", "roles", ")", "==", ...
Returns a list of :py:class:`.User` who are collaborators on this project. Zero or more role arguments can be passed as strings to narrow down the results. If any roles are given, users who possess at least one of the given roles are returned. Examples:: all_collab...
[ "Returns", "a", "list", "of", ":", "py", ":", "class", ":", ".", "User", "who", "are", "collaborators", "on", "this", "project", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/project.py#L63-L85
zooniverse/panoptes-python-client
panoptes_client/panoptes.py
Panoptes.connect
def connect(cls, *args, **kwargs): """ connect(username=None, password=None, endpoint=None, admin=False) Configures the Panoptes client for use. Note that there is no need to call this unless you need to pass one or more of the below arguments. By default, the client will conn...
python
def connect(cls, *args, **kwargs): """ connect(username=None, password=None, endpoint=None, admin=False) Configures the Panoptes client for use. Note that there is no need to call this unless you need to pass one or more of the below arguments. By default, the client will conn...
[ "def", "connect", "(", "cls", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "cls", ".", "_local", ".", "panoptes_client", "=", "cls", "(", "*", "args", ",", "*", "*", "kwargs", ")", "cls", ".", "_local", ".", "panoptes_client", ".", "login",...
connect(username=None, password=None, endpoint=None, admin=False) Configures the Panoptes client for use. Note that there is no need to call this unless you need to pass one or more of the below arguments. By default, the client will connect to the public Zooniverse.org API as an anon...
[ "connect", "(", "username", "=", "None", "password", "=", "None", "endpoint", "=", "None", "admin", "=", "False", ")" ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/panoptes.py#L82-L110
zooniverse/panoptes-python-client
panoptes_client/panoptes.py
PanoptesObject.where
def where(cls, **kwargs): """ Returns a generator which yields instances matching the given query arguments. For example, this would yield all :py:class:`.Project`:: Project.where() And this would yield all launch approved :py:class:`.Project`:: Projec...
python
def where(cls, **kwargs): """ Returns a generator which yields instances matching the given query arguments. For example, this would yield all :py:class:`.Project`:: Project.where() And this would yield all launch approved :py:class:`.Project`:: Projec...
[ "def", "where", "(", "cls", ",", "*", "*", "kwargs", ")", ":", "_id", "=", "kwargs", ".", "pop", "(", "'id'", ",", "''", ")", "return", "cls", ".", "paginated_results", "(", "*", "cls", ".", "http_get", "(", "_id", ",", "params", "=", "kwargs", "...
Returns a generator which yields instances matching the given query arguments. For example, this would yield all :py:class:`.Project`:: Project.where() And this would yield all launch approved :py:class:`.Project`:: Project.where(launch_approved=True)
[ "Returns", "a", "generator", "which", "yields", "instances", "matching", "the", "given", "query", "arguments", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/panoptes.py#L657-L672
zooniverse/panoptes-python-client
panoptes_client/panoptes.py
PanoptesObject.find
def find(cls, _id): """ Returns the individual instance with the given ID, if it exists. Raises :py:class:`PanoptesAPIException` if the object with that ID is not found. """ if not _id: return None try: return next(cls.where(id=_id)) ...
python
def find(cls, _id): """ Returns the individual instance with the given ID, if it exists. Raises :py:class:`PanoptesAPIException` if the object with that ID is not found. """ if not _id: return None try: return next(cls.where(id=_id)) ...
[ "def", "find", "(", "cls", ",", "_id", ")", ":", "if", "not", "_id", ":", "return", "None", "try", ":", "return", "next", "(", "cls", ".", "where", "(", "id", "=", "_id", ")", ")", "except", "StopIteration", ":", "raise", "PanoptesAPIException", "(",...
Returns the individual instance with the given ID, if it exists. Raises :py:class:`PanoptesAPIException` if the object with that ID is not found.
[ "Returns", "the", "individual", "instance", "with", "the", "given", "ID", "if", "it", "exists", ".", "Raises", ":", "py", ":", "class", ":", "PanoptesAPIException", "if", "the", "object", "with", "that", "ID", "is", "not", "found", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/panoptes.py#L675-L689
zooniverse/panoptes-python-client
panoptes_client/panoptes.py
PanoptesObject.save
def save(self): """ Saves the object. If the object has not been saved before (i.e. it's new), then a new object is created. Otherwise, any changes are submitted to the API. """ if not self.id: save_method = Panoptes.client().post force_reload = F...
python
def save(self): """ Saves the object. If the object has not been saved before (i.e. it's new), then a new object is created. Otherwise, any changes are submitted to the API. """ if not self.id: save_method = Panoptes.client().post force_reload = F...
[ "def", "save", "(", "self", ")", ":", "if", "not", "self", ".", "id", ":", "save_method", "=", "Panoptes", ".", "client", "(", ")", ".", "post", "force_reload", "=", "False", "else", ":", "if", "not", "self", ".", "modified_attributes", ":", "return", ...
Saves the object. If the object has not been saved before (i.e. it's new), then a new object is created. Otherwise, any changes are submitted to the API.
[ "Saves", "the", "object", ".", "If", "the", "object", "has", "not", "been", "saved", "before", "(", "i", ".", "e", ".", "it", "s", "new", ")", "then", "a", "new", "object", "is", "created", ".", "Otherwise", "any", "changes", "are", "submitted", "to"...
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/panoptes.py#L792-L824
zooniverse/panoptes-python-client
panoptes_client/panoptes.py
PanoptesObject.reload
def reload(self): """ Re-fetches the object from the API, discarding any local changes. Returns without doing anything if the object is new. """ if not self.id: return reloaded_object = self.__class__.find(self.id) self.set_raw( reloaded_o...
python
def reload(self): """ Re-fetches the object from the API, discarding any local changes. Returns without doing anything if the object is new. """ if not self.id: return reloaded_object = self.__class__.find(self.id) self.set_raw( reloaded_o...
[ "def", "reload", "(", "self", ")", ":", "if", "not", "self", ".", "id", ":", "return", "reloaded_object", "=", "self", ".", "__class__", ".", "find", "(", "self", ".", "id", ")", "self", ".", "set_raw", "(", "reloaded_object", ".", "raw", ",", "reloa...
Re-fetches the object from the API, discarding any local changes. Returns without doing anything if the object is new.
[ "Re", "-", "fetches", "the", "object", "from", "the", "API", "discarding", "any", "local", "changes", ".", "Returns", "without", "doing", "anything", "if", "the", "object", "is", "new", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/panoptes.py#L826-L838
zooniverse/panoptes-python-client
panoptes_client/panoptes.py
PanoptesObject.delete
def delete(self): """ Deletes the object. Returns without doing anything if the object is new. """ if not self.id: return if not self._loaded: self.reload() return self.http_delete(self.id, etag=self.etag)
python
def delete(self): """ Deletes the object. Returns without doing anything if the object is new. """ if not self.id: return if not self._loaded: self.reload() return self.http_delete(self.id, etag=self.etag)
[ "def", "delete", "(", "self", ")", ":", "if", "not", "self", ".", "id", ":", "return", "if", "not", "self", ".", "_loaded", ":", "self", ".", "reload", "(", ")", "return", "self", ".", "http_delete", "(", "self", ".", "id", ",", "etag", "=", "sel...
Deletes the object. Returns without doing anything if the object is new.
[ "Deletes", "the", "object", ".", "Returns", "without", "doing", "anything", "if", "the", "object", "is", "new", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/panoptes.py#L840-L850
zooniverse/panoptes-python-client
panoptes_client/panoptes.py
LinkCollection.add
def add(self, objs): """ Adds the given `objs` to this `LinkCollection`. - **objs** can be a list of :py:class:`.PanoptesObject` instances, a list of object IDs, a single :py:class:`.PanoptesObject` instance, or a single object ID. Examples:: organizati...
python
def add(self, objs): """ Adds the given `objs` to this `LinkCollection`. - **objs** can be a list of :py:class:`.PanoptesObject` instances, a list of object IDs, a single :py:class:`.PanoptesObject` instance, or a single object ID. Examples:: organizati...
[ "def", "add", "(", "self", ",", "objs", ")", ":", "if", "self", ".", "readonly", ":", "raise", "NotImplementedError", "(", "'{} links can\\'t be modified'", ".", "format", "(", "self", ".", "_slug", ")", ")", "if", "not", "self", ".", "_parent", ".", "id...
Adds the given `objs` to this `LinkCollection`. - **objs** can be a list of :py:class:`.PanoptesObject` instances, a list of object IDs, a single :py:class:`.PanoptesObject` instance, or a single object ID. Examples:: organization.links.projects.add(1234) o...
[ "Adds", "the", "given", "objs", "to", "this", "LinkCollection", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/panoptes.py#L1011-L1046
zooniverse/panoptes-python-client
panoptes_client/panoptes.py
LinkCollection.remove
def remove(self, objs): """ Removes the given `objs` from this `LinkCollection`. - **objs** can be a list of :py:class:`.PanoptesObject` instances, a list of object IDs, a single :py:class:`.PanoptesObject` instance, or a single object ID. Examples:: or...
python
def remove(self, objs): """ Removes the given `objs` from this `LinkCollection`. - **objs** can be a list of :py:class:`.PanoptesObject` instances, a list of object IDs, a single :py:class:`.PanoptesObject` instance, or a single object ID. Examples:: or...
[ "def", "remove", "(", "self", ",", "objs", ")", ":", "if", "self", ".", "readonly", ":", "raise", "NotImplementedError", "(", "'{} links can\\'t be modified'", ".", "format", "(", "self", ".", "_slug", ")", ")", "if", "not", "self", ".", "_parent", ".", ...
Removes the given `objs` from this `LinkCollection`. - **objs** can be a list of :py:class:`.PanoptesObject` instances, a list of object IDs, a single :py:class:`.PanoptesObject` instance, or a single object ID. Examples:: organization.links.projects.remove(1234) ...
[ "Removes", "the", "given", "objs", "from", "this", "LinkCollection", "." ]
train
https://github.com/zooniverse/panoptes-python-client/blob/138d93cb03378501a8d349428e381ad73f928680/panoptes_client/panoptes.py#L1049-L1086
marshallward/f90nml
f90nml/cli.py
parse
def parse(): """Parse the command line input arguments.""" parser = argparse.ArgumentParser() parser.add_argument('--version', action='version', version='f90nml {0}'.format(f90nml.__version__)) parser.add_argument('--group', '-g', action='store', help="s...
python
def parse(): """Parse the command line input arguments.""" parser = argparse.ArgumentParser() parser.add_argument('--version', action='version', version='f90nml {0}'.format(f90nml.__version__)) parser.add_argument('--group', '-g', action='store', help="s...
[ "def", "parse", "(", ")", ":", "parser", "=", "argparse", ".", "ArgumentParser", "(", ")", "parser", ".", "add_argument", "(", "'--version'", ",", "action", "=", "'version'", ",", "version", "=", "'f90nml {0}'", ".", "format", "(", "f90nml", ".", "__versio...
Parse the command line input arguments.
[ "Parse", "the", "command", "line", "input", "arguments", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/cli.py#L38-L188
marshallward/f90nml
f90nml/__init__.py
write
def write(nml, nml_path, force=False, sort=False): """Save a namelist to disk using either a file object or its file path. File object usage: >>> with open(nml_path, 'w') as nml_file: >>> f90nml.write(nml, nml_file) File path usage: >>> f90nml.write(nml, 'data.nml') This function is...
python
def write(nml, nml_path, force=False, sort=False): """Save a namelist to disk using either a file object or its file path. File object usage: >>> with open(nml_path, 'w') as nml_file: >>> f90nml.write(nml, nml_file) File path usage: >>> f90nml.write(nml, 'data.nml') This function is...
[ "def", "write", "(", "nml", ",", "nml_path", ",", "force", "=", "False", ",", "sort", "=", "False", ")", ":", "# Promote dicts to Namelists", "if", "not", "isinstance", "(", "nml", ",", "Namelist", ")", "and", "isinstance", "(", "nml", ",", "dict", ")", ...
Save a namelist to disk using either a file object or its file path. File object usage: >>> with open(nml_path, 'w') as nml_file: >>> f90nml.write(nml, nml_file) File path usage: >>> f90nml.write(nml, 'data.nml') This function is equivalent to the ``write`` function of the ``Namelist`` ...
[ "Save", "a", "namelist", "to", "disk", "using", "either", "a", "file", "object", "or", "its", "file", "path", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/__init__.py#L50-L82
marshallward/f90nml
f90nml/__init__.py
patch
def patch(nml_path, nml_patch, out_path=None): """Create a new namelist based on an input namelist and reference dict. >>> f90nml.patch('data.nml', nml_patch, 'patched_data.nml') This function is equivalent to the ``read`` function of the ``Parser`` object with the patch output arguments. >>> par...
python
def patch(nml_path, nml_patch, out_path=None): """Create a new namelist based on an input namelist and reference dict. >>> f90nml.patch('data.nml', nml_patch, 'patched_data.nml') This function is equivalent to the ``read`` function of the ``Parser`` object with the patch output arguments. >>> par...
[ "def", "patch", "(", "nml_path", ",", "nml_patch", ",", "out_path", "=", "None", ")", ":", "parser", "=", "Parser", "(", ")", "return", "parser", ".", "read", "(", "nml_path", ",", "nml_patch", ",", "out_path", ")" ]
Create a new namelist based on an input namelist and reference dict. >>> f90nml.patch('data.nml', nml_patch, 'patched_data.nml') This function is equivalent to the ``read`` function of the ``Parser`` object with the patch output arguments. >>> parser = f90nml.Parser() >>> nml = parser.read('data....
[ "Create", "a", "new", "namelist", "based", "on", "an", "input", "namelist", "and", "reference", "dict", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/__init__.py#L85-L102
Calysto/calysto
calysto/graphics.py
Canvas.setCoords
def setCoords(self, x1, y1, x2, y2): """Set coordinates of window to run from (x1,y1) in the lower-left corner to (x2,y2) in the upper-right corner.""" self.trans = Transform(self.size[0], self.size[1], x1, y1, x2, y2)
python
def setCoords(self, x1, y1, x2, y2): """Set coordinates of window to run from (x1,y1) in the lower-left corner to (x2,y2) in the upper-right corner.""" self.trans = Transform(self.size[0], self.size[1], x1, y1, x2, y2)
[ "def", "setCoords", "(", "self", ",", "x1", ",", "y1", ",", "x2", ",", "y2", ")", ":", "self", ".", "trans", "=", "Transform", "(", "self", ".", "size", "[", "0", "]", ",", "self", ".", "size", "[", "1", "]", ",", "x1", ",", "y1", ",", "x2"...
Set coordinates of window to run from (x1,y1) in the lower-left corner to (x2,y2) in the upper-right corner.
[ "Set", "coordinates", "of", "window", "to", "run", "from", "(", "x1", "y1", ")", "in", "the", "lower", "-", "left", "corner", "to", "(", "x2", "y2", ")", "in", "the", "upper", "-", "right", "corner", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/graphics.py#L94-L97
Calysto/calysto
calysto/graphics.py
Canvas.convert
def convert(self, format="png", **kwargs): """ png, ps, pdf, gif, jpg, svg returns image in format as bytes """ if format.upper() in cairosvg.SURFACES: surface = cairosvg.SURFACES[format.upper()] else: raise Exception("'%s' image format unavailable...
python
def convert(self, format="png", **kwargs): """ png, ps, pdf, gif, jpg, svg returns image in format as bytes """ if format.upper() in cairosvg.SURFACES: surface = cairosvg.SURFACES[format.upper()] else: raise Exception("'%s' image format unavailable...
[ "def", "convert", "(", "self", ",", "format", "=", "\"png\"", ",", "*", "*", "kwargs", ")", ":", "if", "format", ".", "upper", "(", ")", "in", "cairosvg", ".", "SURFACES", ":", "surface", "=", "cairosvg", ".", "SURFACES", "[", "format", ".", "upper",...
png, ps, pdf, gif, jpg, svg returns image in format as bytes
[ "png", "ps", "pdf", "gif", "jpg", "svg", "returns", "image", "in", "format", "as", "bytes" ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/graphics.py#L226-L236
Calysto/calysto
calysto/graphics.py
Canvas.toPIL
def toPIL(self, **attribs): """ Convert canvas to a PIL image """ import PIL.Image bytes = self.convert("png") sfile = io.BytesIO(bytes) pil = PIL.Image.open(sfile) return pil
python
def toPIL(self, **attribs): """ Convert canvas to a PIL image """ import PIL.Image bytes = self.convert("png") sfile = io.BytesIO(bytes) pil = PIL.Image.open(sfile) return pil
[ "def", "toPIL", "(", "self", ",", "*", "*", "attribs", ")", ":", "import", "PIL", ".", "Image", "bytes", "=", "self", ".", "convert", "(", "\"png\"", ")", "sfile", "=", "io", ".", "BytesIO", "(", "bytes", ")", "pil", "=", "PIL", ".", "Image", "."...
Convert canvas to a PIL image
[ "Convert", "canvas", "to", "a", "PIL", "image" ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/graphics.py#L238-L246
Calysto/calysto
calysto/graphics.py
Canvas.toGIF
def toGIF(self, **attribs): """ Convert canvas to GIF bytes """ im = self.toPIL(**attribs) sfile = io.BytesIO() im.save(sfile, format="gif") return sfile.getvalue()
python
def toGIF(self, **attribs): """ Convert canvas to GIF bytes """ im = self.toPIL(**attribs) sfile = io.BytesIO() im.save(sfile, format="gif") return sfile.getvalue()
[ "def", "toGIF", "(", "self", ",", "*", "*", "attribs", ")", ":", "im", "=", "self", ".", "toPIL", "(", "*", "*", "attribs", ")", "sfile", "=", "io", ".", "BytesIO", "(", ")", "im", ".", "save", "(", "sfile", ",", "format", "=", "\"gif\"", ")", ...
Convert canvas to GIF bytes
[ "Convert", "canvas", "to", "GIF", "bytes" ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/graphics.py#L248-L255
Calysto/calysto
calysto/graphics.py
Canvas.getPixels
def getPixels(self): """ Return a stream of pixels from current Canvas. """ array = self.toArray() (width, height, depth) = array.size for x in range(width): for y in range(height): yield Pixel(array, x, y)
python
def getPixels(self): """ Return a stream of pixels from current Canvas. """ array = self.toArray() (width, height, depth) = array.size for x in range(width): for y in range(height): yield Pixel(array, x, y)
[ "def", "getPixels", "(", "self", ")", ":", "array", "=", "self", ".", "toArray", "(", ")", "(", "width", ",", "height", ",", "depth", ")", "=", "array", ".", "size", "for", "x", "in", "range", "(", "width", ")", ":", "for", "y", "in", "range", ...
Return a stream of pixels from current Canvas.
[ "Return", "a", "stream", "of", "pixels", "from", "current", "Canvas", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/graphics.py#L273-L281
Calysto/calysto
calysto/graphics.py
Circle.getP1
def getP1(self): """ Left, upper point """ return Point(self.center[0] - self.radius, self.center[1] - self.radius)
python
def getP1(self): """ Left, upper point """ return Point(self.center[0] - self.radius, self.center[1] - self.radius)
[ "def", "getP1", "(", "self", ")", ":", "return", "Point", "(", "self", ".", "center", "[", "0", "]", "-", "self", ".", "radius", ",", "self", ".", "center", "[", "1", "]", "-", "self", ".", "radius", ")" ]
Left, upper point
[ "Left", "upper", "point" ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/graphics.py#L454-L459
Calysto/calysto
calysto/graphics.py
Circle.getP2
def getP2(self): """ Right, lower point """ return Point(self.center[0] + self.radius, self.center[1] + self.radius)
python
def getP2(self): """ Right, lower point """ return Point(self.center[0] + self.radius, self.center[1] + self.radius)
[ "def", "getP2", "(", "self", ")", ":", "return", "Point", "(", "self", ".", "center", "[", "0", "]", "+", "self", ".", "radius", ",", "self", ".", "center", "[", "1", "]", "+", "self", ".", "radius", ")" ]
Right, lower point
[ "Right", "lower", "point" ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/graphics.py#L461-L466
Calysto/calysto
calysto/simulation.py
Simulation.start_sim
def start_sim(self, gui=True, set_values={}, error=None): """ Run the simulation in the background, showing the GUI by default. """ self.error = error if not self.is_running.is_set(): def loop(): self.need_to_stop.clear() self.is_runnin...
python
def start_sim(self, gui=True, set_values={}, error=None): """ Run the simulation in the background, showing the GUI by default. """ self.error = error if not self.is_running.is_set(): def loop(): self.need_to_stop.clear() self.is_runnin...
[ "def", "start_sim", "(", "self", ",", "gui", "=", "True", ",", "set_values", "=", "{", "}", ",", "error", "=", "None", ")", ":", "self", ".", "error", "=", "error", "if", "not", "self", ".", "is_running", ".", "is_set", "(", ")", ":", "def", "loo...
Run the simulation in the background, showing the GUI by default.
[ "Run", "the", "simulation", "in", "the", "background", "showing", "the", "GUI", "by", "default", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/simulation.py#L109-L149
Calysto/calysto
calysto/simulation.py
Simulation.draw
def draw(self): """ Render and draw the world and robots. """ from calysto.display import display, clear_output canvas = self.render() clear_output(wait=True) display(canvas)
python
def draw(self): """ Render and draw the world and robots. """ from calysto.display import display, clear_output canvas = self.render() clear_output(wait=True) display(canvas)
[ "def", "draw", "(", "self", ")", ":", "from", "calysto", ".", "display", "import", "display", ",", "clear_output", "canvas", "=", "self", ".", "render", "(", ")", "clear_output", "(", "wait", "=", "True", ")", "display", "(", "canvas", ")" ]
Render and draw the world and robots.
[ "Render", "and", "draw", "the", "world", "and", "robots", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/simulation.py#L180-L187
Calysto/calysto
calysto/simulation.py
Simulation.sleep
def sleep(self, seconds): """ Sleep in simulated time. """ start = self.time() while (self.time() - start < seconds and not self.need_to_stop.is_set()): self.need_to_stop.wait(self.sim_time)
python
def sleep(self, seconds): """ Sleep in simulated time. """ start = self.time() while (self.time() - start < seconds and not self.need_to_stop.is_set()): self.need_to_stop.wait(self.sim_time)
[ "def", "sleep", "(", "self", ",", "seconds", ")", ":", "start", "=", "self", ".", "time", "(", ")", "while", "(", "self", ".", "time", "(", ")", "-", "start", "<", "seconds", "and", "not", "self", ".", "need_to_stop", ".", "is_set", "(", ")", ")"...
Sleep in simulated time.
[ "Sleep", "in", "simulated", "time", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/simulation.py#L209-L216
Calysto/calysto
calysto/simulation.py
Simulation.runBrain
def runBrain(self, f): """ Run a brain program in the background. """ if self.error: self.error.value = "" def wrapper(): self.brain_running.set() try: f() except KeyboardInterrupt: # Just stop ...
python
def runBrain(self, f): """ Run a brain program in the background. """ if self.error: self.error.value = "" def wrapper(): self.brain_running.set() try: f() except KeyboardInterrupt: # Just stop ...
[ "def", "runBrain", "(", "self", ",", "f", ")", ":", "if", "self", ".", "error", ":", "self", ".", "error", ".", "value", "=", "\"\"", "def", "wrapper", "(", ")", ":", "self", ".", "brain_running", ".", "set", "(", ")", "try", ":", "f", "(", ")"...
Run a brain program in the background.
[ "Run", "a", "brain", "program", "in", "the", "background", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/simulation.py#L221-L242
Calysto/calysto
calysto/simulation.py
DiscreteSimulation.addCluster
def addCluster(self, cx, cy, item, count, lam_percent=.25): """ Add a Poisson cluster of count items around (x,y). """ dx, dy = map(lambda v: v * lam_percent, self.psize) total = 0 while total < count: points = np.random.poisson(lam=(dx, dy), size=(count, 2)) ...
python
def addCluster(self, cx, cy, item, count, lam_percent=.25): """ Add a Poisson cluster of count items around (x,y). """ dx, dy = map(lambda v: v * lam_percent, self.psize) total = 0 while total < count: points = np.random.poisson(lam=(dx, dy), size=(count, 2)) ...
[ "def", "addCluster", "(", "self", ",", "cx", ",", "cy", ",", "item", ",", "count", ",", "lam_percent", "=", ".25", ")", ":", "dx", ",", "dy", "=", "map", "(", "lambda", "v", ":", "v", "*", "lam_percent", ",", "self", ".", "psize", ")", "total", ...
Add a Poisson cluster of count items around (x,y).
[ "Add", "a", "Poisson", "cluster", "of", "count", "items", "around", "(", "x", "y", ")", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/simulation.py#L286-L300
Calysto/calysto
calysto/simulation.py
Robot.forward
def forward(self, seconds, vx=5): """ Move continuously in simulator for seconds and velocity vx. """ self.vx = vx self.sleep(seconds) self.vx = 0
python
def forward(self, seconds, vx=5): """ Move continuously in simulator for seconds and velocity vx. """ self.vx = vx self.sleep(seconds) self.vx = 0
[ "def", "forward", "(", "self", ",", "seconds", ",", "vx", "=", "5", ")", ":", "self", ".", "vx", "=", "vx", "self", ".", "sleep", "(", "seconds", ")", "self", ".", "vx", "=", "0" ]
Move continuously in simulator for seconds and velocity vx.
[ "Move", "continuously", "in", "simulator", "for", "seconds", "and", "velocity", "vx", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/simulation.py#L393-L399
Calysto/calysto
calysto/simulation.py
DNARobot.codon2weight
def codon2weight(self, codon): """ Turn a codon of "000" to "999" to a number between -5.0 and 5.0. """ length = len(codon) retval = int(codon) return retval/(10 ** (length - 1)) - 5.0
python
def codon2weight(self, codon): """ Turn a codon of "000" to "999" to a number between -5.0 and 5.0. """ length = len(codon) retval = int(codon) return retval/(10 ** (length - 1)) - 5.0
[ "def", "codon2weight", "(", "self", ",", "codon", ")", ":", "length", "=", "len", "(", "codon", ")", "retval", "=", "int", "(", "codon", ")", "return", "retval", "/", "(", "10", "**", "(", "length", "-", "1", ")", ")", "-", "5.0" ]
Turn a codon of "000" to "999" to a number between -5.0 and 5.0.
[ "Turn", "a", "codon", "of", "000", "to", "999", "to", "a", "number", "between", "-", "5", ".", "0", "and", "5", ".", "0", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/simulation.py#L1248-L1255
Calysto/calysto
calysto/simulation.py
DNARobot.weight2codon
def weight2codon(self, weight, length=None): """ Given a weight between -5 and 5, turn it into a codon, eg "000" to "999" """ if length is None: length = self.clen retval = 0 weight = min(max(weight + 5.0, 0), 10.0) * (10 ** (length - 1)) for i...
python
def weight2codon(self, weight, length=None): """ Given a weight between -5 and 5, turn it into a codon, eg "000" to "999" """ if length is None: length = self.clen retval = 0 weight = min(max(weight + 5.0, 0), 10.0) * (10 ** (length - 1)) for i...
[ "def", "weight2codon", "(", "self", ",", "weight", ",", "length", "=", "None", ")", ":", "if", "length", "is", "None", ":", "length", "=", "self", ".", "clen", "retval", "=", "0", "weight", "=", "min", "(", "max", "(", "weight", "+", "5.0", ",", ...
Given a weight between -5 and 5, turn it into a codon, eg "000" to "999"
[ "Given", "a", "weight", "between", "-", "5", "and", "5", "turn", "it", "into", "a", "codon", "eg", "000", "to", "999" ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/simulation.py#L1257-L1273
marshallward/f90nml
f90nml/namelist.py
is_nullable_list
def is_nullable_list(val, vtype): """Return True if list contains either values of type `vtype` or None.""" return (isinstance(val, list) and any(isinstance(v, vtype) for v in val) and all((isinstance(v, vtype) or v is None) for v in val))
python
def is_nullable_list(val, vtype): """Return True if list contains either values of type `vtype` or None.""" return (isinstance(val, list) and any(isinstance(v, vtype) for v in val) and all((isinstance(v, vtype) or v is None) for v in val))
[ "def", "is_nullable_list", "(", "val", ",", "vtype", ")", ":", "return", "(", "isinstance", "(", "val", ",", "list", ")", "and", "any", "(", "isinstance", "(", "v", ",", "vtype", ")", "for", "v", "in", "val", ")", "and", "all", "(", "(", "isinstanc...
Return True if list contains either values of type `vtype` or None.
[ "Return", "True", "if", "list", "contains", "either", "values", "of", "type", "vtype", "or", "None", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L721-L725
marshallward/f90nml
f90nml/namelist.py
Namelist.column_width
def column_width(self, width): """Validate and set the column width.""" if isinstance(width, int): if width >= 0: self._column_width = width else: raise ValueError('Column width must be nonnegative.') else: raise TypeError('Colu...
python
def column_width(self, width): """Validate and set the column width.""" if isinstance(width, int): if width >= 0: self._column_width = width else: raise ValueError('Column width must be nonnegative.') else: raise TypeError('Colu...
[ "def", "column_width", "(", "self", ",", "width", ")", ":", "if", "isinstance", "(", "width", ",", "int", ")", ":", "if", "width", ">=", "0", ":", "self", ".", "_column_width", "=", "width", "else", ":", "raise", "ValueError", "(", "'Column width must be...
Validate and set the column width.
[ "Validate", "and", "set", "the", "column", "width", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L158-L166
marshallward/f90nml
f90nml/namelist.py
Namelist.indent
def indent(self, value): """Validate and set the indent width.""" # Explicit indent setting if isinstance(value, str): if value.isspace() or len(value) == 0: self._indent = value else: raise ValueError('String indentation can only contain '...
python
def indent(self, value): """Validate and set the indent width.""" # Explicit indent setting if isinstance(value, str): if value.isspace() or len(value) == 0: self._indent = value else: raise ValueError('String indentation can only contain '...
[ "def", "indent", "(", "self", ",", "value", ")", ":", "# Explicit indent setting", "if", "isinstance", "(", "value", ",", "str", ")", ":", "if", "value", ".", "isspace", "(", ")", "or", "len", "(", "value", ")", "==", "0", ":", "self", ".", "_indent"...
Validate and set the indent width.
[ "Validate", "and", "set", "the", "indent", "width", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L179-L198
marshallward/f90nml
f90nml/namelist.py
Namelist.end_comma
def end_comma(self, value): """Validate and set the comma termination flag.""" if not isinstance(value, bool): raise TypeError('end_comma attribute must be a logical type.') self._end_comma = value
python
def end_comma(self, value): """Validate and set the comma termination flag.""" if not isinstance(value, bool): raise TypeError('end_comma attribute must be a logical type.') self._end_comma = value
[ "def", "end_comma", "(", "self", ",", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "bool", ")", ":", "raise", "TypeError", "(", "'end_comma attribute must be a logical type.'", ")", "self", ".", "_end_comma", "=", "value" ]
Validate and set the comma termination flag.
[ "Validate", "and", "set", "the", "comma", "termination", "flag", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L212-L216
marshallward/f90nml
f90nml/namelist.py
Namelist.index_spacing
def index_spacing(self, value): """Validate and set the index_spacing flag.""" if not isinstance(value, bool): raise TypeError('index_spacing attribute must be a logical type.') self._index_spacing = value
python
def index_spacing(self, value): """Validate and set the index_spacing flag.""" if not isinstance(value, bool): raise TypeError('index_spacing attribute must be a logical type.') self._index_spacing = value
[ "def", "index_spacing", "(", "self", ",", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "bool", ")", ":", "raise", "TypeError", "(", "'index_spacing attribute must be a logical type.'", ")", "self", ".", "_index_spacing", "=", "value" ]
Validate and set the index_spacing flag.
[ "Validate", "and", "set", "the", "index_spacing", "flag", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L224-L228
marshallward/f90nml
f90nml/namelist.py
Namelist.uppercase
def uppercase(self, value): """Validate and set the uppercase flag.""" if not isinstance(value, bool): raise TypeError('uppercase attribute must be a logical type.') self._uppercase = value
python
def uppercase(self, value): """Validate and set the uppercase flag.""" if not isinstance(value, bool): raise TypeError('uppercase attribute must be a logical type.') self._uppercase = value
[ "def", "uppercase", "(", "self", ",", "value", ")", ":", "if", "not", "isinstance", "(", "value", ",", "bool", ")", ":", "raise", "TypeError", "(", "'uppercase attribute must be a logical type.'", ")", "self", ".", "_uppercase", "=", "value" ]
Validate and set the uppercase flag.
[ "Validate", "and", "set", "the", "uppercase", "flag", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L236-L240
marshallward/f90nml
f90nml/namelist.py
Namelist.float_format
def float_format(self, value): """Validate and set the upper case flag.""" if isinstance(value, str): # Duck-test the format string; raise ValueError on fail '{0:{1}}'.format(1.23, value) self._float_format = value else: raise TypeError('Floating ...
python
def float_format(self, value): """Validate and set the upper case flag.""" if isinstance(value, str): # Duck-test the format string; raise ValueError on fail '{0:{1}}'.format(1.23, value) self._float_format = value else: raise TypeError('Floating ...
[ "def", "float_format", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "str", ")", ":", "# Duck-test the format string; raise ValueError on fail", "'{0:{1}}'", ".", "format", "(", "1.23", ",", "value", ")", "self", ".", "_float_format...
Validate and set the upper case flag.
[ "Validate", "and", "set", "the", "upper", "case", "flag", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L252-L260
marshallward/f90nml
f90nml/namelist.py
Namelist.logical_repr
def logical_repr(self, value): """Set the string representation of logical values.""" if not any(isinstance(value, t) for t in (list, tuple)): raise TypeError("Logical representation must be a tuple with " "a valid true and false value.") if not len(value)...
python
def logical_repr(self, value): """Set the string representation of logical values.""" if not any(isinstance(value, t) for t in (list, tuple)): raise TypeError("Logical representation must be a tuple with " "a valid true and false value.") if not len(value)...
[ "def", "logical_repr", "(", "self", ",", "value", ")", ":", "if", "not", "any", "(", "isinstance", "(", "value", ",", "t", ")", "for", "t", "in", "(", "list", ",", "tuple", ")", ")", ":", "raise", "TypeError", "(", "\"Logical representation must be a tup...
Set the string representation of logical values.
[ "Set", "the", "string", "representation", "of", "logical", "values", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L278-L287
marshallward/f90nml
f90nml/namelist.py
Namelist.false_repr
def false_repr(self, value): """Validate and set the logical false representation.""" if isinstance(value, str): if not (value.lower().startswith('f') or value.lower().startswith('.f')): raise ValueError("Logical false representation must start " ...
python
def false_repr(self, value): """Validate and set the logical false representation.""" if isinstance(value, str): if not (value.lower().startswith('f') or value.lower().startswith('.f')): raise ValueError("Logical false representation must start " ...
[ "def", "false_repr", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "str", ")", ":", "if", "not", "(", "value", ".", "lower", "(", ")", ".", "startswith", "(", "'f'", ")", "or", "value", ".", "lower", "(", ")", ".", ...
Validate and set the logical false representation.
[ "Validate", "and", "set", "the", "logical", "false", "representation", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L319-L329
marshallward/f90nml
f90nml/namelist.py
Namelist.start_index
def start_index(self, value): """Validate and set the vector start index.""" # TODO: Validate contents? (May want to set before adding the data.) if not isinstance(value, dict): raise TypeError('start_index attribute must be a dict.') self._start_index = value
python
def start_index(self, value): """Validate and set the vector start index.""" # TODO: Validate contents? (May want to set before adding the data.) if not isinstance(value, dict): raise TypeError('start_index attribute must be a dict.') self._start_index = value
[ "def", "start_index", "(", "self", ",", "value", ")", ":", "# TODO: Validate contents? (May want to set before adding the data.)", "if", "not", "isinstance", "(", "value", ",", "dict", ")", ":", "raise", "TypeError", "(", "'start_index attribute must be a dict.'", ")", ...
Validate and set the vector start index.
[ "Validate", "and", "set", "the", "vector", "start", "index", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L364-L369
marshallward/f90nml
f90nml/namelist.py
Namelist.write
def write(self, nml_path, force=False, sort=False): """Write Namelist to a Fortran 90 namelist file. >>> nml = f90nml.read('input.nml') >>> nml.write('out.nml') """ nml_is_file = hasattr(nml_path, 'read') if not force and not nml_is_file and os.path.isfile(nml_path): ...
python
def write(self, nml_path, force=False, sort=False): """Write Namelist to a Fortran 90 namelist file. >>> nml = f90nml.read('input.nml') >>> nml.write('out.nml') """ nml_is_file = hasattr(nml_path, 'read') if not force and not nml_is_file and os.path.isfile(nml_path): ...
[ "def", "write", "(", "self", ",", "nml_path", ",", "force", "=", "False", ",", "sort", "=", "False", ")", ":", "nml_is_file", "=", "hasattr", "(", "nml_path", ",", "'read'", ")", "if", "not", "force", "and", "not", "nml_is_file", "and", "os", ".", "p...
Write Namelist to a Fortran 90 namelist file. >>> nml = f90nml.read('input.nml') >>> nml.write('out.nml')
[ "Write", "Namelist", "to", "a", "Fortran", "90", "namelist", "file", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L391-L406
marshallward/f90nml
f90nml/namelist.py
Namelist.patch
def patch(self, nml_patch): """Update the namelist from another partial or full namelist. This is different from the intrinsic `update()` method, which replaces a namelist section. Rather, it updates the values within a section. """ for sec in nml_patch: if sec not ...
python
def patch(self, nml_patch): """Update the namelist from another partial or full namelist. This is different from the intrinsic `update()` method, which replaces a namelist section. Rather, it updates the values within a section. """ for sec in nml_patch: if sec not ...
[ "def", "patch", "(", "self", ",", "nml_patch", ")", ":", "for", "sec", "in", "nml_patch", ":", "if", "sec", "not", "in", "self", ":", "self", "[", "sec", "]", "=", "Namelist", "(", ")", "self", "[", "sec", "]", ".", "update", "(", "nml_patch", "[...
Update the namelist from another partial or full namelist. This is different from the intrinsic `update()` method, which replaces a namelist section. Rather, it updates the values within a section.
[ "Update", "the", "namelist", "from", "another", "partial", "or", "full", "namelist", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L408-L417
marshallward/f90nml
f90nml/namelist.py
Namelist.groups
def groups(self): """Return an iterator that spans values with group and variable names. Elements of the iterator consist of a tuple containing two values. The first is internal tuple containing the current namelist group and its variable name. The second element of the returned tuple...
python
def groups(self): """Return an iterator that spans values with group and variable names. Elements of the iterator consist of a tuple containing two values. The first is internal tuple containing the current namelist group and its variable name. The second element of the returned tuple...
[ "def", "groups", "(", "self", ")", ":", "for", "key", ",", "value", "in", "self", ".", "items", "(", ")", ":", "for", "inner_key", ",", "inner_value", "in", "value", ".", "items", "(", ")", ":", "yield", "(", "key", ",", "inner_key", ")", ",", "i...
Return an iterator that spans values with group and variable names. Elements of the iterator consist of a tuple containing two values. The first is internal tuple containing the current namelist group and its variable name. The second element of the returned tuple is the value associa...
[ "Return", "an", "iterator", "that", "spans", "values", "with", "group", "and", "variable", "names", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L419-L429
marshallward/f90nml
f90nml/namelist.py
Namelist._write_nmlgrp
def _write_nmlgrp(self, grp_name, grp_vars, nml_file, sort=False): """Write namelist group to target file.""" if self._newline: print(file=nml_file) self._newline = True if self.uppercase: grp_name = grp_name.upper() if sort: grp_vars = Namel...
python
def _write_nmlgrp(self, grp_name, grp_vars, nml_file, sort=False): """Write namelist group to target file.""" if self._newline: print(file=nml_file) self._newline = True if self.uppercase: grp_name = grp_name.upper() if sort: grp_vars = Namel...
[ "def", "_write_nmlgrp", "(", "self", ",", "grp_name", ",", "grp_vars", ",", "nml_file", ",", "sort", "=", "False", ")", ":", "if", "self", ".", "_newline", ":", "print", "(", "file", "=", "nml_file", ")", "self", ".", "_newline", "=", "True", "if", "...
Write namelist group to target file.
[ "Write", "namelist", "group", "to", "target", "file", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L449-L471
marshallward/f90nml
f90nml/namelist.py
Namelist._var_strings
def _var_strings(self, v_name, v_values, v_idx=None, v_start=None): """Convert namelist variable to list of fixed-width strings.""" if self.uppercase: v_name = v_name.upper() var_strs = [] # Parse a multidimensional array if is_nullable_list(v_values, list): ...
python
def _var_strings(self, v_name, v_values, v_idx=None, v_start=None): """Convert namelist variable to list of fixed-width strings.""" if self.uppercase: v_name = v_name.upper() var_strs = [] # Parse a multidimensional array if is_nullable_list(v_values, list): ...
[ "def", "_var_strings", "(", "self", ",", "v_name", ",", "v_values", ",", "v_idx", "=", "None", ",", "v_start", "=", "None", ")", ":", "if", "self", ".", "uppercase", ":", "v_name", "=", "v_name", ".", "upper", "(", ")", "var_strs", "=", "[", "]", "...
Convert namelist variable to list of fixed-width strings.
[ "Convert", "namelist", "variable", "to", "list", "of", "fixed", "-", "width", "strings", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L473-L622
marshallward/f90nml
f90nml/namelist.py
Namelist.todict
def todict(self, complex_tuple=False): """Return a dict equivalent to the namelist. Since Fortran variables and names cannot start with the ``_`` character, any keys starting with this token denote metadata, such as starting index. The ``complex_tuple`` flag is used to convert ...
python
def todict(self, complex_tuple=False): """Return a dict equivalent to the namelist. Since Fortran variables and names cannot start with the ``_`` character, any keys starting with this token denote metadata, such as starting index. The ``complex_tuple`` flag is used to convert ...
[ "def", "todict", "(", "self", ",", "complex_tuple", "=", "False", ")", ":", "# TODO: Preserve ordering", "nmldict", "=", "OrderedDict", "(", "self", ")", "# Search for namelists within the namelist", "# TODO: Move repeated stuff to new functions", "for", "key", ",", "valu...
Return a dict equivalent to the namelist. Since Fortran variables and names cannot start with the ``_`` character, any keys starting with this token denote metadata, such as starting index. The ``complex_tuple`` flag is used to convert complex data into an equivalent 2-tuple, w...
[ "Return", "a", "dict", "equivalent", "to", "the", "namelist", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L624-L673
marshallward/f90nml
f90nml/namelist.py
Namelist._f90repr
def _f90repr(self, value): """Convert primitive Python types to equivalent Fortran strings.""" if isinstance(value, bool): return self._f90bool(value) elif isinstance(value, numbers.Integral): return self._f90int(value) elif isinstance(value, numbers.Real): ...
python
def _f90repr(self, value): """Convert primitive Python types to equivalent Fortran strings.""" if isinstance(value, bool): return self._f90bool(value) elif isinstance(value, numbers.Integral): return self._f90int(value) elif isinstance(value, numbers.Real): ...
[ "def", "_f90repr", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "bool", ")", ":", "return", "self", ".", "_f90bool", "(", "value", ")", "elif", "isinstance", "(", "value", ",", "numbers", ".", "Integral", ")", ":", "ret...
Convert primitive Python types to equivalent Fortran strings.
[ "Convert", "primitive", "Python", "types", "to", "equivalent", "Fortran", "strings", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L675-L691
marshallward/f90nml
f90nml/namelist.py
Namelist._f90complex
def _f90complex(self, value): """Return a Fortran 90 representation of a complex number.""" return '({0:{fmt}}, {1:{fmt}})'.format(value.real, value.imag, fmt=self.float_format)
python
def _f90complex(self, value): """Return a Fortran 90 representation of a complex number.""" return '({0:{fmt}}, {1:{fmt}})'.format(value.real, value.imag, fmt=self.float_format)
[ "def", "_f90complex", "(", "self", ",", "value", ")", ":", "return", "'({0:{fmt}}, {1:{fmt}})'", ".", "format", "(", "value", ".", "real", ",", "value", ".", "imag", ",", "fmt", "=", "self", ".", "float_format", ")" ]
Return a Fortran 90 representation of a complex number.
[ "Return", "a", "Fortran", "90", "representation", "of", "a", "complex", "number", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L705-L708
marshallward/f90nml
f90nml/namelist.py
Namelist._f90str
def _f90str(self, value): """Return a Fortran 90 representation of a string.""" # Replace Python quote escape sequence with Fortran result = repr(str(value)).replace("\\'", "''").replace('\\"', '""') # Un-escape the Python backslash escape sequence result = result.replace('\\\\'...
python
def _f90str(self, value): """Return a Fortran 90 representation of a string.""" # Replace Python quote escape sequence with Fortran result = repr(str(value)).replace("\\'", "''").replace('\\"', '""') # Un-escape the Python backslash escape sequence result = result.replace('\\\\'...
[ "def", "_f90str", "(", "self", ",", "value", ")", ":", "# Replace Python quote escape sequence with Fortran", "result", "=", "repr", "(", "str", "(", "value", ")", ")", ".", "replace", "(", "\"\\\\'\"", ",", "\"''\"", ")", ".", "replace", "(", "'\\\\\"'", ",...
Return a Fortran 90 representation of a string.
[ "Return", "a", "Fortran", "90", "representation", "of", "a", "string", "." ]
train
https://github.com/marshallward/f90nml/blob/4932cabc5221afc844ee6a5b4a05ceb8bd4a2711/f90nml/namelist.py#L710-L718
numberly/appnexus-client
appnexus/cursor.py
Cursor.extract_data
def extract_data(self, page): """Extract the AppNexus object or list of objects from the response""" response_keys = set(page.keys()) uncommon_keys = response_keys - self.common_keys for possible_data_key in uncommon_keys: element = page[possible_data_key] if isi...
python
def extract_data(self, page): """Extract the AppNexus object or list of objects from the response""" response_keys = set(page.keys()) uncommon_keys = response_keys - self.common_keys for possible_data_key in uncommon_keys: element = page[possible_data_key] if isi...
[ "def", "extract_data", "(", "self", ",", "page", ")", ":", "response_keys", "=", "set", "(", "page", ".", "keys", "(", ")", ")", "uncommon_keys", "=", "response_keys", "-", "self", ".", "common_keys", "for", "possible_data_key", "in", "uncommon_keys", ":", ...
Extract the AppNexus object or list of objects from the response
[ "Extract", "the", "AppNexus", "object", "or", "list", "of", "objects", "from", "the", "response" ]
train
https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/cursor.py#L59-L71
numberly/appnexus-client
appnexus/cursor.py
Cursor.first
def first(self): """Extract the first AppNexus object present in the response""" page = self.get_page(num_elements=1) data = self.extract_data(page) if data: return data[0]
python
def first(self): """Extract the first AppNexus object present in the response""" page = self.get_page(num_elements=1) data = self.extract_data(page) if data: return data[0]
[ "def", "first", "(", "self", ")", ":", "page", "=", "self", ".", "get_page", "(", "num_elements", "=", "1", ")", "data", "=", "self", ".", "extract_data", "(", "page", ")", "if", "data", ":", "return", "data", "[", "0", "]" ]
Extract the first AppNexus object present in the response
[ "Extract", "the", "first", "AppNexus", "object", "present", "in", "the", "response" ]
train
https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/cursor.py#L74-L79
numberly/appnexus-client
appnexus/cursor.py
Cursor.get_page
def get_page(self, start_element=0, num_elements=None): """Get a page (100 elements) starting from `start_element`""" if num_elements is None: num_elements = self.batch_size specs = self.specs.copy() specs.update(start_element=start_element, num_elements=num_elements) ...
python
def get_page(self, start_element=0, num_elements=None): """Get a page (100 elements) starting from `start_element`""" if num_elements is None: num_elements = self.batch_size specs = self.specs.copy() specs.update(start_element=start_element, num_elements=num_elements) ...
[ "def", "get_page", "(", "self", ",", "start_element", "=", "0", ",", "num_elements", "=", "None", ")", ":", "if", "num_elements", "is", "None", ":", "num_elements", "=", "self", ".", "batch_size", "specs", "=", "self", ".", "specs", ".", "copy", "(", "...
Get a page (100 elements) starting from `start_element`
[ "Get", "a", "page", "(", "100", "elements", ")", "starting", "from", "start_element" ]
train
https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/cursor.py#L81-L87
numberly/appnexus-client
appnexus/cursor.py
Cursor.size
def size(self): """Return the number of elements of the cursor with skip and limit""" initial_count = self.count() count_with_skip = max(0, initial_count - self._skip) size = min(count_with_skip, self._limit) return size
python
def size(self): """Return the number of elements of the cursor with skip and limit""" initial_count = self.count() count_with_skip = max(0, initial_count - self._skip) size = min(count_with_skip, self._limit) return size
[ "def", "size", "(", "self", ")", ":", "initial_count", "=", "self", ".", "count", "(", ")", "count_with_skip", "=", "max", "(", "0", ",", "initial_count", "-", "self", ".", "_skip", ")", "size", "=", "min", "(", "count_with_skip", ",", "self", ".", "...
Return the number of elements of the cursor with skip and limit
[ "Return", "the", "number", "of", "elements", "of", "the", "cursor", "with", "skip", "and", "limit" ]
train
https://github.com/numberly/appnexus-client/blob/d6a813449ab6fd93bfbceaa937a168fa9a78b890/appnexus/cursor.py#L115-L120
Calysto/calysto
calysto/ai/conx.py
pad
def pad(s, n, p = " ", sep = "|", align = "left"): """ Returns a padded string. s = string to pad n = width of string to return sep = separator (on end of string) align = text alignment, "left", "center", or "right" """ if align == "left": return (s + (p * n))[:n] + sep elif ...
python
def pad(s, n, p = " ", sep = "|", align = "left"): """ Returns a padded string. s = string to pad n = width of string to return sep = separator (on end of string) align = text alignment, "left", "center", or "right" """ if align == "left": return (s + (p * n))[:n] + sep elif ...
[ "def", "pad", "(", "s", ",", "n", ",", "p", "=", "\" \"", ",", "sep", "=", "\"|\"", ",", "align", "=", "\"left\"", ")", ":", "if", "align", "==", "\"left\"", ":", "return", "(", "s", "+", "(", "p", "*", "n", ")", ")", "[", ":", "n", "]", ...
Returns a padded string. s = string to pad n = width of string to return sep = separator (on end of string) align = text alignment, "left", "center", or "right"
[ "Returns", "a", "padded", "string", ".", "s", "=", "string", "to", "pad", "n", "=", "width", "of", "string", "to", "return", "sep", "=", "separator", "(", "on", "end", "of", "string", ")", "align", "=", "text", "alignment", "left", "center", "or", "r...
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L33-L47
Calysto/calysto
calysto/ai/conx.py
sumMerge
def sumMerge(dict1, dict2): """ Adds two dictionaries together, and merges into the first, dict1. Returns first dict. """ for key in dict2: dict1[key] = list(map(lambda a,b: a + b, dict1.get(key, [0,0,0,0]), dict2[key])) return dict1
python
def sumMerge(dict1, dict2): """ Adds two dictionaries together, and merges into the first, dict1. Returns first dict. """ for key in dict2: dict1[key] = list(map(lambda a,b: a + b, dict1.get(key, [0,0,0,0]), dict2[key])) return dict1
[ "def", "sumMerge", "(", "dict1", ",", "dict2", ")", ":", "for", "key", "in", "dict2", ":", "dict1", "[", "key", "]", "=", "list", "(", "map", "(", "lambda", "a", ",", "b", ":", "a", "+", "b", ",", "dict1", ".", "get", "(", "key", ",", "[", ...
Adds two dictionaries together, and merges into the first, dict1. Returns first dict.
[ "Adds", "two", "dictionaries", "together", "and", "merges", "into", "the", "first", "dict1", ".", "Returns", "first", "dict", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L49-L56
Calysto/calysto
calysto/ai/conx.py
loadNetworkFromFile
def loadNetworkFromFile(filename, mode = 'pickle'): """ Deprecated. Use loadNetwork instead. """ if mode == 'pickle': import pickle fp = open(filename) network = pickle.load(fp) fp.close() return network elif mode in ['plain', 'conx']: fp = open(filena...
python
def loadNetworkFromFile(filename, mode = 'pickle'): """ Deprecated. Use loadNetwork instead. """ if mode == 'pickle': import pickle fp = open(filename) network = pickle.load(fp) fp.close() return network elif mode in ['plain', 'conx']: fp = open(filena...
[ "def", "loadNetworkFromFile", "(", "filename", ",", "mode", "=", "'pickle'", ")", ":", "if", "mode", "==", "'pickle'", ":", "import", "pickle", "fp", "=", "open", "(", "filename", ")", "network", "=", "pickle", ".", "load", "(", "fp", ")", "fp", ".", ...
Deprecated. Use loadNetwork instead.
[ "Deprecated", ".", "Use", "loadNetwork", "instead", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L64-L115
Calysto/calysto
calysto/ai/conx.py
ndim
def ndim(n, *args, **kwargs): """ Makes a multi-dimensional array of random floats. (Replaces RandomArray). """ thunk = kwargs.get("thunk", lambda: random.random()) if not args: return [thunk() for i in range(n)] A = [] for i in range(n): A.append( ndim(*args, thunk=thunk) ...
python
def ndim(n, *args, **kwargs): """ Makes a multi-dimensional array of random floats. (Replaces RandomArray). """ thunk = kwargs.get("thunk", lambda: random.random()) if not args: return [thunk() for i in range(n)] A = [] for i in range(n): A.append( ndim(*args, thunk=thunk) ...
[ "def", "ndim", "(", "n", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "thunk", "=", "kwargs", ".", "get", "(", "\"thunk\"", ",", "lambda", ":", "random", ".", "random", "(", ")", ")", "if", "not", "args", ":", "return", "[", "thunk", "(...
Makes a multi-dimensional array of random floats. (Replaces RandomArray).
[ "Makes", "a", "multi", "-", "dimensional", "array", "of", "random", "floats", ".", "(", "Replaces", "RandomArray", ")", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L117-L127
Calysto/calysto
calysto/ai/conx.py
randomArray2
def randomArray2(size, bound): """ Returns an array initialized to random values between -bound and bound distributed in a gaussian probability distribution more appropriate for a Tanh activation function. """ if type(size) == type(1): size = (size,) temp = Numeric.array( ndim(*size)...
python
def randomArray2(size, bound): """ Returns an array initialized to random values between -bound and bound distributed in a gaussian probability distribution more appropriate for a Tanh activation function. """ if type(size) == type(1): size = (size,) temp = Numeric.array( ndim(*size)...
[ "def", "randomArray2", "(", "size", ",", "bound", ")", ":", "if", "type", "(", "size", ")", "==", "type", "(", "1", ")", ":", "size", "=", "(", "size", ",", ")", "temp", "=", "Numeric", ".", "array", "(", "ndim", "(", "*", "size", ")", ",", "...
Returns an array initialized to random values between -bound and bound distributed in a gaussian probability distribution more appropriate for a Tanh activation function.
[ "Returns", "an", "array", "initialized", "to", "random", "values", "between", "-", "bound", "and", "bound", "distributed", "in", "a", "gaussian", "probability", "distribution", "more", "appropriate", "for", "a", "Tanh", "activation", "function", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L129-L138
Calysto/calysto
calysto/ai/conx.py
randomArray
def randomArray(size, bound): """ Returns an array initialized to random values between -max and max. """ if type(size) == type(1): size = (size,) temp = Numeric.array( ndim(*size) ) * (2.0 * bound) return temp - bound
python
def randomArray(size, bound): """ Returns an array initialized to random values between -max and max. """ if type(size) == type(1): size = (size,) temp = Numeric.array( ndim(*size) ) * (2.0 * bound) return temp - bound
[ "def", "randomArray", "(", "size", ",", "bound", ")", ":", "if", "type", "(", "size", ")", "==", "type", "(", "1", ")", ":", "size", "=", "(", "size", ",", ")", "temp", "=", "Numeric", ".", "array", "(", "ndim", "(", "*", "size", ")", ")", "*...
Returns an array initialized to random values between -max and max.
[ "Returns", "an", "array", "initialized", "to", "random", "values", "between", "-", "max", "and", "max", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L140-L147
Calysto/calysto
calysto/ai/conx.py
displayArray
def displayArray(name, a, width = 0): """ Prints an array (any sequence of floats, really) to the screen. """ print(name + ": ", end=" ") cnt = 0 for i in a: print("%4.2f" % i, end=" ") if width > 0 and (cnt + 1) % width == 0: print('') cnt += 1
python
def displayArray(name, a, width = 0): """ Prints an array (any sequence of floats, really) to the screen. """ print(name + ": ", end=" ") cnt = 0 for i in a: print("%4.2f" % i, end=" ") if width > 0 and (cnt + 1) % width == 0: print('') cnt += 1
[ "def", "displayArray", "(", "name", ",", "a", ",", "width", "=", "0", ")", ":", "print", "(", "name", "+", "\": \"", ",", "end", "=", "\" \"", ")", "cnt", "=", "0", "for", "i", "in", "a", ":", "print", "(", "\"%4.2f\"", "%", "i", ",", "end", ...
Prints an array (any sequence of floats, really) to the screen.
[ "Prints", "an", "array", "(", "any", "sequence", "of", "floats", "really", ")", "to", "the", "screen", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L149-L159
Calysto/calysto
calysto/ai/conx.py
toStringArray
def toStringArray(name, a, width = 0): """ Returns an array (any sequence of floats, really) as a string. """ string = name + ": " cnt = 0 for i in a: string += "%4.2f " % i if width > 0 and (cnt + 1) % width == 0: string += '\n' cnt += 1 return string
python
def toStringArray(name, a, width = 0): """ Returns an array (any sequence of floats, really) as a string. """ string = name + ": " cnt = 0 for i in a: string += "%4.2f " % i if width > 0 and (cnt + 1) % width == 0: string += '\n' cnt += 1 return string
[ "def", "toStringArray", "(", "name", ",", "a", ",", "width", "=", "0", ")", ":", "string", "=", "name", "+", "\": \"", "cnt", "=", "0", "for", "i", "in", "a", ":", "string", "+=", "\"%4.2f \"", "%", "i", "if", "width", ">", "0", "and", "(", "c...
Returns an array (any sequence of floats, really) as a string.
[ "Returns", "an", "array", "(", "any", "sequence", "of", "floats", "really", ")", "as", "a", "string", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L161-L172
Calysto/calysto
calysto/ai/conx.py
writeArray
def writeArray(fp, a, delim = " ", nl = 1): """ Writes a sequence a of floats to file pointed to by file pointer. """ for i in a: fp.write("%f%s" % (i, delim)) if nl: fp.write("\n")
python
def writeArray(fp, a, delim = " ", nl = 1): """ Writes a sequence a of floats to file pointed to by file pointer. """ for i in a: fp.write("%f%s" % (i, delim)) if nl: fp.write("\n")
[ "def", "writeArray", "(", "fp", ",", "a", ",", "delim", "=", "\" \"", ",", "nl", "=", "1", ")", ":", "for", "i", "in", "a", ":", "fp", ".", "write", "(", "\"%f%s\"", "%", "(", "i", ",", "delim", ")", ")", "if", "nl", ":", "fp", ".", "write"...
Writes a sequence a of floats to file pointed to by file pointer.
[ "Writes", "a", "sequence", "a", "of", "floats", "to", "file", "pointed", "to", "by", "file", "pointer", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L174-L181
Calysto/calysto
calysto/ai/conx.py
Layer.initialize
def initialize(self): """ Initializes important node values to zero for each node in the layer (target, error, activation, dbias, delta, netinput, bed). """ self.randomize() self.dweight = Numeric.zeros(self.size, 'f') self.delta = Numeric.zeros(self.size, 'f') ...
python
def initialize(self): """ Initializes important node values to zero for each node in the layer (target, error, activation, dbias, delta, netinput, bed). """ self.randomize() self.dweight = Numeric.zeros(self.size, 'f') self.delta = Numeric.zeros(self.size, 'f') ...
[ "def", "initialize", "(", "self", ")", ":", "self", ".", "randomize", "(", ")", "self", ".", "dweight", "=", "Numeric", ".", "zeros", "(", "self", ".", "size", ",", "'f'", ")", "self", ".", "delta", "=", "Numeric", ".", "zeros", "(", "self", ".", ...
Initializes important node values to zero for each node in the layer (target, error, activation, dbias, delta, netinput, bed).
[ "Initializes", "important", "node", "values", "to", "zero", "for", "each", "node", "in", "the", "layer", "(", "target", "error", "activation", "dbias", "delta", "netinput", "bed", ")", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L266-L291
Calysto/calysto
calysto/ai/conx.py
Layer.randomize
def randomize(self, force = 0): """ Initialize node biases to random values in the range [-max, max]. """ if force or not self.frozen: self.weight = randomArray(self.size, self._maxRandom)
python
def randomize(self, force = 0): """ Initialize node biases to random values in the range [-max, max]. """ if force or not self.frozen: self.weight = randomArray(self.size, self._maxRandom)
[ "def", "randomize", "(", "self", ",", "force", "=", "0", ")", ":", "if", "force", "or", "not", "self", ".", "frozen", ":", "self", ".", "weight", "=", "randomArray", "(", "self", ".", "size", ",", "self", ".", "_maxRandom", ")" ]
Initialize node biases to random values in the range [-max, max].
[ "Initialize", "node", "biases", "to", "random", "values", "in", "the", "range", "[", "-", "max", "max", "]", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L293-L298
Calysto/calysto
calysto/ai/conx.py
Layer.changeSize
def changeSize(self, newsize): """ Changes the size of the layer. Should only be called through Network.changeLayerSize(). """ # overwrites current data if newsize <= 0: raise LayerError('Layer size changed to zero.', newsize) minSize = min(self.size, ...
python
def changeSize(self, newsize): """ Changes the size of the layer. Should only be called through Network.changeLayerSize(). """ # overwrites current data if newsize <= 0: raise LayerError('Layer size changed to zero.', newsize) minSize = min(self.size, ...
[ "def", "changeSize", "(", "self", ",", "newsize", ")", ":", "# overwrites current data", "if", "newsize", "<=", "0", ":", "raise", "LayerError", "(", "'Layer size changed to zero.'", ",", "newsize", ")", "minSize", "=", "min", "(", "self", ".", "size", ",", ...
Changes the size of the layer. Should only be called through Network.changeLayerSize().
[ "Changes", "the", "size", "of", "the", "layer", ".", "Should", "only", "be", "called", "through", "Network", ".", "changeLayerSize", "()", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L335-L358
Calysto/calysto
calysto/ai/conx.py
Layer.RMSError
def RMSError(self): """ Returns Root Mean Squared Error for this layer's pattern. """ tss = self.TSSError() return math.sqrt(tss / self.size)
python
def RMSError(self): """ Returns Root Mean Squared Error for this layer's pattern. """ tss = self.TSSError() return math.sqrt(tss / self.size)
[ "def", "RMSError", "(", "self", ")", ":", "tss", "=", "self", ".", "TSSError", "(", ")", "return", "math", ".", "sqrt", "(", "tss", "/", "self", ".", "size", ")" ]
Returns Root Mean Squared Error for this layer's pattern.
[ "Returns", "Root", "Mean", "Squared", "Error", "for", "this", "layer", "s", "pattern", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L366-L371
Calysto/calysto
calysto/ai/conx.py
Layer.getCorrect
def getCorrect(self, tolerance): """ Returns the number of nodes within tolerance of the target. """ return Numeric.add.reduce(Numeric.fabs(self.target - self.activation) < tolerance)
python
def getCorrect(self, tolerance): """ Returns the number of nodes within tolerance of the target. """ return Numeric.add.reduce(Numeric.fabs(self.target - self.activation) < tolerance)
[ "def", "getCorrect", "(", "self", ",", "tolerance", ")", ":", "return", "Numeric", ".", "add", ".", "reduce", "(", "Numeric", ".", "fabs", "(", "self", ".", "target", "-", "self", ".", "activation", ")", "<", "tolerance", ")" ]
Returns the number of nodes within tolerance of the target.
[ "Returns", "the", "number", "of", "nodes", "within", "tolerance", "of", "the", "target", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L372-L376
Calysto/calysto
calysto/ai/conx.py
Layer.getWinner
def getWinner(self, type = 'activation'): """ Returns the winner of the type specified {'activation' or 'target'}. """ maxvalue = -10000 maxpos = -1 ttlvalue = 0 if type == 'activation': ttlvalue = Numeric.add.reduce(self.activation) ...
python
def getWinner(self, type = 'activation'): """ Returns the winner of the type specified {'activation' or 'target'}. """ maxvalue = -10000 maxpos = -1 ttlvalue = 0 if type == 'activation': ttlvalue = Numeric.add.reduce(self.activation) ...
[ "def", "getWinner", "(", "self", ",", "type", "=", "'activation'", ")", ":", "maxvalue", "=", "-", "10000", "maxpos", "=", "-", "1", "ttlvalue", "=", "0", "if", "type", "==", "'activation'", ":", "ttlvalue", "=", "Numeric", ".", "add", ".", "reduce", ...
Returns the winner of the type specified {'activation' or 'target'}.
[ "Returns", "the", "winner", "of", "the", "type", "specified", "{", "activation", "or", "target", "}", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L377-L405
Calysto/calysto
calysto/ai/conx.py
Layer.setLog
def setLog(self, fileName, writeName=False): """ Opens a log file with name fileName. """ self.log = 1 self.logFile = fileName self._logPtr = open(fileName, "w") if writeName: self._namePtr = open(fileName + ".name", "w")
python
def setLog(self, fileName, writeName=False): """ Opens a log file with name fileName. """ self.log = 1 self.logFile = fileName self._logPtr = open(fileName, "w") if writeName: self._namePtr = open(fileName + ".name", "w")
[ "def", "setLog", "(", "self", ",", "fileName", ",", "writeName", "=", "False", ")", ":", "self", ".", "log", "=", "1", "self", ".", "logFile", "=", "fileName", "self", ".", "_logPtr", "=", "open", "(", "fileName", ",", "\"w\"", ")", "if", "writeName"...
Opens a log file with name fileName.
[ "Opens", "a", "log", "file", "with", "name", "fileName", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L420-L428
Calysto/calysto
calysto/ai/conx.py
Layer.closeLog
def closeLog(self): """ Closes the log file. """ self._logPtr.close() if self._namePtr: self._namePtr.close() self.log = 0
python
def closeLog(self): """ Closes the log file. """ self._logPtr.close() if self._namePtr: self._namePtr.close() self.log = 0
[ "def", "closeLog", "(", "self", ")", ":", "self", ".", "_logPtr", ".", "close", "(", ")", "if", "self", ".", "_namePtr", ":", "self", ".", "_namePtr", ".", "close", "(", ")", "self", ".", "log", "=", "0" ]
Closes the log file.
[ "Closes", "the", "log", "file", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L434-L441
Calysto/calysto
calysto/ai/conx.py
Layer.writeLog
def writeLog(self, network): """ Writes to the log file. """ if self.log: writeArray(self._logPtr, self.activation) if self._namePtr: self._namePtr.write(network.getWord(self.activation)) self._namePtr.write("\n")
python
def writeLog(self, network): """ Writes to the log file. """ if self.log: writeArray(self._logPtr, self.activation) if self._namePtr: self._namePtr.write(network.getWord(self.activation)) self._namePtr.write("\n")
[ "def", "writeLog", "(", "self", ",", "network", ")", ":", "if", "self", ".", "log", ":", "writeArray", "(", "self", ".", "_logPtr", ",", "self", ".", "activation", ")", "if", "self", ".", "_namePtr", ":", "self", ".", "_namePtr", ".", "write", "(", ...
Writes to the log file.
[ "Writes", "to", "the", "log", "file", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L442-L450
Calysto/calysto
calysto/ai/conx.py
Layer.toString
def toString(self): """ Returns a string representation of Layer instance. """ string = "Layer '%s': (Kind: %s, Size: %d, Active: %d, Frozen: %d)\n" % ( self.name, self.kind, self.size, self.active, self.frozen) if (self.type == 'Output'): string += toStr...
python
def toString(self): """ Returns a string representation of Layer instance. """ string = "Layer '%s': (Kind: %s, Size: %d, Active: %d, Frozen: %d)\n" % ( self.name, self.kind, self.size, self.active, self.frozen) if (self.type == 'Output'): string += toStr...
[ "def", "toString", "(", "self", ")", ":", "string", "=", "\"Layer '%s': (Kind: %s, Size: %d, Active: %d, Frozen: %d)\\n\"", "%", "(", "self", ".", "name", ",", "self", ".", "kind", ",", "self", ".", "size", ",", "self", ".", "active", ",", "self", ".", "froz...
Returns a string representation of Layer instance.
[ "Returns", "a", "string", "representation", "of", "Layer", "instance", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L458-L475
Calysto/calysto
calysto/ai/conx.py
Layer.display
def display(self): """ Displays the Layer instance to the screen. """ if self.displayWidth == 0: return print("=============================") print("Layer '%s': (Kind: %s, Size: %d, Active: %d, Frozen: %d)" % ( self.name, self.kind, self.size, self.active, se...
python
def display(self): """ Displays the Layer instance to the screen. """ if self.displayWidth == 0: return print("=============================") print("Layer '%s': (Kind: %s, Size: %d, Active: %d, Frozen: %d)" % ( self.name, self.kind, self.size, self.active, se...
[ "def", "display", "(", "self", ")", ":", "if", "self", ".", "displayWidth", "==", "0", ":", "return", "print", "(", "\"=============================\"", ")", "print", "(", "\"Layer '%s': (Kind: %s, Size: %d, Active: %d, Frozen: %d)\"", "%", "(", "self", ".", "name",...
Displays the Layer instance to the screen.
[ "Displays", "the", "Layer", "instance", "to", "the", "screen", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L476-L494
Calysto/calysto
calysto/ai/conx.py
Layer.setActivations
def setActivations(self, value): """ Sets all activations to the value of the argument. Value should be in the range [0,1]. """ #if self.verify and not self.activationSet == 0: # raise LayerError, \ # ('Activation flag not reset. Activations may have been set ...
python
def setActivations(self, value): """ Sets all activations to the value of the argument. Value should be in the range [0,1]. """ #if self.verify and not self.activationSet == 0: # raise LayerError, \ # ('Activation flag not reset. Activations may have been set ...
[ "def", "setActivations", "(", "self", ",", "value", ")", ":", "#if self.verify and not self.activationSet == 0:", "# raise LayerError, \\", "# ('Activation flag not reset. Activations may have been set multiple times without any intervening call to propagate().', self.activationSet)"...
Sets all activations to the value of the argument. Value should be in the range [0,1].
[ "Sets", "all", "activations", "to", "the", "value", "of", "the", "argument", ".", "Value", "should", "be", "in", "the", "range", "[", "0", "1", "]", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L507-L515
Calysto/calysto
calysto/ai/conx.py
Layer.copyActivations
def copyActivations(self, arr, reckless = 0): """ Copies activations from the argument array into layer activations. """ array = Numeric.array(arr) if not len(array) == self.size: raise LayerError('Mismatched activation size and layer size in call to copyActiv...
python
def copyActivations(self, arr, reckless = 0): """ Copies activations from the argument array into layer activations. """ array = Numeric.array(arr) if not len(array) == self.size: raise LayerError('Mismatched activation size and layer size in call to copyActiv...
[ "def", "copyActivations", "(", "self", ",", "arr", ",", "reckless", "=", "0", ")", ":", "array", "=", "Numeric", ".", "array", "(", "arr", ")", "if", "not", "len", "(", "array", ")", "==", "self", ".", "size", ":", "raise", "LayerError", "(", "'Mis...
Copies activations from the argument array into layer activations.
[ "Copies", "activations", "from", "the", "argument", "array", "into", "layer", "activations", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L516-L530
Calysto/calysto
calysto/ai/conx.py
Layer.setTargets
def setTargets(self, value): """ Sets all targets the the value of the argument. This value must be in the range [min,max]. """ # Removed this because both propagate and backprop (via compute_error) set targets #if self.verify and not self.targetSet == 0: # if not self...
python
def setTargets(self, value): """ Sets all targets the the value of the argument. This value must be in the range [min,max]. """ # Removed this because both propagate and backprop (via compute_error) set targets #if self.verify and not self.targetSet == 0: # if not self...
[ "def", "setTargets", "(", "self", ",", "value", ")", ":", "# Removed this because both propagate and backprop (via compute_error) set targets", "#if self.verify and not self.targetSet == 0:", "# if not self.warningIssued:", "# print 'Warning! Targets have already been set and no inte...
Sets all targets the the value of the argument. This value must be in the range [min,max].
[ "Sets", "all", "targets", "the", "the", "value", "of", "the", "argument", ".", "This", "value", "must", "be", "in", "the", "range", "[", "min", "max", "]", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L543-L557
Calysto/calysto
calysto/ai/conx.py
Layer.copyTargets
def copyTargets(self, arr): """ Copies the targets of the argument array into the self.target attribute. """ array = Numeric.array(arr) if not len(array) == self.size: raise LayerError('Mismatched target size and layer size in call to copyTargets()', \ ...
python
def copyTargets(self, arr): """ Copies the targets of the argument array into the self.target attribute. """ array = Numeric.array(arr) if not len(array) == self.size: raise LayerError('Mismatched target size and layer size in call to copyTargets()', \ ...
[ "def", "copyTargets", "(", "self", ",", "arr", ")", ":", "array", "=", "Numeric", ".", "array", "(", "arr", ")", "if", "not", "len", "(", "array", ")", "==", "self", ".", "size", ":", "raise", "LayerError", "(", "'Mismatched target size and layer size in c...
Copies the targets of the argument array into the self.target attribute.
[ "Copies", "the", "targets", "of", "the", "argument", "array", "into", "the", "self", ".", "target", "attribute", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L558-L577
Calysto/calysto
calysto/ai/conx.py
Connection.initialize
def initialize(self): """ Initializes self.dweight and self.wed to zero matrices. """ self.randomize() self.dweight = Numeric.zeros((self.fromLayer.size, \ self.toLayer.size), 'f') self.wed = Numeric.zeros((self.fromLayer.size, \ ...
python
def initialize(self): """ Initializes self.dweight and self.wed to zero matrices. """ self.randomize() self.dweight = Numeric.zeros((self.fromLayer.size, \ self.toLayer.size), 'f') self.wed = Numeric.zeros((self.fromLayer.size, \ ...
[ "def", "initialize", "(", "self", ")", ":", "self", ".", "randomize", "(", ")", "self", ".", "dweight", "=", "Numeric", ".", "zeros", "(", "(", "self", ".", "fromLayer", ".", "size", ",", "self", ".", "toLayer", ".", "size", ")", ",", "'f'", ")", ...
Initializes self.dweight and self.wed to zero matrices.
[ "Initializes", "self", ".", "dweight", "and", "self", ".", "wed", "to", "zero", "matrices", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L615-L625
Calysto/calysto
calysto/ai/conx.py
Connection.changeSize
def changeSize(self, fromLayerSize, toLayerSize): """ Changes the size of the connection depending on the size change of either source or destination layer. Should only be called through Network.changeLayerSize(). """ if toLayerSize <= 0 or fromLayerSize <= 0: ...
python
def changeSize(self, fromLayerSize, toLayerSize): """ Changes the size of the connection depending on the size change of either source or destination layer. Should only be called through Network.changeLayerSize(). """ if toLayerSize <= 0 or fromLayerSize <= 0: ...
[ "def", "changeSize", "(", "self", ",", "fromLayerSize", ",", "toLayerSize", ")", ":", "if", "toLayerSize", "<=", "0", "or", "fromLayerSize", "<=", "0", ":", "raise", "LayerError", "(", "'changeSize() called with invalid layer size.'", ",", "(", "fromLayerSize", ",...
Changes the size of the connection depending on the size change of either source or destination layer. Should only be called through Network.changeLayerSize().
[ "Changes", "the", "size", "of", "the", "connection", "depending", "on", "the", "size", "change", "of", "either", "source", "or", "destination", "layer", ".", "Should", "only", "be", "called", "through", "Network", ".", "changeLayerSize", "()", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L641-L667
Calysto/calysto
calysto/ai/conx.py
Connection.display
def display(self): """ Displays connection information to the screen. """ if self.toLayer._verbosity > 4: print("wed: from '" + self.fromLayer.name + "' to '" + self.toLayer.name +"'") for j in range(self.toLayer.size): print(self.toLayer.name, "["...
python
def display(self): """ Displays connection information to the screen. """ if self.toLayer._verbosity > 4: print("wed: from '" + self.fromLayer.name + "' to '" + self.toLayer.name +"'") for j in range(self.toLayer.size): print(self.toLayer.name, "["...
[ "def", "display", "(", "self", ")", ":", "if", "self", ".", "toLayer", ".", "_verbosity", ">", "4", ":", "print", "(", "\"wed: from '\"", "+", "self", ".", "fromLayer", ".", "name", "+", "\"' to '\"", "+", "self", ".", "toLayer", ".", "name", "+", "\...
Displays connection information to the screen.
[ "Displays", "connection", "information", "to", "the", "screen", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L670-L706
Calysto/calysto
calysto/ai/conx.py
Connection.toString
def toString(self): """ Connection information as a string. """ string = "" if self.toLayer._verbosity > 4: string += "wed: from '" + self.fromLayer.name + "' to '" + self.toLayer.name +"'\n" string += " " for j in range(self.toLaye...
python
def toString(self): """ Connection information as a string. """ string = "" if self.toLayer._verbosity > 4: string += "wed: from '" + self.fromLayer.name + "' to '" + self.toLayer.name +"'\n" string += " " for j in range(self.toLaye...
[ "def", "toString", "(", "self", ")", ":", "string", "=", "\"\"", "if", "self", ".", "toLayer", ".", "_verbosity", ">", "4", ":", "string", "+=", "\"wed: from '\"", "+", "self", ".", "fromLayer", ".", "name", "+", "\"' to '\"", "+", "self", ".", "toLaye...
Connection information as a string.
[ "Connection", "information", "as", "a", "string", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L708-L748
Calysto/calysto
calysto/ai/conx.py
Network.setCache
def setCache(self, val = 1): """ Sets cache on (or updates), or turns off """ # first clear the old cached values self.cacheConnections = [] self.cacheLayers = [] if val: for layer in self.layers: if layer.active and not layer.frozen: ...
python
def setCache(self, val = 1): """ Sets cache on (or updates), or turns off """ # first clear the old cached values self.cacheConnections = [] self.cacheLayers = [] if val: for layer in self.layers: if layer.active and not layer.frozen: ...
[ "def", "setCache", "(", "self", ",", "val", "=", "1", ")", ":", "# first clear the old cached values", "self", ".", "cacheConnections", "=", "[", "]", "self", ".", "cacheLayers", "=", "[", "]", "if", "val", ":", "for", "layer", "in", "self", ".", "layers...
Sets cache on (or updates), or turns off
[ "Sets", "cache", "on", "(", "or", "updates", ")", "or", "turns", "off" ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L829-L840
Calysto/calysto
calysto/ai/conx.py
Network.path
def path(self, startLayer, endLayer): """ Used in error checking with verifyArchitecture() and in prop_from(). """ next = {startLayer.name : startLayer} visited = {} while next != {}: for item in list(next.items()): # item[0] : name, item[1] : ...
python
def path(self, startLayer, endLayer): """ Used in error checking with verifyArchitecture() and in prop_from(). """ next = {startLayer.name : startLayer} visited = {} while next != {}: for item in list(next.items()): # item[0] : name, item[1] : ...
[ "def", "path", "(", "self", ",", "startLayer", ",", "endLayer", ")", ":", "next", "=", "{", "startLayer", ".", "name", ":", "startLayer", "}", "visited", "=", "{", "}", "while", "next", "!=", "{", "}", ":", "for", "item", "in", "list", "(", "next",...
Used in error checking with verifyArchitecture() and in prop_from().
[ "Used", "in", "error", "checking", "with", "verifyArchitecture", "()", "and", "in", "prop_from", "()", "." ]
train
https://github.com/Calysto/calysto/blob/20813c0f48096317aa775d03a5c6b20f12fafc93/calysto/ai/conx.py#L860-L883