repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
globality-corp/microcosm-postgres
microcosm_postgres/temporary/methods.py
upsert_into
def upsert_into(self, table): """ Upsert from a temporarty table into another table. """ return SessionContext.session.execute( insert(table).from_select( self.c, self, ).on_conflict_do_nothing(), ).rowcount
python
def upsert_into(self, table): """ Upsert from a temporarty table into another table. """ return SessionContext.session.execute( insert(table).from_select( self.c, self, ).on_conflict_do_nothing(), ).rowcount
[ "def", "upsert_into", "(", "self", ",", "table", ")", ":", "return", "SessionContext", ".", "session", ".", "execute", "(", "insert", "(", "table", ")", ".", "from_select", "(", "self", ".", "c", ",", "self", ",", ")", ".", "on_conflict_do_nothing", "(",...
Upsert from a temporarty table into another table.
[ "Upsert", "from", "a", "temporarty", "table", "into", "another", "table", "." ]
43dd793b1fc9b84e4056700f350e79e0df5ff501
https://github.com/globality-corp/microcosm-postgres/blob/43dd793b1fc9b84e4056700f350e79e0df5ff501/microcosm_postgres/temporary/methods.py#L36-L46
train
26,500
globality-corp/microcosm-postgres
microcosm_postgres/encryption/providers.py
configure_key_provider
def configure_key_provider(graph, key_ids): """ Configure a key provider. During unit tests, use a static key provider (e.g. without AWS calls). """ if graph.metadata.testing: # use static provider provider = StaticMasterKeyProvider() provider.add_master_keys_from_list(key_...
python
def configure_key_provider(graph, key_ids): """ Configure a key provider. During unit tests, use a static key provider (e.g. without AWS calls). """ if graph.metadata.testing: # use static provider provider = StaticMasterKeyProvider() provider.add_master_keys_from_list(key_...
[ "def", "configure_key_provider", "(", "graph", ",", "key_ids", ")", ":", "if", "graph", ".", "metadata", ".", "testing", ":", "# use static provider", "provider", "=", "StaticMasterKeyProvider", "(", ")", "provider", ".", "add_master_keys_from_list", "(", "key_ids",...
Configure a key provider. During unit tests, use a static key provider (e.g. without AWS calls).
[ "Configure", "a", "key", "provider", "." ]
43dd793b1fc9b84e4056700f350e79e0df5ff501
https://github.com/globality-corp/microcosm-postgres/blob/43dd793b1fc9b84e4056700f350e79e0df5ff501/microcosm_postgres/encryption/providers.py#L40-L54
train
26,501
globality-corp/microcosm-postgres
microcosm_postgres/encryption/providers.py
configure_materials_manager
def configure_materials_manager(graph, key_provider): """ Configure a crypto materials manager """ if graph.config.materials_manager.enable_cache: return CachingCryptoMaterialsManager( cache=LocalCryptoMaterialsCache(graph.config.materials_manager.cache_capacity), master...
python
def configure_materials_manager(graph, key_provider): """ Configure a crypto materials manager """ if graph.config.materials_manager.enable_cache: return CachingCryptoMaterialsManager( cache=LocalCryptoMaterialsCache(graph.config.materials_manager.cache_capacity), master...
[ "def", "configure_materials_manager", "(", "graph", ",", "key_provider", ")", ":", "if", "graph", ".", "config", ".", "materials_manager", ".", "enable_cache", ":", "return", "CachingCryptoMaterialsManager", "(", "cache", "=", "LocalCryptoMaterialsCache", "(", "graph"...
Configure a crypto materials manager
[ "Configure", "a", "crypto", "materials", "manager" ]
43dd793b1fc9b84e4056700f350e79e0df5ff501
https://github.com/globality-corp/microcosm-postgres/blob/43dd793b1fc9b84e4056700f350e79e0df5ff501/microcosm_postgres/encryption/providers.py#L63-L75
train
26,502
globality-corp/microcosm-postgres
microcosm_postgres/createall.py
main
def main(graph): """ Create and drop databases. """ args = parse_args(graph) if args.drop: drop_all(graph) create_all(graph)
python
def main(graph): """ Create and drop databases. """ args = parse_args(graph) if args.drop: drop_all(graph) create_all(graph)
[ "def", "main", "(", "graph", ")", ":", "args", "=", "parse_args", "(", "graph", ")", "if", "args", ".", "drop", ":", "drop_all", "(", "graph", ")", "create_all", "(", "graph", ")" ]
Create and drop databases.
[ "Create", "and", "drop", "databases", "." ]
43dd793b1fc9b84e4056700f350e79e0df5ff501
https://github.com/globality-corp/microcosm-postgres/blob/43dd793b1fc9b84e4056700f350e79e0df5ff501/microcosm_postgres/createall.py#L16-L25
train
26,503
jochym/Elastic
elastic/elastic.py
get_lattice_type
def get_lattice_type(cryst): '''Find the symmetry of the crystal using spglib symmetry finder. Derive name of the space group and its number extracted from the result. Based on the group number identify also the lattice type and the Bravais lattice of the crystal. The lattice type numbers are (the ...
python
def get_lattice_type(cryst): '''Find the symmetry of the crystal using spglib symmetry finder. Derive name of the space group and its number extracted from the result. Based on the group number identify also the lattice type and the Bravais lattice of the crystal. The lattice type numbers are (the ...
[ "def", "get_lattice_type", "(", "cryst", ")", ":", "# Table of lattice types and correcponding group numbers dividing", "# the ranges. See get_lattice_type method for precise definition.", "lattice_types", "=", "[", "[", "3", ",", "\"Triclinic\"", "]", ",", "[", "16", ",", "\...
Find the symmetry of the crystal using spglib symmetry finder. Derive name of the space group and its number extracted from the result. Based on the group number identify also the lattice type and the Bravais lattice of the crystal. The lattice type numbers are (the numbering starts from 1): Tricl...
[ "Find", "the", "symmetry", "of", "the", "crystal", "using", "spglib", "symmetry", "finder", "." ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/elastic/elastic.py#L305-L345
train
26,504
jochym/Elastic
elastic/elastic.py
get_bulk_modulus
def get_bulk_modulus(cryst): '''Calculate bulk modulus using the Birch-Murnaghan equation of state. The EOS must be previously calculated by get_BM_EOS routine. The returned bulk modulus is a :math:`B_0` coefficient of the B-M EOS. The units of the result are defined by ASE. To get the result in an...
python
def get_bulk_modulus(cryst): '''Calculate bulk modulus using the Birch-Murnaghan equation of state. The EOS must be previously calculated by get_BM_EOS routine. The returned bulk modulus is a :math:`B_0` coefficient of the B-M EOS. The units of the result are defined by ASE. To get the result in an...
[ "def", "get_bulk_modulus", "(", "cryst", ")", ":", "if", "getattr", "(", "cryst", ",", "'bm_eos'", ",", "None", ")", "is", "None", ":", "raise", "RuntimeError", "(", "'Missing B-M EOS data.'", ")", "cryst", ".", "bulk_modulus", "=", "cryst", ".", "bm_eos", ...
Calculate bulk modulus using the Birch-Murnaghan equation of state. The EOS must be previously calculated by get_BM_EOS routine. The returned bulk modulus is a :math:`B_0` coefficient of the B-M EOS. The units of the result are defined by ASE. To get the result in any particular units (e.g. GPa) you ne...
[ "Calculate", "bulk", "modulus", "using", "the", "Birch", "-", "Murnaghan", "equation", "of", "state", "." ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/elastic/elastic.py#L348-L367
train
26,505
jochym/Elastic
elastic/elastic.py
get_BM_EOS
def get_BM_EOS(cryst, systems): """Calculate Birch-Murnaghan Equation of State for the crystal. The B-M equation of state is defined by: .. math:: P(V)= \\frac{B_0}{B'_0}\\left[ \\left({\\frac{V}{V_0}}\\right)^{-B'_0} - 1 \\right] It's coefficients are estimated using n single-po...
python
def get_BM_EOS(cryst, systems): """Calculate Birch-Murnaghan Equation of State for the crystal. The B-M equation of state is defined by: .. math:: P(V)= \\frac{B_0}{B'_0}\\left[ \\left({\\frac{V}{V_0}}\\right)^{-B'_0} - 1 \\right] It's coefficients are estimated using n single-po...
[ "def", "get_BM_EOS", "(", "cryst", ",", "systems", ")", ":", "pvdat", "=", "array", "(", "[", "[", "r", ".", "get_volume", "(", ")", ",", "get_pressure", "(", "r", ".", "get_stress", "(", ")", ")", ",", "norm", "(", "r", ".", "get_cell", "(", ")"...
Calculate Birch-Murnaghan Equation of State for the crystal. The B-M equation of state is defined by: .. math:: P(V)= \\frac{B_0}{B'_0}\\left[ \\left({\\frac{V}{V_0}}\\right)^{-B'_0} - 1 \\right] It's coefficients are estimated using n single-point structures ganerated from the c...
[ "Calculate", "Birch", "-", "Murnaghan", "Equation", "of", "State", "for", "the", "crystal", "." ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/elastic/elastic.py#L386-L440
train
26,506
jochym/Elastic
elastic/elastic.py
get_elementary_deformations
def get_elementary_deformations(cryst, n=5, d=2): '''Generate elementary deformations for elastic tensor calculation. The deformations are created based on the symmetry of the crystal and are limited to the non-equivalet axes of the crystal. :param cryst: Atoms object, basic structure :param n: in...
python
def get_elementary_deformations(cryst, n=5, d=2): '''Generate elementary deformations for elastic tensor calculation. The deformations are created based on the symmetry of the crystal and are limited to the non-equivalet axes of the crystal. :param cryst: Atoms object, basic structure :param n: in...
[ "def", "get_elementary_deformations", "(", "cryst", ",", "n", "=", "5", ",", "d", "=", "2", ")", ":", "# Deformation look-up table", "# Perhaps the number of deformations for trigonal", "# system could be reduced to [0,3] but better safe then sorry", "deform", "=", "{", "\"Cu...
Generate elementary deformations for elastic tensor calculation. The deformations are created based on the symmetry of the crystal and are limited to the non-equivalet axes of the crystal. :param cryst: Atoms object, basic structure :param n: integer, number of deformations per non-equivalent axis ...
[ "Generate", "elementary", "deformations", "for", "elastic", "tensor", "calculation", "." ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/elastic/elastic.py#L443-L482
train
26,507
jochym/Elastic
elastic/elastic.py
get_cart_deformed_cell
def get_cart_deformed_cell(base_cryst, axis=0, size=1): '''Return the cell deformed along one of the cartesian directions Creates new deformed structure. The deformation is based on the base structure and is performed along single axis. The axis is specified as follows: 0,1,2 = x,y,z ; sheers: 3,4,5 = ...
python
def get_cart_deformed_cell(base_cryst, axis=0, size=1): '''Return the cell deformed along one of the cartesian directions Creates new deformed structure. The deformation is based on the base structure and is performed along single axis. The axis is specified as follows: 0,1,2 = x,y,z ; sheers: 3,4,5 = ...
[ "def", "get_cart_deformed_cell", "(", "base_cryst", ",", "axis", "=", "0", ",", "size", "=", "1", ")", ":", "cryst", "=", "Atoms", "(", "base_cryst", ")", "uc", "=", "base_cryst", ".", "get_cell", "(", ")", "s", "=", "size", "/", "100.0", "L", "=", ...
Return the cell deformed along one of the cartesian directions Creates new deformed structure. The deformation is based on the base structure and is performed along single axis. The axis is specified as follows: 0,1,2 = x,y,z ; sheers: 3,4,5 = yz, xz, xy. The size of the deformation is in percent and d...
[ "Return", "the", "cell", "deformed", "along", "one", "of", "the", "cartesian", "directions" ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/elastic/elastic.py#L669-L700
train
26,508
jochym/Elastic
elastic/elastic.py
get_strain
def get_strain(cryst, refcell=None): '''Calculate strain tensor in the Voight notation Computes the strain tensor in the Voight notation as a conventional 6-vector. The calculation is done with respect to the crystal geometry passed in refcell parameter. :param cryst: deformed structure :param...
python
def get_strain(cryst, refcell=None): '''Calculate strain tensor in the Voight notation Computes the strain tensor in the Voight notation as a conventional 6-vector. The calculation is done with respect to the crystal geometry passed in refcell parameter. :param cryst: deformed structure :param...
[ "def", "get_strain", "(", "cryst", ",", "refcell", "=", "None", ")", ":", "if", "refcell", "is", "None", ":", "refcell", "=", "cryst", "du", "=", "cryst", ".", "get_cell", "(", ")", "-", "refcell", ".", "get_cell", "(", ")", "m", "=", "refcell", "....
Calculate strain tensor in the Voight notation Computes the strain tensor in the Voight notation as a conventional 6-vector. The calculation is done with respect to the crystal geometry passed in refcell parameter. :param cryst: deformed structure :param refcell: reference, undeformed structure ...
[ "Calculate", "strain", "tensor", "in", "the", "Voight", "notation" ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/elastic/elastic.py#L703-L722
train
26,509
jochym/Elastic
parcalc/parcalc.py
work_dir
def work_dir(path): ''' Context menager for executing commands in some working directory. Returns to the previous wd when finished. Usage: >>> with work_dir(path): ... subprocess.call('git status') ''' starting_directory = os.getcwd() try: os.chdir(path) yield ...
python
def work_dir(path): ''' Context menager for executing commands in some working directory. Returns to the previous wd when finished. Usage: >>> with work_dir(path): ... subprocess.call('git status') ''' starting_directory = os.getcwd() try: os.chdir(path) yield ...
[ "def", "work_dir", "(", "path", ")", ":", "starting_directory", "=", "os", ".", "getcwd", "(", ")", "try", ":", "os", ".", "chdir", "(", "path", ")", "yield", "finally", ":", "os", ".", "chdir", "(", "starting_directory", ")" ]
Context menager for executing commands in some working directory. Returns to the previous wd when finished. Usage: >>> with work_dir(path): ... subprocess.call('git status')
[ "Context", "menager", "for", "executing", "commands", "in", "some", "working", "directory", ".", "Returns", "to", "the", "previous", "wd", "when", "finished", "." ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/parcalc/parcalc.py#L79-L94
train
26,510
jochym/Elastic
parcalc/parcalc.py
ClusterVasp.prepare_calc_dir
def prepare_calc_dir(self): ''' Prepare the calculation directory for VASP execution. This needs to be re-implemented for each local setup. The following code reflects just my particular setup. ''' with open("vasprun.conf","w") as f: f.write('NODES="nodes=%s:p...
python
def prepare_calc_dir(self): ''' Prepare the calculation directory for VASP execution. This needs to be re-implemented for each local setup. The following code reflects just my particular setup. ''' with open("vasprun.conf","w") as f: f.write('NODES="nodes=%s:p...
[ "def", "prepare_calc_dir", "(", "self", ")", ":", "with", "open", "(", "\"vasprun.conf\"", ",", "\"w\"", ")", "as", "f", ":", "f", ".", "write", "(", "'NODES=\"nodes=%s:ppn=%d\"\\n'", "%", "(", "self", ".", "nodes", ",", "self", ".", "ppn", ")", ")", "...
Prepare the calculation directory for VASP execution. This needs to be re-implemented for each local setup. The following code reflects just my particular setup.
[ "Prepare", "the", "calculation", "directory", "for", "VASP", "execution", ".", "This", "needs", "to", "be", "re", "-", "implemented", "for", "each", "local", "setup", ".", "The", "following", "code", "reflects", "just", "my", "particular", "setup", "." ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/parcalc/parcalc.py#L114-L124
train
26,511
jochym/Elastic
parcalc/parcalc.py
ClusterVasp.calc_finished
def calc_finished(self): ''' Check if the lockfile is in the calculation directory. It is removed by the script at the end regardless of the success of the calculation. This is totally tied to implementation and you need to implement your own scheme! ''' #print_st...
python
def calc_finished(self): ''' Check if the lockfile is in the calculation directory. It is removed by the script at the end regardless of the success of the calculation. This is totally tied to implementation and you need to implement your own scheme! ''' #print_st...
[ "def", "calc_finished", "(", "self", ")", ":", "#print_stack(limit=5)", "if", "not", "self", ".", "calc_running", ":", "#print('Calc running:',self.calc_running)", "return", "True", "else", ":", "# The calc is marked as running check if this is still true", "# We do it by exter...
Check if the lockfile is in the calculation directory. It is removed by the script at the end regardless of the success of the calculation. This is totally tied to implementation and you need to implement your own scheme!
[ "Check", "if", "the", "lockfile", "is", "in", "the", "calculation", "directory", ".", "It", "is", "removed", "by", "the", "script", "at", "the", "end", "regardless", "of", "the", "success", "of", "the", "calculation", ".", "This", "is", "totally", "tied", ...
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/parcalc/parcalc.py#L127-L153
train
26,512
jochym/Elastic
parcalc/parcalc.py
RemoteCalculator.run_calculation
def run_calculation(self, atoms=None, properties=['energy'], system_changes=all_changes): ''' Internal calculation executor. We cannot use FileIOCalculator directly since we need to support remote execution. This calculator is different from others. ...
python
def run_calculation(self, atoms=None, properties=['energy'], system_changes=all_changes): ''' Internal calculation executor. We cannot use FileIOCalculator directly since we need to support remote execution. This calculator is different from others. ...
[ "def", "run_calculation", "(", "self", ",", "atoms", "=", "None", ",", "properties", "=", "[", "'energy'", "]", ",", "system_changes", "=", "all_changes", ")", ":", "self", ".", "calc", ".", "calculate", "(", "self", ",", "atoms", ",", "properties", ",",...
Internal calculation executor. We cannot use FileIOCalculator directly since we need to support remote execution. This calculator is different from others. It prepares the directory, launches the remote process and raises the exception to signal that we need to come back for re...
[ "Internal", "calculation", "executor", ".", "We", "cannot", "use", "FileIOCalculator", "directly", "since", "we", "need", "to", "support", "remote", "execution", ".", "This", "calculator", "is", "different", "from", "others", ".", "It", "prepares", "the", "direc...
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/parcalc/parcalc.py#L425-L457
train
26,513
jochym/Elastic
elastic/cli/elastic.py
gen
def gen(ctx, num, lo, hi, size, struct): '''Generate deformed structures''' frmt = ctx.parent.params['frmt'] action = ctx.parent.params['action'] cryst = ase.io.read(struct, format=frmt) fn_tmpl = action if frmt == 'vasp': fn_tmpl += '_%03d.POSCAR' kwargs = {'vasp5': True, 'dire...
python
def gen(ctx, num, lo, hi, size, struct): '''Generate deformed structures''' frmt = ctx.parent.params['frmt'] action = ctx.parent.params['action'] cryst = ase.io.read(struct, format=frmt) fn_tmpl = action if frmt == 'vasp': fn_tmpl += '_%03d.POSCAR' kwargs = {'vasp5': True, 'dire...
[ "def", "gen", "(", "ctx", ",", "num", ",", "lo", ",", "hi", ",", "size", ",", "struct", ")", ":", "frmt", "=", "ctx", ".", "parent", ".", "params", "[", "'frmt'", "]", "action", "=", "ctx", ".", "parent", ".", "params", "[", "'action'", "]", "c...
Generate deformed structures
[ "Generate", "deformed", "structures" ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/elastic/cli/elastic.py#L83-L117
train
26,514
jochym/Elastic
elastic/cli/elastic.py
proc
def proc(ctx, files): '''Process calculated structures''' def calc_reader(fn, verb): if verb: echo('Reading: {:<60s}\r'.format(fn), nl=False, err=True) return ase.io.read(fn) action = ctx.parent.params['action'] systems = [calc_reader(calc, verbose) for calc in files] i...
python
def proc(ctx, files): '''Process calculated structures''' def calc_reader(fn, verb): if verb: echo('Reading: {:<60s}\r'.format(fn), nl=False, err=True) return ase.io.read(fn) action = ctx.parent.params['action'] systems = [calc_reader(calc, verbose) for calc in files] i...
[ "def", "proc", "(", "ctx", ",", "files", ")", ":", "def", "calc_reader", "(", "fn", ",", "verb", ")", ":", "if", "verb", ":", "echo", "(", "'Reading: {:<60s}\\r'", ".", "format", "(", "fn", ")", ",", "nl", "=", "False", ",", "err", "=", "True", "...
Process calculated structures
[ "Process", "calculated", "structures" ]
8daae37d0c48aab8dfb1de2839dab02314817f95
https://github.com/jochym/Elastic/blob/8daae37d0c48aab8dfb1de2839dab02314817f95/elastic/cli/elastic.py#L123-L163
train
26,515
django-blog-zinnia/cmsplugin-zinnia
cmsplugin_zinnia/admin.py
EntryPlaceholderAdmin.save_model
def save_model(self, request, entry, form, change): """ Fill the content field with the interpretation of the placeholder """ context = RequestContext(request) try: content = render_placeholder(entry.content_placeholder, context) entry.content = co...
python
def save_model(self, request, entry, form, change): """ Fill the content field with the interpretation of the placeholder """ context = RequestContext(request) try: content = render_placeholder(entry.content_placeholder, context) entry.content = co...
[ "def", "save_model", "(", "self", ",", "request", ",", "entry", ",", "form", ",", "change", ")", ":", "context", "=", "RequestContext", "(", "request", ")", "try", ":", "content", "=", "render_placeholder", "(", "entry", ".", "content_placeholder", ",", "c...
Fill the content field with the interpretation of the placeholder
[ "Fill", "the", "content", "field", "with", "the", "interpretation", "of", "the", "placeholder" ]
7613c0d9ae29affe9ab97527e4b6d5bef124afdc
https://github.com/django-blog-zinnia/cmsplugin-zinnia/blob/7613c0d9ae29affe9ab97527e4b6d5bef124afdc/cmsplugin_zinnia/admin.py#L22-L35
train
26,516
django-blog-zinnia/cmsplugin-zinnia
cmsplugin_zinnia/menu.py
EntryMenu.get_nodes
def get_nodes(self, request): """ Return menu's node for entries """ nodes = [] archives = [] attributes = {'hidden': HIDE_ENTRY_MENU} for entry in Entry.published.all(): year = entry.creation_date.strftime('%Y') month = entry.creation_date...
python
def get_nodes(self, request): """ Return menu's node for entries """ nodes = [] archives = [] attributes = {'hidden': HIDE_ENTRY_MENU} for entry in Entry.published.all(): year = entry.creation_date.strftime('%Y') month = entry.creation_date...
[ "def", "get_nodes", "(", "self", ",", "request", ")", ":", "nodes", "=", "[", "]", "archives", "=", "[", "]", "attributes", "=", "{", "'hidden'", ":", "HIDE_ENTRY_MENU", "}", "for", "entry", "in", "Entry", ".", "published", ".", "all", "(", ")", ":",...
Return menu's node for entries
[ "Return", "menu", "s", "node", "for", "entries" ]
7613c0d9ae29affe9ab97527e4b6d5bef124afdc
https://github.com/django-blog-zinnia/cmsplugin-zinnia/blob/7613c0d9ae29affe9ab97527e4b6d5bef124afdc/cmsplugin_zinnia/menu.py#L26-L67
train
26,517
django-blog-zinnia/cmsplugin-zinnia
cmsplugin_zinnia/menu.py
CategoryMenu.get_nodes
def get_nodes(self, request): """ Return menu's node for categories """ nodes = [] nodes.append(NavigationNode(_('Categories'), reverse('zinnia:category_list'), 'categories')) for category in Category...
python
def get_nodes(self, request): """ Return menu's node for categories """ nodes = [] nodes.append(NavigationNode(_('Categories'), reverse('zinnia:category_list'), 'categories')) for category in Category...
[ "def", "get_nodes", "(", "self", ",", "request", ")", ":", "nodes", "=", "[", "]", "nodes", ".", "append", "(", "NavigationNode", "(", "_", "(", "'Categories'", ")", ",", "reverse", "(", "'zinnia:category_list'", ")", ",", "'categories'", ")", ")", "for"...
Return menu's node for categories
[ "Return", "menu", "s", "node", "for", "categories" ]
7613c0d9ae29affe9ab97527e4b6d5bef124afdc
https://github.com/django-blog-zinnia/cmsplugin-zinnia/blob/7613c0d9ae29affe9ab97527e4b6d5bef124afdc/cmsplugin_zinnia/menu.py#L76-L88
train
26,518
django-blog-zinnia/cmsplugin-zinnia
cmsplugin_zinnia/menu.py
AuthorMenu.get_nodes
def get_nodes(self, request): """ Return menu's node for authors """ nodes = [] nodes.append(NavigationNode(_('Authors'), reverse('zinnia:author_list'), 'authors')) for author in Author.published.all(...
python
def get_nodes(self, request): """ Return menu's node for authors """ nodes = [] nodes.append(NavigationNode(_('Authors'), reverse('zinnia:author_list'), 'authors')) for author in Author.published.all(...
[ "def", "get_nodes", "(", "self", ",", "request", ")", ":", "nodes", "=", "[", "]", "nodes", ".", "append", "(", "NavigationNode", "(", "_", "(", "'Authors'", ")", ",", "reverse", "(", "'zinnia:author_list'", ")", ",", "'authors'", ")", ")", "for", "aut...
Return menu's node for authors
[ "Return", "menu", "s", "node", "for", "authors" ]
7613c0d9ae29affe9ab97527e4b6d5bef124afdc
https://github.com/django-blog-zinnia/cmsplugin-zinnia/blob/7613c0d9ae29affe9ab97527e4b6d5bef124afdc/cmsplugin_zinnia/menu.py#L97-L109
train
26,519
django-blog-zinnia/cmsplugin-zinnia
cmsplugin_zinnia/menu.py
TagMenu.get_nodes
def get_nodes(self, request): """ Return menu's node for tags """ nodes = [] nodes.append(NavigationNode(_('Tags'), reverse('zinnia:tag_list'), 'tags')) for tag in tags_published(): nodes.append(NavigationNode(tag.name, ...
python
def get_nodes(self, request): """ Return menu's node for tags """ nodes = [] nodes.append(NavigationNode(_('Tags'), reverse('zinnia:tag_list'), 'tags')) for tag in tags_published(): nodes.append(NavigationNode(tag.name, ...
[ "def", "get_nodes", "(", "self", ",", "request", ")", ":", "nodes", "=", "[", "]", "nodes", ".", "append", "(", "NavigationNode", "(", "_", "(", "'Tags'", ")", ",", "reverse", "(", "'zinnia:tag_list'", ")", ",", "'tags'", ")", ")", "for", "tag", "in"...
Return menu's node for tags
[ "Return", "menu", "s", "node", "for", "tags" ]
7613c0d9ae29affe9ab97527e4b6d5bef124afdc
https://github.com/django-blog-zinnia/cmsplugin-zinnia/blob/7613c0d9ae29affe9ab97527e4b6d5bef124afdc/cmsplugin_zinnia/menu.py#L118-L130
train
26,520
django-blog-zinnia/cmsplugin-zinnia
cmsplugin_zinnia/menu.py
EntryModifier.modify
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): """ Modify nodes of a menu """ if breadcrumb: return nodes for node in nodes: if node.attr.get('hidden'): node.visible = False return nodes
python
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb): """ Modify nodes of a menu """ if breadcrumb: return nodes for node in nodes: if node.attr.get('hidden'): node.visible = False return nodes
[ "def", "modify", "(", "self", ",", "request", ",", "nodes", ",", "namespace", ",", "root_id", ",", "post_cut", ",", "breadcrumb", ")", ":", "if", "breadcrumb", ":", "return", "nodes", "for", "node", "in", "nodes", ":", "if", "node", ".", "attr", ".", ...
Modify nodes of a menu
[ "Modify", "nodes", "of", "a", "menu" ]
7613c0d9ae29affe9ab97527e4b6d5bef124afdc
https://github.com/django-blog-zinnia/cmsplugin-zinnia/blob/7613c0d9ae29affe9ab97527e4b6d5bef124afdc/cmsplugin_zinnia/menu.py#L140-L149
train
26,521
django-blog-zinnia/cmsplugin-zinnia
cmsplugin_zinnia/placeholder.py
PlaceholderEntry.acquire_context
def acquire_context(self): """ Inspect the stack to acquire the current context used, to render the placeholder. I'm really sorry for this, but if you have a better way, you are welcome ! """ frame = None request = None try: for f in inspect.s...
python
def acquire_context(self): """ Inspect the stack to acquire the current context used, to render the placeholder. I'm really sorry for this, but if you have a better way, you are welcome ! """ frame = None request = None try: for f in inspect.s...
[ "def", "acquire_context", "(", "self", ")", ":", "frame", "=", "None", "request", "=", "None", "try", ":", "for", "f", "in", "inspect", ".", "stack", "(", ")", "[", "1", ":", "]", ":", "frame", "=", "f", "[", "0", "]", "args", ",", "varargs", "...
Inspect the stack to acquire the current context used, to render the placeholder. I'm really sorry for this, but if you have a better way, you are welcome !
[ "Inspect", "the", "stack", "to", "acquire", "the", "current", "context", "used", "to", "render", "the", "placeholder", ".", "I", "m", "really", "sorry", "for", "this", "but", "if", "you", "have", "a", "better", "way", "you", "are", "welcome", "!" ]
7613c0d9ae29affe9ab97527e4b6d5bef124afdc
https://github.com/django-blog-zinnia/cmsplugin-zinnia/blob/7613c0d9ae29affe9ab97527e4b6d5bef124afdc/cmsplugin_zinnia/placeholder.py#L20-L40
train
26,522
duointeractive/sea-cucumber
seacucumber/util.py
get_boto_ses_connection
def get_boto_ses_connection(): """ Shortcut for instantiating and returning a boto SESConnection object. :rtype: boto.ses.SESConnection :returns: A boto SESConnection object, from which email sending is done. """ access_key_id = getattr( settings, 'CUCUMBER_SES_ACCESS_KEY_ID', ...
python
def get_boto_ses_connection(): """ Shortcut for instantiating and returning a boto SESConnection object. :rtype: boto.ses.SESConnection :returns: A boto SESConnection object, from which email sending is done. """ access_key_id = getattr( settings, 'CUCUMBER_SES_ACCESS_KEY_ID', ...
[ "def", "get_boto_ses_connection", "(", ")", ":", "access_key_id", "=", "getattr", "(", "settings", ",", "'CUCUMBER_SES_ACCESS_KEY_ID'", ",", "getattr", "(", "settings", ",", "'AWS_ACCESS_KEY_ID'", ",", "None", ")", ")", "access_key", "=", "getattr", "(", "settings...
Shortcut for instantiating and returning a boto SESConnection object. :rtype: boto.ses.SESConnection :returns: A boto SESConnection object, from which email sending is done.
[ "Shortcut", "for", "instantiating", "and", "returning", "a", "boto", "SESConnection", "object", "." ]
069637e2cbab561116e23b6723cfc30e779fce03
https://github.com/duointeractive/sea-cucumber/blob/069637e2cbab561116e23b6723cfc30e779fce03/seacucumber/util.py#L21-L49
train
26,523
duointeractive/sea-cucumber
seacucumber/tasks.py
SendEmailTask.run
def run(self, from_email, recipients, message): """ This does the dirty work. Connects to Amazon SES via boto and fires off the message. :param str from_email: The email address the message will show as originating from. :param list recipients: A list of email addres...
python
def run(self, from_email, recipients, message): """ This does the dirty work. Connects to Amazon SES via boto and fires off the message. :param str from_email: The email address the message will show as originating from. :param list recipients: A list of email addres...
[ "def", "run", "(", "self", ",", "from_email", ",", "recipients", ",", "message", ")", ":", "self", ".", "_open_ses_conn", "(", ")", "try", ":", "# We use the send_raw_email func here because the Django", "# EmailMessage object we got these values from constructs all of", "#...
This does the dirty work. Connects to Amazon SES via boto and fires off the message. :param str from_email: The email address the message will show as originating from. :param list recipients: A list of email addresses to send the message to. :param str message: ...
[ "This", "does", "the", "dirty", "work", ".", "Connects", "to", "Amazon", "SES", "via", "boto", "and", "fires", "off", "the", "message", "." ]
069637e2cbab561116e23b6723cfc30e779fce03
https://github.com/duointeractive/sea-cucumber/blob/069637e2cbab561116e23b6723cfc30e779fce03/seacucumber/tasks.py#L28-L99
train
26,524
duointeractive/sea-cucumber
seacucumber/management/commands/ses_usage.py
Command.handle
def handle(self, *args, **options): """ Renders the output by piecing together a few methods that do the dirty work. """ # AWS SES connection, which can be re-used for each query needed. conn = get_boto_ses_connection() self._print_quota(conn) self._print_...
python
def handle(self, *args, **options): """ Renders the output by piecing together a few methods that do the dirty work. """ # AWS SES connection, which can be re-used for each query needed. conn = get_boto_ses_connection() self._print_quota(conn) self._print_...
[ "def", "handle", "(", "self", ",", "*", "args", ",", "*", "*", "options", ")", ":", "# AWS SES connection, which can be re-used for each query needed.", "conn", "=", "get_boto_ses_connection", "(", ")", "self", ".", "_print_quota", "(", "conn", ")", "self", ".", ...
Renders the output by piecing together a few methods that do the dirty work.
[ "Renders", "the", "output", "by", "piecing", "together", "a", "few", "methods", "that", "do", "the", "dirty", "work", "." ]
069637e2cbab561116e23b6723cfc30e779fce03
https://github.com/duointeractive/sea-cucumber/blob/069637e2cbab561116e23b6723cfc30e779fce03/seacucumber/management/commands/ses_usage.py#L14-L22
train
26,525
duointeractive/sea-cucumber
seacucumber/management/commands/ses_usage.py
Command._print_quota
def _print_quota(self, conn): """ Prints some basic quota statistics. """ quota = conn.get_send_quota() quota = quota['GetSendQuotaResponse']['GetSendQuotaResult'] print "--- SES Quota ---" print " 24 Hour Quota: %s" % quota['Max24HourSend'] prin...
python
def _print_quota(self, conn): """ Prints some basic quota statistics. """ quota = conn.get_send_quota() quota = quota['GetSendQuotaResponse']['GetSendQuotaResult'] print "--- SES Quota ---" print " 24 Hour Quota: %s" % quota['Max24HourSend'] prin...
[ "def", "_print_quota", "(", "self", ",", "conn", ")", ":", "quota", "=", "conn", ".", "get_send_quota", "(", ")", "quota", "=", "quota", "[", "'GetSendQuotaResponse'", "]", "[", "'GetSendQuotaResult'", "]", "print", "\"--- SES Quota ---\"", "print", "\" 24 Hour...
Prints some basic quota statistics.
[ "Prints", "some", "basic", "quota", "statistics", "." ]
069637e2cbab561116e23b6723cfc30e779fce03
https://github.com/duointeractive/sea-cucumber/blob/069637e2cbab561116e23b6723cfc30e779fce03/seacucumber/management/commands/ses_usage.py#L24-L34
train
26,526
dwavesystems/dwave-tabu
tabu/sampler.py
TabuSampler.sample
def sample(self, bqm, init_solution=None, tenure=None, scale_factor=1, timeout=20, num_reads=1): """Run a tabu search on a given binary quadratic model. Args: bqm (:obj:`~dimod.BinaryQuadraticModel`): The binary quadratic model (BQM) to be sampled. init_solution ...
python
def sample(self, bqm, init_solution=None, tenure=None, scale_factor=1, timeout=20, num_reads=1): """Run a tabu search on a given binary quadratic model. Args: bqm (:obj:`~dimod.BinaryQuadraticModel`): The binary quadratic model (BQM) to be sampled. init_solution ...
[ "def", "sample", "(", "self", ",", "bqm", ",", "init_solution", "=", "None", ",", "tenure", "=", "None", ",", "scale_factor", "=", "1", ",", "timeout", "=", "20", ",", "num_reads", "=", "1", ")", ":", "# input checking and defaults calculation", "# TODO: one...
Run a tabu search on a given binary quadratic model. Args: bqm (:obj:`~dimod.BinaryQuadraticModel`): The binary quadratic model (BQM) to be sampled. init_solution (:obj:`~dimod.SampleSet`, optional): Single sample that sets an initial state for all the pr...
[ "Run", "a", "tabu", "search", "on", "a", "given", "binary", "quadratic", "model", "." ]
3397479343426a1e20ebf5b90593043904433eea
https://github.com/dwavesystems/dwave-tabu/blob/3397479343426a1e20ebf5b90593043904433eea/tabu/sampler.py#L53-L139
train
26,527
ankeshanand/py-gfycat
gfycat/client.py
GfycatClient.upload_from_url
def upload_from_url(self, url): """ Upload a GIF from a URL. """ self.check_token() params = {'fetchUrl': url} r = requests.get(FETCH_URL_ENDPOINT, params=params) if r.status_code != 200: raise GfycatClientError('Error fetching the URL', r.st...
python
def upload_from_url(self, url): """ Upload a GIF from a URL. """ self.check_token() params = {'fetchUrl': url} r = requests.get(FETCH_URL_ENDPOINT, params=params) if r.status_code != 200: raise GfycatClientError('Error fetching the URL', r.st...
[ "def", "upload_from_url", "(", "self", ",", "url", ")", ":", "self", ".", "check_token", "(", ")", "params", "=", "{", "'fetchUrl'", ":", "url", "}", "r", "=", "requests", ".", "get", "(", "FETCH_URL_ENDPOINT", ",", "params", "=", "params", ")", "if", ...
Upload a GIF from a URL.
[ "Upload", "a", "GIF", "from", "a", "URL", "." ]
74759a88fc59db1c5b270331b24442bc5f4c38e9
https://github.com/ankeshanand/py-gfycat/blob/74759a88fc59db1c5b270331b24442bc5f4c38e9/gfycat/client.py#L23-L39
train
26,528
ankeshanand/py-gfycat
gfycat/client.py
GfycatClient.upload_from_file
def upload_from_file(self, filename): """ Upload a local file to Gfycat """ key = str(uuid.uuid4())[:8] form = [('key', key), ('acl', ACL), ('AWSAccessKeyId', AWS_ACCESS_KEY_ID), ('success_action_status', SUCCESS_ACTION_STATUS), ...
python
def upload_from_file(self, filename): """ Upload a local file to Gfycat """ key = str(uuid.uuid4())[:8] form = [('key', key), ('acl', ACL), ('AWSAccessKeyId', AWS_ACCESS_KEY_ID), ('success_action_status', SUCCESS_ACTION_STATUS), ...
[ "def", "upload_from_file", "(", "self", ",", "filename", ")", ":", "key", "=", "str", "(", "uuid", ".", "uuid4", "(", ")", ")", "[", ":", "8", "]", "form", "=", "[", "(", "'key'", ",", "key", ")", ",", "(", "'acl'", ",", "ACL", ")", ",", "(",...
Upload a local file to Gfycat
[ "Upload", "a", "local", "file", "to", "Gfycat" ]
74759a88fc59db1c5b270331b24442bc5f4c38e9
https://github.com/ankeshanand/py-gfycat/blob/74759a88fc59db1c5b270331b24442bc5f4c38e9/gfycat/client.py#L41-L69
train
26,529
ankeshanand/py-gfycat
gfycat/client.py
GfycatClient.uploaded_file_info
def uploaded_file_info(self, key): """ Get information about an uploaded GIF. """ r = requests.get(FILE_UPLOAD_STATUS_ENDPOINT + key) if r.status_code != 200: raise GfycatClientError('Unable to check the status', r.status_code) ...
python
def uploaded_file_info(self, key): """ Get information about an uploaded GIF. """ r = requests.get(FILE_UPLOAD_STATUS_ENDPOINT + key) if r.status_code != 200: raise GfycatClientError('Unable to check the status', r.status_code) ...
[ "def", "uploaded_file_info", "(", "self", ",", "key", ")", ":", "r", "=", "requests", ".", "get", "(", "FILE_UPLOAD_STATUS_ENDPOINT", "+", "key", ")", "if", "r", ".", "status_code", "!=", "200", ":", "raise", "GfycatClientError", "(", "'Unable to check the sta...
Get information about an uploaded GIF.
[ "Get", "information", "about", "an", "uploaded", "GIF", "." ]
74759a88fc59db1c5b270331b24442bc5f4c38e9
https://github.com/ankeshanand/py-gfycat/blob/74759a88fc59db1c5b270331b24442bc5f4c38e9/gfycat/client.py#L71-L80
train
26,530
ankeshanand/py-gfycat
gfycat/client.py
GfycatClient.query_gfy
def query_gfy(self, gfyname): """ Query a gfy name for URLs and more information. """ self.check_token() r = requests.get(QUERY_ENDPOINT + gfyname, headers=self.headers) response = r.json() if r.status_code != 200 and not ERROR_KEY in re...
python
def query_gfy(self, gfyname): """ Query a gfy name for URLs and more information. """ self.check_token() r = requests.get(QUERY_ENDPOINT + gfyname, headers=self.headers) response = r.json() if r.status_code != 200 and not ERROR_KEY in re...
[ "def", "query_gfy", "(", "self", ",", "gfyname", ")", ":", "self", ".", "check_token", "(", ")", "r", "=", "requests", ".", "get", "(", "QUERY_ENDPOINT", "+", "gfyname", ",", "headers", "=", "self", ".", "headers", ")", "response", "=", "r", ".", "js...
Query a gfy name for URLs and more information.
[ "Query", "a", "gfy", "name", "for", "URLs", "and", "more", "information", "." ]
74759a88fc59db1c5b270331b24442bc5f4c38e9
https://github.com/ankeshanand/py-gfycat/blob/74759a88fc59db1c5b270331b24442bc5f4c38e9/gfycat/client.py#L82-L98
train
26,531
ankeshanand/py-gfycat
gfycat/client.py
GfycatClient.check_link
def check_link(self, link): """ Check if a link has been already converted. """ r = requests.get(CHECK_LINK_ENDPOINT + link) if r.status_code != 200: raise GfycatClientError('Unable to check the link', r.status_code) return...
python
def check_link(self, link): """ Check if a link has been already converted. """ r = requests.get(CHECK_LINK_ENDPOINT + link) if r.status_code != 200: raise GfycatClientError('Unable to check the link', r.status_code) return...
[ "def", "check_link", "(", "self", ",", "link", ")", ":", "r", "=", "requests", ".", "get", "(", "CHECK_LINK_ENDPOINT", "+", "link", ")", "if", "r", ".", "status_code", "!=", "200", ":", "raise", "GfycatClientError", "(", "'Unable to check the link'", ",", ...
Check if a link has been already converted.
[ "Check", "if", "a", "link", "has", "been", "already", "converted", "." ]
74759a88fc59db1c5b270331b24442bc5f4c38e9
https://github.com/ankeshanand/py-gfycat/blob/74759a88fc59db1c5b270331b24442bc5f4c38e9/gfycat/client.py#L100-L109
train
26,532
ankeshanand/py-gfycat
gfycat/client.py
GfycatClient.get_token
def get_token(self): """ Gets the authorization token """ payload = {'grant_type': 'client_credentials', 'client_id': self.client_id, 'client_secret': self.client_secret} r = requests.post(OAUTH_ENDPOINT, data=json.dumps(payload), headers={'content-type': 'application/js...
python
def get_token(self): """ Gets the authorization token """ payload = {'grant_type': 'client_credentials', 'client_id': self.client_id, 'client_secret': self.client_secret} r = requests.post(OAUTH_ENDPOINT, data=json.dumps(payload), headers={'content-type': 'application/js...
[ "def", "get_token", "(", "self", ")", ":", "payload", "=", "{", "'grant_type'", ":", "'client_credentials'", ",", "'client_id'", ":", "self", ".", "client_id", ",", "'client_secret'", ":", "self", ".", "client_secret", "}", "r", "=", "requests", ".", "post",...
Gets the authorization token
[ "Gets", "the", "authorization", "token" ]
74759a88fc59db1c5b270331b24442bc5f4c38e9
https://github.com/ankeshanand/py-gfycat/blob/74759a88fc59db1c5b270331b24442bc5f4c38e9/gfycat/client.py#L118-L137
train
26,533
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata.dict
def dict(self): """ dictionary representation of the metadata. :return: dictionary representation of the metadata :rtype: dict """ metadata = {} properties = {} for name, prop in list(self.properties.items()): properties[name] = prop.dict ...
python
def dict(self): """ dictionary representation of the metadata. :return: dictionary representation of the metadata :rtype: dict """ metadata = {} properties = {} for name, prop in list(self.properties.items()): properties[name] = prop.dict ...
[ "def", "dict", "(", "self", ")", ":", "metadata", "=", "{", "}", "properties", "=", "{", "}", "for", "name", ",", "prop", "in", "list", "(", "self", ".", "properties", ".", "items", "(", ")", ")", ":", "properties", "[", "name", "]", "=", "prop",...
dictionary representation of the metadata. :return: dictionary representation of the metadata :rtype: dict
[ "dictionary", "representation", "of", "the", "metadata", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L251-L263
train
26,534
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata.json
def json(self): """ json representation of the metadata. :return: json representation of the metadata :rtype: str """ json_dumps = json.dumps( self.dict, indent=2, sort_keys=True, separators=(',', ': '), cls=Met...
python
def json(self): """ json representation of the metadata. :return: json representation of the metadata :rtype: str """ json_dumps = json.dumps( self.dict, indent=2, sort_keys=True, separators=(',', ': '), cls=Met...
[ "def", "json", "(", "self", ")", ":", "json_dumps", "=", "json", ".", "dumps", "(", "self", ".", "dict", ",", "indent", "=", "2", ",", "sort_keys", "=", "True", ",", "separators", "=", "(", "','", ",", "': '", ")", ",", "cls", "=", "MetadataEncoder...
json representation of the metadata. :return: json representation of the metadata :rtype: str
[ "json", "representation", "of", "the", "metadata", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L287-L303
train
26,535
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata._read_json_file
def _read_json_file(self): """ read metadata from a json file. :return: the parsed json dict :rtype: dict """ with open(self.json_uri) as metadata_file: try: metadata = json.load(metadata_file) return metadata excep...
python
def _read_json_file(self): """ read metadata from a json file. :return: the parsed json dict :rtype: dict """ with open(self.json_uri) as metadata_file: try: metadata = json.load(metadata_file) return metadata excep...
[ "def", "_read_json_file", "(", "self", ")", ":", "with", "open", "(", "self", ".", "json_uri", ")", "as", "metadata_file", ":", "try", ":", "metadata", "=", "json", ".", "load", "(", "metadata_file", ")", "return", "metadata", "except", "ValueError", ":", ...
read metadata from a json file. :return: the parsed json dict :rtype: dict
[ "read", "metadata", "from", "a", "json", "file", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L330-L344
train
26,536
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata._read_json_db
def _read_json_db(self): """ read metadata from a json string stored in a DB. :return: the parsed json dict :rtype: dict """ try: metadata_str = self.db_io.read_metadata_from_uri( self.layer_uri, 'json') except HashNotFoundError: ...
python
def _read_json_db(self): """ read metadata from a json string stored in a DB. :return: the parsed json dict :rtype: dict """ try: metadata_str = self.db_io.read_metadata_from_uri( self.layer_uri, 'json') except HashNotFoundError: ...
[ "def", "_read_json_db", "(", "self", ")", ":", "try", ":", "metadata_str", "=", "self", ".", "db_io", ".", "read_metadata_from_uri", "(", "self", ".", "layer_uri", ",", "'json'", ")", "except", "HashNotFoundError", ":", "return", "{", "}", "try", ":", "met...
read metadata from a json string stored in a DB. :return: the parsed json dict :rtype: dict
[ "read", "metadata", "from", "a", "json", "string", "stored", "in", "a", "DB", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L346-L365
train
26,537
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata._read_xml_file
def _read_xml_file(self): """ read metadata from an xml file. :return: the root element of the xml :rtype: ElementTree.Element """ # this raises a IOError if the file doesn't exist root = ElementTree.parse(self.xml_uri) root.getroot() return root
python
def _read_xml_file(self): """ read metadata from an xml file. :return: the root element of the xml :rtype: ElementTree.Element """ # this raises a IOError if the file doesn't exist root = ElementTree.parse(self.xml_uri) root.getroot() return root
[ "def", "_read_xml_file", "(", "self", ")", ":", "# this raises a IOError if the file doesn't exist", "root", "=", "ElementTree", ".", "parse", "(", "self", ".", "xml_uri", ")", "root", ".", "getroot", "(", ")", "return", "root" ]
read metadata from an xml file. :return: the root element of the xml :rtype: ElementTree.Element
[ "read", "metadata", "from", "an", "xml", "file", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L388-L398
train
26,538
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata._read_xml_db
def _read_xml_db(self): """ read metadata from an xml string stored in a DB. :return: the root element of the xml :rtype: ElementTree.Element """ try: metadata_str = self.db_io.read_metadata_from_uri( self.layer_uri, 'xml') root = ...
python
def _read_xml_db(self): """ read metadata from an xml string stored in a DB. :return: the root element of the xml :rtype: ElementTree.Element """ try: metadata_str = self.db_io.read_metadata_from_uri( self.layer_uri, 'xml') root = ...
[ "def", "_read_xml_db", "(", "self", ")", ":", "try", ":", "metadata_str", "=", "self", ".", "db_io", ".", "read_metadata_from_uri", "(", "self", ".", "layer_uri", ",", "'xml'", ")", "root", "=", "ElementTree", ".", "fromstring", "(", "metadata_str", ")", "...
read metadata from an xml string stored in a DB. :return: the root element of the xml :rtype: ElementTree.Element
[ "read", "metadata", "from", "an", "xml", "string", "stored", "in", "a", "DB", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L400-L413
train
26,539
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata.set
def set(self, name, value, xml_path): """ Create a new metadata property. The accepted type depends on the property type which is determined by the xml_path :param name: the name of the property :type name: str :param value: the value of the property :ty...
python
def set(self, name, value, xml_path): """ Create a new metadata property. The accepted type depends on the property type which is determined by the xml_path :param name: the name of the property :type name: str :param value: the value of the property :ty...
[ "def", "set", "(", "self", ",", "name", ",", "value", ",", "xml_path", ")", ":", "xml_type", "=", "xml_path", ".", "split", "(", "'/'", ")", "[", "-", "1", "]", "# check if the desired type is supported", "try", ":", "property_class", "=", "TYPE_CONVERSIONS"...
Create a new metadata property. The accepted type depends on the property type which is determined by the xml_path :param name: the name of the property :type name: str :param value: the value of the property :type value: :param xml_path: the xml path where the ...
[ "Create", "a", "new", "metadata", "property", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L531-L565
train
26,540
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata.write_to_file
def write_to_file(self, destination_path): """ Writes the metadata json or xml to a file. :param destination_path: the file path the file format is inferred from the destination_path extension. :type destination_path: str :return: the written metadata :rtype: str...
python
def write_to_file(self, destination_path): """ Writes the metadata json or xml to a file. :param destination_path: the file path the file format is inferred from the destination_path extension. :type destination_path: str :return: the written metadata :rtype: str...
[ "def", "write_to_file", "(", "self", ",", "destination_path", ")", ":", "file_format", "=", "os", ".", "path", ".", "splitext", "(", "destination_path", ")", "[", "1", "]", "[", "1", ":", "]", "metadata", "=", "self", ".", "get_writable_metadata", "(", "...
Writes the metadata json or xml to a file. :param destination_path: the file path the file format is inferred from the destination_path extension. :type destination_path: str :return: the written metadata :rtype: str
[ "Writes", "the", "metadata", "json", "or", "xml", "to", "a", "file", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L584-L600
train
26,541
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata.get_writable_metadata
def get_writable_metadata(self, file_format): """ Convert the metadata to a writable form. :param file_format: the needed format can be json or xml :type file_format: str :return: the dupled metadata :rtype: str """ if file_format == 'json': m...
python
def get_writable_metadata(self, file_format): """ Convert the metadata to a writable form. :param file_format: the needed format can be json or xml :type file_format: str :return: the dupled metadata :rtype: str """ if file_format == 'json': m...
[ "def", "get_writable_metadata", "(", "self", ",", "file_format", ")", ":", "if", "file_format", "==", "'json'", ":", "metadata", "=", "self", ".", "json", "elif", "file_format", "==", "'xml'", ":", "metadata", "=", "self", ".", "xml", "else", ":", "raise",...
Convert the metadata to a writable form. :param file_format: the needed format can be json or xml :type file_format: str :return: the dupled metadata :rtype: str
[ "Convert", "the", "metadata", "to", "a", "writable", "form", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L625-L641
train
26,542
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata.read_from_ancillary_file
def read_from_ancillary_file(self, custom_xml=None): """ try to read xml and json from existing files or db. This is used when instantiating a new metadata object. We explicitly check if a custom XML was passed so we give it priority on the JSON. If no custom XML is passed, JSON...
python
def read_from_ancillary_file(self, custom_xml=None): """ try to read xml and json from existing files or db. This is used when instantiating a new metadata object. We explicitly check if a custom XML was passed so we give it priority on the JSON. If no custom XML is passed, JSON...
[ "def", "read_from_ancillary_file", "(", "self", ",", "custom_xml", "=", "None", ")", ":", "if", "custom_xml", "and", "os", ".", "path", ".", "isfile", "(", "self", ".", "xml_uri", ")", ":", "self", ".", "read_xml", "(", ")", "else", ":", "if", "not", ...
try to read xml and json from existing files or db. This is used when instantiating a new metadata object. We explicitly check if a custom XML was passed so we give it priority on the JSON. If no custom XML is passed, JSON has priority :param custom_xml: the path to a custom xml file ...
[ "try", "to", "read", "xml", "and", "json", "from", "existing", "files", "or", "db", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L643-L659
train
26,543
inasafe/inasafe
safe/metadata/base_metadata.py
BaseMetadata.update_from_dict
def update_from_dict(self, keywords): """Set properties of metadata using key and value from keywords :param keywords: A dictionary of keywords (key, value). :type keywords: dict """ for key, value in list(keywords.items()): setattr(self, key, value)
python
def update_from_dict(self, keywords): """Set properties of metadata using key and value from keywords :param keywords: A dictionary of keywords (key, value). :type keywords: dict """ for key, value in list(keywords.items()): setattr(self, key, value)
[ "def", "update_from_dict", "(", "self", ",", "keywords", ")", ":", "for", "key", ",", "value", "in", "list", "(", "keywords", ".", "items", "(", ")", ")", ":", "setattr", "(", "self", ",", "key", ",", "value", ")" ]
Set properties of metadata using key and value from keywords :param keywords: A dictionary of keywords (key, value). :type keywords: dict
[ "Set", "properties", "of", "metadata", "using", "key", "and", "value", "from", "keywords" ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata/base_metadata.py#L671-L679
train
26,544
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.accept
def accept(self): """Process the layer for multi buffering and generate a new layer. .. note:: This is called on OK click. """ # set parameter from dialog input_layer = self.layer.currentLayer() output_path = self.output_form.text() radius = self.get_classificati...
python
def accept(self): """Process the layer for multi buffering and generate a new layer. .. note:: This is called on OK click. """ # set parameter from dialog input_layer = self.layer.currentLayer() output_path = self.output_form.text() radius = self.get_classificati...
[ "def", "accept", "(", "self", ")", ":", "# set parameter from dialog", "input_layer", "=", "self", ".", "layer", ".", "currentLayer", "(", ")", "output_path", "=", "self", ".", "output_form", ".", "text", "(", ")", "radius", "=", "self", ".", "get_classifica...
Process the layer for multi buffering and generate a new layer. .. note:: This is called on OK click.
[ "Process", "the", "layer", "for", "multi", "buffering", "and", "generate", "a", "new", "layer", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L104-L156
train
26,545
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.on_directory_button_tool_clicked
def on_directory_button_tool_clicked(self): """Autoconnect slot activated when directory button is clicked.""" # noinspection PyCallByClass,PyTypeChecker # set up parameter from dialog input_path = self.layer.currentLayer().source() input_directory, self.output_filename = os.path...
python
def on_directory_button_tool_clicked(self): """Autoconnect slot activated when directory button is clicked.""" # noinspection PyCallByClass,PyTypeChecker # set up parameter from dialog input_path = self.layer.currentLayer().source() input_directory, self.output_filename = os.path...
[ "def", "on_directory_button_tool_clicked", "(", "self", ")", ":", "# noinspection PyCallByClass,PyTypeChecker", "# set up parameter from dialog", "input_path", "=", "self", ".", "layer", ".", "currentLayer", "(", ")", ".", "source", "(", ")", "input_directory", ",", "se...
Autoconnect slot activated when directory button is clicked.
[ "Autoconnect", "slot", "activated", "when", "directory", "button", "is", "clicked", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L159-L176
train
26,546
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.get_output_from_input
def get_output_from_input(self): """Populate output form with default output path based on input layer. """ input_path = self.layer.currentLayer().source() output_path = ( os.path.splitext(input_path)[0] + '_multi_buffer' + os.path.splitext(input_path)[1]) ...
python
def get_output_from_input(self): """Populate output form with default output path based on input layer. """ input_path = self.layer.currentLayer().source() output_path = ( os.path.splitext(input_path)[0] + '_multi_buffer' + os.path.splitext(input_path)[1]) ...
[ "def", "get_output_from_input", "(", "self", ")", ":", "input_path", "=", "self", ".", "layer", ".", "currentLayer", "(", ")", ".", "source", "(", ")", "output_path", "=", "(", "os", ".", "path", ".", "splitext", "(", "input_path", ")", "[", "0", "]", ...
Populate output form with default output path based on input layer.
[ "Populate", "output", "form", "with", "default", "output", "path", "based", "on", "input", "layer", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L178-L185
train
26,547
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.populate_hazard_classification
def populate_hazard_classification(self): """Populate hazard classification on hazard class form.""" new_class = { 'value': self.radius_form.value(), 'name': self.class_form.text()} self.classification.append(new_class) self.classification = sorted( se...
python
def populate_hazard_classification(self): """Populate hazard classification on hazard class form.""" new_class = { 'value': self.radius_form.value(), 'name': self.class_form.text()} self.classification.append(new_class) self.classification = sorted( se...
[ "def", "populate_hazard_classification", "(", "self", ")", ":", "new_class", "=", "{", "'value'", ":", "self", ".", "radius_form", ".", "value", "(", ")", ",", "'name'", ":", "self", ".", "class_form", ".", "text", "(", ")", "}", "self", ".", "classifica...
Populate hazard classification on hazard class form.
[ "Populate", "hazard", "classification", "on", "hazard", "class", "form", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L187-L204
train
26,548
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.remove_selected_classification
def remove_selected_classification(self): """Remove selected item on hazard class form.""" removed_classes = self.hazard_class_form.selectedItems() current_item = self.hazard_class_form.currentItem() removed_index = self.hazard_class_form.indexFromItem(current_item) del self.clas...
python
def remove_selected_classification(self): """Remove selected item on hazard class form.""" removed_classes = self.hazard_class_form.selectedItems() current_item = self.hazard_class_form.currentItem() removed_index = self.hazard_class_form.indexFromItem(current_item) del self.clas...
[ "def", "remove_selected_classification", "(", "self", ")", ":", "removed_classes", "=", "self", ".", "hazard_class_form", ".", "selectedItems", "(", ")", "current_item", "=", "self", ".", "hazard_class_form", ".", "currentItem", "(", ")", "removed_index", "=", "se...
Remove selected item on hazard class form.
[ "Remove", "selected", "item", "on", "hazard", "class", "form", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L206-L214
train
26,549
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.get_classification
def get_classification(self): """Get all hazard class created by user. :return: Hazard class definition created by user. :rtype: OrderedDict """ classification_dictionary = {} for item in self.classification: classification_dictionary[item['value']] = item['n...
python
def get_classification(self): """Get all hazard class created by user. :return: Hazard class definition created by user. :rtype: OrderedDict """ classification_dictionary = {} for item in self.classification: classification_dictionary[item['value']] = item['n...
[ "def", "get_classification", "(", "self", ")", ":", "classification_dictionary", "=", "{", "}", "for", "item", "in", "self", ".", "classification", ":", "classification_dictionary", "[", "item", "[", "'value'", "]", "]", "=", "item", "[", "'name'", "]", "cla...
Get all hazard class created by user. :return: Hazard class definition created by user. :rtype: OrderedDict
[ "Get", "all", "hazard", "class", "created", "by", "user", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L216-L229
train
26,550
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.directory_button_status
def directory_button_status(self): """Function to enable or disable directory button.""" if self.layer.currentLayer(): self.directory_button.setEnabled(True) else: self.directory_button.setEnabled(False)
python
def directory_button_status(self): """Function to enable or disable directory button.""" if self.layer.currentLayer(): self.directory_button.setEnabled(True) else: self.directory_button.setEnabled(False)
[ "def", "directory_button_status", "(", "self", ")", ":", "if", "self", ".", "layer", ".", "currentLayer", "(", ")", ":", "self", ".", "directory_button", ".", "setEnabled", "(", "True", ")", "else", ":", "self", ".", "directory_button", ".", "setEnabled", ...
Function to enable or disable directory button.
[ "Function", "to", "enable", "or", "disable", "directory", "button", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L231-L236
train
26,551
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.add_class_button_status
def add_class_button_status(self): """Function to enable or disable add class button.""" if self.class_form.text() and self.radius_form.value() >= 0: self.add_class_button.setEnabled(True) else: self.add_class_button.setEnabled(False)
python
def add_class_button_status(self): """Function to enable or disable add class button.""" if self.class_form.text() and self.radius_form.value() >= 0: self.add_class_button.setEnabled(True) else: self.add_class_button.setEnabled(False)
[ "def", "add_class_button_status", "(", "self", ")", ":", "if", "self", ".", "class_form", ".", "text", "(", ")", "and", "self", ".", "radius_form", ".", "value", "(", ")", ">=", "0", ":", "self", ".", "add_class_button", ".", "setEnabled", "(", "True", ...
Function to enable or disable add class button.
[ "Function", "to", "enable", "or", "disable", "add", "class", "button", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L238-L243
train
26,552
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.ok_button_status
def ok_button_status(self): """Function to enable or disable OK button.""" if not self.layer.currentLayer(): self.button_box.button( QtWidgets.QDialogButtonBox.Ok).setEnabled(False) elif (self.hazard_class_form.count() > 0 and self.layer.currentLayer().n...
python
def ok_button_status(self): """Function to enable or disable OK button.""" if not self.layer.currentLayer(): self.button_box.button( QtWidgets.QDialogButtonBox.Ok).setEnabled(False) elif (self.hazard_class_form.count() > 0 and self.layer.currentLayer().n...
[ "def", "ok_button_status", "(", "self", ")", ":", "if", "not", "self", ".", "layer", ".", "currentLayer", "(", ")", ":", "self", ".", "button_box", ".", "button", "(", "QtWidgets", ".", "QDialogButtonBox", ".", "Ok", ")", ".", "setEnabled", "(", "False",...
Function to enable or disable OK button.
[ "Function", "to", "enable", "or", "disable", "OK", "button", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L245-L257
train
26,553
inasafe/inasafe
safe/gui/tools/multi_buffer_dialog.py
MultiBufferDialog.help_toggled
def help_toggled(self, flag): """Show or hide the help tab in the stacked widget. :param flag: Flag indicating whether help should be shown or hidden. :type flag: bool """ if flag: self.help_button.setText(self.tr('Hide Help')) self.show_help() el...
python
def help_toggled(self, flag): """Show or hide the help tab in the stacked widget. :param flag: Flag indicating whether help should be shown or hidden. :type flag: bool """ if flag: self.help_button.setText(self.tr('Hide Help')) self.show_help() el...
[ "def", "help_toggled", "(", "self", ",", "flag", ")", ":", "if", "flag", ":", "self", ".", "help_button", ".", "setText", "(", "self", ".", "tr", "(", "'Hide Help'", ")", ")", "self", ".", "show_help", "(", ")", "else", ":", "self", ".", "help_button...
Show or hide the help tab in the stacked widget. :param flag: Flag indicating whether help should be shown or hidden. :type flag: bool
[ "Show", "or", "hide", "the", "help", "tab", "in", "the", "stacked", "widget", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/multi_buffer_dialog.py#L260-L271
train
26,554
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
convert_mmi_data
def convert_mmi_data( grid_xml_path, title, source, output_path=None, algorithm=None, algorithm_filename_flag=True, smoothing_method=NONE_SMOOTHING, smooth_sigma=0.9, extra_keywords=None ): """Convenience function to convert a single file. ...
python
def convert_mmi_data( grid_xml_path, title, source, output_path=None, algorithm=None, algorithm_filename_flag=True, smoothing_method=NONE_SMOOTHING, smooth_sigma=0.9, extra_keywords=None ): """Convenience function to convert a single file. ...
[ "def", "convert_mmi_data", "(", "grid_xml_path", ",", "title", ",", "source", ",", "output_path", "=", "None", ",", "algorithm", "=", "None", ",", "algorithm_filename_flag", "=", "True", ",", "smoothing_method", "=", "NONE_SMOOTHING", ",", "smooth_sigma", "=", "...
Convenience function to convert a single file. :param grid_xml_path: Path to the xml shake grid file. :type grid_xml_path: str :param title: The title of the earthquake. :type title: str :param source: The source of the shake data. :type source: str :param place_layer: Nearby cities/plac...
[ "Convenience", "function", "to", "convert", "a", "single", "file", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L990-L1065
train
26,555
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid.extract_date_time
def extract_date_time(self, the_time_stamp): """Extract the parts of a date given a timestamp as per below example. :param the_time_stamp: The 'event_timestamp' attribute from grid.xml. :type the_time_stamp: str # now separate out its parts # >>> e = "2012-08-07T01:55:12WIB" ...
python
def extract_date_time(self, the_time_stamp): """Extract the parts of a date given a timestamp as per below example. :param the_time_stamp: The 'event_timestamp' attribute from grid.xml. :type the_time_stamp: str # now separate out its parts # >>> e = "2012-08-07T01:55:12WIB" ...
[ "def", "extract_date_time", "(", "self", ",", "the_time_stamp", ")", ":", "date_tokens", "=", "the_time_stamp", "[", "0", ":", "10", "]", ".", "split", "(", "'-'", ")", "self", ".", "year", "=", "int", "(", "date_tokens", "[", "0", "]", ")", "self", ...
Extract the parts of a date given a timestamp as per below example. :param the_time_stamp: The 'event_timestamp' attribute from grid.xml. :type the_time_stamp: str # now separate out its parts # >>> e = "2012-08-07T01:55:12WIB" #>>> e[0:10] #'2012-08-07' #>>> e...
[ "Extract", "the", "parts", "of", "a", "date", "given", "a", "timestamp", "as", "per", "below", "example", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L170-L222
train
26,556
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid.grid_file_path
def grid_file_path(self): """Validate that grid file path points to a file. :return: The grid xml file path. :rtype: str :raises: GridXmlFileNotFoundError """ if os.path.isfile(self.grid_xml_path): return self.grid_xml_path else: raise Gr...
python
def grid_file_path(self): """Validate that grid file path points to a file. :return: The grid xml file path. :rtype: str :raises: GridXmlFileNotFoundError """ if os.path.isfile(self.grid_xml_path): return self.grid_xml_path else: raise Gr...
[ "def", "grid_file_path", "(", "self", ")", ":", "if", "os", ".", "path", ".", "isfile", "(", "self", ".", "grid_xml_path", ")", ":", "return", "self", ".", "grid_xml_path", "else", ":", "raise", "GridXmlFileNotFoundError" ]
Validate that grid file path points to a file. :return: The grid xml file path. :rtype: str :raises: GridXmlFileNotFoundError
[ "Validate", "that", "grid", "file", "path", "points", "to", "a", "file", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L380-L391
train
26,557
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid.mmi_to_delimited_text
def mmi_to_delimited_text(self): """Return the mmi data as a delimited test string. :returns: A delimited text string that can easily be written to disk for e.g. use by gdal_grid. :rtype: str The returned string will look like this:: 123.0750,01.7900,1 ...
python
def mmi_to_delimited_text(self): """Return the mmi data as a delimited test string. :returns: A delimited text string that can easily be written to disk for e.g. use by gdal_grid. :rtype: str The returned string will look like this:: 123.0750,01.7900,1 ...
[ "def", "mmi_to_delimited_text", "(", "self", ")", ":", "delimited_text", "=", "'lon,lat,mmi\\n'", "for", "row", "in", "self", ".", "mmi_data", ":", "delimited_text", "+=", "'%s,%s,%s\\n'", "%", "(", "row", "[", "0", "]", ",", "row", "[", "1", "]", ",", "...
Return the mmi data as a delimited test string. :returns: A delimited text string that can easily be written to disk for e.g. use by gdal_grid. :rtype: str The returned string will look like this:: 123.0750,01.7900,1 123.1000,01.7900,1.14 123.1250,...
[ "Return", "the", "mmi", "data", "as", "a", "delimited", "test", "string", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L393-L411
train
26,558
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid.mmi_to_delimited_file
def mmi_to_delimited_file(self, force_flag=True): """Save mmi_data to delimited text file suitable for gdal_grid. The output file will be of the same format as strings returned from :func:`mmi_to_delimited_text`. :param force_flag: Whether to force the regeneration of the output ...
python
def mmi_to_delimited_file(self, force_flag=True): """Save mmi_data to delimited text file suitable for gdal_grid. The output file will be of the same format as strings returned from :func:`mmi_to_delimited_text`. :param force_flag: Whether to force the regeneration of the output ...
[ "def", "mmi_to_delimited_file", "(", "self", ",", "force_flag", "=", "True", ")", ":", "LOGGER", ".", "debug", "(", "'mmi_to_delimited_text requested.'", ")", "csv_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "output_dir", ",", "'mmi.csv'", ...
Save mmi_data to delimited text file suitable for gdal_grid. The output file will be of the same format as strings returned from :func:`mmi_to_delimited_text`. :param force_flag: Whether to force the regeneration of the output file. Defaults to False. :type force_flag: bool...
[ "Save", "mmi_data", "to", "delimited", "text", "file", "suitable", "for", "gdal_grid", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L413-L451
train
26,559
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid.mmi_to_vrt
def mmi_to_vrt(self, force_flag=True): """Save the mmi_data to an ogr vrt text file. :param force_flag: Whether to force the regeneration of the output file. Defaults to False. :type force_flag: bool :returns: The absolute file system path to the .vrt text file. :rt...
python
def mmi_to_vrt(self, force_flag=True): """Save the mmi_data to an ogr vrt text file. :param force_flag: Whether to force the regeneration of the output file. Defaults to False. :type force_flag: bool :returns: The absolute file system path to the .vrt text file. :rt...
[ "def", "mmi_to_vrt", "(", "self", ",", "force_flag", "=", "True", ")", ":", "# Ensure the delimited mmi file exists", "LOGGER", ".", "debug", "(", "'mmi_to_vrt requested.'", ")", "vrt_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "output_dir", ...
Save the mmi_data to an ogr vrt text file. :param force_flag: Whether to force the regeneration of the output file. Defaults to False. :type force_flag: bool :returns: The absolute file system path to the .vrt text file. :rtype: str :raises: None
[ "Save", "the", "mmi_data", "to", "an", "ogr", "vrt", "text", "file", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L453-L491
train
26,560
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid._run_command
def _run_command(self, command): """Run a command and raise any error as needed. This is a simple runner for executing gdal commands. :param command: A command string to be run. :type command: str :raises: Any exceptions will be propagated. """ try: ...
python
def _run_command(self, command): """Run a command and raise any error as needed. This is a simple runner for executing gdal commands. :param command: A command string to be run. :type command: str :raises: Any exceptions will be propagated. """ try: ...
[ "def", "_run_command", "(", "self", ",", "command", ")", ":", "try", ":", "my_result", "=", "call", "(", "command", ",", "shell", "=", "True", ")", "del", "my_result", "except", "CalledProcessError", "as", "e", ":", "LOGGER", ".", "exception", "(", "'Run...
Run a command and raise any error as needed. This is a simple runner for executing gdal commands. :param command: A command string to be run. :type command: str :raises: Any exceptions will be propagated.
[ "Run", "a", "command", "and", "raise", "any", "error", "as", "needed", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L493-L519
train
26,561
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid.mmi_to_raster
def mmi_to_raster(self, force_flag=False, algorithm=USE_ASCII): """Convert the grid.xml's mmi column to a raster using gdal_grid. A geotiff file will be created. Unfortunately no python bindings exist for doing this so we are going to do it using a shell call. .. see also:: ht...
python
def mmi_to_raster(self, force_flag=False, algorithm=USE_ASCII): """Convert the grid.xml's mmi column to a raster using gdal_grid. A geotiff file will be created. Unfortunately no python bindings exist for doing this so we are going to do it using a shell call. .. see also:: ht...
[ "def", "mmi_to_raster", "(", "self", ",", "force_flag", "=", "False", ",", "algorithm", "=", "USE_ASCII", ")", ":", "LOGGER", ".", "debug", "(", "'mmi_to_raster requested.'", ")", "if", "algorithm", "is", "None", ":", "algorithm", "=", "USE_ASCII", "if", "se...
Convert the grid.xml's mmi column to a raster using gdal_grid. A geotiff file will be created. Unfortunately no python bindings exist for doing this so we are going to do it using a shell call. .. see also:: http://www.gdal.org/gdal_grid.html Example of the gdal_grid call we ...
[ "Convert", "the", "grid", ".", "xml", "s", "mmi", "column", "to", "a", "raster", "using", "gdal_grid", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L521-L654
train
26,562
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid.mmi_to_shapefile
def mmi_to_shapefile(self, force_flag=False): """Convert grid.xml's mmi column to a vector shp file using ogr2ogr. An ESRI shape file will be created. :param force_flag: bool (Optional). Whether to force the regeneration of the output file. Defaults to False. :return: Path...
python
def mmi_to_shapefile(self, force_flag=False): """Convert grid.xml's mmi column to a vector shp file using ogr2ogr. An ESRI shape file will be created. :param force_flag: bool (Optional). Whether to force the regeneration of the output file. Defaults to False. :return: Path...
[ "def", "mmi_to_shapefile", "(", "self", ",", "force_flag", "=", "False", ")", ":", "LOGGER", ".", "debug", "(", "'mmi_to_shapefile requested.'", ")", "shp_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "output_dir", ",", "'%s-points.shp'", "%"...
Convert grid.xml's mmi column to a vector shp file using ogr2ogr. An ESRI shape file will be created. :param force_flag: bool (Optional). Whether to force the regeneration of the output file. Defaults to False. :return: Path to the resulting tif file. :rtype: str ...
[ "Convert", "grid", ".", "xml", "s", "mmi", "column", "to", "a", "vector", "shp", "file", "using", "ogr2ogr", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L656-L710
train
26,563
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid.create_keyword_file
def create_keyword_file(self, algorithm): """Create keyword file for the raster file created. Basically copy a template from keyword file in converter data and add extra keyword (usually a title) :param algorithm: Which re-sampling algorithm to use. valid options are 'neare...
python
def create_keyword_file(self, algorithm): """Create keyword file for the raster file created. Basically copy a template from keyword file in converter data and add extra keyword (usually a title) :param algorithm: Which re-sampling algorithm to use. valid options are 'neare...
[ "def", "create_keyword_file", "(", "self", ",", "algorithm", ")", ":", "keyword_io", "=", "KeywordIO", "(", ")", "# Set thresholds for each exposure", "mmi_default_classes", "=", "default_classification_thresholds", "(", "earthquake_mmi_scale", ")", "mmi_default_threshold", ...
Create keyword file for the raster file created. Basically copy a template from keyword file in converter data and add extra keyword (usually a title) :param algorithm: Which re-sampling algorithm to use. valid options are 'nearest' (for nearest neighbour), 'invdist' (f...
[ "Create", "keyword", "file", "for", "the", "raster", "file", "created", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L850-L956
train
26,564
inasafe/inasafe
safe/gui/tools/shake_grid/shake_grid.py
ShakeGrid.mmi_to_ascii
def mmi_to_ascii(self, force_flag=False): """Convert grid.xml mmi column to a ascii raster file.""" ascii_path = os.path.join( self.output_dir, '%s.asc' % self.output_basename) # Short circuit if the tif is already created. if os.path.exists(ascii_path) and force_flag is not ...
python
def mmi_to_ascii(self, force_flag=False): """Convert grid.xml mmi column to a ascii raster file.""" ascii_path = os.path.join( self.output_dir, '%s.asc' % self.output_basename) # Short circuit if the tif is already created. if os.path.exists(ascii_path) and force_flag is not ...
[ "def", "mmi_to_ascii", "(", "self", ",", "force_flag", "=", "False", ")", ":", "ascii_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "output_dir", ",", "'%s.asc'", "%", "self", ".", "output_basename", ")", "# Short circuit if the tif is already ...
Convert grid.xml mmi column to a ascii raster file.
[ "Convert", "grid", ".", "xml", "mmi", "column", "to", "a", "ascii", "raster", "file", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/shake_grid/shake_grid.py#L958-L987
train
26,565
inasafe/inasafe
safe/gui/tools/wizard/step_fc85_summary.py
StepFcSummary.set_widgets
def set_widgets(self): """Set widgets on the Summary tab.""" if self.parent.aggregation_layer: aggr = self.parent.aggregation_layer.name() else: aggr = self.tr('no aggregation') html = self.tr('Please ensure the following information ' 'is ...
python
def set_widgets(self): """Set widgets on the Summary tab.""" if self.parent.aggregation_layer: aggr = self.parent.aggregation_layer.name() else: aggr = self.tr('no aggregation') html = self.tr('Please ensure the following information ' 'is ...
[ "def", "set_widgets", "(", "self", ")", ":", "if", "self", ".", "parent", ".", "aggregation_layer", ":", "aggr", "=", "self", ".", "parent", ".", "aggregation_layer", ".", "name", "(", ")", "else", ":", "aggr", "=", "self", ".", "tr", "(", "'no aggrega...
Set widgets on the Summary tab.
[ "Set", "widgets", "on", "the", "Summary", "tab", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/wizard/step_fc85_summary.py#L40-L70
train
26,566
inasafe/inasafe
safe/gis/generic_expressions.py
inasafe_analysis_summary_field_value
def inasafe_analysis_summary_field_value(field, feature, parent): """Retrieve a value from a field in the analysis summary layer. e.g. inasafe_analysis_summary_field_value('total_not_exposed') -> 3 """ _ = feature, parent # NOQA project_context_scope = QgsExpressionContextUtils.projectScope( ...
python
def inasafe_analysis_summary_field_value(field, feature, parent): """Retrieve a value from a field in the analysis summary layer. e.g. inasafe_analysis_summary_field_value('total_not_exposed') -> 3 """ _ = feature, parent # NOQA project_context_scope = QgsExpressionContextUtils.projectScope( ...
[ "def", "inasafe_analysis_summary_field_value", "(", "field", ",", "feature", ",", "parent", ")", ":", "_", "=", "feature", ",", "parent", "# NOQA", "project_context_scope", "=", "QgsExpressionContextUtils", ".", "projectScope", "(", "QgsProject", ".", "instance", "(...
Retrieve a value from a field in the analysis summary layer. e.g. inasafe_analysis_summary_field_value('total_not_exposed') -> 3
[ "Retrieve", "a", "value", "from", "a", "field", "in", "the", "analysis", "summary", "layer", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/generic_expressions.py#L50-L74
train
26,567
inasafe/inasafe
safe/gis/generic_expressions.py
inasafe_sub_analysis_summary_field_value
def inasafe_sub_analysis_summary_field_value( exposure_key, field, feature, parent): """Retrieve a value from field in the specified exposure analysis layer. """ _ = feature, parent # NOQA project_context_scope = QgsExpressionContextUtils.projectScope( QgsProject.instance()) projec...
python
def inasafe_sub_analysis_summary_field_value( exposure_key, field, feature, parent): """Retrieve a value from field in the specified exposure analysis layer. """ _ = feature, parent # NOQA project_context_scope = QgsExpressionContextUtils.projectScope( QgsProject.instance()) projec...
[ "def", "inasafe_sub_analysis_summary_field_value", "(", "exposure_key", ",", "field", ",", "feature", ",", "parent", ")", ":", "_", "=", "feature", ",", "parent", "# NOQA", "project_context_scope", "=", "QgsExpressionContextUtils", ".", "projectScope", "(", "QgsProjec...
Retrieve a value from field in the specified exposure analysis layer.
[ "Retrieve", "a", "value", "from", "field", "in", "the", "specified", "exposure", "analysis", "layer", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/generic_expressions.py#L89-L116
train
26,568
inasafe/inasafe
safe/gis/generic_expressions.py
inasafe_exposure_summary_field_values
def inasafe_exposure_summary_field_values(field, feature, parent): """Retrieve all values from a field in the exposure summary layer. """ _ = feature, parent # NOQA layer = exposure_summary_layer() if not layer: return None index = layer.fields().lookupField(field) if index < 0: ...
python
def inasafe_exposure_summary_field_values(field, feature, parent): """Retrieve all values from a field in the exposure summary layer. """ _ = feature, parent # NOQA layer = exposure_summary_layer() if not layer: return None index = layer.fields().lookupField(field) if index < 0: ...
[ "def", "inasafe_exposure_summary_field_values", "(", "field", ",", "feature", ",", "parent", ")", ":", "_", "=", "feature", ",", "parent", "# NOQA", "layer", "=", "exposure_summary_layer", "(", ")", "if", "not", "layer", ":", "return", "None", "index", "=", ...
Retrieve all values from a field in the exposure summary layer.
[ "Retrieve", "all", "values", "from", "a", "field", "in", "the", "exposure", "summary", "layer", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/generic_expressions.py#L130-L148
train
26,569
inasafe/inasafe
safe/gis/generic_expressions.py
inasafe_place_value_name
def inasafe_place_value_name(number, feature, parent): """Given a number, it will return the place value name. For instance: * inasafe_place_value_name(10) -> Ten \n * inasafe_place_value_name(1700) -> Thousand It needs to be used with inasafe_place_value_coefficient. """ _ = feature, pa...
python
def inasafe_place_value_name(number, feature, parent): """Given a number, it will return the place value name. For instance: * inasafe_place_value_name(10) -> Ten \n * inasafe_place_value_name(1700) -> Thousand It needs to be used with inasafe_place_value_coefficient. """ _ = feature, pa...
[ "def", "inasafe_place_value_name", "(", "number", ",", "feature", ",", "parent", ")", ":", "_", "=", "feature", ",", "parent", "# NOQA", "if", "number", "is", "None", ":", "return", "None", "rounded_number", "=", "round_affected_number", "(", "number", ",", ...
Given a number, it will return the place value name. For instance: * inasafe_place_value_name(10) -> Ten \n * inasafe_place_value_name(1700) -> Thousand It needs to be used with inasafe_place_value_coefficient.
[ "Given", "a", "number", "it", "will", "return", "the", "place", "value", "name", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/generic_expressions.py#L164-L185
train
26,570
inasafe/inasafe
safe/gis/generic_expressions.py
inasafe_place_value_coefficient
def inasafe_place_value_coefficient(number, feature, parent): """Given a number, it will return the coefficient of the place value name. For instance: * inasafe_place_value_coefficient(10) -> 1 * inasafe_place_value_coefficient(1700) -> 1.7 It needs to be used with inasafe_number_denomination_un...
python
def inasafe_place_value_coefficient(number, feature, parent): """Given a number, it will return the coefficient of the place value name. For instance: * inasafe_place_value_coefficient(10) -> 1 * inasafe_place_value_coefficient(1700) -> 1.7 It needs to be used with inasafe_number_denomination_un...
[ "def", "inasafe_place_value_coefficient", "(", "number", ",", "feature", ",", "parent", ")", ":", "_", "=", "feature", ",", "parent", "# NOQA", "if", "number", ">=", "0", ":", "rounded_number", "=", "round_affected_number", "(", "number", ",", "use_rounding", ...
Given a number, it will return the coefficient of the place value name. For instance: * inasafe_place_value_coefficient(10) -> 1 * inasafe_place_value_coefficient(1700) -> 1.7 It needs to be used with inasafe_number_denomination_unit.
[ "Given", "a", "number", "it", "will", "return", "the", "coefficient", "of", "the", "place", "value", "name", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/generic_expressions.py#L201-L226
train
26,571
inasafe/inasafe
safe/gis/generic_expressions.py
inasafe_place_value_percentage
def inasafe_place_value_percentage(number, total, feature, parent): """Given a number and total, it will return the percentage of the number to the total. For instance: * inasafe_place_value_percentage(inasafe_analysis_summary_field_value( 'female_displaced'), inasafe_analysis_summary_field_v...
python
def inasafe_place_value_percentage(number, total, feature, parent): """Given a number and total, it will return the percentage of the number to the total. For instance: * inasafe_place_value_percentage(inasafe_analysis_summary_field_value( 'female_displaced'), inasafe_analysis_summary_field_v...
[ "def", "inasafe_place_value_percentage", "(", "number", ",", "total", ",", "feature", ",", "parent", ")", ":", "_", "=", "feature", ",", "parent", "# NOQA", "if", "number", "<", "0", ":", "return", "None", "percentage_format", "=", "'{percentage}%'", "percenta...
Given a number and total, it will return the percentage of the number to the total. For instance: * inasafe_place_value_percentage(inasafe_analysis_summary_field_value( 'female_displaced'), inasafe_analysis_summary_field_value('displaced')) -> will calculate the percentage of female displ...
[ "Given", "a", "number", "and", "total", "it", "will", "return", "the", "percentage", "of", "the", "number", "to", "the", "total", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/generic_expressions.py#L246-L263
train
26,572
inasafe/inasafe
safe/gis/generic_expressions.py
beautify_date
def beautify_date(inasafe_time, feature, parent): """Given an InaSAFE analysis time, it will convert it to a date with year-month-date format. For instance: * beautify_date( @start_datetime ) -> will convert datetime provided by qgis_variable. """ _ = feature, parent # NOQA datet...
python
def beautify_date(inasafe_time, feature, parent): """Given an InaSAFE analysis time, it will convert it to a date with year-month-date format. For instance: * beautify_date( @start_datetime ) -> will convert datetime provided by qgis_variable. """ _ = feature, parent # NOQA datet...
[ "def", "beautify_date", "(", "inasafe_time", ",", "feature", ",", "parent", ")", ":", "_", "=", "feature", ",", "parent", "# NOQA", "datetime_object", "=", "parse", "(", "inasafe_time", ")", "date", "=", "datetime_object", ".", "strftime", "(", "'%Y-%m-%d'", ...
Given an InaSAFE analysis time, it will convert it to a date with year-month-date format. For instance: * beautify_date( @start_datetime ) -> will convert datetime provided by qgis_variable.
[ "Given", "an", "InaSAFE", "analysis", "time", "it", "will", "convert", "it", "to", "a", "date", "with", "year", "-", "month", "-", "date", "format", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/generic_expressions.py#L279-L290
train
26,573
inasafe/inasafe
safe/gis/generic_expressions.py
hazard_extra_keyword
def hazard_extra_keyword(keyword, feature, parent): """Given a keyword, it will return the value of the keyword from the hazard layer's extra keywords. For instance: * hazard_extra_keyword( 'depth' ) -> will return the value of 'depth' in current hazard layer's extra keywords. """ _ =...
python
def hazard_extra_keyword(keyword, feature, parent): """Given a keyword, it will return the value of the keyword from the hazard layer's extra keywords. For instance: * hazard_extra_keyword( 'depth' ) -> will return the value of 'depth' in current hazard layer's extra keywords. """ _ =...
[ "def", "hazard_extra_keyword", "(", "keyword", ",", "feature", ",", "parent", ")", ":", "_", "=", "feature", ",", "parent", "# NOQA", "hazard_layer_path", "=", "QgsExpressionContextUtils", ".", "projectScope", "(", "QgsProject", ".", "instance", "(", ")", ")", ...
Given a keyword, it will return the value of the keyword from the hazard layer's extra keywords. For instance: * hazard_extra_keyword( 'depth' ) -> will return the value of 'depth' in current hazard layer's extra keywords.
[ "Given", "a", "keyword", "it", "will", "return", "the", "value", "of", "the", "keyword", "from", "the", "hazard", "layer", "s", "extra", "keywords", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/generic_expressions.py#L339-L363
train
26,574
inasafe/inasafe
safe/messaging/item/numbered_list.py
NumberedList.to_html
def to_html(self): """Render a Text MessageElement as html Args: None Returns: Str the html representation of the Text MessageElement Raises: Errors are propagated """ if self.items is None: return else: ...
python
def to_html(self): """Render a Text MessageElement as html Args: None Returns: Str the html representation of the Text MessageElement Raises: Errors are propagated """ if self.items is None: return else: ...
[ "def", "to_html", "(", "self", ")", ":", "if", "self", ".", "items", "is", "None", ":", "return", "else", ":", "html", "=", "'<ol%s>\\n'", "%", "self", ".", "html_attributes", "(", ")", "for", "item", "in", "self", ".", "items", ":", "html", "+=", ...
Render a Text MessageElement as html Args: None Returns: Str the html representation of the Text MessageElement Raises: Errors are propagated
[ "Render", "a", "Text", "MessageElement", "as", "html" ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/messaging/item/numbered_list.py#L51-L70
train
26,575
inasafe/inasafe
safe/gis/vector/prepare_vector_layer.py
_check_value_mapping
def _check_value_mapping(layer, exposure_key=None): """Loop over the exposure type field and check if the value map is correct. :param layer: The layer :type layer: QgsVectorLayer :param exposure_key: The exposure key. :type exposure_key: str """ index = layer.fields().lookupField(exposure...
python
def _check_value_mapping(layer, exposure_key=None): """Loop over the exposure type field and check if the value map is correct. :param layer: The layer :type layer: QgsVectorLayer :param exposure_key: The exposure key. :type exposure_key: str """ index = layer.fields().lookupField(exposure...
[ "def", "_check_value_mapping", "(", "layer", ",", "exposure_key", "=", "None", ")", ":", "index", "=", "layer", ".", "fields", "(", ")", ".", "lookupField", "(", "exposure_type_field", "[", "'field_name'", "]", ")", "unique_exposure", "=", "layer", ".", "uni...
Loop over the exposure type field and check if the value map is correct. :param layer: The layer :type layer: QgsVectorLayer :param exposure_key: The exposure key. :type exposure_key: str
[ "Loop", "over", "the", "exposure", "type", "field", "and", "check", "if", "the", "value", "map", "is", "correct", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/vector/prepare_vector_layer.py#L132-L182
train
26,576
inasafe/inasafe
safe/gis/vector/prepare_vector_layer.py
clean_inasafe_fields
def clean_inasafe_fields(layer): """Clean inasafe_fields based on keywords. 1. Must use standard field names. 2. Sum up list of fields' value and put in the standard field name. 3. Remove un-used fields. :param layer: The layer :type layer: QgsVectorLayer """ fields = [] # Exposure...
python
def clean_inasafe_fields(layer): """Clean inasafe_fields based on keywords. 1. Must use standard field names. 2. Sum up list of fields' value and put in the standard field name. 3. Remove un-used fields. :param layer: The layer :type layer: QgsVectorLayer """ fields = [] # Exposure...
[ "def", "clean_inasafe_fields", "(", "layer", ")", ":", "fields", "=", "[", "]", "# Exposure", "if", "layer", ".", "keywords", "[", "'layer_purpose'", "]", "==", "layer_purpose_exposure", "[", "'key'", "]", ":", "fields", "=", "get_fields", "(", "layer", ".",...
Clean inasafe_fields based on keywords. 1. Must use standard field names. 2. Sum up list of fields' value and put in the standard field name. 3. Remove un-used fields. :param layer: The layer :type layer: QgsVectorLayer
[ "Clean", "inasafe_fields", "based", "on", "keywords", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/vector/prepare_vector_layer.py#L186-L243
train
26,577
inasafe/inasafe
safe/gis/vector/prepare_vector_layer.py
_size_is_needed
def _size_is_needed(layer): """Checker if we need the size field. :param layer: The layer to test. :type layer: QgsVectorLayer :return: If we need the size field. :rtype: bool """ exposure = layer.keywords.get('exposure') if not exposure: # The layer is not an exposure. ...
python
def _size_is_needed(layer): """Checker if we need the size field. :param layer: The layer to test. :type layer: QgsVectorLayer :return: If we need the size field. :rtype: bool """ exposure = layer.keywords.get('exposure') if not exposure: # The layer is not an exposure. ...
[ "def", "_size_is_needed", "(", "layer", ")", ":", "exposure", "=", "layer", ".", "keywords", ".", "get", "(", "'exposure'", ")", "if", "not", "exposure", ":", "# The layer is not an exposure.", "return", "False", "indivisible_exposure_keys", "=", "[", "f", "[", ...
Checker if we need the size field. :param layer: The layer to test. :type layer: QgsVectorLayer :return: If we need the size field. :rtype: bool
[ "Checker", "if", "we", "need", "the", "size", "field", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/vector/prepare_vector_layer.py#L246-L280
train
26,578
inasafe/inasafe
safe/gis/vector/prepare_vector_layer.py
_remove_features
def _remove_features(layer): """Remove features which do not have information for InaSAFE or an invalid geometry. :param layer: The vector layer. :type layer: QgsVectorLayer """ # Get the layer purpose of the layer. layer_purpose = layer.keywords['layer_purpose'] layer_subcategory = lay...
python
def _remove_features(layer): """Remove features which do not have information for InaSAFE or an invalid geometry. :param layer: The vector layer. :type layer: QgsVectorLayer """ # Get the layer purpose of the layer. layer_purpose = layer.keywords['layer_purpose'] layer_subcategory = lay...
[ "def", "_remove_features", "(", "layer", ")", ":", "# Get the layer purpose of the layer.", "layer_purpose", "=", "layer", ".", "keywords", "[", "'layer_purpose'", "]", "layer_subcategory", "=", "layer", ".", "keywords", ".", "get", "(", "layer_purpose", ")", "compu...
Remove features which do not have information for InaSAFE or an invalid geometry. :param layer: The vector layer. :type layer: QgsVectorLayer
[ "Remove", "features", "which", "do", "not", "have", "information", "for", "InaSAFE", "or", "an", "invalid", "geometry", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/vector/prepare_vector_layer.py#L284-L368
train
26,579
inasafe/inasafe
safe/gis/vector/prepare_vector_layer.py
_add_id_column
def _add_id_column(layer): """Add an ID column if it's not present in the attribute table. :param layer: The vector layer. :type layer: QgsVectorLayer """ layer_purpose = layer.keywords['layer_purpose'] mapping = { layer_purpose_exposure['key']: exposure_id_field, layer_purpose_...
python
def _add_id_column(layer): """Add an ID column if it's not present in the attribute table. :param layer: The vector layer. :type layer: QgsVectorLayer """ layer_purpose = layer.keywords['layer_purpose'] mapping = { layer_purpose_exposure['key']: exposure_id_field, layer_purpose_...
[ "def", "_add_id_column", "(", "layer", ")", ":", "layer_purpose", "=", "layer", ".", "keywords", "[", "'layer_purpose'", "]", "mapping", "=", "{", "layer_purpose_exposure", "[", "'key'", "]", ":", "exposure_id_field", ",", "layer_purpose_hazard", "[", "'key'", "...
Add an ID column if it's not present in the attribute table. :param layer: The vector layer. :type layer: QgsVectorLayer
[ "Add", "an", "ID", "column", "if", "it", "s", "not", "present", "in", "the", "attribute", "table", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/vector/prepare_vector_layer.py#L372-L420
train
26,580
inasafe/inasafe
safe/gis/vector/prepare_vector_layer.py
_add_default_exposure_class
def _add_default_exposure_class(layer): """The layer doesn't have an exposure class, we need to add it. :param layer: The vector layer. :type layer: QgsVectorLayer """ layer.startEditing() field = create_field_from_definition(exposure_class_field) layer.keywords['inasafe_fields'][exposure_...
python
def _add_default_exposure_class(layer): """The layer doesn't have an exposure class, we need to add it. :param layer: The vector layer. :type layer: QgsVectorLayer """ layer.startEditing() field = create_field_from_definition(exposure_class_field) layer.keywords['inasafe_fields'][exposure_...
[ "def", "_add_default_exposure_class", "(", "layer", ")", ":", "layer", ".", "startEditing", "(", ")", "field", "=", "create_field_from_definition", "(", "exposure_class_field", ")", "layer", ".", "keywords", "[", "'inasafe_fields'", "]", "[", "exposure_class_field", ...
The layer doesn't have an exposure class, we need to add it. :param layer: The vector layer. :type layer: QgsVectorLayer
[ "The", "layer", "doesn", "t", "have", "an", "exposure", "class", "we", "need", "to", "add", "it", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/vector/prepare_vector_layer.py#L424-L447
train
26,581
inasafe/inasafe
safe/gis/vector/prepare_vector_layer.py
sum_fields
def sum_fields(layer, output_field_key, input_fields): """Sum the value of input_fields and put it as output_field. :param layer: The vector layer. :type layer: QgsVectorLayer :param output_field_key: The output field definition key. :type output_field_key: basestring :param input_fields: Lis...
python
def sum_fields(layer, output_field_key, input_fields): """Sum the value of input_fields and put it as output_field. :param layer: The vector layer. :type layer: QgsVectorLayer :param output_field_key: The output field definition key. :type output_field_key: basestring :param input_fields: Lis...
[ "def", "sum_fields", "(", "layer", ",", "output_field_key", ",", "input_fields", ")", ":", "field_definition", "=", "definition", "(", "output_field_key", ")", "output_field_name", "=", "field_definition", "[", "'field_name'", "]", "# If the fields only has one element", ...
Sum the value of input_fields and put it as output_field. :param layer: The vector layer. :type layer: QgsVectorLayer :param output_field_key: The output field definition key. :type output_field_key: basestring :param input_fields: List of input fields' name. :type input_fields: list
[ "Sum", "the", "value", "of", "input_fields", "and", "put", "it", "as", "output_field", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gis/vector/prepare_vector_layer.py#L451-L503
train
26,582
inasafe/inasafe
safe/gui/tools/minimum_needs/needs_profile.py
get_needs_provenance
def get_needs_provenance(parameters): """Get the provenance of minimum needs. :param parameters: A dictionary of impact function parameters. :type parameters: dict :returns: A parameter of provenance :rtype: TextParameter """ if 'minimum needs' not in parameters: return None ne...
python
def get_needs_provenance(parameters): """Get the provenance of minimum needs. :param parameters: A dictionary of impact function parameters. :type parameters: dict :returns: A parameter of provenance :rtype: TextParameter """ if 'minimum needs' not in parameters: return None ne...
[ "def", "get_needs_provenance", "(", "parameters", ")", ":", "if", "'minimum needs'", "not", "in", "parameters", ":", "return", "None", "needs", "=", "parameters", "[", "'minimum needs'", "]", "provenance", "=", "[", "p", "for", "p", "in", "needs", "if", "p",...
Get the provenance of minimum needs. :param parameters: A dictionary of impact function parameters. :type parameters: dict :returns: A parameter of provenance :rtype: TextParameter
[ "Get", "the", "provenance", "of", "minimum", "needs", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/minimum_needs/needs_profile.py#L40-L55
train
26,583
inasafe/inasafe
safe/gui/tools/minimum_needs/needs_profile.py
NeedsProfile.load
def load(self): """Load the minimum needs. If the minimum needs defined in QSettings use it, if not, get the most relevant available minimum needs (based on QGIS locale). The last thing to do is to just use the default minimum needs. """ self.minimum_needs = self.setting...
python
def load(self): """Load the minimum needs. If the minimum needs defined in QSettings use it, if not, get the most relevant available minimum needs (based on QGIS locale). The last thing to do is to just use the default minimum needs. """ self.minimum_needs = self.setting...
[ "def", "load", "(", "self", ")", ":", "self", ".", "minimum_needs", "=", "self", ".", "settings", ".", "value", "(", "'MinimumNeeds'", ")", "if", "not", "self", ".", "minimum_needs", "or", "self", ".", "minimum_needs", "==", "''", ":", "# Load the most rel...
Load the minimum needs. If the minimum needs defined in QSettings use it, if not, get the most relevant available minimum needs (based on QGIS locale). The last thing to do is to just use the default minimum needs.
[ "Load", "the", "minimum", "needs", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/minimum_needs/needs_profile.py#L101-L119
train
26,584
inasafe/inasafe
safe/gui/tools/minimum_needs/needs_profile.py
NeedsProfile.load_profile
def load_profile(self, profile): """Load a specific profile into the current minimum needs. :param profile: The profile's name :type profile: basestring, str """ profile_path = os.path.join( self.root_directory, 'minimum_needs', profile + '.json') self.read_f...
python
def load_profile(self, profile): """Load a specific profile into the current minimum needs. :param profile: The profile's name :type profile: basestring, str """ profile_path = os.path.join( self.root_directory, 'minimum_needs', profile + '.json') self.read_f...
[ "def", "load_profile", "(", "self", ",", "profile", ")", ":", "profile_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "root_directory", ",", "'minimum_needs'", ",", "profile", "+", "'.json'", ")", "self", ".", "read_from_file", "(", "profile...
Load a specific profile into the current minimum needs. :param profile: The profile's name :type profile: basestring, str
[ "Load", "a", "specific", "profile", "into", "the", "current", "minimum", "needs", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/minimum_needs/needs_profile.py#L121-L129
train
26,585
inasafe/inasafe
safe/gui/tools/minimum_needs/needs_profile.py
NeedsProfile.save_profile
def save_profile(self, profile): """Save the current minimum needs into a new profile. :param profile: The profile's name :type profile: basestring, str """ profile = profile.replace('.json', '') profile_path = os.path.join( self.root_directory, '...
python
def save_profile(self, profile): """Save the current minimum needs into a new profile. :param profile: The profile's name :type profile: basestring, str """ profile = profile.replace('.json', '') profile_path = os.path.join( self.root_directory, '...
[ "def", "save_profile", "(", "self", ",", "profile", ")", ":", "profile", "=", "profile", ".", "replace", "(", "'.json'", ",", "''", ")", "profile_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "root_directory", ",", "'minimum_needs'", ",",...
Save the current minimum needs into a new profile. :param profile: The profile's name :type profile: basestring, str
[ "Save", "the", "current", "minimum", "needs", "into", "a", "new", "profile", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/minimum_needs/needs_profile.py#L131-L143
train
26,586
inasafe/inasafe
safe/gui/tools/minimum_needs/needs_profile.py
NeedsProfile.get_profiles
def get_profiles(self, overwrite=False): """Get all the minimum needs profiles. :returns: The minimum needs by name. :rtype: list """ def sort_by_locale(unsorted_profiles, locale): """Sort the profiles by language settings. The profiles that are in the s...
python
def get_profiles(self, overwrite=False): """Get all the minimum needs profiles. :returns: The minimum needs by name. :rtype: list """ def sort_by_locale(unsorted_profiles, locale): """Sort the profiles by language settings. The profiles that are in the s...
[ "def", "get_profiles", "(", "self", ",", "overwrite", "=", "False", ")", ":", "def", "sort_by_locale", "(", "unsorted_profiles", ",", "locale", ")", ":", "\"\"\"Sort the profiles by language settings.\n\n The profiles that are in the same language as the QGIS' locale\n...
Get all the minimum needs profiles. :returns: The minimum needs by name. :rtype: list
[ "Get", "all", "the", "minimum", "needs", "profiles", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/minimum_needs/needs_profile.py#L155-L217
train
26,587
inasafe/inasafe
safe/gui/tools/minimum_needs/needs_profile.py
NeedsProfile.get_needs_parameters
def get_needs_parameters(self): """Get the minimum needs resources in parameter format :returns: The minimum needs resources wrapped in parameters. :rtype: list """ parameters = [] for resource in self.minimum_needs['resources']: parameter = ResourceParameter...
python
def get_needs_parameters(self): """Get the minimum needs resources in parameter format :returns: The minimum needs resources wrapped in parameters. :rtype: list """ parameters = [] for resource in self.minimum_needs['resources']: parameter = ResourceParameter...
[ "def", "get_needs_parameters", "(", "self", ")", ":", "parameters", "=", "[", "]", "for", "resource", "in", "self", ".", "minimum_needs", "[", "'resources'", "]", ":", "parameter", "=", "ResourceParameter", "(", ")", "parameter", ".", "name", "=", "resource"...
Get the minimum needs resources in parameter format :returns: The minimum needs resources wrapped in parameters. :rtype: list
[ "Get", "the", "minimum", "needs", "resources", "in", "parameter", "format" ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/minimum_needs/needs_profile.py#L234-L282
train
26,588
inasafe/inasafe
safe/gui/tools/minimum_needs/needs_profile.py
NeedsProfile.format_sentence
def format_sentence(sentence, resource): """Populate the placeholders in the sentence. :param sentence: The sentence with placeholder keywords. :type sentence: basestring, str :param resource: The resource to be placed into the sentence. :type resource: dict :returns: ...
python
def format_sentence(sentence, resource): """Populate the placeholders in the sentence. :param sentence: The sentence with placeholder keywords. :type sentence: basestring, str :param resource: The resource to be placed into the sentence. :type resource: dict :returns: ...
[ "def", "format_sentence", "(", "sentence", ",", "resource", ")", ":", "sentence", "=", "sentence", ".", "split", "(", "'{{'", ")", "updated_sentence", "=", "sentence", "[", "0", "]", ".", "rstrip", "(", ")", "for", "part", "in", "sentence", "[", "1", "...
Populate the placeholders in the sentence. :param sentence: The sentence with placeholder keywords. :type sentence: basestring, str :param resource: The resource to be placed into the sentence. :type resource: dict :returns: The formatted sentence. :rtype: basestring
[ "Populate", "the", "placeholders", "in", "the", "sentence", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/minimum_needs/needs_profile.py#L314-L336
train
26,589
inasafe/inasafe
safe/gui/tools/minimum_needs/needs_profile.py
NeedsProfile.remove_profile
def remove_profile(self, profile): """Remove a profile. :param profile: The profile to be removed. :type profile: basestring, str """ self.remove_file( os.path.join( self.root_directory, 'minimum_needs', profile + '.json') )
python
def remove_profile(self, profile): """Remove a profile. :param profile: The profile to be removed. :type profile: basestring, str """ self.remove_file( os.path.join( self.root_directory, 'minimum_needs', profile + '.json') )
[ "def", "remove_profile", "(", "self", ",", "profile", ")", ":", "self", ".", "remove_file", "(", "os", ".", "path", ".", "join", "(", "self", ".", "root_directory", ",", "'minimum_needs'", ",", "profile", "+", "'.json'", ")", ")" ]
Remove a profile. :param profile: The profile to be removed. :type profile: basestring, str
[ "Remove", "a", "profile", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/minimum_needs/needs_profile.py#L338-L347
train
26,590
inasafe/inasafe
safe/utilities/i18n.py
tr
def tr(text, context='@default'): """We define a tr function alias here since the utilities implementation below is not a class and does not inherit from QObject. .. note:: see http://tinyurl.com/pyqt-differences :param text: String to be translated :type text: str, unicode :param context: A ...
python
def tr(text, context='@default'): """We define a tr function alias here since the utilities implementation below is not a class and does not inherit from QObject. .. note:: see http://tinyurl.com/pyqt-differences :param text: String to be translated :type text: str, unicode :param context: A ...
[ "def", "tr", "(", "text", ",", "context", "=", "'@default'", ")", ":", "# noinspection PyCallByClass,PyTypeChecker,PyArgumentList", "if", "type", "(", "text", ")", "!=", "str", ":", "text", "=", "str", "(", "text", ")", "translated_text", "=", "QCoreApplication"...
We define a tr function alias here since the utilities implementation below is not a class and does not inherit from QObject. .. note:: see http://tinyurl.com/pyqt-differences :param text: String to be translated :type text: str, unicode :param context: A context for the translation. Since a same...
[ "We", "define", "a", "tr", "function", "alias", "here", "since", "the", "utilities", "implementation", "below", "is", "not", "a", "class", "and", "does", "not", "inherit", "from", "QObject", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/utilities/i18n.py#L24-L63
train
26,591
inasafe/inasafe
safe/utilities/i18n.py
locale
def locale(qsetting=''): """Get the name of the currently active locale. :param qsetting: String to specify the QSettings. By default, use empty string. :type qsetting: str :returns: Name of the locale e.g. 'id' :rtype: str """ override_flag = QSettings(qsetting).value( 'lo...
python
def locale(qsetting=''): """Get the name of the currently active locale. :param qsetting: String to specify the QSettings. By default, use empty string. :type qsetting: str :returns: Name of the locale e.g. 'id' :rtype: str """ override_flag = QSettings(qsetting).value( 'lo...
[ "def", "locale", "(", "qsetting", "=", "''", ")", ":", "override_flag", "=", "QSettings", "(", "qsetting", ")", ".", "value", "(", "'locale/overrideFlag'", ",", "True", ",", "type", "=", "bool", ")", "default", "=", "'en_US'", "if", "override_flag", ":", ...
Get the name of the currently active locale. :param qsetting: String to specify the QSettings. By default, use empty string. :type qsetting: str :returns: Name of the locale e.g. 'id' :rtype: str
[ "Get", "the", "name", "of", "the", "currently", "active", "locale", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/utilities/i18n.py#L66-L95
train
26,592
inasafe/inasafe
safe/gui/tools/wizard/step_kw13_band_selector.py
StepKwBandSelector.update_band_description
def update_band_description(self): """Helper to update band description.""" self.clear_further_steps() # Set widgets selected_band = self.selected_band() statistics = self.parent.layer.dataProvider().bandStatistics( selected_band, QgsRasterBandStats.All, ...
python
def update_band_description(self): """Helper to update band description.""" self.clear_further_steps() # Set widgets selected_band = self.selected_band() statistics = self.parent.layer.dataProvider().bandStatistics( selected_band, QgsRasterBandStats.All, ...
[ "def", "update_band_description", "(", "self", ")", ":", "self", ".", "clear_further_steps", "(", ")", "# Set widgets", "selected_band", "=", "self", ".", "selected_band", "(", ")", "statistics", "=", "self", ".", "parent", ".", "layer", ".", "dataProvider", "...
Helper to update band description.
[ "Helper", "to", "update", "band", "description", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/wizard/step_kw13_band_selector.py#L58-L73
train
26,593
inasafe/inasafe
safe/gui/tools/wizard/step_kw13_band_selector.py
StepKwBandSelector.selected_band
def selected_band(self): """Obtain the layer mode selected by user. :returns: selected layer mode. :rtype: string, None """ item = self.lstBands.currentItem() return item.data(QtCore.Qt.UserRole)
python
def selected_band(self): """Obtain the layer mode selected by user. :returns: selected layer mode. :rtype: string, None """ item = self.lstBands.currentItem() return item.data(QtCore.Qt.UserRole)
[ "def", "selected_band", "(", "self", ")", ":", "item", "=", "self", ".", "lstBands", ".", "currentItem", "(", ")", "return", "item", ".", "data", "(", "QtCore", ".", "Qt", ".", "UserRole", ")" ]
Obtain the layer mode selected by user. :returns: selected layer mode. :rtype: string, None
[ "Obtain", "the", "layer", "mode", "selected", "by", "user", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/gui/tools/wizard/step_kw13_band_selector.py#L75-L82
train
26,594
inasafe/inasafe
safe/metadata35/utils.py
merge_dictionaries
def merge_dictionaries(base_dict, extra_dict): """ merge two dictionaries. if both have a same key, the one from extra_dict is taken :param base_dict: first dictionary :type base_dict: dict :param extra_dict: second dictionary :type extra_dict: dict :return: a merge of the two dictiona...
python
def merge_dictionaries(base_dict, extra_dict): """ merge two dictionaries. if both have a same key, the one from extra_dict is taken :param base_dict: first dictionary :type base_dict: dict :param extra_dict: second dictionary :type extra_dict: dict :return: a merge of the two dictiona...
[ "def", "merge_dictionaries", "(", "base_dict", ",", "extra_dict", ")", ":", "new_dict", "=", "base_dict", ".", "copy", "(", ")", "new_dict", ".", "update", "(", "extra_dict", ")", "return", "new_dict" ]
merge two dictionaries. if both have a same key, the one from extra_dict is taken :param base_dict: first dictionary :type base_dict: dict :param extra_dict: second dictionary :type extra_dict: dict :return: a merge of the two dictionaries :rtype: dicts
[ "merge", "two", "dictionaries", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata35/utils.py#L112-L127
train
26,595
inasafe/inasafe
safe/metadata35/utils.py
read_property_from_xml
def read_property_from_xml(root, path): """ Get the text from an XML property. Whitespaces, tabs and new lines are trimmed :param root: container in which we search :type root: ElementTree.Element :param path: path to search in root :type path: str :return: the text of the element at t...
python
def read_property_from_xml(root, path): """ Get the text from an XML property. Whitespaces, tabs and new lines are trimmed :param root: container in which we search :type root: ElementTree.Element :param path: path to search in root :type path: str :return: the text of the element at t...
[ "def", "read_property_from_xml", "(", "root", ",", "path", ")", ":", "element", "=", "root", ".", "find", "(", "path", ",", "XML_NS", ")", "try", ":", "return", "element", ".", "text", ".", "strip", "(", "' \\t\\n\\r'", ")", "except", "AttributeError", "...
Get the text from an XML property. Whitespaces, tabs and new lines are trimmed :param root: container in which we search :type root: ElementTree.Element :param path: path to search in root :type path: str :return: the text of the element at the given path :rtype: str, None
[ "Get", "the", "text", "from", "an", "XML", "property", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/metadata35/utils.py#L130-L147
train
26,596
inasafe/inasafe
safe/report/impact_report.py
InaSAFEReportContext.north_arrow
def north_arrow(self, north_arrow_path): """Set image that will be used as north arrow in reports. :param north_arrow_path: Path to the north arrow image. :type north_arrow_path: str """ if isinstance(north_arrow_path, str) and os.path.exists( north_arrow_path): ...
python
def north_arrow(self, north_arrow_path): """Set image that will be used as north arrow in reports. :param north_arrow_path: Path to the north arrow image. :type north_arrow_path: str """ if isinstance(north_arrow_path, str) and os.path.exists( north_arrow_path): ...
[ "def", "north_arrow", "(", "self", ",", "north_arrow_path", ")", ":", "if", "isinstance", "(", "north_arrow_path", ",", "str", ")", "and", "os", ".", "path", ".", "exists", "(", "north_arrow_path", ")", ":", "self", ".", "_north_arrow", "=", "north_arrow_pat...
Set image that will be used as north arrow in reports. :param north_arrow_path: Path to the north arrow image. :type north_arrow_path: str
[ "Set", "image", "that", "will", "be", "used", "as", "north", "arrow", "in", "reports", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/report/impact_report.py#L69-L79
train
26,597
inasafe/inasafe
safe/report/impact_report.py
InaSAFEReportContext.organisation_logo
def organisation_logo(self, logo): """Set image that will be used as organisation logo in reports. :param logo: Path to the organisation logo image. :type logo: str """ if isinstance(logo, str) and os.path.exists(logo): self._organisation_logo = logo else: ...
python
def organisation_logo(self, logo): """Set image that will be used as organisation logo in reports. :param logo: Path to the organisation logo image. :type logo: str """ if isinstance(logo, str) and os.path.exists(logo): self._organisation_logo = logo else: ...
[ "def", "organisation_logo", "(", "self", ",", "logo", ")", ":", "if", "isinstance", "(", "logo", ",", "str", ")", "and", "os", ".", "path", ".", "exists", "(", "logo", ")", ":", "self", ".", "_organisation_logo", "=", "logo", "else", ":", "self", "."...
Set image that will be used as organisation logo in reports. :param logo: Path to the organisation logo image. :type logo: str
[ "Set", "image", "that", "will", "be", "used", "as", "organisation", "logo", "in", "reports", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/report/impact_report.py#L116-L125
train
26,598
inasafe/inasafe
safe/report/impact_report.py
InaSAFEReportContext.disclaimer
def disclaimer(self, text): """Set text that will be used as disclaimer in reports. :param text: Disclaimer text :type text: str """ if not isinstance(text, str): self._disclaimer = disclaimer() else: self._disclaimer = text
python
def disclaimer(self, text): """Set text that will be used as disclaimer in reports. :param text: Disclaimer text :type text: str """ if not isinstance(text, str): self._disclaimer = disclaimer() else: self._disclaimer = text
[ "def", "disclaimer", "(", "self", ",", "text", ")", ":", "if", "not", "isinstance", "(", "text", ",", "str", ")", ":", "self", ".", "_disclaimer", "=", "disclaimer", "(", ")", "else", ":", "self", ".", "_disclaimer", "=", "text" ]
Set text that will be used as disclaimer in reports. :param text: Disclaimer text :type text: str
[ "Set", "text", "that", "will", "be", "used", "as", "disclaimer", "in", "reports", "." ]
831d60abba919f6d481dc94a8d988cc205130724
https://github.com/inasafe/inasafe/blob/831d60abba919f6d481dc94a8d988cc205130724/safe/report/impact_report.py#L148-L157
train
26,599