sequence
stringlengths 546
16.2k
| code
stringlengths 108
19.3k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:text_search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:text; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:offset; 11, integer:100; 12, default_parameter; 12, 13; 12, 14; 13, identifier:page; 14, integer:1; 15, block; 15, 16; 15, 18; 15, 23; 15, 39; 15, 58; 16, expression_statement; 16, 17; 17, comment; 18, assert_statement; 18, 19; 18, 22; 19, comparison_operator:>=; 19, 20; 19, 21; 20, identifier:page; 21, integer:1; 22, string:f'Invalid page value {page}. Required page >= 1.'; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:payload; 26, dictionary; 26, 27; 26, 30; 26, 33; 26, 36; 27, pair; 27, 28; 27, 29; 28, string:"text"; 29, identifier:text; 30, pair; 30, 31; 30, 32; 31, string:"sort"; 32, identifier:sort; 33, pair; 33, 34; 33, 35; 34, string:"offset"; 35, identifier:offset; 36, pair; 36, 37; 36, 38; 37, string:"page"; 38, identifier:page; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:response; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:requests_session; 47, identifier:get; 48, argument_list; 48, 49; 48, 50; 48, 53; 49, string:f'{self.url}/query'; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:params; 52, identifier:payload; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:headers; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:_headers; 58, if_statement; 58, 59; 58, 64; 58, 74; 59, comparison_operator:==; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:response; 62, identifier:status_code; 63, integer:200; 64, block; 64, 65; 65, return_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_parse_search_response; 70, argument_list; 70, 71; 71, attribute; 71, 72; 71, 73; 72, identifier:response; 73, identifier:content; 74, else_clause; 74, 75; 75, block; 75, 76; 76, raise_statement; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:Exception; 79, argument_list; 79, 80; 80, string:f'Unable to search for DDO: {response.content}' | def text_search(self, text, sort=None, offset=100, page=1):
"""
Search in aquarius using text query.
Given the string aquarius will do a full-text query to search in all documents.
Currently implemented are the MongoDB and Elastic Search drivers.
For a detailed guide on how to search, see the MongoDB driver documentation:
mongodb driverCurrently implemented in:
https://docs.mongodb.com/manual/reference/operator/query/text/
And the Elastic Search documentation:
https://www.elastic.co/guide/en/elasticsearch/guide/current/full-text-search.html
Other drivers are possible according to each implementation.
:param text: String to be search.
:param sort: 1/-1 to sort ascending or descending.
:param offset: Integer with the number of elements displayed per page.
:param page: Integer with the number of page.
:return: List of DDO instance
"""
assert page >= 1, f'Invalid page value {page}. Required page >= 1.'
payload = {"text": text, "sort": sort, "offset": offset, "page": page}
response = self.requests_session.get(
f'{self.url}/query',
params=payload,
headers=self._headers
)
if response.status_code == 200:
return self._parse_search_response(response.content)
else:
raise Exception(f'Unable to search for DDO: {response.content}') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:query_search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:search_query; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:offset; 11, integer:100; 12, default_parameter; 12, 13; 12, 14; 13, identifier:page; 14, integer:1; 15, block; 15, 16; 15, 18; 15, 23; 15, 29; 15, 35; 15, 41; 15, 65; 16, expression_statement; 16, 17; 17, comment; 18, assert_statement; 18, 19; 18, 22; 19, comparison_operator:>=; 19, 20; 19, 21; 20, identifier:page; 21, integer:1; 22, string:f'Invalid page value {page}. Required page >= 1.'; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:search_query; 27, string:'sort'; 28, identifier:sort; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:search_query; 33, string:'offset'; 34, identifier:offset; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:search_query; 39, string:'page'; 40, identifier:page; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:response; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:requests_session; 49, identifier:post; 50, argument_list; 50, 51; 50, 52; 50, 60; 51, string:f'{self.url}/query'; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:data; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:json; 57, identifier:dumps; 58, argument_list; 58, 59; 59, identifier:search_query; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:headers; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:_headers; 65, if_statement; 65, 66; 65, 71; 65, 81; 66, comparison_operator:==; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:response; 69, identifier:status_code; 70, integer:200; 71, block; 71, 72; 72, return_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:_parse_search_response; 77, argument_list; 77, 78; 78, attribute; 78, 79; 78, 80; 79, identifier:response; 80, identifier:content; 81, else_clause; 81, 82; 82, block; 82, 83; 83, raise_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:Exception; 86, argument_list; 86, 87; 87, string:f'Unable to search for DDO: {response.content}' | def query_search(self, search_query, sort=None, offset=100, page=1):
"""
Search using a query.
Currently implemented is the MongoDB query model to search for documents according to:
https://docs.mongodb.com/manual/tutorial/query-documents/
And an Elastic Search driver, which implements a basic parser to convert the query into
elastic search format.
Example: query_search({"price":[0,10]})
:param search_query: Python dictionary, query following mongodb syntax
:param sort: 1/-1 to sort ascending or descending.
:param offset: Integer with the number of elements displayed per page.
:param page: Integer with the number of page.
:return: List of DDO instance
"""
assert page >= 1, f'Invalid page value {page}. Required page >= 1.'
search_query['sort'] = sort
search_query['offset'] = offset
search_query['page'] = page
response = self.requests_session.post(
f'{self.url}/query',
data=json.dumps(search_query),
headers=self._headers
)
if response.status_code == 200:
return self._parse_search_response(response.content)
else:
raise Exception(f'Unable to search for DDO: {response.content}') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:trunk_angles; 3, parameters; 3, 4; 3, 5; 4, identifier:nrn; 5, default_parameter; 5, 6; 5, 7; 6, identifier:neurite_type; 7, attribute; 7, 8; 7, 9; 8, identifier:NeuriteType; 9, identifier:all; 10, block; 10, 11; 10, 13; 10, 23; 10, 24; 10, 32; 10, 77; 10, 78; 10, 118; 10, 134; 11, expression_statement; 11, 12; 12, string:'''Calculates the angles between all the trunks of the neuron.
The angles are defined on the x-y plane and the trees
are sorted from the y axis and anticlock-wise.
'''; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:vectors; 16, call; 16, 17; 16, 18; 17, identifier:trunk_vectors; 18, argument_list; 18, 19; 18, 20; 19, identifier:nrn; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:neurite_type; 22, identifier:neurite_type; 23, comment; 24, if_statement; 24, 25; 24, 29; 25, not_operator; 25, 26; 26, attribute; 26, 27; 26, 28; 27, identifier:vectors; 28, identifier:size; 29, block; 29, 30; 30, return_statement; 30, 31; 31, list:[]; 32, function_definition; 32, 33; 32, 34; 32, 37; 33, function_name:_sort_angle; 34, parameters; 34, 35; 34, 36; 35, identifier:p1; 36, identifier:p2; 37, block; 37, 38; 37, 40; 37, 56; 37, 72; 38, expression_statement; 38, 39; 39, comment; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:ang1; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:np; 46, identifier:arctan2; 47, argument_list; 47, 48; 48, list_splat; 48, 49; 49, subscript; 49, 50; 49, 51; 50, identifier:p1; 51, slice; 51, 52; 51, 53; 51, 54; 52, colon; 53, colon; 54, unary_operator:-; 54, 55; 55, integer:1; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:ang2; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:np; 62, identifier:arctan2; 63, argument_list; 63, 64; 64, list_splat; 64, 65; 65, subscript; 65, 66; 65, 67; 66, identifier:p2; 67, slice; 67, 68; 67, 69; 67, 70; 68, colon; 69, colon; 70, unary_operator:-; 70, 71; 71, integer:1; 72, return_statement; 72, 73; 73, parenthesized_expression; 73, 74; 74, binary_operator:-; 74, 75; 74, 76; 75, identifier:ang1; 76, identifier:ang2; 77, comment; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:order; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:np; 84, identifier:argsort; 85, argument_list; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:np; 89, identifier:array; 90, argument_list; 90, 91; 91, list_comprehension; 91, 92; 91, 108; 92, call; 92, 93; 92, 94; 93, identifier:_sort_angle; 94, argument_list; 94, 95; 94, 105; 95, binary_operator:/; 95, 96; 95, 97; 96, identifier:i; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:np; 101, identifier:linalg; 102, identifier:norm; 103, argument_list; 103, 104; 104, identifier:i; 105, list:[0, 1]; 105, 106; 105, 107; 106, integer:0; 107, integer:1; 108, for_in_clause; 108, 109; 108, 110; 109, identifier:i; 110, subscript; 110, 111; 110, 112; 110, 114; 111, identifier:vectors; 112, slice; 112, 113; 113, colon; 114, slice; 114, 115; 114, 116; 114, 117; 115, integer:0; 116, colon; 117, integer:2; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:ordered_vectors; 121, subscript; 121, 122; 121, 125; 121, 127; 122, subscript; 122, 123; 122, 124; 123, identifier:vectors; 124, identifier:order; 125, slice; 125, 126; 126, colon; 127, list:[COLS.X, COLS.Y]; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:COLS; 130, identifier:X; 131, attribute; 131, 132; 131, 133; 132, identifier:COLS; 133, identifier:Y; 134, return_statement; 134, 135; 135, list_comprehension; 135, 136; 135, 149; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:morphmath; 139, identifier:angle_between_vectors; 140, argument_list; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:ordered_vectors; 143, identifier:i; 144, subscript; 144, 145; 144, 146; 145, identifier:ordered_vectors; 146, binary_operator:-; 146, 147; 146, 148; 147, identifier:i; 148, integer:1; 149, for_in_clause; 149, 150; 149, 153; 150, pattern_list; 150, 151; 150, 152; 151, identifier:i; 152, identifier:_; 153, call; 153, 154; 153, 155; 154, identifier:enumerate; 155, argument_list; 155, 156; 156, identifier:ordered_vectors | def trunk_angles(nrn, neurite_type=NeuriteType.all):
'''Calculates the angles between all the trunks of the neuron.
The angles are defined on the x-y plane and the trees
are sorted from the y axis and anticlock-wise.
'''
vectors = trunk_vectors(nrn, neurite_type=neurite_type)
# In order to avoid the failure of the process in case the neurite_type does not exist
if not vectors.size:
return []
def _sort_angle(p1, p2):
"""Angle between p1-p2 to sort vectors"""
ang1 = np.arctan2(*p1[::-1])
ang2 = np.arctan2(*p2[::-1])
return (ang1 - ang2)
# Sorting angles according to x-y plane
order = np.argsort(np.array([_sort_angle(i / np.linalg.norm(i), [0, 1])
for i in vectors[:, 0:2]]))
ordered_vectors = vectors[order][:, [COLS.X, COLS.Y]]
return [morphmath.angle_between_vectors(ordered_vectors[i], ordered_vectors[i - 1])
for i, _ in enumerate(ordered_vectors)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:resolve_symbols; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:tree; 6, identifier:database; 7, identifier:link_resolver; 8, block; 8, 9; 8, 11; 8, 21; 8, 27; 8, 53; 8, 84; 8, 110; 8, 140; 8, 141; 8, 153; 8, 164; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:typed_symbols; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:__get_empty_typed_symbols; 20, argument_list; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:all_syms; 24, call; 24, 25; 24, 26; 25, identifier:OrderedSet; 26, argument_list; 27, for_statement; 27, 28; 27, 29; 27, 32; 28, identifier:sym_name; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:symbol_names; 32, block; 32, 33; 32, 42; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:sym; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:database; 39, identifier:get_symbol; 40, argument_list; 40, 41; 41, identifier:sym_name; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:__query_extra_symbols; 47, argument_list; 47, 48; 47, 49; 47, 50; 47, 51; 47, 52; 48, identifier:sym; 49, identifier:all_syms; 50, identifier:tree; 51, identifier:link_resolver; 52, identifier:database; 53, if_statement; 53, 54; 53, 59; 53, 68; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:tree; 57, identifier:project; 58, identifier:is_toplevel; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:page_path; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:link; 67, identifier:ref; 68, else_clause; 68, 69; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:page_path; 73, binary_operator:+; 73, 74; 73, 79; 74, binary_operator:+; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:project_name; 78, string:'/'; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:link; 83, identifier:ref; 84, if_statement; 84, 85; 84, 94; 85, call; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:meta; 90, identifier:get; 91, argument_list; 91, 92; 91, 93; 92, string:"auto-sort"; 93, True; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:all_syms; 98, call; 98, 99; 98, 100; 99, identifier:sorted; 100, argument_list; 100, 101; 100, 102; 101, identifier:all_syms; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:key; 104, lambda; 104, 105; 104, 107; 105, lambda_parameters; 105, 106; 106, identifier:x; 107, attribute; 107, 108; 107, 109; 108, identifier:x; 109, identifier:unique_name; 110, for_statement; 110, 111; 110, 112; 110, 113; 111, identifier:sym; 112, identifier:all_syms; 113, block; 113, 114; 113, 120; 113, 129; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:sym; 118, identifier:update_children_comments; 119, argument_list; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:__resolve_symbol; 125, argument_list; 125, 126; 125, 127; 125, 128; 126, identifier:sym; 127, identifier:link_resolver; 128, identifier:page_path; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:symbol_names; 135, identifier:add; 136, argument_list; 136, 137; 137, attribute; 137, 138; 137, 139; 138, identifier:sym; 139, identifier:unique_name; 140, comment; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:no_parent_syms; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:by_parent_symbols; 149, identifier:pop; 150, argument_list; 150, 151; 150, 152; 151, None; 152, None; 153, if_statement; 153, 154; 153, 155; 154, identifier:no_parent_syms; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 163; 158, subscript; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:by_parent_symbols; 162, None; 163, identifier:no_parent_syms; 164, for_statement; 164, 165; 164, 166; 164, 171; 165, identifier:sym_type; 166, list:[ClassSymbol, AliasSymbol, InterfaceSymbol,
StructSymbol]; 166, 167; 166, 168; 166, 169; 166, 170; 167, identifier:ClassSymbol; 168, identifier:AliasSymbol; 169, identifier:InterfaceSymbol; 170, identifier:StructSymbol; 171, block; 171, 172; 171, 182; 171, 187; 171, 204; 171, 252; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:syms; 175, attribute; 175, 176; 175, 181; 176, subscript; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:typed_symbols; 180, identifier:sym_type; 181, identifier:symbols; 182, if_statement; 182, 183; 182, 185; 183, not_operator; 183, 184; 184, identifier:syms; 185, block; 185, 186; 186, continue_statement; 187, if_statement; 187, 188; 187, 193; 188, comparison_operator:is; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:title; 192, None; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:title; 199, attribute; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:syms; 202, integer:0; 203, identifier:display_name; 204, if_statement; 204, 205; 204, 210; 205, comparison_operator:is; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:comment; 209, None; 210, block; 210, 211; 210, 224; 210, 238; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:comment; 216, call; 216, 217; 216, 218; 217, identifier:Comment; 218, argument_list; 218, 219; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:name; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:name; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 231; 226, attribute; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:comment; 230, identifier:short_description; 231, attribute; 231, 232; 231, 237; 232, attribute; 232, 233; 232, 236; 233, subscript; 233, 234; 233, 235; 234, identifier:syms; 235, integer:0; 236, identifier:comment; 237, identifier:short_description; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 245; 240, attribute; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:comment; 244, identifier:title; 245, attribute; 245, 246; 245, 251; 246, attribute; 246, 247; 246, 250; 247, subscript; 247, 248; 247, 249; 248, identifier:syms; 249, integer:0; 250, identifier:comment; 251, identifier:title; 252, break_statement | def resolve_symbols(self, tree, database, link_resolver):
"""
When this method is called, the page's symbol names are queried
from `database`, and added to lists of actual symbols, sorted
by symbol class.
"""
self.typed_symbols = self.__get_empty_typed_symbols()
all_syms = OrderedSet()
for sym_name in self.symbol_names:
sym = database.get_symbol(sym_name)
self.__query_extra_symbols(
sym, all_syms, tree, link_resolver, database)
if tree.project.is_toplevel:
page_path = self.link.ref
else:
page_path = self.project_name + '/' + self.link.ref
if self.meta.get("auto-sort", True):
all_syms = sorted(all_syms, key=lambda x: x.unique_name)
for sym in all_syms:
sym.update_children_comments()
self.__resolve_symbol(sym, link_resolver, page_path)
self.symbol_names.add(sym.unique_name)
# Always put symbols with no parent at the end
no_parent_syms = self.by_parent_symbols.pop(None, None)
if no_parent_syms:
self.by_parent_symbols[None] = no_parent_syms
for sym_type in [ClassSymbol, AliasSymbol, InterfaceSymbol,
StructSymbol]:
syms = self.typed_symbols[sym_type].symbols
if not syms:
continue
if self.title is None:
self.title = syms[0].display_name
if self.comment is None:
self.comment = Comment(name=self.name)
self.comment.short_description = syms[
0].comment.short_description
self.comment.title = syms[0].comment.title
break |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_klass_parents; 3, parameters; 3, 4; 4, identifier:gi_name; 5, block; 5, 6; 5, 8; 5, 12; 5, 21; 5, 27; 5, 35; 6, expression_statement; 6, 7; 7, string:'''
Returns a sorted list of qualified symbols representing
the parents of the klass-like symbol named gi_name
'''; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:res; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:parents; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:__HIERARCHY_GRAPH; 18, identifier:predecessors; 19, argument_list; 19, 20; 20, identifier:gi_name; 21, if_statement; 21, 22; 21, 24; 22, not_operator; 22, 23; 23, identifier:parents; 24, block; 24, 25; 25, return_statement; 25, 26; 26, list:[]; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:__get_parent_link_recurse; 30, argument_list; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:parents; 33, integer:0; 34, identifier:res; 35, return_statement; 35, 36; 36, identifier:res | def get_klass_parents(gi_name):
'''
Returns a sorted list of qualified symbols representing
the parents of the klass-like symbol named gi_name
'''
res = []
parents = __HIERARCHY_GRAPH.predecessors(gi_name)
if not parents:
return []
__get_parent_link_recurse(parents[0], res)
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sorted_groupby; 3, parameters; 3, 4; 3, 5; 4, identifier:df; 5, identifier:groupby; 6, block; 6, 7; 6, 9; 6, 13; 6, 23; 6, 59; 6, 60; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:start; 12, integer:0; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:prev; 16, subscript; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, subscript; 18, 19; 18, 20; 19, identifier:df; 20, identifier:groupby; 21, identifier:iloc; 22, identifier:start; 23, for_statement; 23, 24; 23, 27; 23, 33; 24, pattern_list; 24, 25; 24, 26; 25, identifier:i; 26, identifier:x; 27, call; 27, 28; 27, 29; 28, identifier:enumerate; 29, argument_list; 29, 30; 30, subscript; 30, 31; 30, 32; 31, identifier:df; 32, identifier:groupby; 33, block; 33, 34; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:!=; 35, 36; 35, 37; 36, identifier:x; 37, identifier:prev; 38, block; 38, 39; 38, 51; 38, 55; 39, expression_statement; 39, 40; 40, yield; 40, 41; 41, expression_list; 41, 42; 41, 43; 42, identifier:prev; 43, subscript; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:df; 46, identifier:iloc; 47, slice; 47, 48; 47, 49; 47, 50; 48, identifier:start; 49, colon; 50, identifier:i; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:prev; 54, identifier:x; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:start; 58, identifier:i; 59, comment; 60, expression_statement; 60, 61; 61, yield; 61, 62; 62, expression_list; 62, 63; 62, 64; 63, identifier:prev; 64, subscript; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:df; 67, identifier:iloc; 68, slice; 68, 69; 68, 70; 69, identifier:start; 70, colon | def sorted_groupby(df, groupby):
"""
Perform a groupby on a DataFrame using a specific column
and assuming that that column is sorted.
Parameters
----------
df : pandas.DataFrame
groupby : object
Column name on which to groupby. This column must be sorted.
Returns
-------
generator
Yields pairs of group_name, DataFrame.
"""
start = 0
prev = df[groupby].iloc[start]
for i, x in enumerate(df[groupby]):
if x != prev:
yield prev, df.iloc[start:i]
prev = x
start = i
# need to send back the last group
yield prev, df.iloc[start:] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:add_note; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:note; 6, default_parameter; 6, 7; 6, 8; 7, identifier:octave; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:dynamics; 11, dictionary; 12, block; 12, 13; 12, 15; 12, 115; 12, 132; 12, 156; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 22; 16, comparison_operator:==; 16, 17; 16, 21; 17, call; 17, 18; 17, 19; 18, identifier:type; 19, argument_list; 19, 20; 20, identifier:note; 21, identifier:str; 22, block; 22, 23; 23, if_statement; 23, 24; 23, 27; 23, 37; 23, 56; 24, comparison_operator:is; 24, 25; 24, 26; 25, identifier:octave; 26, None; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:note; 31, call; 31, 32; 31, 33; 32, identifier:Note; 33, argument_list; 33, 34; 33, 35; 33, 36; 34, identifier:note; 35, identifier:octave; 36, identifier:dynamics; 37, elif_clause; 37, 38; 37, 46; 38, comparison_operator:==; 38, 39; 38, 45; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:notes; 45, integer:0; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:note; 50, call; 50, 51; 50, 52; 51, identifier:Note; 52, argument_list; 52, 53; 52, 54; 52, 55; 53, identifier:note; 54, integer:4; 55, identifier:dynamics; 56, else_clause; 56, 57; 57, block; 57, 58; 58, if_statement; 58, 59; 58, 78; 58, 97; 59, comparison_operator:<; 59, 60; 59, 72; 60, call; 60, 61; 60, 62; 61, identifier:Note; 62, argument_list; 62, 63; 62, 64; 63, identifier:note; 64, attribute; 64, 65; 64, 71; 65, subscript; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:notes; 69, unary_operator:-; 69, 70; 70, integer:1; 71, identifier:octave; 72, subscript; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:notes; 76, unary_operator:-; 76, 77; 77, integer:1; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:note; 82, call; 82, 83; 82, 84; 83, identifier:Note; 84, argument_list; 84, 85; 84, 86; 84, 96; 85, identifier:note; 86, binary_operator:+; 86, 87; 86, 95; 87, attribute; 87, 88; 87, 94; 88, subscript; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:notes; 92, unary_operator:-; 92, 93; 93, integer:1; 94, identifier:octave; 95, integer:1; 96, identifier:dynamics; 97, else_clause; 97, 98; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:note; 102, call; 102, 103; 102, 104; 103, identifier:Note; 104, argument_list; 104, 105; 104, 106; 104, 114; 105, identifier:note; 106, attribute; 106, 107; 106, 113; 107, subscript; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:notes; 111, unary_operator:-; 111, 112; 112, integer:1; 113, identifier:octave; 114, identifier:dynamics; 115, if_statement; 115, 116; 115, 122; 116, not_operator; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:hasattr; 119, argument_list; 119, 120; 119, 121; 120, identifier:note; 121, string:'name'; 122, block; 122, 123; 123, raise_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:UnexpectedObjectError; 126, argument_list; 126, 127; 127, binary_operator:%; 127, 128; 127, 131; 128, concatenated_string; 128, 129; 128, 130; 129, string:"Object '%s' was not expected. "; 130, string:"Expecting a mingus.containers.Note object."; 131, identifier:note; 132, if_statement; 132, 133; 132, 138; 133, comparison_operator:not; 133, 134; 133, 135; 134, identifier:note; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:notes; 138, block; 138, 139; 138, 148; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:notes; 145, identifier:append; 146, argument_list; 146, 147; 147, identifier:note; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:notes; 154, identifier:sort; 155, argument_list; 156, return_statement; 156, 157; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:notes | def add_note(self, note, octave=None, dynamics={}):
"""Add a note to the container and sorts the notes from low to high.
The note can either be a string, in which case you could also use
the octave and dynamics arguments, or a Note object.
"""
if type(note) == str:
if octave is not None:
note = Note(note, octave, dynamics)
elif len(self.notes) == 0:
note = Note(note, 4, dynamics)
else:
if Note(note, self.notes[-1].octave) < self.notes[-1]:
note = Note(note, self.notes[-1].octave + 1, dynamics)
else:
note = Note(note, self.notes[-1].octave, dynamics)
if not hasattr(note, 'name'):
raise UnexpectedObjectError("Object '%s' was not expected. "
"Expecting a mingus.containers.Note object." % note)
if note not in self.notes:
self.notes.append(note)
self.notes.sort()
return self.notes |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 18; 2, function_name:_sort_row_col; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:qubits; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:Iterator; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, identifier:GridQubit; 12, type; 12, 13; 13, generic_type; 13, 14; 13, 15; 14, identifier:List; 15, type_parameter; 15, 16; 16, type; 16, 17; 17, identifier:GridQubit; 18, block; 18, 19; 18, 21; 19, expression_statement; 19, 20; 20, comment; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:sorted; 24, argument_list; 24, 25; 24, 26; 25, identifier:qubits; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:key; 28, lambda; 28, 29; 28, 31; 29, lambda_parameters; 29, 30; 30, identifier:x; 31, tuple; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:x; 34, identifier:row; 35, attribute; 35, 36; 35, 37; 36, identifier:x; 37, identifier:col | def _sort_row_col(qubits: Iterator[GridQubit]) -> List[GridQubit]:
"""Sort grid qubits first by row then by column"""
return sorted(qubits, key=lambda x: (x.row, x.col)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_cmp_bystrlen_reverse; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, identifier:b; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 19; 9, 23; 9, 36; 10, comparison_operator:>; 10, 11; 10, 15; 11, call; 11, 12; 11, 13; 12, identifier:len; 13, argument_list; 13, 14; 14, identifier:a; 15, call; 15, 16; 15, 17; 16, identifier:len; 17, argument_list; 17, 18; 18, identifier:b; 19, block; 19, 20; 20, return_statement; 20, 21; 21, unary_operator:-; 21, 22; 22, integer:1; 23, elif_clause; 23, 24; 23, 33; 24, comparison_operator:<; 24, 25; 24, 29; 25, call; 25, 26; 25, 27; 26, identifier:len; 27, argument_list; 27, 28; 28, identifier:a; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, identifier:b; 33, block; 33, 34; 34, return_statement; 34, 35; 35, integer:1; 36, else_clause; 36, 37; 37, block; 37, 38; 38, return_statement; 38, 39; 39, integer:0 | def _cmp_bystrlen_reverse(a, b):
"""A private "cmp" function to be used by the "sort" function of a
list when ordering the titles found in a knowledge base by string-
length - LONGEST -> SHORTEST.
@param a: (string)
@param b: (string)
@return: (integer) - 0 if len(a) == len(b); 1 if len(a) < len(b);
-1 if len(a) > len(b);
"""
if len(a) > len(b):
return -1
elif len(a) < len(b):
return 1
else:
return 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:prof_main; 3, parameters; 3, 4; 4, identifier:main; 5, block; 5, 6; 5, 8; 5, 181; 6, expression_statement; 6, 7; 7, comment; 8, decorated_definition; 8, 9; 8, 14; 9, decorator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:wraps; 12, argument_list; 12, 13; 13, identifier:main; 14, function_definition; 14, 15; 14, 16; 14, 21; 15, function_name:wrapper; 16, parameters; 16, 17; 16, 19; 17, list_splat_pattern; 17, 18; 18, identifier:args; 19, dictionary_splat_pattern; 19, 20; 20, identifier:kwargs; 21, block; 21, 22; 21, 25; 21, 56; 22, import_statement; 22, 23; 23, dotted_name; 23, 24; 24, identifier:sys; 25, try_statement; 25, 26; 25, 49; 26, block; 26, 27; 26, 37; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:do_prof; 30, comparison_operator:==; 30, 31; 30, 36; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:sys; 34, identifier:argv; 35, integer:1; 36, string:"prof"; 37, if_statement; 37, 38; 37, 39; 38, identifier:do_prof; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:sys; 45, identifier:argv; 46, identifier:pop; 47, argument_list; 47, 48; 48, integer:1; 49, except_clause; 49, 50; 49, 51; 50, identifier:Exception; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:do_prof; 55, False; 56, if_statement; 56, 57; 56, 59; 56, 69; 57, not_operator; 57, 58; 58, identifier:do_prof; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:sys; 64, identifier:exit; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 68; 67, identifier:main; 68, argument_list; 69, else_clause; 69, 70; 70, block; 70, 71; 70, 76; 70, 83; 70, 93; 70, 115; 70, 125; 70, 139; 70, 148; 70, 163; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:print; 74, argument_list; 74, 75; 75, string:"Entering profiling mode..."; 76, import_statement; 76, 77; 76, 79; 76, 81; 77, dotted_name; 77, 78; 78, identifier:pstats; 79, dotted_name; 79, 80; 80, identifier:cProfile; 81, dotted_name; 81, 82; 82, identifier:tempfile; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:prof_file; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:kwargs; 89, identifier:get; 90, argument_list; 90, 91; 90, 92; 91, string:"prof_file"; 92, None; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:prof_file; 96, None; 97, block; 97, 98; 97, 108; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, pattern_list; 100, 101; 100, 102; 101, identifier:_; 102, identifier:prof_file; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:tempfile; 106, identifier:mkstemp; 107, argument_list; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 111; 110, identifier:print; 111, argument_list; 111, 112; 112, binary_operator:%; 112, 113; 112, 114; 113, string:"Profiling data stored in %s"; 114, identifier:prof_file; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:sortby; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:kwargs; 121, identifier:get; 122, argument_list; 122, 123; 122, 124; 123, string:"sortby"; 124, string:"time"; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:cProfile; 129, identifier:runctx; 130, argument_list; 130, 131; 130, 132; 130, 135; 130, 138; 131, string:"main()"; 132, call; 132, 133; 132, 134; 133, identifier:globals; 134, argument_list; 135, call; 135, 136; 135, 137; 136, identifier:locals; 137, argument_list; 138, identifier:prof_file; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:s; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:pstats; 145, identifier:Stats; 146, argument_list; 146, 147; 147, identifier:prof_file; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 162; 150, attribute; 150, 151; 150, 161; 151, call; 151, 152; 151, 159; 152, attribute; 152, 153; 152, 158; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:s; 156, identifier:strip_dirs; 157, argument_list; 158, identifier:sort_stats; 159, argument_list; 159, 160; 160, identifier:sortby; 161, identifier:print_stats; 162, argument_list; 163, if_statement; 163, 164; 163, 167; 163, 175; 164, comparison_operator:not; 164, 165; 164, 166; 165, string:"retval"; 166, identifier:kwargs; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:sys; 172, identifier:exit; 173, argument_list; 173, 174; 174, integer:0; 175, else_clause; 175, 176; 176, block; 176, 177; 177, return_statement; 177, 178; 178, subscript; 178, 179; 178, 180; 179, identifier:kwargs; 180, string:"retval"; 181, return_statement; 181, 182; 182, identifier:wrapper | def prof_main(main):
"""
Decorator for profiling main programs.
Profiling is activated by prepending the command line options
supported by the original main program with the keyword `prof`.
Example:
$ script.py arg --foo=1
becomes
$ script.py prof arg --foo=1
The decorated main accepts two new arguments:
prof_file: Name of the output file with profiling data
If not given, a temporary file is created.
sortby: Profiling data are sorted according to this value.
default is "time". See sort_stats.
"""
@wraps(main)
def wrapper(*args, **kwargs):
import sys
try:
do_prof = sys.argv[1] == "prof"
if do_prof: sys.argv.pop(1)
except Exception:
do_prof = False
if not do_prof:
sys.exit(main())
else:
print("Entering profiling mode...")
import pstats, cProfile, tempfile
prof_file = kwargs.get("prof_file", None)
if prof_file is None:
_, prof_file = tempfile.mkstemp()
print("Profiling data stored in %s" % prof_file)
sortby = kwargs.get("sortby", "time")
cProfile.runctx("main()", globals(), locals(), prof_file)
s = pstats.Stats(prof_file)
s.strip_dirs().sort_stats(sortby).print_stats()
if "retval" not in kwargs:
sys.exit(0)
else:
return kwargs["retval"]
return wrapper |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_least_constraining_values_sorter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:problem; 5, identifier:assignment; 6, identifier:variable; 7, identifier:domains; 8, block; 8, 9; 8, 11; 8, 12; 8, 32; 8, 56; 9, expression_statement; 9, 10; 10, string:'''
Sort values based on how many conflicts they generate if assigned.
'''; 11, comment; 12, function_definition; 12, 13; 12, 14; 12, 16; 13, function_name:update_assignment; 14, parameters; 14, 15; 15, identifier:value; 16, block; 16, 17; 16, 24; 16, 30; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:new_assignment; 20, call; 20, 21; 20, 22; 21, identifier:deepcopy; 22, argument_list; 22, 23; 23, identifier:assignment; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, subscript; 26, 27; 26, 28; 27, identifier:new_assignment; 28, identifier:variable; 29, identifier:value; 30, return_statement; 30, 31; 31, identifier:new_assignment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:values; 35, call; 35, 36; 35, 37; 36, identifier:sorted; 37, argument_list; 37, 38; 37, 44; 38, subscript; 38, 39; 38, 42; 39, subscript; 39, 40; 39, 41; 40, identifier:domains; 41, identifier:variable; 42, slice; 42, 43; 43, colon; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:key; 46, lambda; 46, 47; 46, 49; 47, lambda_parameters; 47, 48; 48, identifier:v; 49, call; 49, 50; 49, 51; 50, identifier:_count_conflicts; 51, argument_list; 51, 52; 51, 53; 51, 54; 51, 55; 52, identifier:problem; 53, identifier:assignment; 54, identifier:variable; 55, identifier:v; 56, return_statement; 56, 57; 57, identifier:values | def _least_constraining_values_sorter(problem, assignment, variable, domains):
'''
Sort values based on how many conflicts they generate if assigned.
'''
# the value that generates less conflicts
def update_assignment(value):
new_assignment = deepcopy(assignment)
new_assignment[variable] = value
return new_assignment
values = sorted(domains[variable][:],
key=lambda v: _count_conflicts(problem, assignment,
variable, v))
return values |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:reading_order; 3, parameters; 3, 4; 3, 5; 4, identifier:e1; 5, identifier:e2; 6, block; 6, 7; 6, 9; 6, 15; 6, 21; 6, 60; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:b1; 12, attribute; 12, 13; 12, 14; 13, identifier:e1; 14, identifier:bbox; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:b2; 18, attribute; 18, 19; 18, 20; 19, identifier:e2; 20, identifier:bbox; 21, if_statement; 21, 22; 21, 49; 22, boolean_operator:or; 22, 23; 22, 36; 23, comparison_operator:==; 23, 24; 23, 30; 24, call; 24, 25; 24, 26; 25, identifier:round; 26, argument_list; 26, 27; 27, subscript; 27, 28; 27, 29; 28, identifier:b1; 29, identifier:y0; 30, call; 30, 31; 30, 32; 31, identifier:round; 32, argument_list; 32, 33; 33, subscript; 33, 34; 33, 35; 34, identifier:b2; 35, identifier:y0; 36, comparison_operator:==; 36, 37; 36, 43; 37, call; 37, 38; 37, 39; 38, identifier:round; 39, argument_list; 39, 40; 40, subscript; 40, 41; 40, 42; 41, identifier:b1; 42, identifier:y1; 43, call; 43, 44; 43, 45; 44, identifier:round; 45, argument_list; 45, 46; 46, subscript; 46, 47; 46, 48; 47, identifier:b2; 48, identifier:y1; 49, block; 49, 50; 50, return_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:float_cmp; 53, argument_list; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:b1; 56, identifier:x0; 57, subscript; 57, 58; 57, 59; 58, identifier:b2; 59, identifier:x0; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:float_cmp; 63, argument_list; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:b1; 66, identifier:y0; 67, subscript; 67, 68; 67, 69; 68, identifier:b2; 69, identifier:y0 | def reading_order(e1, e2):
"""
A comparator to sort bboxes from top to bottom, left to right
"""
b1 = e1.bbox
b2 = e2.bbox
if round(b1[y0]) == round(b2[y0]) or round(b1[y1]) == round(b2[y1]):
return float_cmp(b1[x0], b2[x0])
return float_cmp(b1[y0], b2[y0]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:xy_reading_order; 3, parameters; 3, 4; 3, 5; 4, identifier:e1; 5, identifier:e2; 6, block; 6, 7; 6, 9; 6, 15; 6, 21; 6, 46; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:b1; 12, attribute; 12, 13; 12, 14; 13, identifier:e1; 14, identifier:bbox; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:b2; 18, attribute; 18, 19; 18, 20; 19, identifier:e2; 20, identifier:bbox; 21, if_statement; 21, 22; 21, 35; 22, comparison_operator:==; 22, 23; 22, 29; 23, call; 23, 24; 23, 25; 24, identifier:round; 25, argument_list; 25, 26; 26, subscript; 26, 27; 26, 28; 27, identifier:b1; 28, identifier:x0; 29, call; 29, 30; 29, 31; 30, identifier:round; 31, argument_list; 31, 32; 32, subscript; 32, 33; 32, 34; 33, identifier:b2; 34, identifier:x0; 35, block; 35, 36; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:float_cmp; 39, argument_list; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:b1; 42, identifier:y0; 43, subscript; 43, 44; 43, 45; 44, identifier:b2; 45, identifier:y0; 46, return_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:float_cmp; 49, argument_list; 49, 50; 49, 53; 50, subscript; 50, 51; 50, 52; 51, identifier:b1; 52, identifier:x0; 53, subscript; 53, 54; 53, 55; 54, identifier:b2; 55, identifier:x0 | def xy_reading_order(e1, e2):
"""
A comparator to sort bboxes from left to right, top to bottom
"""
b1 = e1.bbox
b2 = e2.bbox
if round(b1[x0]) == round(b2[x0]):
return float_cmp(b1[y0], b2[y0])
return float_cmp(b1[x0], b2[x0]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:column_order; 3, parameters; 3, 4; 3, 5; 4, identifier:b1; 5, identifier:b2; 6, block; 6, 7; 6, 9; 6, 19; 6, 20; 6, 21; 6, 22; 6, 23; 6, 62; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 15; 11, tuple_pattern; 11, 12; 11, 13; 11, 14; 12, identifier:top; 13, identifier:left; 14, identifier:bottom; 15, tuple; 15, 16; 15, 17; 15, 18; 16, integer:1; 17, integer:2; 18, integer:3; 19, comment; 20, comment; 21, comment; 22, comment; 23, if_statement; 23, 24; 23, 51; 24, boolean_operator:or; 24, 25; 24, 38; 25, comparison_operator:==; 25, 26; 25, 32; 26, call; 26, 27; 26, 28; 27, identifier:round; 28, argument_list; 28, 29; 29, subscript; 29, 30; 29, 31; 30, identifier:b1; 31, identifier:top; 32, call; 32, 33; 32, 34; 33, identifier:round; 34, argument_list; 34, 35; 35, subscript; 35, 36; 35, 37; 36, identifier:b2; 37, identifier:top; 38, comparison_operator:==; 38, 39; 38, 45; 39, call; 39, 40; 39, 41; 40, identifier:round; 41, argument_list; 41, 42; 42, subscript; 42, 43; 42, 44; 43, identifier:b1; 44, identifier:bottom; 45, call; 45, 46; 45, 47; 46, identifier:round; 47, argument_list; 47, 48; 48, subscript; 48, 49; 48, 50; 49, identifier:b2; 50, identifier:bottom; 51, block; 51, 52; 52, return_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:float_cmp; 55, argument_list; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:b1; 58, identifier:left; 59, subscript; 59, 60; 59, 61; 60, identifier:b2; 61, identifier:left; 62, return_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:float_cmp; 65, argument_list; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:b1; 68, identifier:top; 69, subscript; 69, 70; 69, 71; 70, identifier:b2; 71, identifier:top | def column_order(b1, b2):
"""
A comparator that sorts bboxes first by "columns", where a column is made
up of all bboxes that overlap, then by vertical position in each column.
b1 = [b1.type, b1.top, b1.left, b1.bottom, b1.right]
b2 = [b2.type, b2.top, b2.left, b2.bottom, b2.right]
"""
(top, left, bottom) = (1, 2, 3)
# TODO(senwu): Reimplement the functionality of this comparator to
# detect the number of columns, and sort those in reading order.
# TODO: This is just a simple top to bottom, left to right comparator
# for now.
if round(b1[top]) == round(b2[top]) or round(b1[bottom]) == round(b2[bottom]):
return float_cmp(b1[left], b2[left])
return float_cmp(b1[top], b2[top]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:merge_intervals; 3, parameters; 3, 4; 3, 5; 4, identifier:elems; 5, default_parameter; 5, 6; 5, 7; 6, identifier:overlap_thres; 7, float:2.0; 8, block; 8, 9; 8, 11; 8, 19; 8, 34; 8, 38; 8, 46; 8, 101; 8, 108; 8, 109; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:overlap_thres; 14, call; 14, 15; 14, 16; 15, identifier:max; 16, argument_list; 16, 17; 16, 18; 17, float:0.0; 18, identifier:overlap_thres; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:ordered; 22, call; 22, 23; 22, 24; 23, identifier:sorted; 24, argument_list; 24, 25; 24, 26; 25, identifier:elems; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:key; 28, lambda; 28, 29; 28, 31; 29, lambda_parameters; 29, 30; 30, identifier:e; 31, attribute; 31, 32; 31, 33; 32, identifier:e; 33, identifier:x0; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:intervals; 37, list:[]; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:cur; 41, list:[-overlap_thres, -overlap_thres]; 41, 42; 41, 44; 42, unary_operator:-; 42, 43; 43, identifier:overlap_thres; 44, unary_operator:-; 44, 45; 45, identifier:overlap_thres; 46, for_statement; 46, 47; 46, 48; 46, 49; 47, identifier:e; 48, identifier:ordered; 49, block; 49, 50; 49, 87; 50, if_statement; 50, 51; 50, 60; 50, 61; 51, comparison_operator:>; 51, 52; 51, 59; 52, binary_operator:-; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:e; 55, identifier:x0; 56, subscript; 56, 57; 56, 58; 57, identifier:cur; 58, integer:1; 59, identifier:overlap_thres; 60, comment; 61, block; 61, 62; 61, 76; 61, 86; 62, if_statement; 62, 63; 62, 68; 63, comparison_operator:>; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:cur; 66, integer:1; 67, float:0.0; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:intervals; 73, identifier:append; 74, argument_list; 74, 75; 75, identifier:cur; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:cur; 79, list:[e.x0, e.x1]; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:e; 82, identifier:x0; 83, attribute; 83, 84; 83, 85; 84, identifier:e; 85, identifier:x1; 86, continue_statement; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:cur; 91, integer:1; 92, call; 92, 93; 92, 94; 93, identifier:max; 94, argument_list; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:cur; 97, integer:1; 98, attribute; 98, 99; 98, 100; 99, identifier:e; 100, identifier:x1; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:intervals; 105, identifier:append; 106, argument_list; 106, 107; 107, identifier:cur; 108, comment; 109, return_statement; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:map; 112, argument_list; 112, 113; 112, 114; 113, identifier:tuple; 114, identifier:intervals | def merge_intervals(elems, overlap_thres=2.0):
"""
Project in x axis
Sort by start
Go through segments and keep max x1
Return a list of non-overlapping intervals
"""
overlap_thres = max(0.0, overlap_thres)
ordered = sorted(elems, key=lambda e: e.x0)
intervals = []
cur = [-overlap_thres, -overlap_thres]
for e in ordered:
if e.x0 - cur[1] > overlap_thres:
# Check interval validity
if cur[1] > 0.0:
intervals.append(cur)
cur = [e.x0, e.x1]
continue
cur[1] = max(cur[1], e.x1)
intervals.append(cur)
# Freeze the interval to tuples
return map(tuple, intervals) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:predict; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:X; 6, default_parameter; 6, 7; 6, 8; 7, identifier:cost_mat; 8, None; 9, block; 9, 10; 9, 12; 9, 13; 9, 14; 9, 46; 9, 47; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, comment; 14, if_statement; 14, 15; 14, 24; 15, comparison_operator:!=; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:n_features_; 19, subscript; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:X; 22, identifier:shape; 23, integer:1; 24, block; 24, 25; 25, raise_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:ValueError; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 37; 30, attribute; 30, 31; 30, 36; 31, concatenated_string; 31, 32; 31, 33; 31, 34; 31, 35; 32, string:"Number of features of the model must "; 33, string:"match the input. Model n_features is {0} and "; 34, string:"input n_features is {1}."; 35, string:""; 36, identifier:format; 37, argument_list; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:n_features_; 41, subscript; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:X; 44, identifier:shape; 45, integer:1; 46, comment; 47, if_statement; 47, 48; 47, 55; 47, 84; 47, 218; 48, comparison_operator:in; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:combination; 52, list:['stacking', 'stacking_proba']; 52, 53; 52, 54; 53, string:'stacking'; 54, string:'stacking_proba'; 55, block; 55, 56; 55, 75; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:X_stacking; 59, call; 59, 60; 59, 61; 60, identifier:_create_stacking_set; 61, argument_list; 61, 62; 61, 65; 61, 68; 61, 71; 61, 72; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:estimators_; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:estimators_features_; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:estimators_weight_; 71, identifier:X; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:combination; 75, return_statement; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:f_staking; 81, identifier:predict; 82, argument_list; 82, 83; 83, identifier:X_stacking; 84, elif_clause; 84, 85; 84, 92; 84, 93; 85, comparison_operator:in; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:combination; 89, list:['majority_voting', 'weighted_voting']; 89, 90; 89, 91; 90, string:'majority_voting'; 91, string:'weighted_voting'; 92, comment; 93, block; 93, 94; 93, 109; 93, 186; 93, 187; 93, 198; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 100; 96, pattern_list; 96, 97; 96, 98; 96, 99; 97, identifier:n_jobs; 98, identifier:n_estimators; 99, identifier:starts; 100, call; 100, 101; 100, 102; 101, identifier:_partition_estimators; 102, argument_list; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:n_estimators; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:n_jobs; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:all_pred; 112, call; 112, 113; 112, 124; 113, call; 113, 114; 113, 115; 114, identifier:Parallel; 115, argument_list; 115, 116; 115, 119; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:n_jobs; 118, identifier:n_jobs; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:verbose; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:verbose; 124, generator_expression; 124, 125; 124, 180; 125, call; 125, 126; 125, 130; 126, call; 126, 127; 126, 128; 127, identifier:delayed; 128, argument_list; 128, 129; 129, identifier:_parallel_predict; 130, argument_list; 130, 131; 130, 145; 130, 159; 130, 160; 130, 163; 130, 166; 131, subscript; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:estimators_; 135, slice; 135, 136; 135, 139; 135, 140; 136, subscript; 136, 137; 136, 138; 137, identifier:starts; 138, identifier:i; 139, colon; 140, subscript; 140, 141; 140, 142; 141, identifier:starts; 142, binary_operator:+; 142, 143; 142, 144; 143, identifier:i; 144, integer:1; 145, subscript; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:estimators_features_; 149, slice; 149, 150; 149, 153; 149, 154; 150, subscript; 150, 151; 150, 152; 151, identifier:starts; 152, identifier:i; 153, colon; 154, subscript; 154, 155; 154, 156; 155, identifier:starts; 156, binary_operator:+; 156, 157; 156, 158; 157, identifier:i; 158, integer:1; 159, identifier:X; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:n_classes_; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:combination; 166, subscript; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:estimators_weight_; 170, slice; 170, 171; 170, 174; 170, 175; 171, subscript; 171, 172; 171, 173; 172, identifier:starts; 173, identifier:i; 174, colon; 175, subscript; 175, 176; 175, 177; 176, identifier:starts; 177, binary_operator:+; 177, 178; 177, 179; 178, identifier:i; 179, integer:1; 180, for_in_clause; 180, 181; 180, 182; 181, identifier:i; 182, call; 182, 183; 182, 184; 183, identifier:range; 184, argument_list; 184, 185; 185, identifier:n_jobs; 186, comment; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:pred; 190, binary_operator:/; 190, 191; 190, 195; 191, call; 191, 192; 191, 193; 192, identifier:sum; 193, argument_list; 193, 194; 194, identifier:all_pred; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:n_estimators; 198, return_statement; 198, 199; 199, call; 199, 200; 199, 205; 200, attribute; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:classes_; 204, identifier:take; 205, argument_list; 205, 206; 205, 215; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:np; 209, identifier:argmax; 210, argument_list; 210, 211; 210, 212; 211, identifier:pred; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:axis; 214, integer:1; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:axis; 217, integer:0; 218, elif_clause; 218, 219; 218, 228; 218, 229; 219, comparison_operator:in; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:combination; 223, list:['majority_bmr', 'weighted_bmr', 'stacking_bmr', 'stacking_proba_bmr']; 223, 224; 223, 225; 223, 226; 223, 227; 224, string:'majority_bmr'; 225, string:'weighted_bmr'; 226, string:'stacking_bmr'; 227, string:'stacking_proba_bmr'; 228, comment; 229, block; 229, 230; 229, 239; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:X_bmr; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:predict_proba; 237, argument_list; 237, 238; 238, identifier:X; 239, return_statement; 239, 240; 240, call; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:f_bmr; 245, identifier:predict; 246, argument_list; 246, 247; 246, 248; 247, identifier:X_bmr; 248, identifier:cost_mat | def predict(self, X, cost_mat=None):
"""Predict class for X.
The predicted class of an input sample is computed as the class with
the highest mean predicted probability. If base estimators do not
implement a ``predict_proba`` method, then it resorts to voting.
Parameters
----------
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
The training input samples. Sparse matrices are accepted only if
they are supported by the base estimator.
cost_mat : optional array-like of shape = [n_samples, 4], (default=None)
Cost matrix of the classification problem
Where the columns represents the costs of: false positives, false negatives,
true positives and true negatives, for each example.
Returns
-------
pred : array of shape = [n_samples]
The predicted classes.
"""
# Check data
# X = check_array(X, accept_sparse=['csr', 'csc', 'coo']) # Dont in version 0.15
if self.n_features_ != X.shape[1]:
raise ValueError("Number of features of the model must "
"match the input. Model n_features is {0} and "
"input n_features is {1}."
"".format(self.n_features_, X.shape[1]))
#TODO: check if combination in possible combinations
if self.combination in ['stacking', 'stacking_proba']:
X_stacking = _create_stacking_set(self.estimators_, self.estimators_features_,
self.estimators_weight_, X, self.combination)
return self.f_staking.predict(X_stacking)
elif self.combination in ['majority_voting', 'weighted_voting']:
# Parallel loop
n_jobs, n_estimators, starts = _partition_estimators(self.n_estimators,
self.n_jobs)
all_pred = Parallel(n_jobs=n_jobs, verbose=self.verbose)(
delayed(_parallel_predict)(
self.estimators_[starts[i]:starts[i + 1]],
self.estimators_features_[starts[i]:starts[i + 1]],
X,
self.n_classes_,
self.combination,
self.estimators_weight_[starts[i]:starts[i + 1]])
for i in range(n_jobs))
# Reduce
pred = sum(all_pred) / self.n_estimators
return self.classes_.take(np.argmax(pred, axis=1), axis=0)
elif self.combination in ['majority_bmr', 'weighted_bmr', 'stacking_bmr', 'stacking_proba_bmr']:
#TODO: Add check if cost_mat == None
X_bmr = self.predict_proba(X)
return self.f_bmr.predict(X_bmr, cost_mat) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:predict_proba; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:X; 6, block; 6, 7; 6, 9; 6, 10; 6, 11; 6, 43; 6, 44; 6, 59; 6, 136; 6, 137; 6, 214; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, comment; 11, if_statement; 11, 12; 11, 21; 12, comparison_operator:!=; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:n_features_; 16, subscript; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:X; 19, identifier:shape; 20, integer:1; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:ValueError; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 34; 27, attribute; 27, 28; 27, 33; 28, concatenated_string; 28, 29; 28, 30; 28, 31; 28, 32; 29, string:"Number of features of the model must "; 30, string:"match the input. Model n_features is {0} and "; 31, string:"input n_features is {1}."; 32, string:""; 33, identifier:format; 34, argument_list; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:n_features_; 38, subscript; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:X; 41, identifier:shape; 42, integer:1; 43, comment; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 50; 46, pattern_list; 46, 47; 46, 48; 46, 49; 47, identifier:n_jobs; 48, identifier:n_estimators; 49, identifier:starts; 50, call; 50, 51; 50, 52; 51, identifier:_partition_estimators; 52, argument_list; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:n_estimators; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:n_jobs; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:all_proba; 62, call; 62, 63; 62, 74; 63, call; 63, 64; 63, 65; 64, identifier:Parallel; 65, argument_list; 65, 66; 65, 69; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:n_jobs; 68, identifier:n_jobs; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:verbose; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:verbose; 74, generator_expression; 74, 75; 74, 130; 75, call; 75, 76; 75, 80; 76, call; 76, 77; 76, 78; 77, identifier:delayed; 78, argument_list; 78, 79; 79, identifier:_parallel_predict_proba; 80, argument_list; 80, 81; 80, 95; 80, 109; 80, 110; 80, 113; 80, 116; 81, subscript; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:estimators_; 85, slice; 85, 86; 85, 89; 85, 90; 86, subscript; 86, 87; 86, 88; 87, identifier:starts; 88, identifier:i; 89, colon; 90, subscript; 90, 91; 90, 92; 91, identifier:starts; 92, binary_operator:+; 92, 93; 92, 94; 93, identifier:i; 94, integer:1; 95, subscript; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:estimators_features_; 99, slice; 99, 100; 99, 103; 99, 104; 100, subscript; 100, 101; 100, 102; 101, identifier:starts; 102, identifier:i; 103, colon; 104, subscript; 104, 105; 104, 106; 105, identifier:starts; 106, binary_operator:+; 106, 107; 106, 108; 107, identifier:i; 108, integer:1; 109, identifier:X; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:n_classes_; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:combination; 116, subscript; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:estimators_weight_; 120, slice; 120, 121; 120, 124; 120, 125; 121, subscript; 121, 122; 121, 123; 122, identifier:starts; 123, identifier:i; 124, colon; 125, subscript; 125, 126; 125, 127; 126, identifier:starts; 127, binary_operator:+; 127, 128; 127, 129; 128, identifier:i; 129, integer:1; 130, for_in_clause; 130, 131; 130, 132; 131, identifier:i; 132, call; 132, 133; 132, 134; 133, identifier:range; 134, argument_list; 134, 135; 135, identifier:n_jobs; 136, comment; 137, if_statement; 137, 138; 137, 145; 137, 157; 137, 173; 138, comparison_operator:in; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:combination; 142, list:['majority_voting', 'majority_bmr']; 142, 143; 142, 144; 143, string:'majority_voting'; 144, string:'majority_bmr'; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:proba; 149, binary_operator:/; 149, 150; 149, 154; 150, call; 150, 151; 150, 152; 151, identifier:sum; 152, argument_list; 152, 153; 153, identifier:all_proba; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:n_estimators; 157, elif_clause; 157, 158; 157, 165; 158, comparison_operator:in; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:combination; 162, list:['weighted_voting', 'weighted_bmr']; 162, 163; 162, 164; 163, string:'weighted_voting'; 164, string:'weighted_bmr'; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:proba; 169, call; 169, 170; 169, 171; 170, identifier:sum; 171, argument_list; 171, 172; 172, identifier:all_proba; 173, elif_clause; 173, 174; 173, 183; 174, comparison_operator:in; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:combination; 178, list:['stacking', 'stacking_proba', 'stacking_bmr', 'stacking_proba_bmr']; 178, 179; 178, 180; 178, 181; 178, 182; 179, string:'stacking'; 180, string:'stacking_proba'; 181, string:'stacking_bmr'; 182, string:'stacking_proba_bmr'; 183, block; 183, 184; 183, 203; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:X_stacking; 187, call; 187, 188; 187, 189; 188, identifier:_create_stacking_set; 189, argument_list; 189, 190; 189, 193; 189, 196; 189, 199; 189, 200; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:estimators_; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:estimators_features_; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:estimators_weight_; 199, identifier:X; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:combination; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:proba; 206, call; 206, 207; 206, 212; 207, attribute; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:f_staking; 211, identifier:predict_proba; 212, argument_list; 212, 213; 213, identifier:X_stacking; 214, return_statement; 214, 215; 215, identifier:proba | def predict_proba(self, X):
"""Predict class probabilities for X.
The predicted class probabilities of an input sample is computed as
the mean predicted class probabilities of the base estimators in the
ensemble. If base estimators do not implement a ``predict_proba``
method, then it resorts to voting and the predicted class probabilities
of a an input sample represents the proportion of estimators predicting
each class.
Parameters
----------
X : {array-like, sparse matrix} of shape = [n_samples, n_features]
The training input samples. Sparse matrices are accepted only if
they are supported by the base estimator.
Returns
-------
p : array of shape = [n_samples, n_classes]
The class probabilities of the input samples. The order of the
classes corresponds to that in the attribute `classes_`.
"""
# Check data
# X = check_array(X, accept_sparse=['csr', 'csc', 'coo']) # Dont in version 0.15
if self.n_features_ != X.shape[1]:
raise ValueError("Number of features of the model must "
"match the input. Model n_features is {0} and "
"input n_features is {1}."
"".format(self.n_features_, X.shape[1]))
# Parallel loop
n_jobs, n_estimators, starts = _partition_estimators(self.n_estimators, self.n_jobs)
all_proba = Parallel(n_jobs=n_jobs, verbose=self.verbose)(
delayed(_parallel_predict_proba)(
self.estimators_[starts[i]:starts[i + 1]],
self.estimators_features_[starts[i]:starts[i + 1]],
X,
self.n_classes_,
self.combination,
self.estimators_weight_[starts[i]:starts[i + 1]])
for i in range(n_jobs))
# Reduce
if self.combination in ['majority_voting', 'majority_bmr']:
proba = sum(all_proba) / self.n_estimators
elif self.combination in ['weighted_voting', 'weighted_bmr']:
proba = sum(all_proba)
elif self.combination in ['stacking', 'stacking_proba', 'stacking_bmr', 'stacking_proba_bmr']:
X_stacking = _create_stacking_set(self.estimators_, self.estimators_features_,
self.estimators_weight_, X, self.combination)
proba = self.f_staking.predict_proba(X_stacking)
return proba |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:to_param_dict; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 12; 5, 58; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:param_dict; 11, dictionary; 12, for_statement; 12, 13; 12, 16; 12, 22; 13, pattern_list; 13, 14; 13, 15; 14, identifier:index; 15, identifier:dictionary; 16, call; 16, 17; 16, 18; 17, identifier:enumerate; 18, argument_list; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:value; 22, block; 22, 23; 23, for_statement; 23, 24; 23, 27; 23, 32; 24, pattern_list; 24, 25; 24, 26; 25, identifier:key; 26, identifier:value; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:dictionary; 30, identifier:items; 31, argument_list; 32, block; 32, 33; 32, 52; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:param_name; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, string:'{param_name}[{index}][{key}]'; 39, identifier:format; 40, argument_list; 40, 41; 40, 46; 40, 49; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:param_name; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:param_name; 46, keyword_argument; 46, 47; 46, 48; 47, identifier:index; 48, identifier:index; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:key; 51, identifier:key; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, subscript; 54, 55; 54, 56; 55, identifier:param_dict; 56, identifier:param_name; 57, identifier:value; 58, return_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:OrderedDict; 61, argument_list; 61, 62; 62, call; 62, 63; 62, 64; 63, identifier:sorted; 64, argument_list; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:param_dict; 68, identifier:items; 69, argument_list | def to_param_dict(self):
""" Sorts to ensure Order is consistent for Testing """
param_dict = {}
for index, dictionary in enumerate(self.value):
for key, value in dictionary.items():
param_name = '{param_name}[{index}][{key}]'.format(
param_name=self.param_name,
index=index,
key=key)
param_dict[param_name] = value
return OrderedDict(sorted(param_dict.items())) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:datetimes; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, comparison_operator:is; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_timestamps_data; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_calculate_timestamps; 20, argument_list; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:tuple; 24, generator_expression; 24, 25; 24, 34; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:DateTime; 28, identifier:from_moy; 29, argument_list; 29, 30; 29, 31; 30, identifier:moy; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:is_leap_year; 34, for_in_clause; 34, 35; 34, 36; 35, identifier:moy; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_timestamps_data | def datetimes(self):
"""A sorted list of datetimes in this analysis period."""
if self._timestamps_data is None:
self._calculate_timestamps()
return tuple(DateTime.from_moy(moy, self.is_leap_year)
for moy in self._timestamps_data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:hoys; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, comparison_operator:is; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_timestamps_data; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_calculate_timestamps; 20, argument_list; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:tuple; 24, generator_expression; 24, 25; 24, 28; 25, binary_operator:/; 25, 26; 25, 27; 26, identifier:moy; 27, float:60.0; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:moy; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:_timestamps_data | def hoys(self):
"""A sorted list of hours of year in this analysis period."""
if self._timestamps_data is None:
self._calculate_timestamps()
return tuple(moy / 60.0 for moy in self._timestamps_data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:hoys_int; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, comparison_operator:is; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_timestamps_data; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_calculate_timestamps; 20, argument_list; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:tuple; 24, generator_expression; 24, 25; 24, 31; 25, call; 25, 26; 25, 27; 26, identifier:int; 27, argument_list; 27, 28; 28, binary_operator:/; 28, 29; 28, 30; 29, identifier:moy; 30, float:60.0; 31, for_in_clause; 31, 32; 31, 33; 32, identifier:moy; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_timestamps_data | def hoys_int(self):
"""A sorted list of hours of year in this analysis period as integers."""
if self._timestamps_data is None:
self._calculate_timestamps()
return tuple(int(moy / 60.0) for moy in self._timestamps_data) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:doys_int; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 13; 8, 26; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_is_reversed; 13, block; 13, 14; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_calc_daystamps; 19, argument_list; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:st_time; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:end_time; 26, else_clause; 26, 27; 27, block; 27, 28; 27, 45; 27, 62; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:doys_st; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_calc_daystamps; 35, argument_list; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:st_time; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:DateTime; 42, identifier:from_hoy; 43, argument_list; 43, 44; 44, integer:8759; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:doys_end; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_calc_daystamps; 52, argument_list; 52, 53; 52, 59; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:DateTime; 56, identifier:from_hoy; 57, argument_list; 57, 58; 58, integer:0; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:end_time; 62, return_statement; 62, 63; 63, binary_operator:+; 63, 64; 63, 65; 64, identifier:doys_st; 65, identifier:doys_end | def doys_int(self):
"""A sorted list of days of the year in this analysis period as integers."""
if not self._is_reversed:
return self._calc_daystamps(self.st_time, self.end_time)
else:
doys_st = self._calc_daystamps(self.st_time, DateTime.from_hoy(8759))
doys_end = self._calc_daystamps(DateTime.from_hoy(0), self.end_time)
return doys_st + doys_end |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:months_int; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 13; 8, 33; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_is_reversed; 13, block; 13, 14; 14, return_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:list; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:xrange; 20, argument_list; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:st_time; 25, identifier:month; 26, binary_operator:+; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:end_time; 31, identifier:month; 32, integer:1; 33, else_clause; 33, 34; 34, block; 34, 35; 34, 50; 34, 67; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:months_st; 38, call; 38, 39; 38, 40; 39, identifier:list; 40, argument_list; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:xrange; 43, argument_list; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:st_time; 48, identifier:month; 49, integer:13; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:months_end; 53, call; 53, 54; 53, 55; 54, identifier:list; 55, argument_list; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:xrange; 58, argument_list; 58, 59; 58, 60; 59, integer:1; 60, binary_operator:+; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:end_time; 65, identifier:month; 66, integer:1; 67, return_statement; 67, 68; 68, binary_operator:+; 68, 69; 68, 70; 69, identifier:months_st; 70, identifier:months_end | def months_int(self):
"""A sorted list of months of the year in this analysis period as integers."""
if not self._is_reversed:
return list(xrange(self.st_time.month, self.end_time.month + 1))
else:
months_st = list(xrange(self.st_time.month, 13))
months_end = list(xrange(1, self.end_time.month + 1))
return months_st + months_end |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:sorted; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:field_name; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ascending; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:fields; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:count; 13, integer:5; 14, block; 14, 15; 14, 17; 14, 27; 14, 34; 14, 43; 15, expression_statement; 15, 16; 16, comment; 17, if_statement; 17, 18; 17, 21; 18, comparison_operator:is; 18, 19; 18, 20; 19, identifier:field_name; 20, None; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:Exception; 25, argument_list; 25, 26; 26, string:'Sort field must be specified'; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:direction; 30, conditional_expression:if; 30, 31; 30, 32; 30, 33; 31, string:''; 32, identifier:ascending; 33, string:' DESC'; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:projection; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:Sampling; 40, identifier:_create_projection; 41, argument_list; 41, 42; 42, identifier:fields; 43, return_statement; 43, 44; 44, lambda; 44, 45; 44, 47; 45, lambda_parameters; 45, 46; 46, identifier:sql; 47, binary_operator:%; 47, 48; 47, 49; 48, string:'SELECT %s FROM (%s) ORDER BY %s%s LIMIT %d'; 49, tuple; 49, 50; 49, 51; 49, 52; 49, 53; 49, 54; 50, identifier:projection; 51, identifier:sql; 52, identifier:field_name; 53, identifier:direction; 54, identifier:count | def sorted(field_name, ascending=True, fields=None, count=5):
"""Provides a sampling strategy that picks from an ordered set of rows.
Args:
field_name: the name of the field to sort the rows by.
ascending: whether to sort in ascending direction or not.
fields: an optional list of field names to retrieve.
count: optional number of rows to limit the sampled results to.
Returns:
A sampling function that can be applied to get the initial few rows.
"""
if field_name is None:
raise Exception('Sort field must be specified')
direction = '' if ascending else ' DESC'
projection = Sampling._create_projection(fields)
return lambda sql: 'SELECT %s FROM (%s) ORDER BY %s%s LIMIT %d' % (projection, sql, field_name,
direction, count) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_auto; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:method; 5, identifier:fields; 6, identifier:count; 7, identifier:percent; 8, identifier:key_field; 9, identifier:ascending; 10, block; 10, 11; 10, 13; 11, expression_statement; 11, 12; 12, comment; 13, if_statement; 13, 14; 13, 17; 13, 30; 13, 50; 13, 73; 13, 96; 14, comparison_operator:==; 14, 15; 14, 16; 15, identifier:method; 16, string:'limit'; 17, block; 17, 18; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:Sampling; 22, identifier:default; 23, argument_list; 23, 24; 23, 27; 24, keyword_argument; 24, 25; 24, 26; 25, identifier:fields; 26, identifier:fields; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:count; 29, identifier:count; 30, elif_clause; 30, 31; 30, 34; 31, comparison_operator:==; 31, 32; 31, 33; 32, identifier:method; 33, string:'random'; 34, block; 34, 35; 35, return_statement; 35, 36; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:Sampling; 39, identifier:random; 40, argument_list; 40, 41; 40, 44; 40, 47; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:fields; 43, identifier:fields; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:percent; 46, identifier:percent; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:count; 49, identifier:count; 50, elif_clause; 50, 51; 50, 54; 51, comparison_operator:==; 51, 52; 51, 53; 52, identifier:method; 53, string:'hashed'; 54, block; 54, 55; 55, return_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:Sampling; 59, identifier:hashed; 60, argument_list; 60, 61; 60, 64; 60, 67; 60, 70; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:fields; 63, identifier:fields; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:field_name; 66, identifier:key_field; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:percent; 69, identifier:percent; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:count; 72, identifier:count; 73, elif_clause; 73, 74; 73, 77; 74, comparison_operator:==; 74, 75; 74, 76; 75, identifier:method; 76, string:'sorted'; 77, block; 77, 78; 78, return_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:Sampling; 82, identifier:sorted; 83, argument_list; 83, 84; 83, 87; 83, 90; 83, 93; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:fields; 86, identifier:fields; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:field_name; 89, identifier:key_field; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:ascending; 92, identifier:ascending; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:count; 95, identifier:count; 96, else_clause; 96, 97; 97, block; 97, 98; 98, raise_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:Exception; 101, argument_list; 101, 102; 102, binary_operator:%; 102, 103; 102, 104; 103, string:'Unsupported sampling method: %s'; 104, identifier:method | def _auto(method, fields, count, percent, key_field, ascending):
"""Construct a sampling function according to the provided sampling technique, provided all
its needed fields are passed as arguments
Args:
method: one of the supported sampling methods: {limit,random,hashed,sorted}
fields: an optional list of field names to retrieve.
count: maximum number of rows to limit the sampled results to.
percent: the percentage of the resulting hashes to select if using hashed sampling
key_field: the name of the field to sort the rows by or use for hashing
ascending: whether to sort in ascending direction or not.
Returns:
A sampling function using the provided arguments
Raises:
Exception if an unsupported mathod name is passed
"""
if method == 'limit':
return Sampling.default(fields=fields, count=count)
elif method == 'random':
return Sampling.random(fields=fields, percent=percent, count=count)
elif method == 'hashed':
return Sampling.hashed(fields=fields, field_name=key_field, percent=percent, count=count)
elif method == 'sorted':
return Sampling.sorted(fields=fields, field_name=key_field, ascending=ascending, count=count)
else:
raise Exception('Unsupported sampling method: %s' % method) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:pair_SAM_alignments; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:alignments; 5, default_parameter; 5, 6; 5, 7; 6, identifier:bundle; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:primary_only; 10, False; 11, block; 11, 12; 11, 14; 11, 19; 11, 217; 11, 221; 11, 225; 11, 321; 11, 345; 12, expression_statement; 12, 13; 13, string:'''Iterate over SAM aligments, name-sorted paired-end
Args:
alignments (iterator of SAM/BAM alignments): the alignments to wrap
bundle (bool): if True, bundle all alignments from one read pair into a
single yield. If False (default), each pair of alignments is
yielded separately.
primary_only (bool): for each read, consider only the primary line
(SAM flag 0x900 = 0). The SAM specification requires one and only
one of those for each read.
Yields:
2-tuples with each pair of alignments or, if bundle==True, each bundled
list of alignments.
'''; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:mate_missing_count; 17, list:[0]; 17, 18; 18, integer:0; 19, function_definition; 19, 20; 19, 21; 19, 23; 20, function_name:process_list; 21, parameters; 21, 22; 22, identifier:almnt_list; 23, block; 23, 24; 23, 26; 24, expression_statement; 24, 25; 25, string:'''Transform a list of alignment with the same read name into pairs
Args:
almnt_list (list): alignments to process
Yields:
each pair of alignments.
This function is needed because each line of a BAM file is not a read
but an alignment. For uniquely mapped and unmapped reads, those two are
the same. For multimapped reads, however, there can be more than one
alignment for each read. Also, it is normal for a mapper to uniquely
map one read and multimap its mate.
This function goes down the list of alignments for a given read name
and tries to find the first mate. So if read 1 is uniquely mapped but
read 2 is mapped 4 times, only (read 1, read 2 - first occurrence) will
yield; the other 3 alignments of read 2 are ignored.
'''; 26, while_statement; 26, 27; 26, 33; 27, comparison_operator:>; 27, 28; 27, 32; 28, call; 28, 29; 28, 30; 29, identifier:len; 30, argument_list; 30, 31; 31, identifier:almnt_list; 32, integer:0; 33, block; 33, 34; 33, 43; 33, 44; 33, 180; 33, 192; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:a1; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:almnt_list; 40, identifier:pop; 41, argument_list; 41, 42; 42, integer:0; 43, comment; 44, for_statement; 44, 45; 44, 46; 44, 47; 44, 139; 45, identifier:a2; 46, identifier:almnt_list; 47, block; 47, 48; 47, 58; 47, 76; 47, 88; 48, if_statement; 48, 49; 48, 56; 49, comparison_operator:==; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:a1; 52, identifier:pe_which; 53, attribute; 53, 54; 53, 55; 54, identifier:a2; 55, identifier:pe_which; 56, block; 56, 57; 57, continue_statement; 58, if_statement; 58, 59; 58, 74; 59, boolean_operator:or; 59, 60; 59, 67; 60, comparison_operator:!=; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:a1; 63, identifier:aligned; 64, attribute; 64, 65; 64, 66; 65, identifier:a2; 66, identifier:mate_aligned; 67, comparison_operator:!=; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:a1; 70, identifier:mate_aligned; 71, attribute; 71, 72; 71, 73; 72, identifier:a2; 73, identifier:aligned; 74, block; 74, 75; 75, continue_statement; 76, if_statement; 76, 77; 76, 86; 77, not_operator; 77, 78; 78, parenthesized_expression; 78, 79; 79, boolean_operator:and; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:a1; 82, identifier:aligned; 83, attribute; 83, 84; 83, 85; 84, identifier:a2; 85, identifier:aligned; 86, block; 86, 87; 87, break_statement; 88, if_statement; 88, 89; 88, 137; 89, boolean_operator:and; 89, 90; 89, 126; 90, boolean_operator:and; 90, 91; 90, 114; 90, 115; 91, boolean_operator:and; 91, 92; 91, 103; 92, comparison_operator:==; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:a1; 96, identifier:iv; 97, identifier:chrom; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:a2; 101, identifier:mate_start; 102, identifier:chrom; 103, comparison_operator:==; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:a1; 107, identifier:iv; 108, identifier:start; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:a2; 112, identifier:mate_start; 113, identifier:pos; 114, line_continuation:\; 115, comparison_operator:==; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:a2; 119, identifier:iv; 120, identifier:chrom; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:a1; 124, identifier:mate_start; 125, identifier:chrom; 126, comparison_operator:==; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:a2; 130, identifier:iv; 131, identifier:start; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:a1; 135, identifier:mate_start; 136, identifier:pos; 137, block; 137, 138; 138, break_statement; 139, else_clause; 139, 140; 140, block; 140, 141; 140, 176; 141, if_statement; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:a1; 144, identifier:mate_aligned; 145, block; 145, 146; 145, 152; 146, expression_statement; 146, 147; 147, augmented_assignment:+=; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:mate_missing_count; 150, integer:0; 151, integer:1; 152, if_statement; 152, 153; 152, 158; 153, comparison_operator:==; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:mate_missing_count; 156, integer:0; 157, integer:1; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:warnings; 163, identifier:warn; 164, argument_list; 164, 165; 165, binary_operator:+; 165, 166; 165, 175; 166, binary_operator:+; 166, 167; 166, 174; 167, binary_operator:+; 167, 168; 167, 169; 168, string:"Read "; 169, attribute; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:a1; 172, identifier:read; 173, identifier:name; 174, string:" claims to have an aligned mate "; 175, string:"which could not be found in an adjacent line."; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:a2; 179, None; 180, if_statement; 180, 181; 180, 184; 181, comparison_operator:is; 181, 182; 181, 183; 182, identifier:a2; 183, None; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:almnt_list; 189, identifier:remove; 190, argument_list; 190, 191; 191, identifier:a2; 192, if_statement; 192, 193; 192, 198; 192, 204; 193, comparison_operator:==; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:a1; 196, identifier:pe_which; 197, string:"first"; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, yield; 200, 201; 201, tuple; 201, 202; 201, 203; 202, identifier:a1; 203, identifier:a2; 204, else_clause; 204, 205; 205, block; 205, 206; 205, 212; 206, assert_statement; 206, 207; 207, comparison_operator:==; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:a1; 210, identifier:pe_which; 211, string:"second"; 212, expression_statement; 212, 213; 213, yield; 213, 214; 214, tuple; 214, 215; 214, 216; 215, identifier:a2; 216, identifier:a1; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:almnt_list; 220, list:[]; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:current_name; 224, None; 225, for_statement; 225, 226; 225, 227; 225, 228; 226, identifier:almnt; 227, identifier:alignments; 228, block; 228, 229; 228, 240; 228, 252; 228, 253; 228, 266; 229, if_statement; 229, 230; 229, 234; 230, not_operator; 230, 231; 231, attribute; 231, 232; 231, 233; 232, identifier:almnt; 233, identifier:paired_end; 234, block; 234, 235; 235, raise_statement; 235, 236; 236, call; 236, 237; 236, 238; 237, identifier:ValueError; 238, argument_list; 238, 239; 239, string:"'pair_alignments' needs a sequence of paired-end alignments"; 240, if_statement; 240, 241; 240, 246; 241, comparison_operator:==; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:almnt; 244, identifier:pe_which; 245, string:"unknown"; 246, block; 246, 247; 247, raise_statement; 247, 248; 248, call; 248, 249; 248, 250; 249, identifier:ValueError; 250, argument_list; 250, 251; 251, string:"Paired-end read found with 'unknown' 'pe_which' status."; 252, comment; 253, if_statement; 253, 254; 253, 264; 254, boolean_operator:and; 254, 255; 254, 256; 255, identifier:primary_only; 256, parenthesized_expression; 256, 257; 257, boolean_operator:or; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:almnt; 260, identifier:not_primary_alignment; 261, attribute; 261, 262; 261, 263; 262, identifier:almnt; 263, identifier:supplementary; 264, block; 264, 265; 265, continue_statement; 266, if_statement; 266, 267; 266, 274; 266, 282; 267, comparison_operator:==; 267, 268; 267, 273; 268, attribute; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:almnt; 271, identifier:read; 272, identifier:name; 273, identifier:current_name; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:almnt_list; 279, identifier:append; 280, argument_list; 280, 281; 281, identifier:almnt; 282, else_clause; 282, 283; 283, block; 283, 284; 283, 308; 283, 316; 284, if_statement; 284, 285; 284, 286; 284, 296; 285, identifier:bundle; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, yield; 288, 289; 289, call; 289, 290; 289, 291; 290, identifier:list; 291, argument_list; 291, 292; 292, call; 292, 293; 292, 294; 293, identifier:process_list; 294, argument_list; 294, 295; 295, identifier:almnt_list; 296, else_clause; 296, 297; 297, block; 297, 298; 298, for_statement; 298, 299; 298, 300; 298, 304; 299, identifier:p; 300, call; 300, 301; 300, 302; 301, identifier:process_list; 302, argument_list; 302, 303; 303, identifier:almnt_list; 304, block; 304, 305; 305, expression_statement; 305, 306; 306, yield; 306, 307; 307, identifier:p; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:current_name; 311, attribute; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:almnt; 314, identifier:read; 315, identifier:name; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:almnt_list; 319, list:[almnt]; 319, 320; 320, identifier:almnt; 321, if_statement; 321, 322; 321, 323; 321, 333; 322, identifier:bundle; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, yield; 325, 326; 326, call; 326, 327; 326, 328; 327, identifier:list; 328, argument_list; 328, 329; 329, call; 329, 330; 329, 331; 330, identifier:process_list; 331, argument_list; 331, 332; 332, identifier:almnt_list; 333, else_clause; 333, 334; 334, block; 334, 335; 335, for_statement; 335, 336; 335, 337; 335, 341; 336, identifier:p; 337, call; 337, 338; 337, 339; 338, identifier:process_list; 339, argument_list; 339, 340; 340, identifier:almnt_list; 341, block; 341, 342; 342, expression_statement; 342, 343; 343, yield; 343, 344; 344, identifier:p; 345, if_statement; 345, 346; 345, 351; 346, comparison_operator:>; 346, 347; 346, 350; 347, subscript; 347, 348; 347, 349; 348, identifier:mate_missing_count; 349, integer:0; 350, integer:1; 351, block; 351, 352; 352, expression_statement; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:warnings; 356, identifier:warn; 357, argument_list; 357, 358; 358, binary_operator:%; 358, 359; 358, 360; 359, string:"%d reads with missing mate encountered."; 360, subscript; 360, 361; 360, 362; 361, identifier:mate_missing_count; 362, integer:0 | def pair_SAM_alignments(
alignments,
bundle=False,
primary_only=False):
'''Iterate over SAM aligments, name-sorted paired-end
Args:
alignments (iterator of SAM/BAM alignments): the alignments to wrap
bundle (bool): if True, bundle all alignments from one read pair into a
single yield. If False (default), each pair of alignments is
yielded separately.
primary_only (bool): for each read, consider only the primary line
(SAM flag 0x900 = 0). The SAM specification requires one and only
one of those for each read.
Yields:
2-tuples with each pair of alignments or, if bundle==True, each bundled
list of alignments.
'''
mate_missing_count = [0]
def process_list(almnt_list):
'''Transform a list of alignment with the same read name into pairs
Args:
almnt_list (list): alignments to process
Yields:
each pair of alignments.
This function is needed because each line of a BAM file is not a read
but an alignment. For uniquely mapped and unmapped reads, those two are
the same. For multimapped reads, however, there can be more than one
alignment for each read. Also, it is normal for a mapper to uniquely
map one read and multimap its mate.
This function goes down the list of alignments for a given read name
and tries to find the first mate. So if read 1 is uniquely mapped but
read 2 is mapped 4 times, only (read 1, read 2 - first occurrence) will
yield; the other 3 alignments of read 2 are ignored.
'''
while len(almnt_list) > 0:
a1 = almnt_list.pop(0)
# Find its mate
for a2 in almnt_list:
if a1.pe_which == a2.pe_which:
continue
if a1.aligned != a2.mate_aligned or a1.mate_aligned != a2.aligned:
continue
if not (a1.aligned and a2.aligned):
break
if a1.iv.chrom == a2.mate_start.chrom and a1.iv.start == a2.mate_start.pos and \
a2.iv.chrom == a1.mate_start.chrom and a2.iv.start == a1.mate_start.pos:
break
else:
if a1.mate_aligned:
mate_missing_count[0] += 1
if mate_missing_count[0] == 1:
warnings.warn(
"Read " + a1.read.name + " claims to have an aligned mate " +
"which could not be found in an adjacent line.")
a2 = None
if a2 is not None:
almnt_list.remove(a2)
if a1.pe_which == "first":
yield (a1, a2)
else:
assert a1.pe_which == "second"
yield (a2, a1)
almnt_list = []
current_name = None
for almnt in alignments:
if not almnt.paired_end:
raise ValueError(
"'pair_alignments' needs a sequence of paired-end alignments")
if almnt.pe_which == "unknown":
raise ValueError(
"Paired-end read found with 'unknown' 'pe_which' status.")
# FIXME: almnt.not_primary_alignment currently means secondary
if primary_only and (almnt.not_primary_alignment or almnt.supplementary):
continue
if almnt.read.name == current_name:
almnt_list.append(almnt)
else:
if bundle:
yield list(process_list(almnt_list))
else:
for p in process_list(almnt_list):
yield p
current_name = almnt.read.name
almnt_list = [almnt]
if bundle:
yield list(process_list(almnt_list))
else:
for p in process_list(almnt_list):
yield p
if mate_missing_count[0] > 1:
warnings.warn("%d reads with missing mate encountered." %
mate_missing_count[0]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:pair_SAM_alignments_with_buffer; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:alignments; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_buffer_size; 7, integer:30000000; 8, default_parameter; 8, 9; 8, 10; 9, identifier:primary_only; 10, False; 11, block; 11, 12; 11, 14; 11, 18; 11, 22; 11, 307; 11, 377; 12, expression_statement; 12, 13; 13, string:'''Iterate over SAM aligments with buffer, position-sorted paired-end
Args:
alignments (iterator of SAM/BAM alignments): the alignments to wrap
max_buffer_size (int): maxmal numer of alignments to keep in memory.
primary_only (bool): for each read, consider only the primary line
(SAM flag 0x900 = 0). The SAM specification requires one and only
one of those for each read.
Yields:
2-tuples with each pair of alignments.
'''; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:almnt_buffer; 17, dictionary; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:ambiguous_pairing_counter; 21, integer:0; 22, for_statement; 22, 23; 22, 24; 22, 25; 23, identifier:almnt; 24, identifier:alignments; 25, block; 25, 26; 25, 37; 25, 49; 25, 50; 25, 63; 25, 133; 26, if_statement; 26, 27; 26, 31; 27, not_operator; 27, 28; 28, attribute; 28, 29; 28, 30; 29, identifier:almnt; 30, identifier:paired_end; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:ValueError; 35, argument_list; 35, 36; 36, string:"Sequence of paired-end alignments expected, but got single-end alignment."; 37, if_statement; 37, 38; 37, 43; 38, comparison_operator:==; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:almnt; 41, identifier:pe_which; 42, string:"unknown"; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:ValueError; 47, argument_list; 47, 48; 48, string:"Cannot process paired-end alignment found with 'unknown' 'pe_which' status."; 49, comment; 50, if_statement; 50, 51; 50, 61; 51, boolean_operator:and; 51, 52; 51, 53; 52, identifier:primary_only; 53, parenthesized_expression; 53, 54; 54, boolean_operator:or; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:almnt; 57, identifier:not_primary_alignment; 58, attribute; 58, 59; 58, 60; 59, identifier:almnt; 60, identifier:supplementary; 61, block; 61, 62; 62, continue_statement; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:matekey; 66, tuple; 66, 67; 66, 72; 66, 80; 66, 90; 66, 100; 66, 110; 66, 120; 67, attribute; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:almnt; 70, identifier:read; 71, identifier:name; 72, conditional_expression:if; 72, 73; 72, 74; 72, 79; 73, string:"second"; 74, comparison_operator:==; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:almnt; 77, identifier:pe_which; 78, string:"first"; 79, string:"first"; 80, conditional_expression:if; 80, 81; 80, 86; 80, 89; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:almnt; 84, identifier:mate_start; 85, identifier:chrom; 86, attribute; 86, 87; 86, 88; 87, identifier:almnt; 88, identifier:mate_aligned; 89, None; 90, conditional_expression:if; 90, 91; 90, 96; 90, 99; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:almnt; 94, identifier:mate_start; 95, identifier:pos; 96, attribute; 96, 97; 96, 98; 97, identifier:almnt; 98, identifier:mate_aligned; 99, None; 100, conditional_expression:if; 100, 101; 100, 106; 100, 109; 101, attribute; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:almnt; 104, identifier:iv; 105, identifier:chrom; 106, attribute; 106, 107; 106, 108; 107, identifier:almnt; 108, identifier:aligned; 109, None; 110, conditional_expression:if; 110, 111; 110, 116; 110, 119; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:almnt; 114, identifier:iv; 115, identifier:start; 116, attribute; 116, 117; 116, 118; 117, identifier:almnt; 118, identifier:aligned; 119, None; 120, conditional_expression:if; 120, 121; 120, 125; 120, 132; 121, unary_operator:-; 121, 122; 122, attribute; 122, 123; 122, 124; 123, identifier:almnt; 124, identifier:inferred_insert_size; 125, boolean_operator:and; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:almnt; 128, identifier:aligned; 129, attribute; 129, 130; 129, 131; 130, identifier:almnt; 131, identifier:mate_aligned; 132, None; 133, if_statement; 133, 134; 133, 137; 133, 205; 134, comparison_operator:in; 134, 135; 134, 136; 135, identifier:matekey; 136, identifier:almnt_buffer; 137, block; 137, 138; 137, 186; 138, if_statement; 138, 139; 138, 147; 138, 160; 139, comparison_operator:==; 139, 140; 139, 146; 140, call; 140, 141; 140, 142; 141, identifier:len; 142, argument_list; 142, 143; 143, subscript; 143, 144; 143, 145; 144, identifier:almnt_buffer; 145, identifier:matekey; 146, integer:1; 147, block; 147, 148; 147, 156; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:mate; 151, subscript; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:almnt_buffer; 154, identifier:matekey; 155, integer:0; 156, delete_statement; 156, 157; 157, subscript; 157, 158; 157, 159; 158, identifier:almnt_buffer; 159, identifier:matekey; 160, else_clause; 160, 161; 161, block; 161, 162; 161, 173; 161, 182; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:mate; 165, call; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:almnt_buffer; 169, identifier:matekey; 170, identifier:pop; 171, argument_list; 171, 172; 172, integer:0; 173, if_statement; 173, 174; 173, 177; 174, comparison_operator:==; 174, 175; 174, 176; 175, identifier:ambiguous_pairing_counter; 176, integer:0; 177, block; 177, 178; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:ambiguous_pairing_first_occurance; 181, identifier:matekey; 182, expression_statement; 182, 183; 183, augmented_assignment:+=; 183, 184; 183, 185; 184, identifier:ambiguous_pairing_counter; 185, integer:1; 186, if_statement; 186, 187; 186, 192; 186, 198; 187, comparison_operator:==; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:almnt; 190, identifier:pe_which; 191, string:"first"; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, yield; 194, 195; 195, tuple; 195, 196; 195, 197; 196, identifier:almnt; 197, identifier:mate; 198, else_clause; 198, 199; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, yield; 201, 202; 202, tuple; 202, 203; 202, 204; 203, identifier:mate; 204, identifier:almnt; 205, else_clause; 205, 206; 206, block; 206, 207; 206, 271; 206, 294; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:almntkey; 210, tuple; 210, 211; 210, 216; 210, 219; 210, 229; 210, 239; 210, 249; 210, 259; 211, attribute; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:almnt; 214, identifier:read; 215, identifier:name; 216, attribute; 216, 217; 216, 218; 217, identifier:almnt; 218, identifier:pe_which; 219, conditional_expression:if; 219, 220; 219, 225; 219, 228; 220, attribute; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:almnt; 223, identifier:iv; 224, identifier:chrom; 225, attribute; 225, 226; 225, 227; 226, identifier:almnt; 227, identifier:aligned; 228, None; 229, conditional_expression:if; 229, 230; 229, 235; 229, 238; 230, attribute; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:almnt; 233, identifier:iv; 234, identifier:start; 235, attribute; 235, 236; 235, 237; 236, identifier:almnt; 237, identifier:aligned; 238, None; 239, conditional_expression:if; 239, 240; 239, 245; 239, 248; 240, attribute; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:almnt; 243, identifier:mate_start; 244, identifier:chrom; 245, attribute; 245, 246; 245, 247; 246, identifier:almnt; 247, identifier:mate_aligned; 248, None; 249, conditional_expression:if; 249, 250; 249, 255; 249, 258; 250, attribute; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:almnt; 253, identifier:mate_start; 254, identifier:pos; 255, attribute; 255, 256; 255, 257; 256, identifier:almnt; 257, identifier:mate_aligned; 258, None; 259, conditional_expression:if; 259, 260; 259, 263; 259, 270; 260, attribute; 260, 261; 260, 262; 261, identifier:almnt; 262, identifier:inferred_insert_size; 263, boolean_operator:and; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:almnt; 266, identifier:aligned; 267, attribute; 267, 268; 267, 269; 268, identifier:almnt; 269, identifier:mate_aligned; 270, None; 271, if_statement; 271, 272; 271, 275; 271, 283; 272, comparison_operator:not; 272, 273; 272, 274; 273, identifier:almntkey; 274, identifier:almnt_buffer; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 281; 278, subscript; 278, 279; 278, 280; 279, identifier:almnt_buffer; 280, identifier:almntkey; 281, list:[almnt]; 281, 282; 282, identifier:almnt; 283, else_clause; 283, 284; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, call; 286, 287; 286, 292; 287, attribute; 287, 288; 287, 291; 288, subscript; 288, 289; 288, 290; 289, identifier:almnt_buffer; 290, identifier:almntkey; 291, identifier:append; 292, argument_list; 292, 293; 293, identifier:almnt; 294, if_statement; 294, 295; 294, 301; 295, comparison_operator:>; 295, 296; 295, 300; 296, call; 296, 297; 296, 298; 297, identifier:len; 298, argument_list; 298, 299; 299, identifier:almnt_buffer; 300, identifier:max_buffer_size; 301, block; 301, 302; 302, raise_statement; 302, 303; 303, call; 303, 304; 303, 305; 304, identifier:ValueError; 305, argument_list; 305, 306; 306, string:"Maximum alignment buffer size exceeded while pairing SAM alignments."; 307, if_statement; 307, 308; 307, 314; 308, comparison_operator:>; 308, 309; 308, 313; 309, call; 309, 310; 309, 311; 310, identifier:len; 311, argument_list; 311, 312; 312, identifier:almnt_buffer; 313, integer:0; 314, block; 314, 315; 314, 343; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:warnings; 319, identifier:warn; 320, argument_list; 320, 321; 321, binary_operator:%; 321, 322; 321, 323; 322, string:"Mate records missing for %d records; first such record: %s."; 323, tuple; 323, 324; 323, 328; 324, call; 324, 325; 324, 326; 325, identifier:len; 326, argument_list; 326, 327; 327, identifier:almnt_buffer; 328, call; 328, 329; 328, 330; 329, identifier:str; 330, argument_list; 330, 331; 331, subscript; 331, 332; 331, 342; 332, subscript; 332, 333; 332, 341; 333, call; 333, 334; 333, 335; 334, identifier:list; 335, argument_list; 335, 336; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:almnt_buffer; 339, identifier:values; 340, argument_list; 341, integer:0; 342, integer:0; 343, for_statement; 343, 344; 343, 345; 343, 353; 344, identifier:almnt_list; 345, call; 345, 346; 345, 347; 346, identifier:list; 347, argument_list; 347, 348; 348, call; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:almnt_buffer; 351, identifier:values; 352, argument_list; 353, block; 353, 354; 354, for_statement; 354, 355; 354, 356; 354, 357; 355, identifier:almnt; 356, identifier:almnt_list; 357, block; 357, 358; 358, if_statement; 358, 359; 358, 364; 358, 370; 359, comparison_operator:==; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:almnt; 362, identifier:pe_which; 363, string:"first"; 364, block; 364, 365; 365, expression_statement; 365, 366; 366, yield; 366, 367; 367, tuple; 367, 368; 367, 369; 368, identifier:almnt; 369, None; 370, else_clause; 370, 371; 371, block; 371, 372; 372, expression_statement; 372, 373; 373, yield; 373, 374; 374, tuple; 374, 375; 374, 376; 375, None; 376, identifier:almnt; 377, if_statement; 377, 378; 377, 381; 378, comparison_operator:>; 378, 379; 378, 380; 379, identifier:ambiguous_pairing_counter; 380, integer:0; 381, block; 381, 382; 382, expression_statement; 382, 383; 383, call; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:warnings; 386, identifier:warn; 387, argument_list; 387, 388; 388, binary_operator:%; 388, 389; 388, 390; 389, string:"Mate pairing was ambiguous for %d records; mate key for first such record: %s."; 390, tuple; 390, 391; 390, 392; 391, identifier:ambiguous_pairing_counter; 392, call; 392, 393; 392, 394; 393, identifier:str; 394, argument_list; 394, 395; 395, identifier:ambiguous_pairing_first_occurance | def pair_SAM_alignments_with_buffer(
alignments,
max_buffer_size=30000000,
primary_only=False):
'''Iterate over SAM aligments with buffer, position-sorted paired-end
Args:
alignments (iterator of SAM/BAM alignments): the alignments to wrap
max_buffer_size (int): maxmal numer of alignments to keep in memory.
primary_only (bool): for each read, consider only the primary line
(SAM flag 0x900 = 0). The SAM specification requires one and only
one of those for each read.
Yields:
2-tuples with each pair of alignments.
'''
almnt_buffer = {}
ambiguous_pairing_counter = 0
for almnt in alignments:
if not almnt.paired_end:
raise ValueError(
"Sequence of paired-end alignments expected, but got single-end alignment.")
if almnt.pe_which == "unknown":
raise ValueError(
"Cannot process paired-end alignment found with 'unknown' 'pe_which' status.")
# FIXME: almnt.not_primary_alignment currently means secondary
if primary_only and (almnt.not_primary_alignment or almnt.supplementary):
continue
matekey = (
almnt.read.name,
"second" if almnt.pe_which == "first" else "first",
almnt.mate_start.chrom if almnt.mate_aligned else None,
almnt.mate_start.pos if almnt.mate_aligned else None,
almnt.iv.chrom if almnt.aligned else None,
almnt.iv.start if almnt.aligned else None,
-almnt.inferred_insert_size if almnt.aligned and almnt.mate_aligned else None)
if matekey in almnt_buffer:
if len(almnt_buffer[matekey]) == 1:
mate = almnt_buffer[matekey][0]
del almnt_buffer[matekey]
else:
mate = almnt_buffer[matekey].pop(0)
if ambiguous_pairing_counter == 0:
ambiguous_pairing_first_occurance = matekey
ambiguous_pairing_counter += 1
if almnt.pe_which == "first":
yield (almnt, mate)
else:
yield (mate, almnt)
else:
almntkey = (
almnt.read.name, almnt.pe_which,
almnt.iv.chrom if almnt.aligned else None,
almnt.iv.start if almnt.aligned else None,
almnt.mate_start.chrom if almnt.mate_aligned else None,
almnt.mate_start.pos if almnt.mate_aligned else None,
almnt.inferred_insert_size if almnt.aligned and almnt.mate_aligned else None)
if almntkey not in almnt_buffer:
almnt_buffer[almntkey] = [almnt]
else:
almnt_buffer[almntkey].append(almnt)
if len(almnt_buffer) > max_buffer_size:
raise ValueError(
"Maximum alignment buffer size exceeded while pairing SAM alignments.")
if len(almnt_buffer) > 0:
warnings.warn(
"Mate records missing for %d records; first such record: %s." %
(len(almnt_buffer), str(list(almnt_buffer.values())[0][0])))
for almnt_list in list(almnt_buffer.values()):
for almnt in almnt_list:
if almnt.pe_which == "first":
yield (almnt, None)
else:
yield (None, almnt)
if ambiguous_pairing_counter > 0:
warnings.warn(
"Mate pairing was ambiguous for %d records; mate key for first such record: %s." %
(ambiguous_pairing_counter, str(ambiguous_pairing_first_occurance))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:local_maxima; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:vector; 5, default_parameter; 5, 6; 5, 7; 6, identifier:min_distance; 7, integer:4; 8, default_parameter; 8, 9; 8, 10; 9, identifier:brd_mode; 10, string:"wrap"; 11, block; 11, 12; 11, 14; 11, 35; 11, 64; 11, 77; 11, 83; 11, 96; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:fits; 17, call; 17, 18; 17, 19; 18, identifier:gaussian_filter; 19, argument_list; 19, 20; 19, 31; 19, 32; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:numpy; 23, identifier:asarray; 24, argument_list; 24, 25; 24, 26; 25, identifier:vector; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:dtype; 28, attribute; 28, 29; 28, 30; 29, identifier:numpy; 30, identifier:float32; 31, float:1.; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:mode; 34, identifier:brd_mode; 35, for_statement; 35, 36; 35, 37; 35, 44; 36, identifier:ii; 37, call; 37, 38; 37, 39; 38, identifier:range; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, identifier:fits; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 55; 46, comparison_operator:==; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:fits; 49, identifier:ii; 50, subscript; 50, 51; 50, 52; 51, identifier:fits; 52, binary_operator:-; 52, 53; 52, 54; 53, identifier:ii; 54, integer:1; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 63; 58, subscript; 58, 59; 58, 60; 59, identifier:fits; 60, binary_operator:-; 60, 61; 60, 62; 61, identifier:ii; 62, integer:1; 63, float:0.0; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:maxfits; 67, call; 67, 68; 67, 69; 68, identifier:maximum_filter; 69, argument_list; 69, 70; 69, 71; 69, 74; 70, identifier:fits; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:size; 73, identifier:min_distance; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:mode; 76, identifier:brd_mode; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:maxima_mask; 80, comparison_operator:==; 80, 81; 80, 82; 81, identifier:fits; 82, identifier:maxfits; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:maximum; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:numpy; 89, identifier:transpose; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:maxima_mask; 94, identifier:nonzero; 95, argument_list; 96, return_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:numpy; 100, identifier:asarray; 101, argument_list; 101, 102; 102, identifier:maximum | def local_maxima(vector,min_distance = 4, brd_mode = "wrap"):
"""
Internal finder for local maxima .
Returns UNSORTED indices of maxima in input vector.
"""
fits = gaussian_filter(numpy.asarray(vector,dtype=numpy.float32),1., mode=brd_mode)
for ii in range(len(fits)):
if fits[ii] == fits[ii-1]:
fits[ii-1] = 0.0
maxfits = maximum_filter(fits, size=min_distance, mode=brd_mode)
maxima_mask = fits == maxfits
maximum = numpy.transpose(maxima_mask.nonzero())
return numpy.asarray(maximum) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:local_minima; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:vector; 5, default_parameter; 5, 6; 5, 7; 6, identifier:min_distance; 7, integer:4; 8, default_parameter; 8, 9; 8, 10; 9, identifier:brd_mode; 10, string:"wrap"; 11, block; 11, 12; 11, 14; 11, 35; 11, 68; 11, 81; 11, 87; 11, 100; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:fits; 17, call; 17, 18; 17, 19; 18, identifier:gaussian_filter; 19, argument_list; 19, 20; 19, 31; 19, 32; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:numpy; 23, identifier:asarray; 24, argument_list; 24, 25; 24, 26; 25, identifier:vector; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:dtype; 28, attribute; 28, 29; 28, 30; 29, identifier:numpy; 30, identifier:float32; 31, float:1.; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:mode; 34, identifier:brd_mode; 35, for_statement; 35, 36; 35, 37; 35, 44; 36, identifier:ii; 37, call; 37, 38; 37, 39; 38, identifier:range; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, identifier:fits; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 55; 46, comparison_operator:==; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:fits; 49, identifier:ii; 50, subscript; 50, 51; 50, 52; 51, identifier:fits; 52, binary_operator:-; 52, 53; 52, 54; 53, identifier:ii; 54, integer:1; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 63; 58, subscript; 58, 59; 58, 60; 59, identifier:fits; 60, binary_operator:-; 60, 61; 60, 62; 61, identifier:ii; 62, integer:1; 63, binary_operator:/; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:numpy; 66, identifier:pi; 67, float:2.0; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:minfits; 71, call; 71, 72; 71, 73; 72, identifier:minimum_filter; 73, argument_list; 73, 74; 73, 75; 73, 78; 74, identifier:fits; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:size; 77, identifier:min_distance; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:mode; 80, identifier:brd_mode; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:minima_mask; 84, comparison_operator:==; 84, 85; 84, 86; 85, identifier:fits; 86, identifier:minfits; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:minima; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:numpy; 93, identifier:transpose; 94, argument_list; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:minima_mask; 98, identifier:nonzero; 99, argument_list; 100, return_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:numpy; 104, identifier:asarray; 105, argument_list; 105, 106; 106, identifier:minima | def local_minima(vector,min_distance = 4, brd_mode = "wrap"):
"""
Internal finder for local minima .
Returns UNSORTED indices of minima in input vector.
"""
fits = gaussian_filter(numpy.asarray(vector,dtype=numpy.float32),1., mode=brd_mode)
for ii in range(len(fits)):
if fits[ii] == fits[ii-1]:
fits[ii-1] = numpy.pi/2.0
minfits = minimum_filter(fits, size=min_distance, mode=brd_mode)
minima_mask = fits == minfits
minima = numpy.transpose(minima_mask.nonzero())
return numpy.asarray(minima) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:find_valley_range; 3, parameters; 3, 4; 3, 5; 4, identifier:vector; 5, default_parameter; 5, 6; 5, 7; 6, identifier:min_distance; 7, integer:4; 8, block; 8, 9; 8, 11; 8, 12; 8, 13; 8, 17; 8, 26; 8, 35; 8, 79; 8, 209; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:mode; 16, string:"wrap"; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:minima; 20, call; 20, 21; 20, 22; 21, identifier:local_minima; 22, argument_list; 22, 23; 22, 24; 22, 25; 23, identifier:vector; 24, identifier:min_distance; 25, identifier:mode; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:maxima; 29, call; 29, 30; 29, 31; 30, identifier:local_maxima; 31, argument_list; 31, 32; 31, 33; 31, 34; 32, identifier:vector; 33, identifier:min_distance; 34, identifier:mode; 35, if_statement; 35, 36; 35, 45; 36, comparison_operator:>; 36, 37; 36, 41; 37, call; 37, 38; 37, 39; 38, identifier:len; 39, argument_list; 39, 40; 40, identifier:maxima; 41, call; 41, 42; 41, 43; 42, identifier:len; 43, argument_list; 43, 44; 44, identifier:minima; 45, block; 45, 46; 46, if_statement; 46, 47; 46, 59; 46, 68; 47, comparison_operator:>=; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 50; 49, identifier:vector; 50, subscript; 50, 51; 50, 52; 51, identifier:maxima; 52, integer:0; 53, subscript; 53, 54; 53, 55; 54, identifier:vector; 55, subscript; 55, 56; 55, 57; 56, identifier:maxima; 57, unary_operator:-; 57, 58; 58, integer:1; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:maxima; 63, subscript; 63, 64; 63, 65; 64, identifier:maxima; 65, slice; 65, 66; 65, 67; 66, integer:1; 67, colon; 68, else_clause; 68, 69; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:maxima; 73, subscript; 73, 74; 73, 75; 74, identifier:maxima; 75, slice; 75, 76; 75, 77; 76, colon; 77, unary_operator:-; 77, 78; 78, integer:1; 79, if_statement; 79, 80; 79, 89; 79, 180; 80, comparison_operator:==; 80, 81; 80, 85; 81, call; 81, 82; 81, 83; 82, identifier:len; 83, argument_list; 83, 84; 84, identifier:maxima; 85, call; 85, 86; 85, 87; 86, identifier:len; 87, argument_list; 87, 88; 88, identifier:minima; 89, block; 89, 90; 89, 134; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:valley_range; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:numpy; 96, identifier:asarray; 97, argument_list; 97, 98; 98, binary_operator:+; 98, 99; 98, 120; 99, list_comprehension; 99, 100; 99, 109; 100, binary_operator:-; 100, 101; 100, 106; 101, subscript; 101, 102; 101, 103; 102, identifier:minima; 103, binary_operator:+; 103, 104; 103, 105; 104, identifier:ii; 105, integer:1; 106, subscript; 106, 107; 106, 108; 107, identifier:minima; 108, identifier:ii; 109, for_in_clause; 109, 110; 109, 111; 110, identifier:ii; 111, call; 111, 112; 111, 113; 112, identifier:range; 113, argument_list; 113, 114; 114, binary_operator:-; 114, 115; 114, 119; 115, call; 115, 116; 115, 117; 116, identifier:len; 117, argument_list; 117, 118; 118, identifier:minima; 119, integer:1; 120, list:[len(vector)-minima[-1]+minima[0]]; 120, 121; 121, binary_operator:+; 121, 122; 121, 131; 122, binary_operator:-; 122, 123; 122, 127; 123, call; 123, 124; 123, 125; 124, identifier:len; 125, argument_list; 125, 126; 126, identifier:vector; 127, subscript; 127, 128; 127, 129; 128, identifier:minima; 129, unary_operator:-; 129, 130; 130, integer:1; 131, subscript; 131, 132; 131, 133; 132, identifier:minima; 133, integer:0; 134, if_statement; 134, 135; 134, 142; 134, 160; 135, comparison_operator:<; 135, 136; 135, 139; 136, subscript; 136, 137; 136, 138; 137, identifier:minima; 138, integer:0; 139, subscript; 139, 140; 139, 141; 140, identifier:maxima; 141, integer:0; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:minima; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:numpy; 149, identifier:asarray; 150, argument_list; 150, 151; 151, binary_operator:+; 151, 152; 151, 156; 152, call; 152, 153; 152, 154; 153, identifier:list; 154, argument_list; 154, 155; 155, identifier:minima; 156, list:[minima[0]]; 156, 157; 157, subscript; 157, 158; 157, 159; 158, identifier:minima; 159, integer:0; 160, else_clause; 160, 161; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:minima; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:numpy; 168, identifier:asarray; 169, argument_list; 169, 170; 170, binary_operator:+; 170, 171; 170, 175; 171, call; 171, 172; 171, 173; 172, identifier:list; 173, argument_list; 173, 174; 174, identifier:minima; 175, list:[minima[-1]]; 175, 176; 176, subscript; 176, 177; 176, 178; 177, identifier:minima; 178, unary_operator:-; 178, 179; 179, integer:1; 180, else_clause; 180, 181; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:valley_range; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:numpy; 188, identifier:asarray; 189, argument_list; 189, 190; 190, list_comprehension; 190, 191; 190, 200; 191, binary_operator:-; 191, 192; 191, 197; 192, subscript; 192, 193; 192, 194; 193, identifier:minima; 194, binary_operator:+; 194, 195; 194, 196; 195, identifier:ii; 196, integer:1; 197, subscript; 197, 198; 197, 199; 198, identifier:minima; 199, identifier:ii; 200, for_in_clause; 200, 201; 200, 202; 201, identifier:ii; 202, call; 202, 203; 202, 204; 203, identifier:range; 204, argument_list; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:len; 207, argument_list; 207, 208; 208, identifier:maxima; 209, return_statement; 209, 210; 210, expression_list; 210, 211; 210, 212; 210, 213; 211, identifier:maxima; 212, identifier:minima; 213, identifier:valley_range | def find_valley_range(vector, min_distance = 4):
"""
Internal finder peaks and valley ranges.
Returns UNSORTED indices of maxima in input vector.
Returns range of valleys before and after maximum
"""
# http://users.monash.edu.au/~dengs/resource/papers/icme08.pdf
# find min and max with mode = wrap
mode = "wrap"
minima = local_minima(vector,min_distance,mode)
maxima = local_maxima(vector,min_distance,mode)
if len(maxima)>len(minima):
if vector[maxima[0]] >= vector[maxima[-1]]:
maxima=maxima[1:]
else:
maxima=maxima[:-1]
if len(maxima)==len(minima):
valley_range = numpy.asarray([minima[ii+1] - minima[ii] for ii in range(len(minima)-1)] + [len(vector)-minima[-1]+minima[0]])
if minima[0] < maxima[0]:
minima = numpy.asarray(list(minima) + [minima[0]])
else:
minima = numpy.asarray(list(minima) + [minima[-1]])
else:
valley_range = numpy.asarray([minima[ii+1] - minima[ii] for ii in range(len(maxima))])
return maxima, minima, valley_range |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_snps; 3, parameters; 3, 4; 4, identifier:snps; 5, block; 5, 6; 5, 8; 5, 24; 5, 25; 5, 44; 5, 63; 5, 64; 5, 65; 5, 86; 5, 87; 5, 98; 5, 99; 5, 112; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:sorted_list; 11, call; 11, 12; 11, 13; 12, identifier:sorted; 13, argument_list; 13, 14; 13, 21; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, subscript; 16, 17; 16, 18; 17, identifier:snps; 18, string:"chrom"; 19, identifier:unique; 20, argument_list; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:key; 23, identifier:_natural_sort_key; 24, comment; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:in; 26, 27; 26, 28; 27, string:"PAR"; 28, identifier:sorted_list; 29, block; 29, 30; 29, 37; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:sorted_list; 34, identifier:remove; 35, argument_list; 35, 36; 36, string:"PAR"; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:sorted_list; 41, identifier:append; 42, argument_list; 42, 43; 43, string:"PAR"; 44, if_statement; 44, 45; 44, 48; 45, comparison_operator:in; 45, 46; 45, 47; 46, string:"MT"; 47, identifier:sorted_list; 48, block; 48, 49; 48, 56; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:sorted_list; 53, identifier:remove; 54, argument_list; 54, 55; 55, string:"MT"; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:sorted_list; 60, identifier:append; 61, argument_list; 61, 62; 62, string:"MT"; 63, comment; 64, comment; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:snps; 69, string:"chrom"; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:snps; 74, string:"chrom"; 75, identifier:astype; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:CategoricalDtype; 79, argument_list; 79, 80; 79, 83; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:categories; 82, identifier:sorted_list; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:ordered; 85, True; 86, comment; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:snps; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:snps; 93, identifier:sort_values; 94, argument_list; 94, 95; 95, list:["chrom", "pos"]; 95, 96; 95, 97; 96, string:"chrom"; 97, string:"pos"; 98, comment; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:snps; 103, string:"chrom"; 104, call; 104, 105; 104, 110; 105, attribute; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:snps; 108, string:"chrom"; 109, identifier:astype; 110, argument_list; 110, 111; 111, identifier:object; 112, return_statement; 112, 113; 113, identifier:snps | def sort_snps(snps):
""" Sort SNPs based on ordered chromosome list and position. """
sorted_list = sorted(snps["chrom"].unique(), key=_natural_sort_key)
# move PAR and MT to the end of the dataframe
if "PAR" in sorted_list:
sorted_list.remove("PAR")
sorted_list.append("PAR")
if "MT" in sorted_list:
sorted_list.remove("MT")
sorted_list.append("MT")
# convert chrom column to category for sorting
# https://stackoverflow.com/a/26707444
snps["chrom"] = snps["chrom"].astype(
CategoricalDtype(categories=sorted_list, ordered=True)
)
# sort based on ordered chromosome list and position
snps = snps.sort_values(["chrom", "pos"])
# convert chromosome back to object
snps["chrom"] = snps["chrom"].astype(object)
return snps |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_genetic_map_HapMapII_GRCh37; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 30; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, comparison_operator:is; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_genetic_map_HapMapII_GRCh37; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_genetic_map_HapMapII_GRCh37; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_load_genetic_map; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_get_path_genetic_map_HapMapII_GRCh37; 29, argument_list; 30, return_statement; 30, 31; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_genetic_map_HapMapII_GRCh37 | def get_genetic_map_HapMapII_GRCh37(self):
""" Get International HapMap Consortium HapMap Phase II genetic map for Build 37.
Returns
-------
dict
dict of pandas.DataFrame HapMapII genetic maps if loading was successful, else None
"""
if self._genetic_map_HapMapII_GRCh37 is None:
self._genetic_map_HapMapII_GRCh37 = self._load_genetic_map(
self._get_path_genetic_map_HapMapII_GRCh37()
)
return self._genetic_map_HapMapII_GRCh37 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:seperate_symbols; 3, parameters; 3, 4; 4, identifier:func; 5, block; 5, 6; 5, 8; 5, 12; 5, 16; 5, 88; 5, 132; 5, 146; 5, 160; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:params; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:vars; 15, list:[]; 16, for_statement; 16, 17; 16, 18; 16, 21; 17, identifier:symbol; 18, attribute; 18, 19; 18, 20; 19, identifier:func; 20, identifier:free_symbols; 21, block; 21, 22; 21, 34; 22, if_statement; 22, 23; 22, 31; 23, not_operator; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:isidentifier; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:str; 29, argument_list; 29, 30; 30, identifier:symbol; 31, block; 31, 32; 31, 33; 32, continue_statement; 33, comment; 34, if_statement; 34, 35; 34, 40; 34, 48; 34, 57; 34, 73; 35, call; 35, 36; 35, 37; 36, identifier:isinstance; 37, argument_list; 37, 38; 37, 39; 38, identifier:symbol; 39, identifier:Parameter; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:params; 45, identifier:append; 46, argument_list; 46, 47; 47, identifier:symbol; 48, elif_clause; 48, 49; 48, 54; 48, 55; 49, call; 49, 50; 49, 51; 50, identifier:isinstance; 51, argument_list; 51, 52; 51, 53; 52, identifier:symbol; 53, identifier:Idx; 54, comment; 55, block; 55, 56; 56, pass_statement; 57, elif_clause; 57, 58; 57, 65; 58, call; 58, 59; 58, 60; 59, identifier:isinstance; 60, argument_list; 60, 61; 60, 62; 61, identifier:symbol; 62, tuple; 62, 63; 62, 64; 63, identifier:MatrixExpr; 64, identifier:Expr; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:vars; 70, identifier:append; 71, argument_list; 71, 72; 72, identifier:symbol; 73, else_clause; 73, 74; 74, block; 74, 75; 75, raise_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:TypeError; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, string:'model contains an unknown symbol type, {}'; 82, identifier:format; 83, argument_list; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:type; 86, argument_list; 86, 87; 87, identifier:symbol; 88, for_statement; 88, 89; 88, 90; 88, 98; 88, 99; 88, 100; 88, 101; 88, 102; 88, 103; 89, identifier:der; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:func; 93, identifier:atoms; 94, argument_list; 94, 95; 95, attribute; 95, 96; 95, 97; 96, identifier:sympy; 97, identifier:Derivative; 98, comment; 99, comment; 100, comment; 101, comment; 102, comment; 103, block; 103, 104; 104, if_statement; 104, 105; 104, 124; 105, boolean_operator:and; 105, 106; 105, 111; 106, comparison_operator:in; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:der; 109, identifier:expr; 110, identifier:vars; 111, call; 111, 112; 111, 113; 112, identifier:all; 113, generator_expression; 113, 114; 113, 119; 114, call; 114, 115; 114, 116; 115, identifier:isinstance; 116, argument_list; 116, 117; 116, 118; 117, identifier:s; 118, identifier:Parameter; 119, for_in_clause; 119, 120; 119, 121; 120, identifier:s; 121, attribute; 121, 122; 121, 123; 122, identifier:der; 123, identifier:variables; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:vars; 129, identifier:append; 130, argument_list; 130, 131; 131, identifier:der; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:params; 136, identifier:sort; 137, argument_list; 137, 138; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:key; 140, lambda; 140, 141; 140, 143; 141, lambda_parameters; 141, 142; 142, identifier:symbol; 143, attribute; 143, 144; 143, 145; 144, identifier:symbol; 145, identifier:name; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:vars; 150, identifier:sort; 151, argument_list; 151, 152; 152, keyword_argument; 152, 153; 152, 154; 153, identifier:key; 154, lambda; 154, 155; 154, 157; 155, lambda_parameters; 155, 156; 156, identifier:symbol; 157, attribute; 157, 158; 157, 159; 158, identifier:symbol; 159, identifier:name; 160, return_statement; 160, 161; 161, expression_list; 161, 162; 161, 163; 162, identifier:vars; 163, identifier:params | def seperate_symbols(func):
"""
Seperate the symbols in symbolic function func. Return them in alphabetical
order.
:param func: scipy symbolic function.
:return: (vars, params), a tuple of all variables and parameters, each
sorted in alphabetical order.
:raises TypeError: only symfit Variable and Parameter are allowed, not sympy
Symbols.
"""
params = []
vars = []
for symbol in func.free_symbols:
if not isidentifier(str(symbol)):
continue # E.g. Indexed objects might print to A[i, j]
if isinstance(symbol, Parameter):
params.append(symbol)
elif isinstance(symbol, Idx):
# Idx objects are not seen as parameters or vars.
pass
elif isinstance(symbol, (MatrixExpr, Expr)):
vars.append(symbol)
else:
raise TypeError('model contains an unknown symbol type, {}'.format(type(symbol)))
for der in func.atoms(sympy.Derivative):
# Used by jacobians and hessians, where derivatives are treated as
# Variables. This way of writing it is purposefully discriminatory
# against derivatives wrt variables, since such derivatives should be
# performed explicitly in the case of jacs/hess, and are treated
# differently in the case of ODEModels.
if der.expr in vars and all(isinstance(s, Parameter) for s in der.variables):
vars.append(der)
params.sort(key=lambda symbol: symbol.name)
vars.sort(key=lambda symbol: symbol.name)
return vars, params |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:name; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 29; 5, 52; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:base_str; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, string:'d{}{}_'; 14, identifier:format; 15, argument_list; 15, 16; 15, 26; 16, conditional_expression:if; 16, 17; 16, 20; 16, 25; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:derivative_count; 20, comparison_operator:>; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:derivative_count; 24, integer:1; 25, string:''; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:expr; 29, for_statement; 29, 30; 29, 33; 29, 36; 30, pattern_list; 30, 31; 30, 32; 31, identifier:var; 32, identifier:count; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:variable_count; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, augmented_assignment:+=; 38, 39; 38, 40; 39, identifier:base_str; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, string:'d{}{}'; 43, identifier:format; 44, argument_list; 44, 45; 44, 46; 45, identifier:var; 46, conditional_expression:if; 46, 47; 46, 48; 46, 51; 47, identifier:count; 48, comparison_operator:>; 48, 49; 48, 50; 49, identifier:count; 50, integer:1; 51, string:''; 52, return_statement; 52, 53; 53, identifier:base_str | def name(self):
"""
Save name which can be used for alphabetic sorting and can be turned
into a kwarg.
"""
base_str = 'd{}{}_'.format(self.derivative_count if
self.derivative_count > 1 else '', self.expr)
for var, count in self.variable_count:
base_str += 'd{}{}'.format(var, count if count > 1 else '')
return base_str |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_init_from_dict; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:model_dict; 6, block; 6, 7; 6, 9; 6, 18; 6, 45; 6, 46; 6, 47; 6, 59; 6, 74; 6, 92; 6, 111; 6, 112; 6, 134; 6, 150; 6, 192; 6, 193; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:sort_func; 12, lambda; 12, 13; 12, 15; 13, lambda_parameters; 13, 14; 14, identifier:symbol; 15, attribute; 15, 16; 15, 17; 16, identifier:symbol; 17, identifier:name; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:model_dict; 23, call; 23, 24; 23, 25; 24, identifier:OrderedDict; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:sorted; 28, argument_list; 28, 29; 28, 34; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:model_dict; 32, identifier:items; 33, argument_list; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:key; 36, lambda; 36, 37; 36, 39; 37, lambda_parameters; 37, 38; 38, identifier:i; 39, call; 39, 40; 39, 41; 40, identifier:sort_func; 41, argument_list; 41, 42; 42, subscript; 42, 43; 42, 44; 43, identifier:i; 44, integer:0; 45, comment; 46, comment; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:ordered; 50, call; 50, 51; 50, 52; 51, identifier:list; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:toposort; 55, argument_list; 55, 56; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:connectivity_mapping; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:independent; 62, call; 62, 63; 62, 64; 63, identifier:sorted; 64, argument_list; 64, 65; 64, 71; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:ordered; 68, identifier:pop; 69, argument_list; 69, 70; 70, integer:0; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:key; 73, identifier:sort_func; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:dependent_vars; 79, call; 79, 80; 79, 81; 80, identifier:sorted; 81, argument_list; 81, 82; 81, 89; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:ordered; 85, identifier:pop; 86, argument_list; 86, 87; 87, unary_operator:-; 87, 88; 88, integer:1; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:key; 91, identifier:sort_func; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:interdependent_vars; 97, call; 97, 98; 97, 99; 98, identifier:sorted; 99, argument_list; 99, 100; 99, 108; 100, list_comprehension; 100, 101; 100, 102; 100, 105; 101, identifier:item; 102, for_in_clause; 102, 103; 102, 104; 103, identifier:items; 104, identifier:ordered; 105, for_in_clause; 105, 106; 105, 107; 106, identifier:item; 107, identifier:items; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:key; 110, identifier:sort_func; 111, comment; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:independent_vars; 117, list_comprehension; 117, 118; 117, 119; 117, 122; 118, identifier:s; 119, for_in_clause; 119, 120; 119, 121; 120, identifier:s; 121, identifier:independent; 122, if_clause; 122, 123; 123, boolean_operator:and; 123, 124; 123, 130; 124, not_operator; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:isinstance; 127, argument_list; 127, 128; 127, 129; 128, identifier:s; 129, identifier:Parameter; 130, not_operator; 130, 131; 131, comparison_operator:in; 131, 132; 131, 133; 132, identifier:s; 133, identifier:self; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:params; 139, list_comprehension; 139, 140; 139, 141; 139, 144; 140, identifier:s; 141, for_in_clause; 141, 142; 141, 143; 142, identifier:s; 143, identifier:independent; 144, if_clause; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:isinstance; 147, argument_list; 147, 148; 147, 149; 148, identifier:s; 149, identifier:Parameter; 150, try_statement; 150, 151; 150, 182; 151, block; 151, 152; 151, 167; 152, assert_statement; 152, 153; 153, not_operator; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:any; 156, generator_expression; 156, 157; 156, 162; 157, call; 157, 158; 157, 159; 158, identifier:isinstance; 159, argument_list; 159, 160; 159, 161; 160, identifier:var; 161, identifier:Parameter; 162, for_in_clause; 162, 163; 162, 164; 163, identifier:var; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:dependent_vars; 167, assert_statement; 167, 168; 168, not_operator; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:any; 171, generator_expression; 171, 172; 171, 177; 172, call; 172, 173; 172, 174; 173, identifier:isinstance; 174, argument_list; 174, 175; 174, 176; 175, identifier:var; 176, identifier:Parameter; 177, for_in_clause; 177, 178; 177, 179; 178, identifier:var; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:interdependent_vars; 182, except_clause; 182, 183; 182, 184; 183, identifier:AssertionError; 184, block; 184, 185; 185, raise_statement; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:ModelError; 188, argument_list; 188, 189; 189, concatenated_string; 189, 190; 189, 191; 190, string:'`Parameter`\'s can not feature in the role '; 191, string:'of `Variable`'; 192, comment; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:sigmas; 198, dictionary_comprehension; 198, 199; 198, 214; 199, pair; 199, 200; 199, 201; 200, identifier:var; 201, call; 201, 202; 201, 203; 202, identifier:Variable; 203, argument_list; 203, 204; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:name; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, string:'sigma_{}'; 209, identifier:format; 210, argument_list; 210, 211; 211, attribute; 211, 212; 211, 213; 212, identifier:var; 213, identifier:name; 214, for_in_clause; 214, 215; 214, 216; 215, identifier:var; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:dependent_vars | def _init_from_dict(self, model_dict):
"""
Initiate self from a model_dict to make sure attributes such as vars, params are available.
Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters.
Finally it creates a signature for this model so it can be called nicely. This signature only contains
independent vars and params, as one would expect.
:param model_dict: dict of (dependent_var, expression) pairs.
"""
sort_func = lambda symbol: symbol.name
self.model_dict = OrderedDict(sorted(model_dict.items(),
key=lambda i: sort_func(i[0])))
# Everything at the bottom of the toposort is independent, at the top
# dependent, and the rest interdependent.
ordered = list(toposort(self.connectivity_mapping))
independent = sorted(ordered.pop(0), key=sort_func)
self.dependent_vars = sorted(ordered.pop(-1), key=sort_func)
self.interdependent_vars = sorted(
[item for items in ordered for item in items],
key=sort_func
)
# `independent` contains both params and vars, needs to be separated
self.independent_vars = [s for s in independent if
not isinstance(s, Parameter) and not s in self]
self.params = [s for s in independent if isinstance(s, Parameter)]
try:
assert not any(isinstance(var, Parameter)
for var in self.dependent_vars)
assert not any(isinstance(var, Parameter)
for var in self.interdependent_vars)
except AssertionError:
raise ModelError('`Parameter`\'s can not feature in the role '
'of `Variable`')
# Make Variable object corresponding to each depedent var.
self.sigmas = {var: Variable(name='sigma_{}'.format(var.name))
for var in self.dependent_vars} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:function_dict; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 47; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:func_dict; 11, call; 11, 12; 11, 13; 12, identifier:OrderedDict; 13, argument_list; 14, for_statement; 14, 15; 14, 18; 14, 25; 15, pattern_list; 15, 16; 15, 17; 16, identifier:var; 17, identifier:func; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:vars_as_functions; 23, identifier:items; 24, argument_list; 25, block; 25, 26; 25, 41; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:expr; 29, call; 29, 30; 29, 37; 30, attribute; 30, 31; 30, 36; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:model_dict; 35, identifier:var; 36, identifier:xreplace; 37, argument_list; 37, 38; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:vars_as_functions; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:func_dict; 45, identifier:func; 46, identifier:expr; 47, return_statement; 47, 48; 48, identifier:func_dict | def function_dict(self):
"""
Equivalent to ``self.model_dict``, but with all variables replaced by
functions if applicable. Sorted by the evaluation order according to
``self.ordered_symbols``, not alphabetical like ``self.model_dict``!
"""
func_dict = OrderedDict()
for var, func in self.vars_as_functions.items():
expr = self.model_dict[var].xreplace(self.vars_as_functions)
func_dict[func] = expr
return func_dict |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:flatten_; 3, parameters; 3, 4; 4, identifier:structure; 5, block; 5, 6; 5, 8; 5, 50; 5, 79; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argument_list; 11, 12; 11, 13; 12, identifier:structure; 13, identifier:dict; 14, block; 14, 15; 15, if_statement; 15, 16; 15, 17; 15, 43; 16, identifier:structure; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:structure; 21, subscript; 21, 22; 21, 42; 22, call; 22, 23; 22, 24; 23, identifier:zip; 24, argument_list; 24, 25; 25, list_splat; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:sorted; 28, argument_list; 28, 29; 28, 34; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:structure; 32, identifier:items; 33, argument_list; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:key; 36, lambda; 36, 37; 36, 39; 37, lambda_parameters; 37, 38; 38, identifier:x; 39, subscript; 39, 40; 39, 41; 40, identifier:x; 41, integer:0; 42, integer:1; 43, else_clause; 43, 44; 43, 45; 44, comment; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:structure; 49, tuple; 50, if_statement; 50, 51; 50, 58; 51, call; 51, 52; 51, 53; 52, identifier:isinstance; 53, argument_list; 53, 54; 53, 55; 54, identifier:structure; 55, tuple; 55, 56; 55, 57; 56, identifier:tuple; 57, identifier:list; 58, block; 58, 59; 58, 63; 58, 74; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:result; 62, list:[]; 63, for_statement; 63, 64; 63, 65; 63, 66; 64, identifier:element; 65, identifier:structure; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, augmented_assignment:+=; 68, 69; 68, 70; 69, identifier:result; 70, call; 70, 71; 70, 72; 71, identifier:flatten_; 72, argument_list; 72, 73; 73, identifier:element; 74, return_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:tuple; 77, argument_list; 77, 78; 78, identifier:result; 79, return_statement; 79, 80; 80, tuple; 80, 81; 81, identifier:structure | def flatten_(structure):
"""Combine all leaves of a nested structure into a tuple.
The nested structure can consist of any combination of tuples, lists, and
dicts. Dictionary keys will be discarded but values will ordered by the
sorting of the keys.
Args:
structure: Nested structure.
Returns:
Flat tuple.
"""
if isinstance(structure, dict):
if structure:
structure = zip(*sorted(structure.items(), key=lambda x: x[0]))[1]
else:
# Zip doesn't work on an the items of an empty dictionary.
structure = ()
if isinstance(structure, (tuple, list)):
result = []
for element in structure:
result += flatten_(element)
return tuple(result)
return (structure,) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:set_python; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:value; 6, block; 6, 7; 6, 9; 6, 30; 6, 36; 6, 42; 6, 61; 6, 70; 6, 88; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 14; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:multiselect; 14, block; 14, 15; 15, if_statement; 15, 16; 15, 24; 16, boolean_operator:and; 16, 17; 16, 18; 17, identifier:value; 18, not_operator; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:isinstance; 21, argument_list; 21, 22; 21, 23; 22, identifier:value; 23, identifier:list; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:value; 28, list:[value]; 28, 29; 29, identifier:value; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:value; 33, boolean_operator:or; 33, 34; 33, 35; 34, identifier:value; 35, list:[]; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:records; 39, call; 39, 40; 39, 41; 40, identifier:SortedDict; 41, argument_list; 42, for_statement; 42, 43; 42, 44; 42, 45; 43, identifier:record; 44, identifier:value; 45, block; 45, 46; 45, 53; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:validate_value; 51, argument_list; 51, 52; 52, identifier:record; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 60; 55, subscript; 55, 56; 55, 57; 56, identifier:records; 57, attribute; 57, 58; 57, 59; 58, identifier:record; 59, identifier:id; 60, identifier:record; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:return_value; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:_set; 68, argument_list; 68, 69; 69, identifier:records; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 83; 72, subscript; 72, 73; 72, 80; 73, subscript; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:record; 78, identifier:_raw; 79, string:'values'; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:id; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:get_swimlane; 87, argument_list; 88, return_statement; 88, 89; 89, identifier:return_value | def set_python(self, value):
"""Expect list of record instances, convert to a SortedDict for internal representation"""
if not self.multiselect:
if value and not isinstance(value, list):
value = [value]
value = value or []
records = SortedDict()
for record in value:
self.validate_value(record)
records[record.id] = record
return_value = self._set(records)
self.record._raw['values'][self.id] = self.get_swimlane()
return return_value |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:get_filetypes; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:filelist; 5, default_parameter; 5, 6; 5, 7; 6, identifier:path; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:size; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:os; 13, identifier:path; 14, identifier:getsize; 15, block; 15, 16; 15, 18; 15, 28; 15, 29; 15, 36; 15, 115; 15, 116; 15, 127; 15, 155; 16, expression_statement; 16, 17; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:path; 21, boolean_operator:or; 21, 22; 21, 23; 22, identifier:path; 23, parenthesized_expression; 23, 24; 24, lambda; 24, 25; 24, 27; 25, lambda_parameters; 25, 26; 26, identifier:_; 27, identifier:_; 28, comment; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:histo; 32, call; 32, 33; 32, 34; 33, identifier:defaultdict; 34, argument_list; 34, 35; 35, identifier:int; 36, for_statement; 36, 37; 36, 38; 36, 39; 37, identifier:entry; 38, identifier:filelist; 39, block; 39, 40; 39, 65; 39, 106; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:ext; 43, call; 43, 44; 43, 64; 44, attribute; 44, 45; 44, 63; 45, call; 45, 46; 45, 61; 46, attribute; 46, 47; 46, 60; 47, subscript; 47, 48; 47, 59; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:os; 52, identifier:path; 53, identifier:splitext; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 57; 56, identifier:path; 57, argument_list; 57, 58; 58, identifier:entry; 59, integer:1; 60, identifier:lstrip; 61, argument_list; 61, 62; 62, string:'.'; 63, identifier:lower; 64, argument_list; 65, if_statement; 65, 66; 65, 83; 65, 88; 65, 97; 66, boolean_operator:and; 66, 67; 66, 74; 67, boolean_operator:and; 67, 68; 67, 69; 68, identifier:ext; 69, comparison_operator:==; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:ext; 72, integer:0; 73, string:'r'; 74, call; 74, 75; 74, 82; 75, attribute; 75, 76; 75, 81; 76, subscript; 76, 77; 76, 78; 77, identifier:ext; 78, slice; 78, 79; 78, 80; 79, integer:1; 80, colon; 81, identifier:isdigit; 82, argument_list; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:ext; 87, string:"rar"; 88, elif_clause; 88, 89; 88, 92; 89, comparison_operator:==; 89, 90; 89, 91; 90, identifier:ext; 91, string:"jpeg"; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:ext; 96, string:"jpg"; 97, elif_clause; 97, 98; 97, 101; 98, comparison_operator:==; 98, 99; 98, 100; 99, identifier:ext; 100, string:"mpeg"; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:ext; 105, string:"mpg"; 106, expression_statement; 106, 107; 107, augmented_assignment:+=; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:histo; 110, identifier:ext; 111, call; 111, 112; 111, 113; 112, identifier:size; 113, argument_list; 113, 114; 114, identifier:entry; 115, comment; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:total; 119, call; 119, 120; 119, 121; 120, identifier:sum; 121, argument_list; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:histo; 125, identifier:values; 126, argument_list; 127, if_statement; 127, 128; 127, 129; 128, identifier:total; 129, block; 129, 130; 130, for_statement; 130, 131; 130, 134; 130, 139; 131, pattern_list; 131, 132; 131, 133; 132, identifier:ext; 133, identifier:val; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:histo; 137, identifier:items; 138, argument_list; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 145; 142, subscript; 142, 143; 142, 144; 143, identifier:histo; 144, identifier:ext; 145, call; 145, 146; 145, 147; 146, identifier:int; 147, argument_list; 147, 148; 148, binary_operator:+; 148, 149; 148, 154; 149, binary_operator:/; 149, 150; 149, 153; 150, binary_operator:*; 150, 151; 150, 152; 151, identifier:val; 152, float:100.0; 153, identifier:total; 154, float:.499; 155, return_statement; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:sorted; 158, argument_list; 158, 159; 158, 172; 159, call; 159, 160; 159, 161; 160, identifier:zip; 161, argument_list; 161, 162; 161, 167; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:histo; 165, identifier:values; 166, argument_list; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:histo; 170, identifier:keys; 171, argument_list; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:reverse; 174, True | def get_filetypes(filelist, path=None, size=os.path.getsize):
""" Get a sorted list of file types and their weight in percent
from an iterable of file names.
@return: List of weighted file extensions (no '.'), sorted in descending order
@rtype: list of (weight, filetype)
"""
path = path or (lambda _: _)
# Get total size for each file extension
histo = defaultdict(int)
for entry in filelist:
ext = os.path.splitext(path(entry))[1].lstrip('.').lower()
if ext and ext[0] == 'r' and ext[1:].isdigit():
ext = "rar"
elif ext == "jpeg":
ext = "jpg"
elif ext == "mpeg":
ext = "mpg"
histo[ext] += size(entry)
# Normalize values to integer percent
total = sum(histo.values())
if total:
for ext, val in histo.items():
histo[ext] = int(val * 100.0 / total + .499)
return sorted(zip(histo.values(), histo.keys()), reverse=True) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:validate_sort_fields; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 5, 34; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:sort_fields; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, string:','; 14, identifier:join; 15, argument_list; 15, 16; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:options; 20, identifier:sort_fields; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:==; 22, 23; 22, 24; 23, identifier:sort_fields; 24, string:'*'; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:sort_fields; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:get_output_fields; 33, argument_list; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:formatting; 38, identifier:validate_sort_fields; 39, argument_list; 39, 40; 40, boolean_operator:or; 40, 41; 40, 42; 41, identifier:sort_fields; 42, attribute; 42, 43; 42, 44; 43, identifier:config; 44, identifier:sort_fields | def validate_sort_fields(self):
""" Take care of sorting.
"""
sort_fields = ','.join(self.options.sort_fields)
if sort_fields == '*':
sort_fields = self.get_output_fields()
return formatting.validate_sort_fields(sort_fields or config.sort_fields) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:validate_sort_fields; 3, parameters; 3, 4; 4, identifier:sort_fields; 5, block; 5, 6; 5, 8; 5, 9; 5, 15; 5, 47; 5, 48; 5, 58; 5, 84; 5, 85; 5, 100; 5, 101; 5, 175; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:descending; 12, call; 12, 13; 12, 14; 13, identifier:set; 14, argument_list; 15, function_definition; 15, 16; 15, 17; 15, 19; 16, function_name:sort_order_filter; 17, parameters; 17, 18; 18, identifier:name; 19, block; 19, 20; 19, 22; 19, 45; 20, expression_statement; 20, 21; 21, string:"Helper to remove flag and memoize sort order"; 22, if_statement; 22, 23; 22, 29; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:name; 26, identifier:startswith; 27, argument_list; 27, 28; 28, string:'-'; 29, block; 29, 30; 29, 38; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:name; 33, subscript; 33, 34; 33, 35; 34, identifier:name; 35, slice; 35, 36; 35, 37; 36, integer:1; 37, colon; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:descending; 42, identifier:add; 43, argument_list; 43, 44; 44, identifier:name; 45, return_statement; 45, 46; 46, identifier:name; 47, comment; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:sort_fields; 51, call; 51, 52; 51, 53; 52, identifier:validate_field_list; 53, argument_list; 53, 54; 53, 55; 54, identifier:sort_fields; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:name_filter; 57, identifier:sort_order_filter; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:log; 62, identifier:debug; 63, argument_list; 63, 64; 64, binary_operator:%; 64, 65; 64, 66; 65, string:"Sorting order is: %s"; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, string:", "; 69, identifier:join; 70, argument_list; 70, 71; 71, list_comprehension; 71, 72; 71, 81; 72, binary_operator:+; 72, 73; 72, 80; 73, parenthesized_expression; 73, 74; 74, conditional_expression:if; 74, 75; 74, 76; 74, 79; 75, string:'-'; 76, comparison_operator:in; 76, 77; 76, 78; 77, identifier:i; 78, identifier:descending; 79, string:''; 80, identifier:i; 81, for_in_clause; 81, 82; 81, 83; 82, identifier:i; 83, identifier:sort_fields; 84, comment; 85, if_statement; 85, 86; 85, 88; 86, not_operator; 86, 87; 87, identifier:descending; 88, block; 88, 89; 89, return_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:operator; 93, identifier:attrgetter; 94, argument_list; 94, 95; 95, list_splat; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:tuple; 98, argument_list; 98, 99; 99, identifier:sort_fields; 100, comment; 101, class_definition; 101, 102; 101, 103; 101, 105; 102, identifier:Key; 103, argument_list; 103, 104; 104, identifier:object; 105, block; 105, 106; 105, 108; 105, 124; 106, expression_statement; 106, 107; 107, string:"Complex sort order key"; 108, function_definition; 108, 109; 108, 110; 108, 115; 109, function_name:__init__; 110, parameters; 110, 111; 110, 112; 110, 113; 111, identifier:self; 112, identifier:obj; 113, list_splat_pattern; 113, 114; 114, identifier:args; 115, block; 115, 116; 115, 118; 116, expression_statement; 116, 117; 117, string:"Remember object to be compared"; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:obj; 123, identifier:obj; 124, function_definition; 124, 125; 124, 126; 124, 129; 125, function_name:__lt__; 126, parameters; 126, 127; 126, 128; 127, identifier:self; 128, identifier:other; 129, block; 129, 130; 129, 132; 129, 173; 130, expression_statement; 130, 131; 131, string:"Compare to other key"; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:field; 134, identifier:sort_fields; 135, block; 135, 136; 135, 156; 135, 162; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 141; 138, pattern_list; 138, 139; 138, 140; 139, identifier:lhs; 140, identifier:rhs; 141, expression_list; 141, 142; 141, 149; 142, call; 142, 143; 142, 144; 143, identifier:getattr; 144, argument_list; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:obj; 148, identifier:field; 149, call; 149, 150; 149, 151; 150, identifier:getattr; 151, argument_list; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:other; 154, identifier:obj; 155, identifier:field; 156, if_statement; 156, 157; 156, 160; 157, comparison_operator:==; 157, 158; 157, 159; 158, identifier:lhs; 159, identifier:rhs; 160, block; 160, 161; 161, continue_statement; 162, return_statement; 162, 163; 163, conditional_expression:if; 163, 164; 163, 167; 163, 170; 164, comparison_operator:<; 164, 165; 164, 166; 165, identifier:rhs; 166, identifier:lhs; 167, comparison_operator:in; 167, 168; 167, 169; 168, identifier:field; 169, identifier:descending; 170, comparison_operator:<; 170, 171; 170, 172; 171, identifier:lhs; 172, identifier:rhs; 173, return_statement; 173, 174; 174, False; 175, return_statement; 175, 176; 176, identifier:Key | def validate_sort_fields(sort_fields):
""" Make sure the fields in the given list exist, and return sorting key.
If field names are prefixed with '-', sort order is reversed for that field (descending).
"""
# Allow descending order per field by prefixing with '-'
descending = set()
def sort_order_filter(name):
"Helper to remove flag and memoize sort order"
if name.startswith('-'):
name = name[1:]
descending.add(name)
return name
# Split and validate field list
sort_fields = validate_field_list(sort_fields, name_filter=sort_order_filter)
log.debug("Sorting order is: %s" % ", ".join([('-' if i in descending else '') + i
for i in sort_fields]))
# No descending fields?
if not descending:
return operator.attrgetter(*tuple(sort_fields))
# Need to provide complex key
class Key(object):
"Complex sort order key"
def __init__(self, obj, *args):
"Remember object to be compared"
self.obj = obj
def __lt__(self, other):
"Compare to other key"
for field in sort_fields:
lhs, rhs = getattr(self.obj, field), getattr(other.obj, field)
if lhs == rhs:
continue
return rhs < lhs if field in descending else lhs < rhs
return False
return Key |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:load_data_source; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 12; 3, 17; 4, identifier:local_path; 5, identifier:remote_source_list; 6, identifier:open_method; 7, default_parameter; 7, 8; 7, 9; 8, identifier:open_method_kwargs; 9, call; 9, 10; 9, 11; 10, identifier:dict; 11, argument_list; 12, default_parameter; 12, 13; 12, 14; 13, identifier:remote_kwargs; 14, call; 14, 15; 14, 16; 15, identifier:dict; 16, argument_list; 17, default_parameter; 17, 18; 17, 19; 18, identifier:verbose; 19, True; 20, block; 20, 21; 20, 23; 20, 151; 21, expression_statement; 21, 22; 22, string:'''Flexible data retreiver to download and cache the data files locally.
Usage example (this makes a local copy of the ozone data file):
:Example:
.. code-block:: python
from climlab.utils.data_source import load_data_source
from xarray import open_dataset
ozonename = 'apeozone_cam3_5_54.nc'
ozonepath = 'http://thredds.atmos.albany.edu:8080/thredds/fileServer/CLIMLAB/ozone/' + ozonename
data, path = load_data_source(local_path=ozonename,
remote_source_list=[ozonepath],
open_method=open_dataset)
print(data)
The order of operations is
1. Try to read the data directly from ``local_path``
2. If the file doesn't exist then iterate through ``remote_source_list``.
Try to download and save the file to ``local_path`` using http request
If that works then open the data from ``local_path``.
3. As a last resort, try to read the data remotely from URLs in ``remote_source_list``
In all cases the file is opened and read by the user-supplied ``open_method``
(e.g. ``xarray.open_dataset``), with additional keyword arguments supplied
as a dictionary through ``open_method_kwargs``.
These are passed straight through to ``open_method``.
Additional keyword arguments in ``remote_kwargs``
are only passed to ``open_method`` in option 3 above
(remote access, e.g. through OpenDAP)
Quiet all output by passing ``verbose=False``.
Returns:
- ``data`` is the data object returned by the successful call to ``open_method``
- ``path`` is the path that resulted in a successful call to ``open_method``.
'''; 23, try_statement; 23, 24; 23, 51; 23, 52; 24, block; 24, 25; 24, 29; 24, 38; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:path; 28, identifier:local_path; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:data; 32, call; 32, 33; 32, 34; 33, identifier:open_method; 34, argument_list; 34, 35; 34, 36; 35, identifier:path; 36, dictionary_splat; 36, 37; 37, identifier:open_method_kwargs; 38, if_statement; 38, 39; 38, 40; 39, identifier:verbose; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:print; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, string:'Opened data from {}'; 48, identifier:format; 49, argument_list; 49, 50; 50, identifier:path; 51, comment; 52, except_clause; 52, 53; 52, 54; 52, 55; 52, 56; 53, identifier:IOError; 54, comment; 55, comment; 56, block; 56, 57; 57, for_statement; 57, 58; 57, 59; 57, 60; 57, 98; 58, identifier:source; 59, identifier:remote_source_list; 60, block; 60, 61; 61, try_statement; 61, 62; 61, 94; 62, block; 62, 63; 62, 71; 62, 80; 62, 93; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:response; 66, call; 66, 67; 66, 68; 67, identifier:_download_and_cache; 68, argument_list; 68, 69; 68, 70; 69, identifier:source; 70, identifier:local_path; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:data; 74, call; 74, 75; 74, 76; 75, identifier:open_method; 76, argument_list; 76, 77; 76, 78; 77, identifier:local_path; 78, dictionary_splat; 78, 79; 79, identifier:open_method_kwargs; 80, if_statement; 80, 81; 80, 82; 81, identifier:verbose; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:print; 86, argument_list; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, string:'Data retrieved from {} and saved locally.'; 90, identifier:format; 91, argument_list; 91, 92; 92, identifier:source; 93, break_statement; 94, except_clause; 94, 95; 94, 96; 95, identifier:Exception; 96, block; 96, 97; 97, continue_statement; 98, else_clause; 98, 99; 98, 100; 99, comment; 100, block; 100, 101; 101, for_statement; 101, 102; 101, 103; 101, 104; 101, 144; 102, identifier:source; 103, identifier:remote_source_list; 104, block; 104, 105; 104, 109; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:path; 108, identifier:source; 109, try_statement; 109, 110; 109, 111; 109, 112; 109, 140; 110, comment; 111, comment; 112, block; 112, 113; 112, 126; 112, 139; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:data; 116, call; 116, 117; 116, 118; 117, identifier:open_method; 118, argument_list; 118, 119; 118, 120; 119, identifier:path; 120, dictionary_splat; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:merge_two_dicts; 123, argument_list; 123, 124; 123, 125; 124, identifier:open_method_kwargs; 125, identifier:remote_kwargs; 126, if_statement; 126, 127; 126, 128; 127, identifier:verbose; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:print; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, string:'Opened data remotely from {}'; 136, identifier:format; 137, argument_list; 137, 138; 138, identifier:source; 139, break_statement; 140, except_clause; 140, 141; 140, 142; 141, identifier:Exception; 142, block; 142, 143; 143, continue_statement; 144, else_clause; 144, 145; 145, block; 145, 146; 146, raise_statement; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:Exception; 149, argument_list; 149, 150; 150, string:'All data access methods have failed.'; 151, return_statement; 151, 152; 152, expression_list; 152, 153; 152, 154; 153, identifier:data; 154, identifier:path | def load_data_source(local_path,
remote_source_list,
open_method,
open_method_kwargs=dict(),
remote_kwargs=dict(),
verbose=True):
'''Flexible data retreiver to download and cache the data files locally.
Usage example (this makes a local copy of the ozone data file):
:Example:
.. code-block:: python
from climlab.utils.data_source import load_data_source
from xarray import open_dataset
ozonename = 'apeozone_cam3_5_54.nc'
ozonepath = 'http://thredds.atmos.albany.edu:8080/thredds/fileServer/CLIMLAB/ozone/' + ozonename
data, path = load_data_source(local_path=ozonename,
remote_source_list=[ozonepath],
open_method=open_dataset)
print(data)
The order of operations is
1. Try to read the data directly from ``local_path``
2. If the file doesn't exist then iterate through ``remote_source_list``.
Try to download and save the file to ``local_path`` using http request
If that works then open the data from ``local_path``.
3. As a last resort, try to read the data remotely from URLs in ``remote_source_list``
In all cases the file is opened and read by the user-supplied ``open_method``
(e.g. ``xarray.open_dataset``), with additional keyword arguments supplied
as a dictionary through ``open_method_kwargs``.
These are passed straight through to ``open_method``.
Additional keyword arguments in ``remote_kwargs``
are only passed to ``open_method`` in option 3 above
(remote access, e.g. through OpenDAP)
Quiet all output by passing ``verbose=False``.
Returns:
- ``data`` is the data object returned by the successful call to ``open_method``
- ``path`` is the path that resulted in a successful call to ``open_method``.
'''
try:
path = local_path
data = open_method(path, **open_method_kwargs)
if verbose:
print('Opened data from {}'.format(path))
#except FileNotFoundError: # this is a more specific exception in Python 3
except IOError: # works for Py2.7 and Py3.x
# First try to load from remote sources and cache the file locally
for source in remote_source_list:
try:
response = _download_and_cache(source, local_path)
data = open_method(local_path, **open_method_kwargs)
if verbose:
print('Data retrieved from {} and saved locally.'.format(source))
break
except Exception:
continue
else:
# as a final resort, try opening the source remotely
for source in remote_source_list:
path = source
try:
# This works fine for Python >= 3.5
#data = open_method(path, **open_method_kwargs, **remote_kwargs)
data = open_method(path, **merge_two_dicts(open_method_kwargs, remote_kwargs))
if verbose:
print('Opened data remotely from {}'.format(source))
break
except Exception:
continue
else:
raise Exception('All data access methods have failed.')
return data, path |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:grouped_mean; 3, parameters; 3, 4; 3, 5; 4, identifier:arr; 5, identifier:spike_clusters; 6, block; 6, 7; 6, 9; 6, 18; 6, 27; 6, 33; 6, 44; 6, 51; 6, 59; 6, 68; 6, 78; 6, 90; 6, 91; 6, 102; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:arr; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:np; 15, identifier:asarray; 16, argument_list; 16, 17; 17, identifier:arr; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:spike_clusters; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:np; 24, identifier:asarray; 25, argument_list; 25, 26; 26, identifier:spike_clusters; 27, assert_statement; 27, 28; 28, comparison_operator:==; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:arr; 31, identifier:ndim; 32, integer:1; 33, assert_statement; 33, 34; 34, comparison_operator:==; 34, 35; 34, 40; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:arr; 38, identifier:shape; 39, integer:0; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, identifier:spike_clusters; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:cluster_ids; 47, call; 47, 48; 47, 49; 48, identifier:_unique; 49, argument_list; 49, 50; 50, identifier:spike_clusters; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:spike_clusters_rel; 54, call; 54, 55; 54, 56; 55, identifier:_index_of; 56, argument_list; 56, 57; 56, 58; 57, identifier:spike_clusters; 58, identifier:cluster_ids; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:spike_counts; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:np; 65, identifier:bincount; 66, argument_list; 66, 67; 67, identifier:spike_clusters_rel; 68, assert_statement; 68, 69; 69, comparison_operator:==; 69, 70; 69, 74; 70, call; 70, 71; 70, 72; 71, identifier:len; 72, argument_list; 72, 73; 73, identifier:spike_counts; 74, call; 74, 75; 74, 76; 75, identifier:len; 76, argument_list; 76, 77; 77, identifier:cluster_ids; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:t; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:np; 84, identifier:zeros; 85, argument_list; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:len; 88, argument_list; 88, 89; 89, identifier:cluster_ids; 90, comment; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:np; 96, identifier:add; 97, identifier:at; 98, argument_list; 98, 99; 98, 100; 98, 101; 99, identifier:t; 100, identifier:spike_clusters_rel; 101, identifier:arr; 102, return_statement; 102, 103; 103, binary_operator:/; 103, 104; 103, 105; 104, identifier:t; 105, identifier:spike_counts | def grouped_mean(arr, spike_clusters):
"""Compute the mean of a spike-dependent quantity for every cluster.
The two arguments should be 1D array with `n_spikes` elements.
The output is a 1D array with `n_clusters` elements. The clusters are
sorted in increasing order.
"""
arr = np.asarray(arr)
spike_clusters = np.asarray(spike_clusters)
assert arr.ndim == 1
assert arr.shape[0] == len(spike_clusters)
cluster_ids = _unique(spike_clusters)
spike_clusters_rel = _index_of(spike_clusters, cluster_ids)
spike_counts = np.bincount(spike_clusters_rel)
assert len(spike_counts) == len(cluster_ids)
t = np.zeros(len(cluster_ids))
# Compute the sum with possible repetitions.
np.add.at(t, spike_clusters_rel, arr)
return t / spike_counts |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort_by; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort_dir; 8, string:'asc'; 9, block; 9, 10; 9, 12; 9, 22; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:logger; 16, identifier:log; 17, argument_list; 17, 18; 17, 19; 17, 20; 17, 21; 18, integer:5; 19, string:"Sort by `%s` %s."; 20, identifier:name; 21, identifier:sort_dir; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:eval_js; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, string:'table.sortBy("{}", "{}");'; 31, identifier:format; 32, argument_list; 32, 33; 32, 34; 33, identifier:name; 34, identifier:sort_dir | def sort_by(self, name, sort_dir='asc'):
"""Sort by a given variable."""
logger.log(5, "Sort by `%s` %s.", name, sort_dir)
self.eval_js('table.sortBy("{}", "{}");'.format(name, sort_dir)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:find_column; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:search; 6, default_parameter; 6, 7; 6, 8; 7, identifier:data_type; 8, None; 9, block; 9, 10; 9, 12; 9, 24; 9, 28; 9, 98; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:data_type; 17, identifier:str; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:data_type; 22, list:[data_type]; 22, 23; 23, identifier:data_type; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:cols; 27, list:[]; 28, for_statement; 28, 29; 28, 30; 28, 33; 29, identifier:table; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:tables; 33, block; 33, 34; 34, for_statement; 34, 35; 34, 36; 34, 40; 35, identifier:col; 36, call; 36, 37; 36, 38; 37, identifier:vars; 38, argument_list; 38, 39; 39, identifier:table; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 51; 42, call; 42, 43; 42, 48; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:glob; 46, identifier:fnmatch; 47, identifier:fnmatch; 48, argument_list; 48, 49; 48, 50; 49, identifier:col; 50, identifier:search; 51, block; 51, 52; 51, 76; 52, if_statement; 52, 53; 52, 74; 53, boolean_operator:and; 53, 54; 53, 65; 54, boolean_operator:and; 54, 55; 54, 56; 55, identifier:data_type; 56, call; 56, 57; 56, 58; 57, identifier:isinstance; 58, argument_list; 58, 59; 58, 64; 59, call; 59, 60; 59, 61; 60, identifier:getattr; 61, argument_list; 61, 62; 61, 63; 62, identifier:table; 63, identifier:col; 64, identifier:Column; 65, comparison_operator:not; 65, 66; 65, 73; 66, attribute; 66, 67; 66, 72; 67, call; 67, 68; 67, 69; 68, identifier:getattr; 69, argument_list; 69, 70; 69, 71; 70, identifier:table; 71, identifier:col; 72, identifier:type; 73, identifier:data_type; 74, block; 74, 75; 75, continue_statement; 76, if_statement; 76, 77; 76, 86; 77, call; 77, 78; 77, 79; 78, identifier:isinstance; 79, argument_list; 79, 80; 79, 85; 80, call; 80, 81; 80, 82; 81, identifier:getattr; 82, argument_list; 82, 83; 82, 84; 83, identifier:table; 84, identifier:col; 85, identifier:Column; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:cols; 91, identifier:append; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:getattr; 95, argument_list; 95, 96; 95, 97; 96, identifier:table; 97, identifier:col; 98, return_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:ColumnSet; 101, argument_list; 101, 102; 102, identifier:cols | def find_column(self, search, data_type=None):
"""
Aggresively search through your database's schema for a column.
Parameters
-----------
search: str
glob pattern for what you're looking for
data_type: str, list
(optional) specify which data type(s) you want to return
Examples
----------
>>> from db import DemoDB
>>> db = DemoDB()
>>> len(db.find_column("Name").columns)
5
>>> len(db.find_column("*Id").columns)
20
>>> len(db.find_column("*Address*").columns)
3
>>> len(db.find_column("*Address*", data_type="NVARCHAR(70)").columns)
3
>>> len(db.find_column("*e*", data_type=["NVARCHAR(70)", "INTEGER"]).columns)
17
-= Should sort in some way for all those doctests to be viable...
-= if not, there's always a random issue where rows are not in the same order, making doctest fail.
db.find_column("Name") # returns all columns named "Name"
+-----------+-------------+---------------+
| Table | Column Name | Type |
+-----------+-------------+---------------+
| Artist | Name | NVARCHAR(120) |
| Genre | Name | NVARCHAR(120) |
| MediaType | Name | NVARCHAR(120) |
| Playlist | Name | NVARCHAR(120) |
| Track | Name | NVARCHAR(200) |
+-----------+-------------+---------------+
db.find_column("*Id") # returns all columns ending w/ Id
+---------------+---------------+---------+
| Table | Column Name | Type |
+---------------+---------------+---------+
| Album | AlbumId | INTEGER |
| Album | ArtistId | INTEGER |
| Artist | ArtistId | INTEGER |
| Customer | SupportRepId | INTEGER |
| Customer | CustomerId | INTEGER |
| Employee | EmployeeId | INTEGER |
| Genre | GenreId | INTEGER |
| Invoice | InvoiceId | INTEGER |
| Invoice | CustomerId | INTEGER |
| InvoiceLine | TrackId | INTEGER |
| InvoiceLine | InvoiceLineId | INTEGER |
| InvoiceLine | InvoiceId | INTEGER |
| MediaType | MediaTypeId | INTEGER |
| Playlist | PlaylistId | INTEGER |
| PlaylistTrack | TrackId | INTEGER |
| PlaylistTrack | PlaylistId | INTEGER |
| Track | TrackId | INTEGER |
| Track | AlbumId | INTEGER |
| Track | MediaTypeId | INTEGER |
| Track | GenreId | INTEGER |
+---------------+---------------+---------+
db.find_column("*Address*") # returns all columns containing Address
+----------+----------------+--------------+
| Table | Column Name | Type |
+----------+----------------+--------------+
| Customer | Address | NVARCHAR(70) |
| Employee | Address | NVARCHAR(70) |
| Invoice | BillingAddress | NVARCHAR(70) |
+----------+----------------+--------------+
db.find_column("*Address*", data_type="NVARCHAR(70)") # returns all columns containing Address that are varchars
+----------+----------------+--------------+
| Table | Column Name | Type |
+----------+----------------+--------------+
| Customer | Address | NVARCHAR(70) |
| Employee | Address | NVARCHAR(70) |
| Invoice | BillingAddress | NVARCHAR(70) |
+----------+----------------+--------------+
db.find_column("*e*", data_type=["NVARCHAR(70)", "INTEGER"]) # returns all columns have an "e" and are NVARCHAR(70)S or INTEGERS
+-------------+----------------+--------------+
| Table | Column Name | Type |
+-------------+----------------+--------------+
| Customer | Address | NVARCHAR(70) |
| Customer | SupportRepId | INTEGER |
| Customer | CustomerId | INTEGER |
| Employee | ReportsTo | INTEGER |
| Employee | EmployeeId | INTEGER |
| Employee | Address | NVARCHAR(70) |
| Genre | GenreId | INTEGER |
| Invoice | InvoiceId | INTEGER |
| Invoice | CustomerId | INTEGER |
| Invoice | BillingAddress | NVARCHAR(70) |
| InvoiceLine | InvoiceLineId | INTEGER |
| InvoiceLine | InvoiceId | INTEGER |
| MediaType | MediaTypeId | INTEGER |
| Track | MediaTypeId | INTEGER |
| Track | Milliseconds | INTEGER |
| Track | GenreId | INTEGER |
| Track | Bytes | INTEGER |
+-------------+----------------+--------------+
"""
if isinstance(data_type, str):
data_type = [data_type]
cols = []
for table in self.tables:
for col in vars(table):
if glob.fnmatch.fnmatch(col, search):
if data_type and isinstance(getattr(table, col), Column) and getattr(table, col).type not in data_type:
continue
if isinstance(getattr(table, col), Column):
cols.append(getattr(table, col))
return ColumnSet(cols) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:to_linear; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:index; 7, None; 8, block; 8, 9; 8, 11; 8, 67; 8, 80; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:index; 14, None; 15, block; 15, 16; 15, 27; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:n; 19, binary_operator:-; 19, 20; 19, 26; 20, call; 20, 21; 20, 22; 21, identifier:len; 22, argument_list; 22, 23; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:index; 26, integer:1; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:index; 30, list_comprehension; 30, 31; 30, 61; 31, binary_operator:+; 31, 32; 31, 47; 32, binary_operator:*; 32, 33; 32, 38; 33, subscript; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:index; 37, identifier:i; 38, parenthesized_expression; 38, 39; 39, binary_operator:-; 39, 40; 39, 41; 40, float:1.; 41, binary_operator:/; 41, 42; 41, 43; 42, identifier:i; 43, parenthesized_expression; 43, 44; 44, binary_operator:-; 44, 45; 44, 46; 45, identifier:n; 46, float:1.; 47, binary_operator:/; 47, 48; 47, 57; 48, binary_operator:*; 48, 49; 48, 56; 49, subscript; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:index; 53, binary_operator:+; 53, 54; 53, 55; 54, identifier:i; 55, integer:1; 56, identifier:i; 57, parenthesized_expression; 57, 58; 58, binary_operator:-; 58, 59; 58, 60; 59, identifier:n; 60, float:1.; 61, for_in_clause; 61, 62; 61, 63; 62, identifier:i; 63, call; 63, 64; 63, 65; 64, identifier:range; 65, argument_list; 65, 66; 66, identifier:n; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:colors; 70, list_comprehension; 70, 71; 70, 77; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:rgba_floats_tuple; 75, argument_list; 75, 76; 76, identifier:x; 77, for_in_clause; 77, 78; 77, 79; 78, identifier:x; 79, identifier:index; 80, return_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:LinearColormap; 83, argument_list; 83, 84; 83, 85; 83, 88; 83, 93; 84, identifier:colors; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:index; 87, identifier:index; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:vmin; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:vmin; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:vmax; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:vmax | def to_linear(self, index=None):
"""
Transforms the StepColormap into a LinearColormap.
Parameters
----------
index : list of floats, default None
The values corresponding to each color in the output colormap.
It has to be sorted.
If None, a regular grid between `vmin` and `vmax` is created.
"""
if index is None:
n = len(self.index)-1
index = [self.index[i]*(1.-i/(n-1.))+self.index[i+1]*i/(n-1.) for
i in range(n)]
colors = [self.rgba_floats_tuple(x) for x in index]
return LinearColormap(colors, index=index,
vmin=self.vmin, vmax=self.vmax) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:regex_opt_inner; 3, parameters; 3, 4; 3, 5; 4, identifier:strings; 5, identifier:open_paren; 6, block; 6, 7; 6, 9; 6, 17; 6, 18; 6, 25; 6, 31; 6, 49; 6, 71; 6, 157; 6, 164; 6, 201; 6, 202; 6, 216; 6, 223; 6, 268; 6, 269; 6, 270; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:close_paren; 12, boolean_operator:or; 12, 13; 12, 16; 13, boolean_operator:and; 13, 14; 13, 15; 14, identifier:open_paren; 15, string:')'; 16, string:''; 17, comment; 18, if_statement; 18, 19; 18, 21; 18, 22; 19, not_operator; 19, 20; 20, identifier:strings; 21, comment; 22, block; 22, 23; 23, return_statement; 23, 24; 24, string:''; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:first; 28, subscript; 28, 29; 28, 30; 29, identifier:strings; 30, integer:0; 31, if_statement; 31, 32; 31, 38; 31, 39; 32, comparison_operator:==; 32, 33; 32, 37; 33, call; 33, 34; 33, 35; 34, identifier:len; 35, argument_list; 35, 36; 36, identifier:strings; 37, integer:1; 38, comment; 39, block; 39, 40; 40, return_statement; 40, 41; 41, binary_operator:+; 41, 42; 41, 48; 42, binary_operator:+; 42, 43; 42, 44; 43, identifier:open_paren; 44, call; 44, 45; 44, 46; 45, identifier:escape; 46, argument_list; 46, 47; 47, identifier:first; 48, identifier:close_paren; 49, if_statement; 49, 50; 49, 52; 49, 53; 50, not_operator; 50, 51; 51, identifier:first; 52, comment; 53, block; 53, 54; 54, return_statement; 54, 55; 55, binary_operator:+; 55, 56; 55, 70; 56, binary_operator:+; 56, 57; 56, 68; 56, 69; 57, binary_operator:+; 57, 58; 57, 59; 58, identifier:open_paren; 59, call; 59, 60; 59, 61; 60, identifier:regex_opt_inner; 61, argument_list; 61, 62; 61, 67; 62, subscript; 62, 63; 62, 64; 63, identifier:strings; 64, slice; 64, 65; 64, 66; 65, integer:1; 66, colon; 67, string:'(?:'; 68, line_continuation:\; 69, string:'?'; 70, identifier:close_paren; 71, if_statement; 71, 72; 71, 78; 71, 79; 72, comparison_operator:==; 72, 73; 72, 77; 73, call; 73, 74; 73, 75; 74, identifier:len; 75, argument_list; 75, 76; 76, identifier:first; 77, integer:1; 78, comment; 79, block; 79, 80; 79, 84; 79, 88; 79, 116; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:oneletter; 83, list:[]; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:rest; 87, list:[]; 88, for_statement; 88, 89; 88, 90; 88, 91; 89, identifier:s; 90, identifier:strings; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 99; 92, 107; 93, comparison_operator:==; 93, 94; 93, 98; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, identifier:s; 98, integer:1; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:oneletter; 104, identifier:append; 105, argument_list; 105, 106; 106, identifier:s; 107, else_clause; 107, 108; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:rest; 113, identifier:append; 114, argument_list; 114, 115; 115, identifier:s; 116, if_statement; 116, 117; 116, 123; 116, 124; 117, comparison_operator:>; 117, 118; 117, 122; 118, call; 118, 119; 118, 120; 119, identifier:len; 120, argument_list; 120, 121; 121, identifier:oneletter; 122, integer:1; 123, comment; 124, block; 124, 125; 124, 147; 124, 148; 125, if_statement; 125, 126; 125, 127; 125, 128; 126, identifier:rest; 127, comment; 128, block; 128, 129; 129, return_statement; 129, 130; 130, binary_operator:+; 130, 131; 130, 146; 131, binary_operator:+; 131, 132; 131, 141; 131, 142; 132, binary_operator:+; 132, 133; 132, 140; 133, binary_operator:+; 133, 134; 133, 135; 134, identifier:open_paren; 135, call; 135, 136; 135, 137; 136, identifier:regex_opt_inner; 137, argument_list; 137, 138; 137, 139; 138, identifier:rest; 139, string:''; 140, string:'|'; 141, line_continuation:\; 142, call; 142, 143; 142, 144; 143, identifier:make_charset; 144, argument_list; 144, 145; 145, identifier:oneletter; 146, identifier:close_paren; 147, comment; 148, return_statement; 148, 149; 149, binary_operator:+; 149, 150; 149, 156; 150, binary_operator:+; 150, 151; 150, 152; 151, identifier:open_paren; 152, call; 152, 153; 152, 154; 153, identifier:make_charset; 154, argument_list; 154, 155; 155, identifier:oneletter; 156, identifier:close_paren; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:prefix; 160, call; 160, 161; 160, 162; 161, identifier:commonprefix; 162, argument_list; 162, 163; 163, identifier:strings; 164, if_statement; 164, 165; 164, 166; 165, identifier:prefix; 166, block; 166, 167; 166, 174; 166, 175; 166, 176; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:plen; 170, call; 170, 171; 170, 172; 171, identifier:len; 172, argument_list; 172, 173; 173, identifier:prefix; 174, comment; 175, comment; 176, return_statement; 176, 177; 177, binary_operator:+; 177, 178; 177, 199; 177, 200; 178, binary_operator:+; 178, 179; 178, 185; 178, 186; 179, binary_operator:+; 179, 180; 179, 181; 180, identifier:open_paren; 181, call; 181, 182; 181, 183; 182, identifier:escape; 183, argument_list; 183, 184; 184, identifier:prefix; 185, line_continuation:\; 186, call; 186, 187; 186, 188; 187, identifier:regex_opt_inner; 188, argument_list; 188, 189; 188, 198; 189, list_comprehension; 189, 190; 189, 195; 190, subscript; 190, 191; 190, 192; 191, identifier:s; 192, slice; 192, 193; 192, 194; 193, identifier:plen; 194, colon; 195, for_in_clause; 195, 196; 195, 197; 196, identifier:s; 197, identifier:strings; 198, string:'(?:'; 199, line_continuation:\; 200, identifier:close_paren; 201, comment; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:strings_rev; 205, list_comprehension; 205, 206; 205, 213; 206, subscript; 206, 207; 206, 208; 207, identifier:s; 208, slice; 208, 209; 208, 210; 208, 211; 209, colon; 210, colon; 211, unary_operator:-; 211, 212; 212, integer:1; 213, for_in_clause; 213, 214; 213, 215; 214, identifier:s; 215, identifier:strings; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:suffix; 219, call; 219, 220; 219, 221; 220, identifier:commonprefix; 221, argument_list; 221, 222; 222, identifier:strings_rev; 223, if_statement; 223, 224; 223, 225; 224, identifier:suffix; 225, block; 225, 226; 225, 233; 225, 234; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:slen; 229, call; 229, 230; 229, 231; 230, identifier:len; 231, argument_list; 231, 232; 232, identifier:suffix; 233, comment; 234, return_statement; 234, 235; 235, binary_operator:+; 235, 236; 235, 267; 236, binary_operator:+; 236, 237; 236, 256; 236, 257; 237, binary_operator:+; 237, 238; 237, 239; 237, 240; 238, identifier:open_paren; 239, line_continuation:\; 240, call; 240, 241; 240, 242; 241, identifier:regex_opt_inner; 242, argument_list; 242, 243; 242, 255; 243, call; 243, 244; 243, 245; 244, identifier:sorted; 245, generator_expression; 245, 246; 245, 252; 246, subscript; 246, 247; 246, 248; 247, identifier:s; 248, slice; 248, 249; 248, 250; 249, colon; 250, unary_operator:-; 250, 251; 251, identifier:slen; 252, for_in_clause; 252, 253; 252, 254; 253, identifier:s; 254, identifier:strings; 255, string:'(?:'; 256, line_continuation:\; 257, call; 257, 258; 257, 259; 258, identifier:escape; 259, argument_list; 259, 260; 260, subscript; 260, 261; 260, 262; 261, identifier:suffix; 262, slice; 262, 263; 262, 264; 262, 265; 263, colon; 264, colon; 265, unary_operator:-; 265, 266; 266, integer:1; 267, identifier:close_paren; 268, comment; 269, comment; 270, return_statement; 270, 271; 271, binary_operator:+; 271, 272; 271, 305; 271, 306; 272, binary_operator:+; 272, 273; 272, 274; 273, identifier:open_paren; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, string:'|'; 277, identifier:join; 278, generator_expression; 278, 279; 278, 289; 279, call; 279, 280; 279, 281; 280, identifier:regex_opt_inner; 281, argument_list; 281, 282; 281, 288; 282, call; 282, 283; 282, 284; 283, identifier:list; 284, argument_list; 284, 285; 285, subscript; 285, 286; 285, 287; 286, identifier:group; 287, integer:1; 288, string:''; 289, for_in_clause; 289, 290; 289, 291; 290, identifier:group; 291, call; 291, 292; 291, 293; 292, identifier:groupby; 293, argument_list; 293, 294; 293, 295; 294, identifier:strings; 295, lambda; 295, 296; 295, 298; 296, lambda_parameters; 296, 297; 297, identifier:s; 298, comparison_operator:==; 298, 299; 298, 302; 299, subscript; 299, 300; 299, 301; 300, identifier:s; 301, integer:0; 302, subscript; 302, 303; 302, 304; 303, identifier:first; 304, integer:0; 305, line_continuation:\; 306, identifier:close_paren | def regex_opt_inner(strings, open_paren):
"""Return a regex that matches any string in the sorted list of strings."""
close_paren = open_paren and ')' or ''
# print strings, repr(open_paren)
if not strings:
# print '-> nothing left'
return ''
first = strings[0]
if len(strings) == 1:
# print '-> only 1 string'
return open_paren + escape(first) + close_paren
if not first:
# print '-> first string empty'
return open_paren + regex_opt_inner(strings[1:], '(?:') \
+ '?' + close_paren
if len(first) == 1:
# multiple one-char strings? make a charset
oneletter = []
rest = []
for s in strings:
if len(s) == 1:
oneletter.append(s)
else:
rest.append(s)
if len(oneletter) > 1: # do we have more than one oneletter string?
if rest:
# print '-> 1-character + rest'
return open_paren + regex_opt_inner(rest, '') + '|' \
+ make_charset(oneletter) + close_paren
# print '-> only 1-character'
return open_paren + make_charset(oneletter) + close_paren
prefix = commonprefix(strings)
if prefix:
plen = len(prefix)
# we have a prefix for all strings
# print '-> prefix:', prefix
return open_paren + escape(prefix) \
+ regex_opt_inner([s[plen:] for s in strings], '(?:') \
+ close_paren
# is there a suffix?
strings_rev = [s[::-1] for s in strings]
suffix = commonprefix(strings_rev)
if suffix:
slen = len(suffix)
# print '-> suffix:', suffix[::-1]
return open_paren \
+ regex_opt_inner(sorted(s[:-slen] for s in strings), '(?:') \
+ escape(suffix[::-1]) + close_paren
# recurse on common 1-string prefixes
# print '-> last resort'
return open_paren + \
'|'.join(regex_opt_inner(list(group[1]), '')
for group in groupby(strings, lambda s: s[0] == first[0])) \
+ close_paren |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_substitutions_from_config; 3, parameters; 3, 4; 4, identifier:config; 5, block; 5, 6; 5, 8; 5, 12; 5, 21; 5, 27; 5, 64; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:result; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:pattern_names; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:config; 18, identifier:options; 19, argument_list; 19, 20; 20, identifier:SUBSTITUTION_SECTION; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:pattern_names; 25, identifier:sort; 26, argument_list; 27, for_statement; 27, 28; 27, 29; 27, 30; 28, identifier:name; 29, identifier:pattern_names; 30, block; 30, 31; 30, 41; 30, 50; 30, 57; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:pattern_val; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:config; 37, identifier:get; 38, argument_list; 38, 39; 38, 40; 39, identifier:SUBSTITUTION_SECTION; 40, identifier:name; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:list_rep; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:ast; 47, identifier:literal_eval; 48, argument_list; 48, 49; 49, identifier:pattern_val; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:substitution; 53, call; 53, 54; 53, 55; 54, identifier:parse_substitution_from_list; 55, argument_list; 55, 56; 56, identifier:list_rep; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:result; 61, identifier:append; 62, argument_list; 62, 63; 63, identifier:substitution; 64, return_statement; 64, 65; 65, identifier:result | def get_substitutions_from_config(config):
"""
Return a list of Substitution objects from the config, sorted
alphabetically by pattern name. Returns an empty list if no Substitutions
are specified. If there are problems parsing the values, a help message
will be printed and an error will be thrown.
"""
result = []
pattern_names = config.options(SUBSTITUTION_SECTION)
pattern_names.sort()
for name in pattern_names:
pattern_val = config.get(SUBSTITUTION_SECTION, name)
list_rep = ast.literal_eval(pattern_val)
substitution = parse_substitution_from_list(list_rep)
result.append(substitution)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:next_sibling; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 104; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 8, 48; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:parent; 12, block; 12, 13; 12, 21; 12, 30; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:nodes; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:parent; 20, identifier:children; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:index; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:nodes; 27, identifier:index; 28, argument_list; 28, 29; 29, identifier:self; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:sibling; 33, conditional_expression:if; 33, 34; 33, 39; 33, 47; 34, subscript; 34, 35; 34, 36; 35, identifier:nodes; 36, binary_operator:+; 36, 37; 36, 38; 37, identifier:index; 38, integer:1; 39, comparison_operator:<; 39, 40; 39, 41; 40, identifier:index; 41, binary_operator:-; 41, 42; 41, 46; 42, call; 42, 43; 42, 44; 43, identifier:len; 44, argument_list; 44, 45; 45, identifier:nodes; 46, integer:1; 47, None; 48, else_clause; 48, 49; 49, block; 49, 50; 49, 58; 49, 67; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:nodes; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:tree; 57, identifier:nodes; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:index; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:nodes; 64, identifier:index; 65, argument_list; 65, 66; 66, identifier:self; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:sibling; 70, parenthesized_expression; 70, 71; 71, conditional_expression:if; 71, 72; 71, 95; 71, 103; 72, call; 72, 73; 72, 74; 73, identifier:next; 74, argument_list; 74, 75; 74, 94; 75, generator_expression; 75, 76; 75, 77; 75, 86; 76, identifier:n; 77, for_in_clause; 77, 78; 77, 79; 78, identifier:n; 79, subscript; 79, 80; 79, 81; 80, identifier:nodes; 81, slice; 81, 82; 81, 85; 82, binary_operator:+; 82, 83; 82, 84; 83, identifier:index; 84, integer:1; 85, colon; 86, if_clause; 86, 87; 87, comparison_operator:==; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:n; 90, identifier:level; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:level; 94, None; 95, comparison_operator:<; 95, 96; 95, 97; 96, identifier:index; 97, binary_operator:-; 97, 98; 97, 102; 98, call; 98, 99; 98, 100; 99, identifier:len; 100, argument_list; 100, 101; 101, identifier:nodes; 102, integer:1; 103, None; 104, return_statement; 104, 105; 105, identifier:sibling | def next_sibling(self):
""" Returns the next sibling of the current node.
The next sibling is searched in the parent node if we are not considering a top-level node.
Otherwise it is searched inside the list of nodes (which should be sorted by tree ID) that
is associated with the considered tree instance.
"""
if self.parent:
nodes = self.parent.children
index = nodes.index(self)
sibling = nodes[index + 1] if index < len(nodes) - 1 else None
else:
nodes = self.tree.nodes
index = nodes.index(self)
sibling = (
next((n for n in nodes[index + 1:] if n.level == self.level), None)
if index < len(nodes) - 1 else None
)
return sibling |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:previous_sibling; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 95; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 8, 43; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:parent; 12, block; 12, 13; 12, 21; 12, 30; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:nodes; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:parent; 20, identifier:children; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:index; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:nodes; 27, identifier:index; 28, argument_list; 28, 29; 29, identifier:self; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:sibling; 33, conditional_expression:if; 33, 34; 33, 39; 33, 42; 34, subscript; 34, 35; 34, 36; 35, identifier:nodes; 36, binary_operator:-; 36, 37; 36, 38; 37, identifier:index; 38, integer:1; 39, comparison_operator:>; 39, 40; 39, 41; 40, identifier:index; 41, integer:0; 42, None; 43, else_clause; 43, 44; 44, block; 44, 45; 44, 53; 44, 62; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:nodes; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:tree; 52, identifier:nodes; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:index; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:nodes; 59, identifier:index; 60, argument_list; 60, 61; 61, identifier:self; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:sibling; 65, parenthesized_expression; 65, 66; 66, conditional_expression:if; 66, 67; 66, 91; 66, 94; 67, call; 67, 68; 67, 69; 68, identifier:next; 69, argument_list; 69, 70; 69, 90; 70, generator_expression; 70, 71; 70, 72; 70, 82; 71, identifier:n; 72, for_in_clause; 72, 73; 72, 74; 73, identifier:n; 74, call; 74, 75; 74, 76; 75, identifier:reversed; 76, argument_list; 76, 77; 77, subscript; 77, 78; 77, 79; 78, identifier:nodes; 79, slice; 79, 80; 79, 81; 80, colon; 81, identifier:index; 82, if_clause; 82, 83; 83, comparison_operator:==; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:n; 86, identifier:level; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:level; 90, None; 91, comparison_operator:>; 91, 92; 91, 93; 92, identifier:index; 93, integer:0; 94, None; 95, return_statement; 95, 96; 96, identifier:sibling | def previous_sibling(self):
""" Returns the previous sibling of the current node.
The previous sibling is searched in the parent node if we are not considering a top-level
node. Otherwise it is searched inside the list of nodes (which should be sorted by tree ID)
that is associated with the considered tree instance.
"""
if self.parent:
nodes = self.parent.children
index = nodes.index(self)
sibling = nodes[index - 1] if index > 0 else None
else:
nodes = self.tree.nodes
index = nodes.index(self)
sibling = (
next((n for n in reversed(nodes[:index]) if n.level == self.level), None)
if index > 0 else None
)
return sibling |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:delay_or_run; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 20; 9, 28; 9, 69; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:warnings; 16, identifier:warn; 17, argument_list; 17, 18; 17, 19; 18, string:"delay_or_run is deprecated. Please use delay_or_eager"; 19, identifier:DeprecationWarning; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:possible_broker_errors; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_get_possible_broker_errors_tuple; 27, argument_list; 28, try_statement; 28, 29; 28, 48; 29, block; 29, 30; 29, 44; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:result; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:apply_async; 37, argument_list; 37, 38; 37, 41; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:args; 40, identifier:args; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:kwargs; 43, identifier:kwargs; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:required_fallback; 47, False; 48, except_clause; 48, 49; 48, 50; 49, identifier:possible_broker_errors; 50, block; 50, 51; 50, 65; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:result; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, call; 56, 57; 56, 58; 57, identifier:self; 58, argument_list; 59, identifier:run; 60, argument_list; 60, 61; 60, 63; 61, list_splat; 61, 62; 62, identifier:args; 63, dictionary_splat; 63, 64; 64, identifier:kwargs; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:required_fallback; 68, True; 69, return_statement; 69, 70; 70, expression_list; 70, 71; 70, 72; 71, identifier:result; 72, identifier:required_fallback | def delay_or_run(self, *args, **kwargs):
"""
Attempt to call self.delay, or if that fails, call self.run.
Returns a tuple, (result, required_fallback). ``result`` is the result
of calling delay or run. ``required_fallback`` is True if the broker
failed we had to resort to `self.run`.
"""
warnings.warn(
"delay_or_run is deprecated. Please use delay_or_eager",
DeprecationWarning,
)
possible_broker_errors = self._get_possible_broker_errors_tuple()
try:
result = self.apply_async(args=args, kwargs=kwargs)
required_fallback = False
except possible_broker_errors:
result = self().run(*args, **kwargs)
required_fallback = True
return result, required_fallback |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:arrange; 3, parameters; 3, 4; 4, list_splat_pattern; 4, 5; 5, identifier:args; 6, block; 6, 7; 6, 9; 6, 19; 6, 58; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:names; 12, list_comprehension; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:column; 15, identifier:_name; 16, for_in_clause; 16, 17; 16, 18; 17, identifier:column; 18, identifier:args; 19, function_definition; 19, 20; 19, 21; 19, 23; 20, function_name:f; 21, parameters; 21, 22; 22, identifier:df; 23, block; 23, 24; 23, 34; 23, 52; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:sortby_df; 27, binary_operator:>>; 27, 28; 27, 29; 28, identifier:df; 29, call; 29, 30; 29, 31; 30, identifier:mutate; 31, argument_list; 31, 32; 32, list_splat; 32, 33; 33, identifier:args; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:index; 37, attribute; 37, 38; 37, 51; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:sortby_df; 41, identifier:sort_values; 42, argument_list; 42, 43; 43, list_comprehension; 43, 44; 43, 48; 44, call; 44, 45; 44, 46; 45, identifier:str; 46, argument_list; 46, 47; 47, identifier:arg; 48, for_in_clause; 48, 49; 48, 50; 49, identifier:arg; 50, identifier:args; 51, identifier:index; 52, return_statement; 52, 53; 53, subscript; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:df; 56, identifier:loc; 57, identifier:index; 58, return_statement; 58, 59; 59, identifier:f | def arrange(*args):
"""Sort DataFrame by the input column arguments.
>>> diamonds >> sample_n(5) >> arrange(X.price) >> select(X.depth, X.price)
Out:
depth price
28547 61.0 675
35132 59.1 889
42526 61.3 1323
3468 61.6 3392
23829 62.0 11903
"""
names = [column._name for column in args]
def f(df):
sortby_df = df >> mutate(*args)
index = sortby_df.sort_values([str(arg) for arg in args]).index
return df.loc[index]
return f |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:filenames; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:directory; 5, default_parameter; 5, 6; 5, 7; 6, identifier:tag; 7, string:''; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sorted; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:recursive; 13, False; 14, block; 14, 15; 14, 17; 14, 90; 14, 99; 15, expression_statement; 15, 16; 16, comment; 17, if_statement; 17, 18; 17, 19; 17, 57; 18, identifier:recursive; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:f; 23, list_comprehension; 23, 24; 23, 33; 23, 44; 23, 47; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:os; 28, identifier:path; 29, identifier:join; 30, argument_list; 30, 31; 30, 32; 31, identifier:directory; 32, identifier:f; 33, for_in_clause; 33, 34; 33, 38; 34, pattern_list; 34, 35; 34, 36; 34, 37; 35, identifier:directory; 36, identifier:_; 37, identifier:filename; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:os; 41, identifier:walk; 42, argument_list; 42, 43; 43, identifier:directory; 44, for_in_clause; 44, 45; 44, 46; 45, identifier:f; 46, identifier:filename; 47, if_clause; 47, 48; 48, comparison_operator:>; 48, 49; 48, 55; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:f; 52, identifier:find; 53, argument_list; 53, 54; 54, identifier:tag; 55, unary_operator:-; 55, 56; 56, integer:1; 57, else_clause; 57, 58; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:f; 62, list_comprehension; 62, 63; 62, 72; 62, 80; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:os; 67, identifier:path; 68, identifier:join; 69, argument_list; 69, 70; 69, 71; 70, identifier:directory; 71, identifier:f; 72, for_in_clause; 72, 73; 72, 74; 73, identifier:f; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:os; 77, identifier:listdir; 78, argument_list; 78, 79; 79, identifier:directory; 80, if_clause; 80, 81; 81, comparison_operator:>; 81, 82; 81, 88; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:f; 85, identifier:find; 86, argument_list; 86, 87; 87, identifier:tag; 88, unary_operator:-; 88, 89; 89, integer:1; 90, if_statement; 90, 91; 90, 92; 91, identifier:sorted; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:f; 97, identifier:sort; 98, argument_list; 99, return_statement; 99, 100; 100, identifier:f | def filenames(directory, tag='', sorted=False, recursive=False):
""" Reads in all filenames from a directory that contain a specified substring.
Parameters
----------
directory : :obj:`str`
the directory to read from
tag : :obj:`str`
optional tag to match in the filenames
sorted : bool
whether or not to sort the filenames
recursive : bool
whether or not to search for the files recursively
Returns
-------
:obj:`list` of :obj:`str`
filenames to read from
"""
if recursive:
f = [os.path.join(directory, f) for directory, _, filename in os.walk(directory) for f in filename if f.find(tag) > -1]
else:
f = [os.path.join(directory, f) for f in os.listdir(directory) if f.find(tag) > -1]
if sorted:
f.sort()
return f |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_iterargs; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:item; 6, block; 6, 7; 6, 9; 6, 10; 6, 11; 6, 21; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:args; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:_get_aggregate_args; 18, argument_list; 18, 19; 18, 20; 19, identifier:item; 20, string:'mandatoryArgs'; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:tuple; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:sorted; 27, argument_list; 27, 28; 28, list_comprehension; 28, 29; 28, 30; 28, 33; 29, identifier:arg; 30, for_in_clause; 30, 31; 30, 32; 31, identifier:arg; 32, identifier:args; 33, if_clause; 33, 34; 34, comparison_operator:in; 34, 35; 34, 36; 35, identifier:arg; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:iterargs | def get_iterargs(self, item):
""" Returns a tuple of all iterags for item, sorted by name."""
# iterargs should always be mandatory, unless there's a good reason
# not to, which I can't think of right now.
args = self._get_aggregate_args(item, 'mandatoryArgs')
return tuple(sorted([arg for arg in args if arg in self.iterargs])) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:merge_dict; 3, parameters; 3, 4; 3, 5; 4, identifier:a; 5, identifier:b; 6, block; 6, 7; 6, 9; 6, 19; 6, 26; 6, 108; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 16; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:isinstance; 13, argument_list; 13, 14; 13, 15; 14, identifier:b; 15, identifier:dict; 16, block; 16, 17; 17, return_statement; 17, 18; 18, identifier:b; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:result; 22, call; 22, 23; 22, 24; 23, identifier:deepcopy; 24, argument_list; 24, 25; 25, identifier:a; 26, for_statement; 26, 27; 26, 30; 26, 36; 27, pattern_list; 27, 28; 27, 29; 28, identifier:key; 29, identifier:val; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:six; 33, identifier:iteritems; 34, argument_list; 34, 35; 35, identifier:b; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 49; 37, 62; 37, 97; 38, boolean_operator:and; 38, 39; 38, 42; 39, comparison_operator:in; 39, 40; 39, 41; 40, identifier:key; 41, identifier:result; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:result; 47, identifier:key; 48, identifier:dict; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:result; 54, identifier:key; 55, call; 55, 56; 55, 57; 56, identifier:merge_dict; 57, argument_list; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:result; 60, identifier:key; 61, identifier:val; 62, elif_clause; 62, 63; 62, 74; 63, boolean_operator:and; 63, 64; 63, 67; 64, comparison_operator:in; 64, 65; 64, 66; 65, identifier:key; 66, identifier:result; 67, call; 67, 68; 67, 69; 68, identifier:isinstance; 69, argument_list; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:result; 72, identifier:key; 73, identifier:list; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:result; 79, identifier:key; 80, call; 80, 81; 80, 82; 81, identifier:sorted; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:list; 85, argument_list; 85, 86; 86, binary_operator:|; 86, 87; 86, 91; 87, call; 87, 88; 87, 89; 88, identifier:set; 89, argument_list; 89, 90; 90, identifier:val; 91, call; 91, 92; 91, 93; 92, identifier:set; 93, argument_list; 93, 94; 94, subscript; 94, 95; 94, 96; 95, identifier:result; 96, identifier:key; 97, else_clause; 97, 98; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:result; 103, identifier:key; 104, call; 104, 105; 104, 106; 105, identifier:deepcopy; 106, argument_list; 106, 107; 107, identifier:val; 108, return_statement; 108, 109; 109, identifier:result | def merge_dict(a, b):
"""
Recursively merges and returns dict a with dict b.
Any list values will be combined and returned sorted.
:param a: dictionary object
:param b: dictionary object
:return: merged dictionary object
"""
if not isinstance(b, dict):
return b
result = deepcopy(a)
for key, val in six.iteritems(b):
if key in result and isinstance(result[key], dict):
result[key] = merge_dict(result[key], val)
elif key in result and isinstance(result[key], list):
result[key] = sorted(list(set(val) | set(result[key])))
else:
result[key] = deepcopy(val)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:posthoc_mannwhitney; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:a; 5, default_parameter; 5, 6; 5, 7; 6, identifier:val_col; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:group_col; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:use_continuity; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:alternative; 16, string:'two-sided'; 17, default_parameter; 17, 18; 17, 19; 18, identifier:p_adjust; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:sort; 22, True; 23, block; 23, 24; 23, 26; 23, 38; 23, 65; 23, 82; 23, 93; 23, 99; 23, 110; 23, 124; 23, 139; 23, 148; 23, 161; 23, 210; 23, 229; 23, 239; 23, 248; 24, expression_statement; 24, 25; 25, string:'''Pairwise comparisons with Mann-Whitney rank test.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interface or a pandas
DataFrame. Array must be two-dimensional.
val_col : str, optional
Name of a DataFrame column that contains dependent variable values (test
or response variable). Values should have a non-nominal scale. Must be
specified if `a` is a pandas DataFrame object.
group_col : str, optional
Name of a DataFrame column that contains independent variable values
(grouping or predictor variable). Values should have a nominal scale
(categorical). Must be specified if `a` is a pandas DataFrame object.
use_continuity : bool, optional
Whether a continuity correction (1/2.) should be taken into account.
Default is True.
alternative : ['two-sided', 'less', or 'greater'], optional
Whether to get the p-value for the one-sided hypothesis
('less' or 'greater') or for the two-sided hypothesis ('two-sided').
Defaults to 'two-sided'.
p_adjust : str, optional
Method for adjusting p values.
See statsmodels.sandbox.stats.multicomp for details.
Available methods are:
'bonferroni' : one-step correction
'sidak' : one-step correction
'holm-sidak' : step-down method using Sidak adjustments
'holm' : step-down method using Bonferroni adjustments
'simes-hochberg' : step-up method (independent)
'hommel' : closed method based on Simes tests (non-negative)
'fdr_bh' : Benjamini/Hochberg (non-negative)
'fdr_by' : Benjamini/Yekutieli (negative)
'fdr_tsbh' : two stage fdr correction (non-negative)
'fdr_tsbky' : two stage fdr correction (non-negative)
sort : bool, optional
Specifies whether to sort DataFrame by group_col or not. Recommended
unless you sort your data manually.
Returns
-------
result : pandas DataFrame
P values.
Notes
-----
Refer to `scipy.stats.mannwhitneyu` reference page for further details.
Examples
--------
>>> x = [[1,2,3,4,5], [35,31,75,40,21], [10,6,9,6,1]]
>>> sp.posthoc_mannwhitney(x, p_adjust = 'holm')
'''; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 32; 28, pattern_list; 28, 29; 28, 30; 28, 31; 29, identifier:x; 30, identifier:_val_col; 31, identifier:_group_col; 32, call; 32, 33; 32, 34; 33, identifier:__convert_to_df; 34, argument_list; 34, 35; 34, 36; 34, 37; 35, identifier:a; 36, identifier:val_col; 37, identifier:group_col; 38, if_statement; 38, 39; 38, 41; 39, not_operator; 39, 40; 40, identifier:sort; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:x; 46, identifier:_group_col; 47, call; 47, 48; 47, 49; 48, identifier:Categorical; 49, argument_list; 49, 50; 49, 53; 49, 62; 50, subscript; 50, 51; 50, 52; 51, identifier:x; 52, identifier:_group_col; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:categories; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:x; 59, identifier:_group_col; 60, identifier:unique; 61, argument_list; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:ordered; 64, True; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:x; 69, identifier:sort_values; 70, argument_list; 70, 71; 70, 76; 70, 79; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:by; 73, list:[_group_col, _val_col]; 73, 74; 73, 75; 74, identifier:_group_col; 75, identifier:_val_col; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:ascending; 78, True; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:inplace; 81, True; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:groups; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:np; 88, identifier:unique; 89, argument_list; 89, 90; 90, subscript; 90, 91; 90, 92; 91, identifier:x; 92, identifier:_group_col; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:x_len; 96, attribute; 96, 97; 96, 98; 97, identifier:groups; 98, identifier:size; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:vs; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:np; 105, identifier:zeros; 106, argument_list; 106, 107; 107, tuple; 107, 108; 107, 109; 108, identifier:x_len; 109, identifier:x_len; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:tri_upper; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:np; 116, identifier:triu_indices; 117, argument_list; 117, 118; 117, 123; 118, subscript; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:vs; 121, identifier:shape; 122, integer:0; 123, integer:1; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:tri_lower; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:np; 130, identifier:tril_indices; 131, argument_list; 131, 132; 131, 137; 132, subscript; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:vs; 135, identifier:shape; 136, integer:0; 137, unary_operator:-; 137, 138; 138, integer:1; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 147; 141, subscript; 141, 142; 141, 143; 141, 145; 142, identifier:vs; 143, slice; 143, 144; 144, colon; 145, slice; 145, 146; 146, colon; 147, integer:0; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:combs; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:it; 154, identifier:combinations; 155, argument_list; 155, 156; 155, 160; 156, call; 156, 157; 156, 158; 157, identifier:range; 158, argument_list; 158, 159; 159, identifier:x_len; 160, integer:2; 161, for_statement; 161, 162; 161, 165; 161, 166; 162, pattern_list; 162, 163; 162, 164; 163, identifier:i; 164, identifier:j; 165, identifier:combs; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 173; 169, subscript; 169, 170; 169, 171; 169, 172; 170, identifier:vs; 171, identifier:i; 172, identifier:j; 173, subscript; 173, 174; 173, 209; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:ss; 177, identifier:mannwhitneyu; 178, argument_list; 178, 179; 178, 191; 178, 203; 178, 206; 179, subscript; 179, 180; 179, 183; 179, 190; 180, attribute; 180, 181; 180, 182; 181, identifier:x; 182, identifier:loc; 183, comparison_operator:==; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:x; 186, identifier:_group_col; 187, subscript; 187, 188; 187, 189; 188, identifier:groups; 189, identifier:i; 190, identifier:_val_col; 191, subscript; 191, 192; 191, 195; 191, 202; 192, attribute; 192, 193; 192, 194; 193, identifier:x; 194, identifier:loc; 195, comparison_operator:==; 195, 196; 195, 199; 196, subscript; 196, 197; 196, 198; 197, identifier:x; 198, identifier:_group_col; 199, subscript; 199, 200; 199, 201; 200, identifier:groups; 201, identifier:j; 202, identifier:_val_col; 203, keyword_argument; 203, 204; 203, 205; 204, identifier:use_continuity; 205, identifier:use_continuity; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:alternative; 208, identifier:alternative; 209, integer:1; 210, if_statement; 210, 211; 210, 212; 211, identifier:p_adjust; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 218; 215, subscript; 215, 216; 215, 217; 216, identifier:vs; 217, identifier:tri_upper; 218, subscript; 218, 219; 218, 228; 219, call; 219, 220; 219, 221; 220, identifier:multipletests; 221, argument_list; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:vs; 224, identifier:tri_upper; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:method; 227, identifier:p_adjust; 228, integer:1; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 234; 231, subscript; 231, 232; 231, 233; 232, identifier:vs; 233, identifier:tri_lower; 234, subscript; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:vs; 237, identifier:T; 238, identifier:tri_lower; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:np; 243, identifier:fill_diagonal; 244, argument_list; 244, 245; 244, 246; 245, identifier:vs; 246, unary_operator:-; 246, 247; 247, integer:1; 248, return_statement; 248, 249; 249, call; 249, 250; 249, 251; 250, identifier:DataFrame; 251, argument_list; 251, 252; 251, 253; 251, 256; 252, identifier:vs; 253, keyword_argument; 253, 254; 253, 255; 254, identifier:index; 255, identifier:groups; 256, keyword_argument; 256, 257; 256, 258; 257, identifier:columns; 258, identifier:groups | def posthoc_mannwhitney(a, val_col=None, group_col=None, use_continuity=True, alternative='two-sided', p_adjust=None, sort=True):
'''Pairwise comparisons with Mann-Whitney rank test.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interface or a pandas
DataFrame. Array must be two-dimensional.
val_col : str, optional
Name of a DataFrame column that contains dependent variable values (test
or response variable). Values should have a non-nominal scale. Must be
specified if `a` is a pandas DataFrame object.
group_col : str, optional
Name of a DataFrame column that contains independent variable values
(grouping or predictor variable). Values should have a nominal scale
(categorical). Must be specified if `a` is a pandas DataFrame object.
use_continuity : bool, optional
Whether a continuity correction (1/2.) should be taken into account.
Default is True.
alternative : ['two-sided', 'less', or 'greater'], optional
Whether to get the p-value for the one-sided hypothesis
('less' or 'greater') or for the two-sided hypothesis ('two-sided').
Defaults to 'two-sided'.
p_adjust : str, optional
Method for adjusting p values.
See statsmodels.sandbox.stats.multicomp for details.
Available methods are:
'bonferroni' : one-step correction
'sidak' : one-step correction
'holm-sidak' : step-down method using Sidak adjustments
'holm' : step-down method using Bonferroni adjustments
'simes-hochberg' : step-up method (independent)
'hommel' : closed method based on Simes tests (non-negative)
'fdr_bh' : Benjamini/Hochberg (non-negative)
'fdr_by' : Benjamini/Yekutieli (negative)
'fdr_tsbh' : two stage fdr correction (non-negative)
'fdr_tsbky' : two stage fdr correction (non-negative)
sort : bool, optional
Specifies whether to sort DataFrame by group_col or not. Recommended
unless you sort your data manually.
Returns
-------
result : pandas DataFrame
P values.
Notes
-----
Refer to `scipy.stats.mannwhitneyu` reference page for further details.
Examples
--------
>>> x = [[1,2,3,4,5], [35,31,75,40,21], [10,6,9,6,1]]
>>> sp.posthoc_mannwhitney(x, p_adjust = 'holm')
'''
x, _val_col, _group_col = __convert_to_df(a, val_col, group_col)
if not sort:
x[_group_col] = Categorical(x[_group_col], categories=x[_group_col].unique(), ordered=True)
x.sort_values(by=[_group_col, _val_col], ascending=True, inplace=True)
groups = np.unique(x[_group_col])
x_len = groups.size
vs = np.zeros((x_len, x_len))
tri_upper = np.triu_indices(vs.shape[0], 1)
tri_lower = np.tril_indices(vs.shape[0], -1)
vs[:,:] = 0
combs = it.combinations(range(x_len), 2)
for i,j in combs:
vs[i, j] = ss.mannwhitneyu(x.loc[x[_group_col] == groups[i], _val_col],
x.loc[x[_group_col] == groups[j], _val_col],
use_continuity=use_continuity,
alternative=alternative)[1]
if p_adjust:
vs[tri_upper] = multipletests(vs[tri_upper], method = p_adjust)[1]
vs[tri_lower] = vs.T[tri_lower]
np.fill_diagonal(vs, -1)
return DataFrame(vs, index=groups, columns=groups) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:posthoc_wilcoxon; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:a; 5, default_parameter; 5, 6; 5, 7; 6, identifier:val_col; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:group_col; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:zero_method; 13, string:'wilcox'; 14, default_parameter; 14, 15; 14, 16; 15, identifier:correction; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:p_adjust; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:sort; 22, False; 23, block; 23, 24; 23, 26; 23, 38; 23, 65; 23, 66; 23, 77; 23, 83; 23, 94; 23, 108; 23, 123; 23, 132; 23, 145; 23, 194; 23, 213; 23, 223; 23, 232; 24, expression_statement; 24, 25; 25, string:'''Pairwise comparisons with Wilcoxon signed-rank test. It is a non-parametric
version of the paired T-test for use with non-parametric ANOVA.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interface or a pandas
DataFrame. Array must be two-dimensional.
val_col : str, optional
Name of a DataFrame column that contains dependent variable values (test
or response variable). Values should have a non-nominal scale. Must be
specified if `a` is a pandas DataFrame object.
group_col : str, optional
Name of a DataFrame column that contains independent variable values
(grouping or predictor variable). Values should have a nominal scale
(categorical). Must be specified if `a` is a pandas DataFrame object.
zero_method : string, {"pratt", "wilcox", "zsplit"}, optional
"pratt": Pratt treatment, includes zero-differences in the ranking
process (more conservative)
"wilcox": Wilcox treatment, discards all zero-differences
"zsplit": Zero rank split, just like Pratt, but spliting the zero rank
between positive and negative ones
correction : bool, optional
If True, apply continuity correction by adjusting the Wilcoxon rank
statistic by 0.5 towards the mean value when computing the z-statistic.
Default is False.
p_adjust : str, optional
Method for adjusting p values.
See statsmodels.sandbox.stats.multicomp for details.
Available methods are:
'bonferroni' : one-step correction
'sidak' : one-step correction
'holm-sidak' : step-down method using Sidak adjustments
'holm' : step-down method using Bonferroni adjustments
'simes-hochberg' : step-up method (independent)
'hommel' : closed method based on Simes tests (non-negative)
'fdr_bh' : Benjamini/Hochberg (non-negative)
'fdr_by' : Benjamini/Yekutieli (negative)
'fdr_tsbh' : two stage fdr correction (non-negative)
'fdr_tsbky' : two stage fdr correction (non-negative)
sort : bool, optional
Specifies whether to sort DataFrame by group_col and val_col or not.
Default is False.
Returns
-------
result : pandas DataFrame
P values.
Notes
-----
Refer to `scipy.stats.wilcoxon` reference page for further details.
Examples
--------
>>> x = [[1,2,3,4,5], [35,31,75,40,21], [10,6,9,6,1]]
>>> sp.posthoc_wilcoxon(x)
'''; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 32; 28, pattern_list; 28, 29; 28, 30; 28, 31; 29, identifier:x; 30, identifier:_val_col; 31, identifier:_group_col; 32, call; 32, 33; 32, 34; 33, identifier:__convert_to_df; 34, argument_list; 34, 35; 34, 36; 34, 37; 35, identifier:a; 36, identifier:val_col; 37, identifier:group_col; 38, if_statement; 38, 39; 38, 41; 39, not_operator; 39, 40; 40, identifier:sort; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 47; 44, subscript; 44, 45; 44, 46; 45, identifier:x; 46, identifier:_group_col; 47, call; 47, 48; 47, 49; 48, identifier:Categorical; 49, argument_list; 49, 50; 49, 53; 49, 62; 50, subscript; 50, 51; 50, 52; 51, identifier:x; 52, identifier:_group_col; 53, keyword_argument; 53, 54; 53, 55; 54, identifier:categories; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, subscript; 57, 58; 57, 59; 58, identifier:x; 59, identifier:_group_col; 60, identifier:unique; 61, argument_list; 62, keyword_argument; 62, 63; 62, 64; 63, identifier:ordered; 64, True; 65, comment; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:groups; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:np; 72, identifier:unique; 73, argument_list; 73, 74; 74, subscript; 74, 75; 74, 76; 75, identifier:x; 76, identifier:_group_col; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:x_len; 80, attribute; 80, 81; 80, 82; 81, identifier:groups; 82, identifier:size; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:vs; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:np; 89, identifier:zeros; 90, argument_list; 90, 91; 91, tuple; 91, 92; 91, 93; 92, identifier:x_len; 93, identifier:x_len; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:tri_upper; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:np; 100, identifier:triu_indices; 101, argument_list; 101, 102; 101, 107; 102, subscript; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:vs; 105, identifier:shape; 106, integer:0; 107, integer:1; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:tri_lower; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:np; 114, identifier:tril_indices; 115, argument_list; 115, 116; 115, 121; 116, subscript; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:vs; 119, identifier:shape; 120, integer:0; 121, unary_operator:-; 121, 122; 122, integer:1; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 131; 125, subscript; 125, 126; 125, 127; 125, 129; 126, identifier:vs; 127, slice; 127, 128; 128, colon; 129, slice; 129, 130; 130, colon; 131, integer:0; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:combs; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:it; 138, identifier:combinations; 139, argument_list; 139, 140; 139, 144; 140, call; 140, 141; 140, 142; 141, identifier:range; 142, argument_list; 142, 143; 143, identifier:x_len; 144, integer:2; 145, for_statement; 145, 146; 145, 149; 145, 150; 146, pattern_list; 146, 147; 146, 148; 147, identifier:i; 148, identifier:j; 149, identifier:combs; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 157; 153, subscript; 153, 154; 153, 155; 153, 156; 154, identifier:vs; 155, identifier:i; 156, identifier:j; 157, subscript; 157, 158; 157, 193; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:ss; 161, identifier:wilcoxon; 162, argument_list; 162, 163; 162, 175; 162, 187; 162, 190; 163, subscript; 163, 164; 163, 167; 163, 174; 164, attribute; 164, 165; 164, 166; 165, identifier:x; 166, identifier:loc; 167, comparison_operator:==; 167, 168; 167, 171; 168, subscript; 168, 169; 168, 170; 169, identifier:x; 170, identifier:_group_col; 171, subscript; 171, 172; 171, 173; 172, identifier:groups; 173, identifier:i; 174, identifier:_val_col; 175, subscript; 175, 176; 175, 179; 175, 186; 176, attribute; 176, 177; 176, 178; 177, identifier:x; 178, identifier:loc; 179, comparison_operator:==; 179, 180; 179, 183; 180, subscript; 180, 181; 180, 182; 181, identifier:x; 182, identifier:_group_col; 183, subscript; 183, 184; 183, 185; 184, identifier:groups; 185, identifier:j; 186, identifier:_val_col; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:zero_method; 189, identifier:zero_method; 190, keyword_argument; 190, 191; 190, 192; 191, identifier:correction; 192, identifier:correction; 193, integer:1; 194, if_statement; 194, 195; 194, 196; 195, identifier:p_adjust; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 202; 199, subscript; 199, 200; 199, 201; 200, identifier:vs; 201, identifier:tri_upper; 202, subscript; 202, 203; 202, 212; 203, call; 203, 204; 203, 205; 204, identifier:multipletests; 205, argument_list; 205, 206; 205, 209; 206, subscript; 206, 207; 206, 208; 207, identifier:vs; 208, identifier:tri_upper; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:method; 211, identifier:p_adjust; 212, integer:1; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 218; 215, subscript; 215, 216; 215, 217; 216, identifier:vs; 217, identifier:tri_lower; 218, subscript; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:vs; 221, identifier:T; 222, identifier:tri_lower; 223, expression_statement; 223, 224; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:np; 227, identifier:fill_diagonal; 228, argument_list; 228, 229; 228, 230; 229, identifier:vs; 230, unary_operator:-; 230, 231; 231, integer:1; 232, return_statement; 232, 233; 233, call; 233, 234; 233, 235; 234, identifier:DataFrame; 235, argument_list; 235, 236; 235, 237; 235, 240; 236, identifier:vs; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:index; 239, identifier:groups; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:columns; 242, identifier:groups | def posthoc_wilcoxon(a, val_col=None, group_col=None, zero_method='wilcox', correction=False, p_adjust=None, sort=False):
'''Pairwise comparisons with Wilcoxon signed-rank test. It is a non-parametric
version of the paired T-test for use with non-parametric ANOVA.
Parameters
----------
a : array_like or pandas DataFrame object
An array, any object exposing the array interface or a pandas
DataFrame. Array must be two-dimensional.
val_col : str, optional
Name of a DataFrame column that contains dependent variable values (test
or response variable). Values should have a non-nominal scale. Must be
specified if `a` is a pandas DataFrame object.
group_col : str, optional
Name of a DataFrame column that contains independent variable values
(grouping or predictor variable). Values should have a nominal scale
(categorical). Must be specified if `a` is a pandas DataFrame object.
zero_method : string, {"pratt", "wilcox", "zsplit"}, optional
"pratt": Pratt treatment, includes zero-differences in the ranking
process (more conservative)
"wilcox": Wilcox treatment, discards all zero-differences
"zsplit": Zero rank split, just like Pratt, but spliting the zero rank
between positive and negative ones
correction : bool, optional
If True, apply continuity correction by adjusting the Wilcoxon rank
statistic by 0.5 towards the mean value when computing the z-statistic.
Default is False.
p_adjust : str, optional
Method for adjusting p values.
See statsmodels.sandbox.stats.multicomp for details.
Available methods are:
'bonferroni' : one-step correction
'sidak' : one-step correction
'holm-sidak' : step-down method using Sidak adjustments
'holm' : step-down method using Bonferroni adjustments
'simes-hochberg' : step-up method (independent)
'hommel' : closed method based on Simes tests (non-negative)
'fdr_bh' : Benjamini/Hochberg (non-negative)
'fdr_by' : Benjamini/Yekutieli (negative)
'fdr_tsbh' : two stage fdr correction (non-negative)
'fdr_tsbky' : two stage fdr correction (non-negative)
sort : bool, optional
Specifies whether to sort DataFrame by group_col and val_col or not.
Default is False.
Returns
-------
result : pandas DataFrame
P values.
Notes
-----
Refer to `scipy.stats.wilcoxon` reference page for further details.
Examples
--------
>>> x = [[1,2,3,4,5], [35,31,75,40,21], [10,6,9,6,1]]
>>> sp.posthoc_wilcoxon(x)
'''
x, _val_col, _group_col = __convert_to_df(a, val_col, group_col)
if not sort:
x[_group_col] = Categorical(x[_group_col], categories=x[_group_col].unique(), ordered=True)
#x.sort_values(by=[_group_col, _val_col], ascending=True, inplace=True)
groups = np.unique(x[_group_col])
x_len = groups.size
vs = np.zeros((x_len, x_len))
tri_upper = np.triu_indices(vs.shape[0], 1)
tri_lower = np.tril_indices(vs.shape[0], -1)
vs[:,:] = 0
combs = it.combinations(range(x_len), 2)
for i,j in combs:
vs[i, j] = ss.wilcoxon(x.loc[x[_group_col] == groups[i], _val_col],
x.loc[x[_group_col] == groups[j], _val_col],
zero_method=zero_method, correction=correction)[1]
if p_adjust:
vs[tri_upper] = multipletests(vs[tri_upper], method=p_adjust)[1]
vs[tri_lower] = vs.T[tri_lower]
np.fill_diagonal(vs, -1)
return DataFrame(vs, index=groups, columns=groups) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:calendarplot; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:how; 7, string:'sum'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:yearlabels; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:yearascending; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:yearlabel_kws; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:subplot_kws; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:gridspec_kws; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:fig_kws; 25, None; 26, dictionary_splat_pattern; 26, 27; 27, identifier:kwargs; 28, block; 28, 29; 28, 31; 28, 37; 28, 43; 28, 49; 28, 55; 28, 68; 28, 82; 28, 112; 28, 120; 28, 121; 28, 163; 28, 190; 28, 197; 28, 201; 28, 256; 28, 257; 28, 258; 28, 270; 28, 271; 28, 277; 29, expression_statement; 29, 30; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:yearlabel_kws; 34, boolean_operator:or; 34, 35; 34, 36; 35, identifier:yearlabel_kws; 36, dictionary; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:subplot_kws; 40, boolean_operator:or; 40, 41; 40, 42; 41, identifier:subplot_kws; 42, dictionary; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:gridspec_kws; 46, boolean_operator:or; 46, 47; 46, 48; 47, identifier:gridspec_kws; 48, dictionary; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:fig_kws; 52, boolean_operator:or; 52, 53; 52, 54; 53, identifier:fig_kws; 54, dictionary; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:years; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:np; 61, identifier:unique; 62, argument_list; 62, 63; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:data; 66, identifier:index; 67, identifier:year; 68, if_statement; 68, 69; 68, 71; 69, not_operator; 69, 70; 70, identifier:yearascending; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:years; 75, subscript; 75, 76; 75, 77; 76, identifier:years; 77, slice; 77, 78; 77, 79; 77, 80; 78, colon; 79, colon; 80, unary_operator:-; 80, 81; 81, integer:1; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, pattern_list; 84, 85; 84, 86; 85, identifier:fig; 86, identifier:axes; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:plt; 90, identifier:subplots; 91, argument_list; 91, 92; 91, 98; 91, 101; 91, 104; 91, 107; 91, 110; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:nrows; 94, call; 94, 95; 94, 96; 95, identifier:len; 96, argument_list; 96, 97; 97, identifier:years; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:ncols; 100, integer:1; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:squeeze; 103, False; 104, keyword_argument; 104, 105; 104, 106; 105, identifier:subplot_kw; 106, identifier:subplot_kws; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:gridspec_kw; 109, identifier:gridspec_kws; 110, dictionary_splat; 110, 111; 111, identifier:fig_kws; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:axes; 115, subscript; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:axes; 118, identifier:T; 119, integer:0; 120, comment; 121, if_statement; 121, 122; 121, 125; 121, 130; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:how; 124, None; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:by_day; 129, identifier:data; 130, else_clause; 130, 131; 131, block; 131, 132; 132, if_statement; 132, 133; 132, 134; 132, 149; 133, identifier:_pandas_18; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:by_day; 138, call; 138, 139; 138, 147; 139, attribute; 139, 140; 139, 146; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:data; 143, identifier:resample; 144, argument_list; 144, 145; 145, string:'D'; 146, identifier:agg; 147, argument_list; 147, 148; 148, identifier:how; 149, else_clause; 149, 150; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:by_day; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:data; 157, identifier:resample; 158, argument_list; 158, 159; 158, 160; 159, string:'D'; 160, keyword_argument; 160, 161; 160, 162; 161, identifier:how; 162, identifier:how; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:ylabel_kws; 166, call; 166, 167; 166, 168; 167, identifier:dict; 168, argument_list; 168, 169; 168, 172; 168, 181; 168, 184; 168, 187; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:fontsize; 171, integer:32; 172, keyword_argument; 172, 173; 172, 174; 173, identifier:color; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:kwargs; 177, identifier:get; 178, argument_list; 178, 179; 178, 180; 179, string:'fillcolor'; 180, string:'whitesmoke'; 181, keyword_argument; 181, 182; 181, 183; 182, identifier:fontweight; 183, string:'bold'; 184, keyword_argument; 184, 185; 184, 186; 185, identifier:fontname; 186, string:'Arial'; 187, keyword_argument; 187, 188; 187, 189; 188, identifier:ha; 189, string:'center'; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:ylabel_kws; 194, identifier:update; 195, argument_list; 195, 196; 196, identifier:yearlabel_kws; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:max_weeks; 200, integer:0; 201, for_statement; 201, 202; 201, 205; 201, 210; 202, pattern_list; 202, 203; 202, 204; 203, identifier:year; 204, identifier:ax; 205, call; 205, 206; 205, 207; 206, identifier:zip; 207, argument_list; 207, 208; 207, 209; 208, identifier:years; 209, identifier:axes; 210, block; 210, 211; 210, 227; 210, 241; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:yearplot; 214, argument_list; 214, 215; 214, 216; 214, 219; 214, 222; 214, 225; 215, identifier:by_day; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:year; 218, identifier:year; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:how; 221, None; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:ax; 224, identifier:ax; 225, dictionary_splat; 225, 226; 226, identifier:kwargs; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:max_weeks; 230, call; 230, 231; 230, 232; 231, identifier:max; 232, argument_list; 232, 233; 232, 234; 233, identifier:max_weeks; 234, subscript; 234, 235; 234, 240; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:ax; 238, identifier:get_xlim; 239, argument_list; 240, integer:1; 241, if_statement; 241, 242; 241, 243; 242, identifier:yearlabels; 243, block; 243, 244; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:ax; 248, identifier:set_ylabel; 249, argument_list; 249, 250; 249, 254; 250, call; 250, 251; 250, 252; 251, identifier:str; 252, argument_list; 252, 253; 253, identifier:year; 254, dictionary_splat; 254, 255; 255, identifier:ylabel_kws; 256, comment; 257, comment; 258, for_statement; 258, 259; 258, 260; 258, 261; 259, identifier:ax; 260, identifier:axes; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:ax; 266, identifier:set_xlim; 267, argument_list; 267, 268; 267, 269; 268, integer:0; 269, identifier:max_weeks; 270, comment; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:plt; 275, identifier:tight_layout; 276, argument_list; 277, return_statement; 277, 278; 278, expression_list; 278, 279; 278, 280; 279, identifier:fig; 280, identifier:axes | def calendarplot(data, how='sum', yearlabels=True, yearascending=True, yearlabel_kws=None,
subplot_kws=None, gridspec_kws=None, fig_kws=None, **kwargs):
"""
Plot a timeseries as a calendar heatmap.
Parameters
----------
data : Series
Data for the plot. Must be indexed by a DatetimeIndex.
how : string
Method for resampling data by day. If `None`, assume data is already
sampled by day and don't resample. Otherwise, this is passed to Pandas
`Series.resample`.
yearlabels : bool
Whether or not to draw the year for each subplot.
yearascending : bool
Sort the calendar in ascending or descending order.
yearlabel_kws : dict
Keyword arguments passed to the matplotlib `set_ylabel` call which is
used to draw the year for each subplot.
subplot_kws : dict
Keyword arguments passed to the matplotlib `add_subplot` call used to
create each subplot.
gridspec_kws : dict
Keyword arguments passed to the matplotlib `GridSpec` constructor used
to create the grid the subplots are placed on.
fig_kws : dict
Keyword arguments passed to the matplotlib `figure` call.
kwargs : other keyword arguments
All other keyword arguments are passed to `yearplot`.
Returns
-------
fig, axes : matplotlib Figure and Axes
Tuple where `fig` is the matplotlib Figure object `axes` is an array
of matplotlib Axes objects with the calendar heatmaps, one per year.
Examples
--------
With `calendarplot` we can plot several years in one figure:
.. plot::
:context: close-figs
calmap.calendarplot(events)
"""
yearlabel_kws = yearlabel_kws or {}
subplot_kws = subplot_kws or {}
gridspec_kws = gridspec_kws or {}
fig_kws = fig_kws or {}
years = np.unique(data.index.year)
if not yearascending:
years = years[::-1]
fig, axes = plt.subplots(nrows=len(years), ncols=1, squeeze=False,
subplot_kw=subplot_kws,
gridspec_kw=gridspec_kws, **fig_kws)
axes = axes.T[0]
# We explicitely resample by day only once. This is an optimization.
if how is None:
by_day = data
else:
if _pandas_18:
by_day = data.resample('D').agg(how)
else:
by_day = data.resample('D', how=how)
ylabel_kws = dict(
fontsize=32,
color=kwargs.get('fillcolor', 'whitesmoke'),
fontweight='bold',
fontname='Arial',
ha='center')
ylabel_kws.update(yearlabel_kws)
max_weeks = 0
for year, ax in zip(years, axes):
yearplot(by_day, year=year, how=None, ax=ax, **kwargs)
max_weeks = max(max_weeks, ax.get_xlim()[1])
if yearlabels:
ax.set_ylabel(str(year), **ylabel_kws)
# In a leap year it might happen that we have 54 weeks (e.g., 2012).
# Here we make sure the width is consistent over all years.
for ax in axes:
ax.set_xlim(0, max_weeks)
# Make the axes look good.
plt.tight_layout()
return fig, axes |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:tasks; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:pattern; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:negate; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:state; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:limit; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:reverse; 19, True; 20, default_parameter; 20, 21; 20, 22; 21, identifier:params; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:success; 25, False; 26, default_parameter; 26, 27; 26, 28; 27, identifier:error; 28, True; 29, block; 29, 30; 29, 32; 29, 66; 30, expression_statement; 30, 31; 31, comment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:request; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:clearly_pb2; 38, identifier:FilterTasksRequest; 39, argument_list; 39, 40; 39, 55; 39, 60; 39, 63; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:tasks_filter; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:clearly_pb2; 45, identifier:PatternFilter; 46, argument_list; 46, 47; 46, 52; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:pattern; 49, boolean_operator:or; 49, 50; 49, 51; 50, identifier:pattern; 51, string:'.'; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:negate; 54, identifier:negate; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:state_pattern; 57, boolean_operator:or; 57, 58; 57, 59; 58, identifier:state; 59, string:'.'; 60, keyword_argument; 60, 61; 60, 62; 61, identifier:limit; 62, identifier:limit; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:reverse; 65, identifier:reverse; 66, for_statement; 66, 67; 66, 68; 66, 82; 67, identifier:task; 68, call; 68, 69; 68, 70; 69, identifier:about_time; 70, argument_list; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:ClearlyClient; 73, identifier:_fetched_callback; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:_stub; 79, identifier:filter_tasks; 80, argument_list; 80, 81; 81, identifier:request; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:ClearlyClient; 87, identifier:_display_task; 88, argument_list; 88, 89; 88, 90; 88, 91; 88, 92; 89, identifier:task; 90, identifier:params; 91, identifier:success; 92, identifier:error | def tasks(self, pattern=None, negate=False, state=None, limit=None, reverse=True,
params=None, success=False, error=True):
"""Filters stored tasks and displays their current statuses.
Note that, to be able to list the tasks sorted chronologically, celery retrieves
tasks from the LRU event heap instead of the dict storage, so the total number
of tasks fetched may be different than the server `max_tasks` setting. For
instance, the `limit` field refers to max events searched, not max tasks.
Args:
Filter args:
pattern (Optional[str]): a pattern to filter tasks
ex.: '^dispatch|^email' to filter names starting with that
or 'dispatch.*123456' to filter that exact name and number
or even '123456' to filter that exact number anywhere.
negate (bool): if True, finds tasks that do not match criteria
state (Optional[str]): a celery task state to filter
limit (int): the maximum number of events to fetch
if None or 0, fetches all.
reverse (bool): if True (default), shows the most recent first
Display args:
params (Optional[bool]): if True shows args and kwargs in the first and
last seen states, if False never shows, and if None follows the
success and error arguments.
default is None
success (bool): if True shows successful tasks' results
default is False
error (bool): if True shows failed and retried tasks' tracebacks.
default is True, as you're monitoring to find errors, right?
"""
request = clearly_pb2.FilterTasksRequest(
tasks_filter=clearly_pb2.PatternFilter(pattern=pattern or '.',
negate=negate),
state_pattern=state or '.', limit=limit, reverse=reverse
)
for task in about_time(ClearlyClient._fetched_callback, self._stub.filter_tasks(request)):
ClearlyClient._display_task(task, params, success, error) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:echo_headers; 3, parameters; 3, 4; 3, 5; 4, identifier:headers; 5, default_parameter; 5, 6; 5, 7; 6, identifier:file; 7, None; 8, block; 8, 9; 8, 11; 8, 44; 9, expression_statement; 9, 10; 10, comment; 11, for_statement; 11, 12; 11, 15; 11, 23; 12, pattern_list; 12, 13; 12, 14; 13, identifier:k; 14, identifier:v; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:headers; 21, identifier:items; 22, argument_list; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:click; 28, identifier:echo; 29, argument_list; 29, 30; 29, 41; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, string:"{0}: {1}"; 33, identifier:format; 34, argument_list; 34, 35; 34, 40; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:k; 38, identifier:title; 39, argument_list; 40, identifier:v; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:file; 43, identifier:file; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:click; 48, identifier:echo; 49, argument_list; 49, 50; 50, keyword_argument; 50, 51; 50, 52; 51, identifier:file; 52, identifier:file | def echo_headers(headers, file=None):
"""Echo headers, sorted."""
for k, v in sorted(headers.items()):
click.echo("{0}: {1}".format(k.title(), v), file=file)
click.echo(file=file) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:by_own_time_per_call; 3, parameters; 3, 4; 4, identifier:stat; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, return_statement; 8, 9; 9, tuple; 9, 10; 9, 22; 10, conditional_expression:if; 10, 11; 10, 15; 10, 18; 11, unary_operator:-; 11, 12; 12, attribute; 12, 13; 12, 14; 13, identifier:stat; 14, identifier:own_time_per_call; 15, attribute; 15, 16; 15, 17; 16, identifier:stat; 17, identifier:own_hits; 18, unary_operator:-; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:stat; 21, identifier:own_time; 22, call; 22, 23; 22, 24; 23, identifier:by_deep_time_per_call; 24, argument_list; 24, 25; 25, identifier:stat | def by_own_time_per_call(stat):
"""Sorting by exclusive elapsed time per call in descending order."""
return (-stat.own_time_per_call if stat.own_hits else -stat.own_time,
by_deep_time_per_call(stat)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:missing_labels; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, return_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:np; 12, identifier:array; 13, argument_list; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:sorted; 16, argument_list; 16, 17; 17, call; 17, 18; 17, 32; 18, attribute; 18, 19; 18, 31; 19, call; 19, 20; 19, 21; 20, identifier:set; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:range; 24, argument_list; 24, 25; 24, 26; 25, integer:0; 26, binary_operator:+; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:max_label; 30, integer:1; 31, identifier:difference; 32, argument_list; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:np; 36, identifier:insert; 37, argument_list; 37, 38; 37, 41; 37, 42; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:labels; 41, integer:0; 42, integer:0 | def missing_labels(self):
"""
A 1D `~numpy.ndarray` of the sorted non-zero labels that are
missing in the consecutive sequence from zero to the maximum
label number.
"""
return np.array(sorted(set(range(0, self.max_label + 1)).
difference(np.insert(self.labels, 0, 0)))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 47; 1, 48; 1, 49; 1, 50; 1, 51; 2, function_name:fit_image; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 3, 38; 3, 41; 3, 44; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sma0; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:minsma; 10, float:0.; 11, default_parameter; 11, 12; 11, 13; 12, identifier:maxsma; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:step; 16, float:0.1; 17, default_parameter; 17, 18; 17, 19; 18, identifier:conver; 19, identifier:DEFAULT_CONVERGENCE; 20, default_parameter; 20, 21; 20, 22; 21, identifier:minit; 22, identifier:DEFAULT_MINIT; 23, default_parameter; 23, 24; 23, 25; 24, identifier:maxit; 25, identifier:DEFAULT_MAXIT; 26, default_parameter; 26, 27; 26, 28; 27, identifier:fflag; 28, identifier:DEFAULT_FFLAG; 29, default_parameter; 29, 30; 29, 31; 30, identifier:maxgerr; 31, identifier:DEFAULT_MAXGERR; 32, default_parameter; 32, 33; 32, 34; 33, identifier:sclip; 34, float:3.; 35, default_parameter; 35, 36; 35, 37; 36, identifier:nclip; 37, integer:0; 38, default_parameter; 38, 39; 38, 40; 39, identifier:integrmode; 40, identifier:BILINEAR; 41, default_parameter; 41, 42; 41, 43; 42, identifier:linear; 43, False; 44, default_parameter; 44, 45; 44, 46; 45, identifier:maxrit; 46, None; 47, comment; 48, comment; 49, comment; 50, comment; 51, block; 51, 52; 51, 54; 51, 55; 51, 59; 51, 60; 51, 61; 51, 90; 51, 91; 51, 92; 51, 96; 51, 100; 51, 290; 51, 291; 51, 297; 51, 312; 51, 313; 51, 392; 51, 393; 51, 410; 51, 411; 51, 417; 52, expression_statement; 52, 53; 53, comment; 54, comment; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:isophote_list; 58, list:[]; 59, comment; 60, comment; 61, if_statement; 61, 62; 61, 64; 61, 84; 62, not_operator; 62, 63; 63, identifier:sma0; 64, block; 64, 65; 65, if_statement; 65, 66; 65, 69; 65, 78; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:_geometry; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:sma; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:_geometry; 77, identifier:sma; 78, else_clause; 78, 79; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:sma; 83, float:10.; 84, else_clause; 84, 85; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:sma; 89, identifier:sma0; 90, comment; 91, comment; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:noiter; 95, False; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:first_isophote; 99, True; 100, while_statement; 100, 101; 100, 102; 100, 103; 101, True; 102, comment; 103, block; 103, 104; 103, 113; 103, 117; 103, 143; 103, 144; 103, 258; 103, 259; 103, 260; 103, 267; 103, 268; 103, 269; 103, 282; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:minit_a; 107, conditional_expression:if; 107, 108; 107, 111; 107, 112; 108, binary_operator:*; 108, 109; 108, 110; 109, integer:2; 110, identifier:minit; 111, identifier:first_isophote; 112, identifier:minit; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:first_isophote; 116, False; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:isophote; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:fit_isophote; 124, argument_list; 124, 125; 124, 126; 124, 127; 124, 128; 124, 129; 124, 130; 124, 131; 124, 132; 124, 133; 124, 134; 124, 135; 124, 136; 124, 137; 124, 140; 125, identifier:sma; 126, identifier:step; 127, identifier:conver; 128, identifier:minit_a; 129, identifier:maxit; 130, identifier:fflag; 131, identifier:maxgerr; 132, identifier:sclip; 133, identifier:nclip; 134, identifier:integrmode; 135, identifier:linear; 136, identifier:maxrit; 137, keyword_argument; 137, 138; 137, 139; 138, identifier:noniterate; 139, identifier:noiter; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:isophote_list; 142, identifier:isophote_list; 143, comment; 144, if_statement; 144, 145; 144, 157; 144, 158; 144, 159; 144, 160; 144, 161; 145, parenthesized_expression; 145, 146; 146, boolean_operator:or; 146, 147; 146, 152; 147, comparison_operator:<; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:isophote; 150, identifier:stop_code; 151, integer:0; 152, comparison_operator:==; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:isophote; 155, identifier:stop_code; 156, integer:1; 157, comment; 158, comment; 159, comment; 160, comment; 161, block; 161, 162; 161, 183; 161, 192; 161, 193; 161, 194; 161, 201; 161, 202; 161, 203; 161, 204; 162, if_statement; 162, 163; 162, 169; 163, comparison_operator:==; 163, 164; 163, 168; 164, call; 164, 165; 164, 166; 165, identifier:len; 166, argument_list; 166, 167; 167, identifier:isophote_list; 168, integer:1; 169, block; 169, 170; 169, 178; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:warnings; 174, identifier:warn; 175, argument_list; 175, 176; 175, 177; 176, string:'No meaningful fit was possible.'; 177, identifier:AstropyUserWarning; 178, return_statement; 178, 179; 179, call; 179, 180; 179, 181; 180, identifier:IsophoteList; 181, argument_list; 181, 182; 182, list:[]; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:_fix_last_isophote; 188, argument_list; 188, 189; 188, 190; 189, identifier:isophote_list; 190, unary_operator:-; 190, 191; 191, integer:1; 192, comment; 193, comment; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:isophote; 197, subscript; 197, 198; 197, 199; 198, identifier:isophote_list; 199, unary_operator:-; 199, 200; 200, integer:1; 201, comment; 202, comment; 203, comment; 204, if_statement; 204, 205; 204, 211; 205, comparison_operator:>; 205, 206; 205, 210; 206, call; 206, 207; 206, 208; 207, identifier:len; 208, argument_list; 208, 209; 209, identifier:isophote_list; 210, integer:2; 211, block; 211, 212; 212, if_statement; 212, 213; 212, 235; 213, parenthesized_expression; 213, 214; 214, boolean_operator:or; 214, 215; 214, 230; 215, parenthesized_expression; 215, 216; 216, boolean_operator:and; 216, 217; 216, 222; 217, comparison_operator:==; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:isophote; 220, identifier:stop_code; 221, integer:5; 222, comparison_operator:==; 222, 223; 222, 229; 223, attribute; 223, 224; 223, 228; 224, subscript; 224, 225; 224, 226; 225, identifier:isophote_list; 226, unary_operator:-; 226, 227; 227, integer:2; 228, identifier:stop_code; 229, integer:5; 230, comparison_operator:==; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:isophote; 233, identifier:stop_code; 234, integer:1; 235, block; 235, 236; 236, if_statement; 236, 237; 236, 244; 236, 245; 236, 246; 236, 247; 236, 248; 236, 253; 237, boolean_operator:and; 237, 238; 237, 239; 238, identifier:maxsma; 239, comparison_operator:>; 239, 240; 239, 241; 240, identifier:maxsma; 241, attribute; 241, 242; 241, 243; 242, identifier:isophote; 243, identifier:sma; 244, comment; 245, comment; 246, comment; 247, comment; 248, block; 248, 249; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:noiter; 252, True; 253, else_clause; 253, 254; 253, 255; 253, 256; 254, comment; 255, comment; 256, block; 256, 257; 257, break_statement; 258, comment; 259, comment; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:isophote; 263, subscript; 263, 264; 263, 265; 264, identifier:isophote_list; 265, unary_operator:-; 265, 266; 266, integer:1; 267, comment; 268, comment; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:sma; 272, call; 272, 273; 272, 280; 273, attribute; 273, 274; 273, 279; 274, attribute; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:isophote; 277, identifier:sample; 278, identifier:geometry; 279, identifier:update_sma; 280, argument_list; 280, 281; 281, identifier:step; 282, if_statement; 282, 283; 282, 288; 283, boolean_operator:and; 283, 284; 283, 285; 284, identifier:maxsma; 285, comparison_operator:>=; 285, 286; 285, 287; 286, identifier:sma; 287, identifier:maxsma; 288, block; 288, 289; 289, break_statement; 290, comment; 291, expression_statement; 291, 292; 292, assignment; 292, 293; 292, 294; 293, identifier:first_isophote; 294, subscript; 294, 295; 294, 296; 295, identifier:isophote_list; 296, integer:0; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 302; 299, pattern_list; 299, 300; 299, 301; 300, identifier:sma; 301, identifier:step; 302, call; 302, 303; 302, 310; 303, attribute; 303, 304; 303, 309; 304, attribute; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:first_isophote; 307, identifier:sample; 308, identifier:geometry; 309, identifier:reset_sma; 310, argument_list; 310, 311; 311, identifier:step; 312, comment; 313, while_statement; 313, 314; 313, 315; 314, True; 315, block; 315, 316; 315, 342; 315, 343; 315, 358; 315, 359; 315, 360; 315, 367; 315, 368; 315, 369; 315, 382; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:isophote; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:self; 322, identifier:fit_isophote; 323, argument_list; 323, 324; 323, 325; 323, 326; 323, 327; 323, 328; 323, 329; 323, 330; 323, 331; 323, 332; 323, 333; 323, 334; 323, 335; 323, 336; 323, 339; 324, identifier:sma; 325, identifier:step; 326, identifier:conver; 327, identifier:minit; 328, identifier:maxit; 329, identifier:fflag; 330, identifier:maxgerr; 331, identifier:sclip; 332, identifier:nclip; 333, identifier:integrmode; 334, identifier:linear; 335, identifier:maxrit; 336, keyword_argument; 336, 337; 336, 338; 337, identifier:going_inwards; 338, True; 339, keyword_argument; 339, 340; 339, 341; 340, identifier:isophote_list; 341, identifier:isophote_list; 342, comment; 343, if_statement; 343, 344; 343, 349; 344, comparison_operator:<; 344, 345; 344, 348; 345, attribute; 345, 346; 345, 347; 346, identifier:isophote; 347, identifier:stop_code; 348, integer:0; 349, block; 349, 350; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:self; 354, identifier:_fix_last_isophote; 355, argument_list; 355, 356; 355, 357; 356, identifier:isophote_list; 357, integer:0; 358, comment; 359, comment; 360, expression_statement; 360, 361; 361, assignment; 361, 362; 361, 363; 362, identifier:isophote; 363, subscript; 363, 364; 363, 365; 364, identifier:isophote_list; 365, unary_operator:-; 365, 366; 366, integer:1; 367, comment; 368, comment; 369, expression_statement; 369, 370; 370, assignment; 370, 371; 370, 372; 371, identifier:sma; 372, call; 372, 373; 372, 380; 373, attribute; 373, 374; 373, 379; 374, attribute; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:isophote; 377, identifier:sample; 378, identifier:geometry; 379, identifier:update_sma; 380, argument_list; 380, 381; 381, identifier:step; 382, if_statement; 382, 383; 382, 390; 383, comparison_operator:<=; 383, 384; 383, 385; 384, identifier:sma; 385, call; 385, 386; 385, 387; 386, identifier:max; 387, argument_list; 387, 388; 387, 389; 388, identifier:minsma; 389, float:0.5; 390, block; 390, 391; 391, break_statement; 392, comment; 393, if_statement; 393, 394; 393, 397; 394, comparison_operator:==; 394, 395; 394, 396; 395, identifier:minsma; 396, float:0.0; 397, block; 397, 398; 398, expression_statement; 398, 399; 399, assignment; 399, 400; 399, 401; 400, identifier:isophote; 401, call; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:self; 404, identifier:fit_isophote; 405, argument_list; 405, 406; 405, 407; 406, float:0.0; 407, keyword_argument; 407, 408; 407, 409; 408, identifier:isophote_list; 409, identifier:isophote_list; 410, comment; 411, expression_statement; 411, 412; 412, call; 412, 413; 412, 416; 413, attribute; 413, 414; 413, 415; 414, identifier:isophote_list; 415, identifier:sort; 416, argument_list; 417, return_statement; 417, 418; 418, call; 418, 419; 418, 420; 419, identifier:IsophoteList; 420, argument_list; 420, 421; 421, identifier:isophote_list | def fit_image(self, sma0=None, minsma=0., maxsma=None, step=0.1,
conver=DEFAULT_CONVERGENCE, minit=DEFAULT_MINIT,
maxit=DEFAULT_MAXIT, fflag=DEFAULT_FFLAG,
maxgerr=DEFAULT_MAXGERR, sclip=3., nclip=0,
integrmode=BILINEAR, linear=False, maxrit=None):
# This parameter list is quite large and should in principle be
# simplified by re-distributing these controls to somewhere else.
# We keep this design though because it better mimics the flat
# architecture used in the original STSDAS task `ellipse`.
"""
Fit multiple isophotes to the image array.
This method loops over each value of the semimajor axis (sma)
length (constructed from the input parameters), fitting a single
isophote at each sma. The entire set of isophotes is returned
in an `~photutils.isophote.IsophoteList` instance.
Parameters
----------
sma0 : float, optional
The starting value for the semimajor axis length (pixels).
This value must not be the minimum or maximum semimajor axis
length, but something in between. The algorithm can't start
from the very center of the galaxy image because the
modelling of elliptical isophotes on that region is poor and
it will diverge very easily if not tied to other previously
fit isophotes. It can't start from the maximum value either
because the maximum is not known beforehand, depending on
signal-to-noise. The ``sma0`` value should be selected such
that the corresponding isophote has a good signal-to-noise
ratio and a clearly defined geometry. If set to `None` (the
default), one of two actions will be taken: if a
`~photutils.isophote.EllipseGeometry` instance was input to
the `~photutils.isophote.Ellipse` constructor, its ``sma``
value will be used. Otherwise, a default value of 10. will
be used.
minsma : float, optional
The minimum value for the semimajor axis length (pixels).
The default is 0.
maxsma : float or `None`, optional
The maximum value for the semimajor axis length (pixels).
When set to `None` (default), the algorithm will increase
the semimajor axis until one of several conditions will
cause it to stop and revert to fit ellipses with sma <
``sma0``.
step : float, optional
The step value used to grow/shrink the semimajor axis length
(pixels if ``linear=True``, or a relative value if
``linear=False``). See the ``linear`` parameter. The
default is 0.1.
conver : float, optional
The main convergence criterion. Iterations stop when the
largest harmonic amplitude becomes smaller (in absolute
value) than ``conver`` times the harmonic fit rms. The
default is 0.05.
minit : int, optional
The minimum number of iterations to perform. A minimum of 10
(the default) iterations guarantees that, on average, 2
iterations will be available for fitting each independent
parameter (the four harmonic amplitudes and the intensity
level). For the first isophote, the minimum number of
iterations is 2 * ``minit`` to ensure that, even departing
from not-so-good initial values, the algorithm has a better
chance to converge to a sensible solution.
maxit : int, optional
The maximum number of iterations to perform. The default is
50.
fflag : float, optional
The acceptable fraction of flagged data points in the
sample. If the actual fraction of valid data points is
smaller than this, the iterations will stop and the current
`~photutils.isophote.Isophote` will be returned. Flagged
data points are points that either lie outside the image
frame, are masked, or were rejected by sigma-clipping. The
default is 0.7.
maxgerr : float, optional
The maximum acceptable relative error in the local radial
intensity gradient. This is the main control for preventing
ellipses to grow to regions of too low signal-to-noise
ratio. It specifies the maximum acceptable relative error
in the local radial intensity gradient. `Busko (1996; ASPC
101, 139)
<http://adsabs.harvard.edu/abs/1996ASPC..101..139B>`_ showed
that the fitting precision relates to that relative error.
The usual behavior of the gradient relative error is to
increase with semimajor axis, being larger in outer, fainter
regions of a galaxy image. In the current implementation,
the ``maxgerr`` criterion is triggered only when two
consecutive isophotes exceed the value specified by the
parameter. This prevents premature stopping caused by
contamination such as stars and HII regions.
A number of actions may happen when the gradient error
exceeds ``maxgerr`` (or becomes non-significant and is set
to `None`). If the maximum semimajor axis specified by
``maxsma`` is set to `None`, semimajor axis growth is
stopped and the algorithm proceeds inwards to the galaxy
center. If ``maxsma`` is set to some finite value, and this
value is larger than the current semimajor axis length, the
algorithm enters non-iterative mode and proceeds outwards
until reaching ``maxsma``. The default is 0.5.
sclip : float, optional
The sigma-clip sigma value. The default is 3.0.
nclip : int, optional
The number of sigma-clip interations. The default is 0,
which means sigma-clipping is skipped.
integrmode : {'bilinear', 'nearest_neighbor', 'mean', 'median'}, optional
The area integration mode. The default is 'bilinear'.
linear : bool, optional
The semimajor axis growing/shrinking mode. If `False`
(default), the geometric growing mode is chosen, thus the
semimajor axis length is increased by a factor of (1. +
``step``), and the process is repeated until either the
semimajor axis value reaches the value of parameter
``maxsma``, or the last fitted ellipse has more than a given
fraction of its sampled points flagged out (see ``fflag``).
The process then resumes from the first fitted ellipse (at
``sma0``) inwards, in steps of (1./(1. + ``step``)), until
the semimajor axis length reaches the value ``minsma``. In
case of linear growing, the increment or decrement value is
given directly by ``step`` in pixels. If ``maxsma`` is set
to `None`, the semimajor axis will grow until a low
signal-to-noise criterion is met. See ``maxgerr``.
maxrit : float or `None`, optional
The maximum value of semimajor axis to perform an actual
fit. Whenever the current semimajor axis length is larger
than ``maxrit``, the isophotes will be extracted using the
current geometry, without being fitted. This non-iterative
mode may be useful for sampling regions of very low surface
brightness, where the algorithm may become unstable and
unable to recover reliable geometry information.
Non-iterative mode can also be entered automatically
whenever the ellipticity exceeds 1.0 or the ellipse center
crosses the image boundaries. If `None` (default), then no
maximum value is used.
Returns
-------
result : `~photutils.isophote.IsophoteList` instance
A list-like object of `~photutils.isophote.Isophote`
instances, sorted by increasing semimajor axis length.
"""
# multiple fitted isophotes will be stored here
isophote_list = []
# get starting sma from appropriate source: keyword parameter,
# internal EllipseGeometry instance, or fixed default value.
if not sma0:
if self._geometry:
sma = self._geometry.sma
else:
sma = 10.
else:
sma = sma0
# first, go from initial sma outwards until
# hitting one of several stopping criteria.
noiter = False
first_isophote = True
while True:
# first isophote runs longer
minit_a = 2 * minit if first_isophote else minit
first_isophote = False
isophote = self.fit_isophote(sma, step, conver, minit_a, maxit,
fflag, maxgerr, sclip, nclip,
integrmode, linear, maxrit,
noniterate=noiter,
isophote_list=isophote_list)
# check for failed fit.
if (isophote.stop_code < 0 or isophote.stop_code == 1):
# in case the fit failed right at the outset, return an
# empty list. This is the usual case when the user
# provides initial guesses that are too way off to enable
# the fitting algorithm to find any meaningful solution.
if len(isophote_list) == 1:
warnings.warn('No meaningful fit was possible.',
AstropyUserWarning)
return IsophoteList([])
self._fix_last_isophote(isophote_list, -1)
# get last isophote from the actual list, since the last
# `isophote` instance in this context may no longer be OK.
isophote = isophote_list[-1]
# if two consecutive isophotes failed to fit,
# shut off iterative mode. Or, bail out and
# change to go inwards.
if len(isophote_list) > 2:
if ((isophote.stop_code == 5 and
isophote_list[-2].stop_code == 5)
or isophote.stop_code == 1):
if maxsma and maxsma > isophote.sma:
# if a maximum sma value was provided by
# user, and the current sma is smaller than
# maxsma, keep growing sma in non-iterative
# mode until reaching it.
noiter = True
else:
# if no maximum sma, stop growing and change
# to go inwards.
break
# reset variable from the actual list, since the last
# `isophote` instance may no longer be OK.
isophote = isophote_list[-1]
# update sma. If exceeded user-defined
# maximum, bail out from this loop.
sma = isophote.sample.geometry.update_sma(step)
if maxsma and sma >= maxsma:
break
# reset sma so as to go inwards.
first_isophote = isophote_list[0]
sma, step = first_isophote.sample.geometry.reset_sma(step)
# now, go from initial sma inwards towards center.
while True:
isophote = self.fit_isophote(sma, step, conver, minit, maxit,
fflag, maxgerr, sclip, nclip,
integrmode, linear, maxrit,
going_inwards=True,
isophote_list=isophote_list)
# if abnormal condition, fix isophote but keep going.
if isophote.stop_code < 0:
self._fix_last_isophote(isophote_list, 0)
# reset variable from the actual list, since the last
# `isophote` instance may no longer be OK.
isophote = isophote_list[-1]
# figure out next sma; if exceeded user-defined
# minimum, or too small, bail out from this loop
sma = isophote.sample.geometry.update_sma(step)
if sma <= max(minsma, 0.5):
break
# if user asked for minsma=0, extract special isophote there
if minsma == 0.0:
isophote = self.fit_isophote(0.0, isophote_list=isophote_list)
# sort list of isophotes according to sma
isophote_list.sort()
return IsophoteList(isophote_list) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:values; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, for_statement; 9, 10; 9, 11; 9, 12; 10, identifier:level; 11, identifier:self; 12, block; 12, 13; 13, for_statement; 13, 14; 13, 17; 13, 18; 14, pattern_list; 14, 15; 14, 16; 15, identifier:wire1; 16, identifier:wire2; 17, identifier:level; 18, block; 18, 19; 19, if_statement; 19, 20; 19, 27; 20, comparison_operator:>; 20, 21; 20, 24; 21, subscript; 21, 22; 21, 23; 22, identifier:values; 23, identifier:wire1; 24, subscript; 24, 25; 24, 26; 25, identifier:values; 26, identifier:wire2; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 37; 30, pattern_list; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:values; 33, identifier:wire1; 34, subscript; 34, 35; 34, 36; 35, identifier:values; 36, identifier:wire2; 37, expression_list; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:values; 40, identifier:wire2; 41, subscript; 41, 42; 41, 43; 42, identifier:values; 43, identifier:wire1 | def sort(self, values):
"""Sort the values in-place based on the connectors in the network."""
for level in self:
for wire1, wire2 in level:
if values[wire1] > values[wire2]:
values[wire1], values[wire2] = values[wire2], values[wire1] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:getWorkersName; 3, parameters; 3, 4; 4, identifier:data; 5, block; 5, 6; 5, 8; 5, 20; 5, 26; 5, 39; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:names; 11, list_comprehension; 11, 12; 11, 13; 12, identifier:fichier; 13, for_in_clause; 13, 14; 13, 15; 14, identifier:fichier; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:data; 18, identifier:keys; 19, argument_list; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:names; 24, identifier:sort; 25, argument_list; 26, try_statement; 26, 27; 26, 35; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:names; 32, identifier:remove; 33, argument_list; 33, 34; 34, string:"broker"; 35, except_clause; 35, 36; 35, 37; 36, identifier:ValueError; 37, block; 37, 38; 38, pass_statement; 39, return_statement; 39, 40; 40, identifier:names | def getWorkersName(data):
"""Returns the list of the names of the workers sorted alphabetically"""
names = [fichier for fichier in data.keys()]
names.sort()
try:
names.remove("broker")
except ValueError:
pass
return names |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 1, 32; 2, function_name:parse_commit_message; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:message; 6, type; 6, 7; 7, identifier:str; 8, type; 8, 9; 9, generic_type; 9, 10; 9, 11; 10, identifier:Tuple; 11, type_parameter; 11, 12; 11, 14; 11, 16; 11, 22; 12, type; 12, 13; 13, identifier:int; 14, type; 14, 15; 15, identifier:str; 16, type; 16, 17; 17, generic_type; 17, 18; 17, 19; 18, identifier:Optional; 19, type_parameter; 19, 20; 20, type; 20, 21; 21, identifier:str; 22, type; 22, 23; 23, generic_type; 23, 24; 23, 25; 24, identifier:Tuple; 25, type_parameter; 25, 26; 25, 28; 25, 30; 26, type; 26, 27; 27, identifier:str; 28, type; 28, 29; 29, identifier:str; 30, type; 30, 31; 31, identifier:str; 32, block; 32, 33; 32, 35; 32, 44; 32, 58; 32, 67; 32, 165; 32, 190; 32, 204; 33, expression_statement; 33, 34; 34, comment; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:parsed; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:re_parser; 41, identifier:match; 42, argument_list; 42, 43; 43, identifier:message; 44, if_statement; 44, 45; 44, 47; 45, not_operator; 45, 46; 46, identifier:parsed; 47, block; 47, 48; 48, raise_statement; 48, 49; 49, call; 49, 50; 49, 51; 50, identifier:UnknownCommitMessageStyleError; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, string:'Unable to parse the given commit message: {0}'; 55, identifier:format; 56, argument_list; 56, 57; 57, identifier:message; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:subject; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:parsed; 64, identifier:group; 65, argument_list; 65, 66; 66, string:'subject'; 67, if_statement; 67, 68; 67, 77; 67, 110; 67, 153; 68, comparison_operator:in; 68, 69; 68, 76; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:config; 72, identifier:get; 73, argument_list; 73, 74; 73, 75; 74, string:'semantic_release'; 75, string:'minor_tag'; 76, identifier:message; 77, block; 77, 78; 77, 82; 77, 86; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:level; 81, string:'feature'; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:level_bump; 85, integer:2; 86, if_statement; 86, 87; 86, 88; 87, identifier:subject; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:subject; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:subject; 95, identifier:replace; 96, argument_list; 96, 97; 96, 109; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:config; 100, identifier:get; 101, argument_list; 101, 102; 101, 103; 102, string:'semantic_release'; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, string:'minor_tag'; 106, identifier:format; 107, argument_list; 107, 108; 108, identifier:level; 109, string:''; 110, elif_clause; 110, 111; 110, 120; 111, comparison_operator:in; 111, 112; 111, 119; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:config; 115, identifier:get; 116, argument_list; 116, 117; 116, 118; 117, string:'semantic_release'; 118, string:'fix_tag'; 119, identifier:message; 120, block; 120, 121; 120, 125; 120, 129; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:level; 124, string:'fix'; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:level_bump; 128, integer:1; 129, if_statement; 129, 130; 129, 131; 130, identifier:subject; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:subject; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:subject; 138, identifier:replace; 139, argument_list; 139, 140; 139, 152; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:config; 143, identifier:get; 144, argument_list; 144, 145; 144, 146; 145, string:'semantic_release'; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, string:'fix_tag'; 149, identifier:format; 150, argument_list; 150, 151; 151, identifier:level; 152, string:''; 153, else_clause; 153, 154; 154, block; 154, 155; 155, raise_statement; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:UnknownCommitMessageStyleError; 158, argument_list; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, string:'Unable to parse the given commit message: {0}'; 162, identifier:format; 163, argument_list; 163, 164; 164, identifier:message; 165, if_statement; 165, 166; 165, 181; 166, boolean_operator:and; 166, 167; 166, 173; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:parsed; 170, identifier:group; 171, argument_list; 171, 172; 172, string:'text'; 173, comparison_operator:in; 173, 174; 173, 175; 174, string:'BREAKING CHANGE'; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:parsed; 178, identifier:group; 179, argument_list; 179, 180; 180, string:'text'; 181, block; 181, 182; 181, 186; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:level; 185, string:'breaking'; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:level_bump; 189, integer:3; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 195; 192, pattern_list; 192, 193; 192, 194; 193, identifier:body; 194, identifier:footer; 195, call; 195, 196; 195, 197; 196, identifier:parse_text_block; 197, argument_list; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:parsed; 201, identifier:group; 202, argument_list; 202, 203; 203, string:'text'; 204, return_statement; 204, 205; 205, expression_list; 205, 206; 205, 207; 205, 208; 205, 209; 206, identifier:level_bump; 207, identifier:level; 208, None; 209, tuple; 209, 210; 209, 215; 209, 220; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:subject; 213, identifier:strip; 214, argument_list; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:body; 218, identifier:strip; 219, argument_list; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:footer; 223, identifier:strip; 224, argument_list | def parse_commit_message(message: str) -> Tuple[int, str, Optional[str], Tuple[str, str, str]]:
"""
Parses a commit message according to the 1.0 version of python-semantic-release. It expects
a tag of some sort in the commit message and will use the rest of the first line as changelog
content.
:param message: A string of a commit message.
:raises UnknownCommitMessageStyleError: If it does not recognise the commit style
:return: A tuple of (level to bump, type of change, scope of change, a tuple with descriptions)
"""
parsed = re_parser.match(message)
if not parsed:
raise UnknownCommitMessageStyleError(
'Unable to parse the given commit message: {0}'.format(message)
)
subject = parsed.group('subject')
if config.get('semantic_release', 'minor_tag') in message:
level = 'feature'
level_bump = 2
if subject:
subject = subject.replace(config.get('semantic_release', 'minor_tag'.format(level)), '')
elif config.get('semantic_release', 'fix_tag') in message:
level = 'fix'
level_bump = 1
if subject:
subject = subject.replace(config.get('semantic_release', 'fix_tag'.format(level)), '')
else:
raise UnknownCommitMessageStyleError(
'Unable to parse the given commit message: {0}'.format(message)
)
if parsed.group('text') and 'BREAKING CHANGE' in parsed.group('text'):
level = 'breaking'
level_bump = 3
body, footer = parse_text_block(parsed.group('text'))
return level_bump, level, None, (subject.strip(), body.strip(), footer.strip()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:todos; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 25; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:result; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_sorter; 16, identifier:sort; 17, argument_list; 17, 18; 18, call; 18, 19; 18, 24; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:todolist; 23, identifier:todos; 24, argument_list; 25, return_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_apply_filters; 30, argument_list; 30, 31; 31, identifier:result | def todos(self):
""" Returns a sorted and filtered list of todos in this view. """
result = self._sorter.sort(self.todolist.todos())
return self._apply_filters(result) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:group; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:p_todos; 6, block; 6, 7; 6, 9; 6, 10; 6, 20; 6, 21; 6, 31; 6, 135; 6, 136; 6, 157; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:p_todos; 13, call; 13, 14; 13, 15; 14, identifier:_apply_sort_functions; 15, argument_list; 15, 16; 15, 17; 16, identifier:p_todos; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:pregroupfunctions; 20, comment; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:result; 24, call; 24, 25; 24, 26; 25, identifier:OrderedDict; 26, argument_list; 26, 27; 27, list:[((), p_todos)]; 27, 28; 28, tuple; 28, 29; 28, 30; 29, tuple; 30, identifier:p_todos; 31, for_statement; 31, 32; 31, 37; 31, 40; 32, pattern_list; 32, 33; 32, 36; 33, tuple_pattern; 33, 34; 33, 35; 34, identifier:function; 35, identifier:label; 36, identifier:_; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:groupfunctions; 40, block; 40, 41; 40, 45; 40, 51; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:oldresult; 44, identifier:result; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:result; 48, call; 48, 49; 48, 50; 49, identifier:OrderedDict; 50, argument_list; 51, for_statement; 51, 52; 51, 55; 51, 60; 52, pattern_list; 52, 53; 52, 54; 53, identifier:oldkey; 54, identifier:oldgroup; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:oldresult; 58, identifier:items; 59, argument_list; 60, block; 60, 61; 61, for_statement; 61, 62; 61, 65; 61, 70; 62, pattern_list; 62, 63; 62, 64; 63, identifier:key; 64, identifier:_group; 65, call; 65, 66; 65, 67; 66, identifier:groupby; 67, argument_list; 67, 68; 67, 69; 68, identifier:oldgroup; 69, identifier:function; 70, block; 70, 71; 70, 78; 70, 91; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:newgroup; 74, call; 74, 75; 74, 76; 75, identifier:list; 76, argument_list; 76, 77; 77, identifier:_group; 78, if_statement; 78, 79; 78, 85; 79, not_operator; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:isinstance; 82, argument_list; 82, 83; 82, 84; 83, identifier:key; 84, identifier:list; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:key; 89, list:[key]; 89, 90; 90, identifier:key; 91, for_statement; 91, 92; 91, 93; 91, 94; 92, identifier:subkey; 93, identifier:key; 94, block; 94, 95; 94, 105; 94, 112; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:subkey; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, string:"{}: {}"; 101, identifier:format; 102, argument_list; 102, 103; 102, 104; 103, identifier:label; 104, identifier:subkey; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:newkey; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:oldkey; 110, tuple; 110, 111; 111, identifier:subkey; 112, if_statement; 112, 113; 112, 116; 112, 127; 113, comparison_operator:in; 113, 114; 113, 115; 114, identifier:newkey; 115, identifier:result; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, subscript; 119, 120; 119, 121; 120, identifier:result; 121, identifier:newkey; 122, binary_operator:+; 122, 123; 122, 126; 123, subscript; 123, 124; 123, 125; 124, identifier:result; 125, identifier:newkey; 126, identifier:newgroup; 127, else_clause; 127, 128; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:result; 133, identifier:newkey; 134, identifier:newgroup; 135, comment; 136, for_statement; 136, 137; 136, 140; 136, 145; 137, pattern_list; 137, 138; 137, 139; 138, identifier:key; 139, identifier:_group; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:result; 143, identifier:items; 144, argument_list; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:result; 150, identifier:key; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:sort; 155, argument_list; 155, 156; 156, identifier:_group; 157, return_statement; 157, 158; 158, identifier:result | def group(self, p_todos):
"""
Groups the todos according to the given group string.
"""
# preorder todos for the group sort
p_todos = _apply_sort_functions(p_todos, self.pregroupfunctions)
# initialize result with a single group
result = OrderedDict([((), p_todos)])
for (function, label), _ in self.groupfunctions:
oldresult = result
result = OrderedDict()
for oldkey, oldgroup in oldresult.items():
for key, _group in groupby(oldgroup, function):
newgroup = list(_group)
if not isinstance(key, list):
key = [key]
for subkey in key:
subkey = "{}: {}".format(label, subkey)
newkey = oldkey + (subkey,)
if newkey in result:
result[newkey] = result[newkey] + newgroup
else:
result[newkey] = newgroup
# sort all groups
for key, _group in result.items():
result[key] = self.sort(_group)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:process_other_set; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:hdf5_file; 5, identifier:which_set; 6, identifier:image_archive; 7, identifier:patch_archive; 8, identifier:groundtruth; 9, identifier:offset; 10, block; 10, 11; 10, 13; 10, 32; 10, 51; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:producer; 16, call; 16, 17; 16, 18; 17, identifier:partial; 18, argument_list; 18, 19; 18, 20; 18, 23; 18, 26; 18, 29; 19, identifier:other_set_producer; 20, keyword_argument; 20, 21; 20, 22; 21, identifier:image_archive; 22, identifier:image_archive; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:patch_archive; 25, identifier:patch_archive; 26, keyword_argument; 26, 27; 26, 28; 27, identifier:groundtruth; 28, identifier:groundtruth; 29, keyword_argument; 29, 30; 29, 31; 30, identifier:which_set; 31, identifier:which_set; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:consumer; 35, call; 35, 36; 35, 37; 36, identifier:partial; 37, argument_list; 37, 38; 37, 39; 37, 42; 37, 48; 38, identifier:image_consumer; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:hdf5_file; 41, identifier:hdf5_file; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:num_expected; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, identifier:groundtruth; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:offset; 50, identifier:offset; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:producer_consumer; 54, argument_list; 54, 55; 54, 56; 55, identifier:producer; 56, identifier:consumer | def process_other_set(hdf5_file, which_set, image_archive, patch_archive,
groundtruth, offset):
"""Process the validation or test set.
Parameters
----------
hdf5_file : :class:`h5py.File` instance
HDF5 file handle to which to write. Assumes `features`, `targets`
and `filenames` already exist and have first dimension larger than
`sum(images_per_class)`.
which_set : str
Which set of images is being processed. One of 'train', 'valid',
'test'. Used for extracting the appropriate images from the patch
archive.
image_archive : str or file-like object
The filename or file-handle for the TAR archive containing images.
patch_archive : str or file-like object
Filename or file handle for the TAR archive of patch images.
groundtruth : iterable
Iterable container containing scalar 0-based class index for each
image, sorted by filename.
offset : int
The offset in the HDF5 datasets at which to start writing.
"""
producer = partial(other_set_producer, image_archive=image_archive,
patch_archive=patch_archive,
groundtruth=groundtruth, which_set=which_set)
consumer = partial(image_consumer, hdf5_file=hdf5_file,
num_expected=len(groundtruth), offset=offset)
producer_consumer(producer, consumer) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sorted_fancy_indexing; 3, parameters; 3, 4; 3, 5; 4, identifier:indexable; 5, identifier:request; 6, block; 6, 7; 6, 9; 6, 78; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 16; 9, 70; 10, comparison_operator:>; 10, 11; 10, 15; 11, call; 11, 12; 11, 13; 12, identifier:len; 13, argument_list; 13, 14; 14, identifier:request; 15, integer:1; 16, block; 16, 17; 16, 26; 16, 54; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:indices; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:numpy; 23, identifier:argsort; 24, argument_list; 24, 25; 25, identifier:request; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:data; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:numpy; 32, identifier:empty; 33, argument_list; 33, 34; 33, 49; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:shape; 36, binary_operator:+; 36, 37; 36, 42; 37, tuple; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:len; 40, argument_list; 40, 41; 41, identifier:request; 42, subscript; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:indexable; 45, identifier:shape; 46, slice; 46, 47; 46, 48; 47, integer:1; 48, colon; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:dtype; 51, attribute; 51, 52; 51, 53; 52, identifier:indexable; 53, identifier:dtype; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:data; 58, identifier:indices; 59, subscript; 59, 60; 59, 61; 59, 69; 60, identifier:indexable; 61, subscript; 61, 62; 61, 68; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:numpy; 65, identifier:array; 66, argument_list; 66, 67; 67, identifier:request; 68, identifier:indices; 69, ellipsis:...; 70, else_clause; 70, 71; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:data; 75, subscript; 75, 76; 75, 77; 76, identifier:indexable; 77, identifier:request; 78, return_statement; 78, 79; 79, identifier:data | def sorted_fancy_indexing(indexable, request):
"""Safe fancy indexing.
Some objects, such as h5py datasets, only support list indexing
if the list is sorted.
This static method adds support for unsorted list indexing by
sorting the requested indices, accessing the corresponding
elements and re-shuffling the result.
Parameters
----------
request : list of int
Unsorted list of example indices.
indexable : any fancy-indexable object
Indexable we'd like to do unsorted fancy indexing on.
"""
if len(request) > 1:
indices = numpy.argsort(request)
data = numpy.empty(shape=(len(request),) + indexable.shape[1:],
dtype=indexable.dtype)
data[indices] = indexable[numpy.array(request)[indices], ...]
else:
data = indexable[request]
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:index_within_subset; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:indexable; 6, identifier:subset_request; 7, default_parameter; 7, 8; 7, 9; 8, identifier:sort_indices; 9, False; 10, block; 10, 11; 10, 13; 10, 14; 10, 15; 10, 40; 10, 41; 10, 60; 10, 61; 10, 62; 10, 73; 10, 74; 10, 75; 10, 92; 10, 93; 10, 94; 11, expression_statement; 11, 12; 12, comment; 13, comment; 14, comment; 15, if_statement; 15, 16; 15, 23; 15, 32; 16, call; 16, 17; 16, 18; 17, identifier:isinstance; 18, argument_list; 18, 19; 18, 20; 19, identifier:subset_request; 20, attribute; 20, 21; 20, 22; 21, identifier:numbers; 22, identifier:Integral; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 28; 26, pattern_list; 26, 27; 27, identifier:request; 28, subscript; 28, 29; 28, 30; 29, identifier:self; 30, list:[subset_request]; 30, 31; 31, identifier:subset_request; 32, else_clause; 32, 33; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:request; 37, subscript; 37, 38; 37, 39; 38, identifier:self; 39, identifier:subset_request; 40, comment; 41, if_statement; 41, 42; 41, 55; 42, boolean_operator:or; 42, 43; 42, 50; 43, call; 43, 44; 43, 45; 44, identifier:isinstance; 45, argument_list; 45, 46; 45, 47; 46, identifier:request; 47, attribute; 47, 48; 47, 49; 48, identifier:numbers; 49, identifier:Integral; 50, call; 50, 51; 50, 52; 51, identifier:hasattr; 52, argument_list; 52, 53; 52, 54; 53, identifier:request; 54, string:'step'; 55, block; 55, 56; 56, return_statement; 56, 57; 57, subscript; 57, 58; 57, 59; 58, identifier:indexable; 59, identifier:request; 60, comment; 61, comment; 62, if_statement; 62, 63; 62, 64; 63, identifier:sort_indices; 64, block; 64, 65; 65, return_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:sorted_fancy_indexing; 70, argument_list; 70, 71; 70, 72; 71, identifier:indexable; 72, identifier:request; 73, comment; 74, comment; 75, if_statement; 75, 76; 75, 87; 76, call; 76, 77; 76, 78; 77, identifier:isinstance; 78, argument_list; 78, 79; 78, 80; 79, identifier:indexable; 80, tuple; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:numpy; 83, identifier:ndarray; 84, attribute; 84, 85; 84, 86; 85, identifier:h5py; 86, identifier:Dataset; 87, block; 87, 88; 88, return_statement; 88, 89; 89, subscript; 89, 90; 89, 91; 90, identifier:indexable; 91, identifier:request; 92, comment; 93, comment; 94, return_statement; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:iterable_fancy_indexing; 97, argument_list; 97, 98; 97, 99; 98, identifier:indexable; 99, identifier:request | def index_within_subset(self, indexable, subset_request,
sort_indices=False):
"""Index an indexable object within the context of this subset.
Parameters
----------
indexable : indexable object
The object to index through.
subset_request : :class:`list` or :class:`slice`
List of positive integer indices or slice that constitutes
the request *within the context of this subset*. This
request will be translated to a request on the indexable
object.
sort_indices : bool, optional
If the request is a list of indices, indexes in sorted order
and reshuffles the result in the original order. Defaults to
`False`.
"""
# Translate the request within the context of this subset to a
# request to the indexable object
if isinstance(subset_request, numbers.Integral):
request, = self[[subset_request]]
else:
request = self[subset_request]
# Integer or slice requests can be processed directly.
if isinstance(request, numbers.Integral) or hasattr(request, 'step'):
return indexable[request]
# If requested, we do fancy indexing in sorted order and reshuffle the
# result back in the original order.
if sort_indices:
return self.sorted_fancy_indexing(indexable, request)
# If the indexable supports fancy indexing (numpy array, HDF5 dataset),
# the request can be processed directly.
if isinstance(indexable, (numpy.ndarray, h5py.Dataset)):
return indexable[request]
# Anything else (e.g. lists) isn't considered to support fancy
# indexing, so Subset does it manually.
return iterable_fancy_indexing(indexable, request) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 2, function_name:degree_circle; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 15; 3, 18; 3, 21; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:EdgeAttribute; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:network; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:NodeAttribute; 13, None; 14, line_continuation:\; 15, default_parameter; 15, 16; 15, 17; 16, identifier:nodeList; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:singlePartition; 20, None; 21, default_parameter; 21, 22; 21, 23; 22, identifier:verbose; 23, None; 24, block; 24, 25; 24, 27; 24, 38; 24, 57; 24, 79; 25, expression_statement; 25, 26; 26, comment; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:network; 30, call; 30, 31; 30, 32; 31, identifier:check_network; 32, argument_list; 32, 33; 32, 34; 32, 35; 33, identifier:self; 34, identifier:network; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:verbose; 37, identifier:verbose; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:PARAMS; 41, call; 41, 42; 41, 43; 42, identifier:set_param; 43, argument_list; 43, 44; 43, 50; 44, list:['EdgeAttribute','network','NodeAttribute','nodeList',\
'singlePartition']; 44, 45; 44, 46; 44, 47; 44, 48; 44, 49; 45, string:'EdgeAttribute'; 46, string:'network'; 47, string:'NodeAttribute'; 48, string:'nodeList'; 49, string:'singlePartition'; 50, list:[EdgeAttribute,network,NodeAttribute,nodeList,\
singlePartition]; 50, 51; 50, 52; 50, 53; 50, 54; 50, 55; 50, 56; 51, identifier:EdgeAttribute; 52, identifier:network; 53, identifier:NodeAttribute; 54, identifier:nodeList; 55, line_continuation:\; 56, identifier:singlePartition; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:response; 60, call; 60, 61; 60, 62; 61, identifier:api; 62, argument_list; 62, 63; 62, 70; 62, 73; 62, 76; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:url; 65, binary_operator:+; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:__url; 69, string:"/degree-circle"; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:PARAMS; 72, identifier:PARAMS; 73, keyword_argument; 73, 74; 73, 75; 74, identifier:method; 75, string:"POST"; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:verbose; 78, identifier:verbose; 79, return_statement; 79, 80; 80, identifier:response | def degree_circle(self,EdgeAttribute=None,network=None,NodeAttribute=None,\
nodeList=None,singlePartition=None,verbose=None):
"""
Execute the Degree Sorted Circle Layout on a network.
:param EdgeAttribute (string, optional): The name of the edge column contai
ning numeric values that will be used as weights in the layout algor
ithm. Only columns containing numeric values are shown
:param network (string, optional): Specifies a network by name, or by SUID
if the prefix SUID: is used. The keyword CURRENT, or a blank value c
an also be used to specify the current network.
:param NodeAttribute (string, optional): The name of the node column contai
ning numeric values that will be used as weights in the layout algor
ithm. Only columns containing numeric values are shown
:param nodeList (string, optional): Specifies a list of nodes. The keywords
all, selected, or unselected can be used to specify nodes by their
selection state. The pattern COLUMN:VALUE sets this parameter to any
rows that contain the specified column value; if the COLUMN prefix
is not used, the NAME column is matched by default. A list of COLUMN
:VALUE pairs of the format COLUMN1:VALUE1,COLUMN2:VALUE2,... can be
used to match multiple values.
:param singlePartition (string, optional): Don't partition graph before lay
out; boolean values only, true or false; defaults to false
"""
network=check_network(self,network,verbose=verbose)
PARAMS=set_param(['EdgeAttribute','network','NodeAttribute','nodeList',\
'singlePartition'],[EdgeAttribute,network,NodeAttribute,nodeList,\
singlePartition])
response=api(url=self.__url+"/degree-circle", PARAMS=PARAMS, method="POST", verbose=verbose)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 66; 2, function_name:import_url; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 9; 3, 12; 3, 15; 3, 16; 3, 19; 3, 22; 3, 23; 3, 26; 3, 29; 3, 32; 3, 33; 3, 36; 3, 39; 3, 40; 3, 43; 3, 46; 3, 49; 3, 50; 3, 53; 3, 56; 3, 59; 3, 60; 3, 63; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:caseSensitiveNetworkCollectionKeys; 7, None; 8, line_continuation:\; 9, default_parameter; 9, 10; 9, 11; 10, identifier:caseSensitiveNetworkKeys; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:dataTypeList; 14, None; 15, line_continuation:\; 16, default_parameter; 16, 17; 16, 18; 17, identifier:DataTypeTargetForNetworkCollection; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:DataTypeTargetForNetworkList; 21, None; 22, line_continuation:\; 23, default_parameter; 23, 24; 23, 25; 24, identifier:delimiters; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:delimitersForDataList; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:firstRowAsColumnNames; 31, None; 32, line_continuation:\; 33, default_parameter; 33, 34; 33, 35; 34, identifier:KeyColumnForMapping; 35, None; 36, default_parameter; 36, 37; 36, 38; 37, identifier:KeyColumnForMappingNetworkList; 38, None; 39, line_continuation:\; 40, default_parameter; 40, 41; 40, 42; 41, identifier:keyColumnIndex; 42, None; 43, default_parameter; 43, 44; 43, 45; 44, identifier:newTableName; 45, None; 46, default_parameter; 46, 47; 46, 48; 47, identifier:startLoadRow; 48, None; 49, line_continuation:\; 50, default_parameter; 50, 51; 50, 52; 51, identifier:TargetNetworkCollection; 52, None; 53, default_parameter; 53, 54; 53, 55; 54, identifier:TargetNetworkList; 55, None; 56, default_parameter; 56, 57; 56, 58; 57, identifier:url; 58, None; 59, line_continuation:\; 60, default_parameter; 60, 61; 60, 62; 61, identifier:WhereImportTable; 62, None; 63, default_parameter; 63, 64; 63, 65; 64, identifier:verbose; 65, None; 66, block; 66, 67; 66, 69; 66, 116; 66, 138; 67, expression_statement; 67, 68; 68, comment; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:PARAMS; 72, call; 72, 73; 72, 74; 73, identifier:set_param; 74, argument_list; 74, 75; 74, 93; 75, list:['caseSensitiveNetworkCollectionKeys',\
'caseSensitiveNetworkKeys','dataTypeList','DataTypeTargetForNetworkCollection',\
'DataTypeTargetForNetworkList','delimiters','delimitersForDataList',\
'firstRowAsColumnNames','KeyColumnForMapping','KeyColumnForMappingNetworkList',\
'keyColumnIndex','newTableName','startLoadRow','TargetNetworkCollection',\
'TargetNetworkList','url','WhereImportTable']; 75, 76; 75, 77; 75, 78; 75, 79; 75, 80; 75, 81; 75, 82; 75, 83; 75, 84; 75, 85; 75, 86; 75, 87; 75, 88; 75, 89; 75, 90; 75, 91; 75, 92; 76, string:'caseSensitiveNetworkCollectionKeys'; 77, string:'caseSensitiveNetworkKeys'; 78, string:'dataTypeList'; 79, string:'DataTypeTargetForNetworkCollection'; 80, string:'DataTypeTargetForNetworkList'; 81, string:'delimiters'; 82, string:'delimitersForDataList'; 83, string:'firstRowAsColumnNames'; 84, string:'KeyColumnForMapping'; 85, string:'KeyColumnForMappingNetworkList'; 86, string:'keyColumnIndex'; 87, string:'newTableName'; 88, string:'startLoadRow'; 89, string:'TargetNetworkCollection'; 90, string:'TargetNetworkList'; 91, string:'url'; 92, string:'WhereImportTable'; 93, list:[caseSensitiveNetworkCollectionKeys,\
caseSensitiveNetworkKeys,dataTypeList,DataTypeTargetForNetworkCollection,\
DataTypeTargetForNetworkList,delimiters,delimitersForDataList,\
firstRowAsColumnNames,KeyColumnForMapping,KeyColumnForMappingNetworkList,\
keyColumnIndex,newTableName,startLoadRow,TargetNetworkCollection,\
TargetNetworkList,url,WhereImportTable]; 93, 94; 93, 95; 93, 96; 93, 97; 93, 98; 93, 99; 93, 100; 93, 101; 93, 102; 93, 103; 93, 104; 93, 105; 93, 106; 93, 107; 93, 108; 93, 109; 93, 110; 93, 111; 93, 112; 93, 113; 93, 114; 93, 115; 94, identifier:caseSensitiveNetworkCollectionKeys; 95, line_continuation:\; 96, identifier:caseSensitiveNetworkKeys; 97, identifier:dataTypeList; 98, identifier:DataTypeTargetForNetworkCollection; 99, line_continuation:\; 100, identifier:DataTypeTargetForNetworkList; 101, identifier:delimiters; 102, identifier:delimitersForDataList; 103, line_continuation:\; 104, identifier:firstRowAsColumnNames; 105, identifier:KeyColumnForMapping; 106, identifier:KeyColumnForMappingNetworkList; 107, line_continuation:\; 108, identifier:keyColumnIndex; 109, identifier:newTableName; 110, identifier:startLoadRow; 111, identifier:TargetNetworkCollection; 112, line_continuation:\; 113, identifier:TargetNetworkList; 114, identifier:url; 115, identifier:WhereImportTable; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:response; 119, call; 119, 120; 119, 121; 120, identifier:api; 121, argument_list; 121, 122; 121, 129; 121, 132; 121, 135; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:url; 124, binary_operator:+; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:__url; 128, string:"/import url"; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:PARAMS; 131, identifier:PARAMS; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:method; 134, string:"POST"; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:verbose; 137, identifier:verbose; 138, return_statement; 138, 139; 139, identifier:response | def import_url(self,caseSensitiveNetworkCollectionKeys=None,\
caseSensitiveNetworkKeys=None,dataTypeList=None,\
DataTypeTargetForNetworkCollection=None,DataTypeTargetForNetworkList=None,\
delimiters=None,delimitersForDataList=None,firstRowAsColumnNames=None,\
KeyColumnForMapping=None,KeyColumnForMappingNetworkList=None,\
keyColumnIndex=None,newTableName=None,startLoadRow=None,\
TargetNetworkCollection=None,TargetNetworkList=None,url=None,\
WhereImportTable=None,verbose=None):
"""
Similar to Import Table this uses a long list of input parameters to
specify the attributes of the table, the mapping keys, and the destination
table for the input.
:param caseSensitiveNetworkCollectionKeys (string, optional): Determines wh
ether capitalization is considered in matching and sorting
:param caseSensitiveNetworkKeys (string, optional): Determines whether capi
talization is considered in matching and sorting
:param dataTypeList (string, optional): List of column data types ordered b
y column index (e.g. "string,int,long,double,boolean,intlist" or jus
t "s,i,l,d,b,il")
:param DataTypeTargetForNetworkCollection (string, optional): Select whethe
r to import the data as Node Table Columns, Edge Table Columns, or N
etwork Table Columns
:param DataTypeTargetForNetworkList (string, optional): The data type of th
e targets
:param delimiters (string, optional): The list of delimiters that separate
columns in the table.
:param delimitersForDataList (string, optional): The delimiters between ele
ments of list columns in the table.
:param firstRowAsColumnNames (string, optional): If the first imported row
contains column names, set this to true.
:param KeyColumnForMapping (string, optional): The column in the network to
use as the merge key
:param KeyColumnForMappingNetworkList (string, optional): The column in the
network to use as the merge key
:param keyColumnIndex (string, optional): The column that contains the key
values for this import. These values will be used to match with the
key values in the network.
:param newTableName (string, optional): The title of the new table
:param startLoadRow (string, optional): The first row of the input table to
load. This allows the skipping of headers that are not part of the
import.
:param TargetNetworkCollection (string, optional): The network collection t
o use for the table import
:param TargetNetworkList (string, optional): The list of networks into whic
h the table is imported
:param url (string): The URL of the file or resource that provides the tabl
e or network to be imported.
:param WhereImportTable (string, optional): Determines what network(s) the
imported table will be associated with (if any). A table can be impo
rted into a Network Collection, Selected networks or to an unassigne
d table.
"""
PARAMS=set_param(['caseSensitiveNetworkCollectionKeys',\
'caseSensitiveNetworkKeys','dataTypeList','DataTypeTargetForNetworkCollection',\
'DataTypeTargetForNetworkList','delimiters','delimitersForDataList',\
'firstRowAsColumnNames','KeyColumnForMapping','KeyColumnForMappingNetworkList',\
'keyColumnIndex','newTableName','startLoadRow','TargetNetworkCollection',\
'TargetNetworkList','url','WhereImportTable'],[caseSensitiveNetworkCollectionKeys,\
caseSensitiveNetworkKeys,dataTypeList,DataTypeTargetForNetworkCollection,\
DataTypeTargetForNetworkList,delimiters,delimitersForDataList,\
firstRowAsColumnNames,KeyColumnForMapping,KeyColumnForMappingNetworkList,\
keyColumnIndex,newTableName,startLoadRow,TargetNetworkCollection,\
TargetNetworkList,url,WhereImportTable])
response=api(url=self.__url+"/import url", PARAMS=PARAMS, method="POST", verbose=verbose)
return response |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 35; 2, function_name:fromtif; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ext; 7, string:'tif'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:start; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:stop; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:recursive; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:nplanes; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:npartitions; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:labels; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:engine; 28, None; 29, default_parameter; 29, 30; 29, 31; 30, identifier:credentials; 31, None; 32, default_parameter; 32, 33; 32, 34; 33, identifier:discard_extra; 34, False; 35, block; 35, 36; 35, 38; 35, 43; 35, 59; 35, 234; 35, 243; 35, 280; 35, 306; 36, expression_statement; 36, 37; 37, comment; 38, import_from_statement; 38, 39; 38, 41; 39, dotted_name; 39, 40; 40, identifier:tifffile; 41, dotted_name; 41, 42; 42, identifier:TiffFile; 43, if_statement; 43, 44; 43, 51; 44, boolean_operator:and; 44, 45; 44, 48; 45, comparison_operator:is; 45, 46; 45, 47; 46, identifier:nplanes; 47, None; 48, comparison_operator:<=; 48, 49; 48, 50; 49, identifier:nplanes; 50, integer:0; 51, block; 51, 52; 52, raise_statement; 52, 53; 53, call; 53, 54; 53, 55; 54, identifier:ValueError; 55, argument_list; 55, 56; 56, binary_operator:%; 56, 57; 56, 58; 57, string:'nplanes must be positive if passed, got %d'; 58, identifier:nplanes; 59, function_definition; 59, 60; 59, 61; 59, 63; 60, function_name:getarray; 61, parameters; 61, 62; 62, identifier:idx_buffer_filename; 63, block; 63, 64; 63, 71; 63, 78; 63, 85; 63, 93; 63, 101; 63, 180; 63, 186; 63, 205; 63, 212; 63, 228; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 70; 66, pattern_list; 66, 67; 66, 68; 66, 69; 67, identifier:idx; 68, identifier:buf; 69, identifier:fname; 70, identifier:idx_buffer_filename; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:fbuf; 74, call; 74, 75; 74, 76; 75, identifier:BytesIO; 76, argument_list; 76, 77; 77, identifier:buf; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:tfh; 81, call; 81, 82; 81, 83; 82, identifier:TiffFile; 83, argument_list; 83, 84; 84, identifier:fbuf; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:ary; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:tfh; 91, identifier:asarray; 92, argument_list; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:pageCount; 96, subscript; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:ary; 99, identifier:shape; 100, integer:0; 101, if_statement; 101, 102; 101, 105; 101, 173; 102, comparison_operator:is; 102, 103; 102, 104; 103, identifier:nplanes; 104, None; 105, block; 105, 106; 105, 112; 105, 152; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:extra; 109, binary_operator:%; 109, 110; 109, 111; 110, identifier:pageCount; 111, identifier:nplanes; 112, if_statement; 112, 113; 112, 114; 113, identifier:extra; 114, block; 114, 115; 115, if_statement; 115, 116; 115, 117; 115, 140; 116, identifier:discard_extra; 117, block; 117, 118; 117, 124; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:pageCount; 121, binary_operator:-; 121, 122; 121, 123; 122, identifier:pageCount; 123, identifier:extra; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 134; 126, attribute; 126, 127; 126, 133; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:logging; 130, identifier:getLogger; 131, argument_list; 131, 132; 132, string:'thunder'; 133, identifier:warn; 134, argument_list; 134, 135; 135, binary_operator:%; 135, 136; 135, 137; 136, string:'Ignored %d pages in file %s'; 137, tuple; 137, 138; 137, 139; 138, identifier:extra; 139, identifier:fname; 140, else_clause; 140, 141; 141, block; 141, 142; 142, raise_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:ValueError; 145, argument_list; 145, 146; 146, binary_operator:%; 146, 147; 146, 148; 147, string:"nplanes '%d' does not evenly divide '%d in file %s'"; 148, tuple; 148, 149; 148, 150; 148, 151; 149, identifier:nplanes; 150, identifier:pageCount; 151, identifier:fname; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:values; 155, list_comprehension; 155, 156; 155, 165; 156, subscript; 156, 157; 156, 158; 157, identifier:ary; 158, slice; 158, 159; 158, 160; 158, 161; 159, identifier:i; 160, colon; 161, parenthesized_expression; 161, 162; 162, binary_operator:+; 162, 163; 162, 164; 163, identifier:i; 164, identifier:nplanes; 165, for_in_clause; 165, 166; 165, 167; 166, identifier:i; 167, call; 167, 168; 167, 169; 168, identifier:range; 169, argument_list; 169, 170; 169, 171; 169, 172; 170, integer:0; 171, identifier:pageCount; 172, identifier:nplanes; 173, else_clause; 173, 174; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:values; 178, list:[ary]; 178, 179; 179, identifier:ary; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:tfh; 184, identifier:close; 185, argument_list; 186, if_statement; 186, 187; 186, 192; 187, comparison_operator:==; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:ary; 190, identifier:ndim; 191, integer:3; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:values; 196, list_comprehension; 196, 197; 196, 202; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:val; 200, identifier:squeeze; 201, argument_list; 202, for_in_clause; 202, 203; 202, 204; 203, identifier:val; 204, identifier:values; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:nvals; 208, call; 208, 209; 208, 210; 209, identifier:len; 210, argument_list; 210, 211; 211, identifier:values; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:keys; 215, list_comprehension; 215, 216; 215, 222; 216, tuple; 216, 217; 217, binary_operator:+; 217, 218; 217, 221; 218, binary_operator:*; 218, 219; 218, 220; 219, identifier:idx; 220, identifier:nvals; 221, identifier:timepoint; 222, for_in_clause; 222, 223; 222, 224; 223, identifier:timepoint; 224, call; 224, 225; 224, 226; 225, identifier:range; 226, argument_list; 226, 227; 227, identifier:nvals; 228, return_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:zip; 231, argument_list; 231, 232; 231, 233; 232, identifier:keys; 233, identifier:values; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:recount; 237, conditional_expression:if; 237, 238; 237, 239; 237, 242; 238, False; 239, comparison_operator:is; 239, 240; 239, 241; 240, identifier:nplanes; 241, None; 242, True; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:data; 246, call; 246, 247; 246, 248; 247, identifier:frompath; 248, argument_list; 248, 249; 248, 250; 248, 253; 248, 256; 248, 259; 248, 262; 248, 265; 248, 268; 248, 271; 248, 274; 248, 277; 249, identifier:path; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:accessor; 252, identifier:getarray; 253, keyword_argument; 253, 254; 253, 255; 254, identifier:ext; 255, identifier:ext; 256, keyword_argument; 256, 257; 256, 258; 257, identifier:start; 258, identifier:start; 259, keyword_argument; 259, 260; 259, 261; 260, identifier:stop; 261, identifier:stop; 262, keyword_argument; 262, 263; 262, 264; 263, identifier:recursive; 264, identifier:recursive; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:npartitions; 267, identifier:npartitions; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:recount; 270, identifier:recount; 271, keyword_argument; 271, 272; 271, 273; 272, identifier:labels; 273, identifier:labels; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:engine; 276, identifier:engine; 277, keyword_argument; 277, 278; 277, 279; 278, identifier:credentials; 279, identifier:credentials; 280, if_statement; 280, 281; 280, 296; 281, boolean_operator:and; 281, 282; 281, 289; 282, boolean_operator:and; 282, 283; 282, 286; 283, comparison_operator:is; 283, 284; 283, 285; 284, identifier:engine; 285, None; 286, comparison_operator:is; 286, 287; 286, 288; 287, identifier:npartitions; 288, None; 289, comparison_operator:<; 289, 290; 289, 295; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:data; 293, identifier:npartitions; 294, argument_list; 295, identifier:npartitions; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 300; 299, identifier:data; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:data; 303, identifier:repartition; 304, argument_list; 304, 305; 305, identifier:npartitions; 306, return_statement; 306, 307; 307, identifier:data | def fromtif(path, ext='tif', start=None, stop=None, recursive=False, nplanes=None, npartitions=None, labels=None, engine=None, credentials=None, discard_extra=False):
"""
Loads images from single or multi-page TIF files.
Parameters
----------
path : str
Path to data files or directory, specified as either a local filesystem path
or in a URI-like format, including scheme. May include a single '*' wildcard character.
ext : string, optional, default = 'tif'
Extension required on data files to be loaded.
start, stop : nonnegative int, optional, default = None
Indices of the first and last-plus-one file to load, relative to the sorted
filenames matching 'path' and 'ext'. Interpreted using python slice indexing conventions.
recursive : boolean, optional, default = False
If true, will recursively descend directories from path, loading all files
with an extension matching 'ext'.
nplanes : positive integer, optional, default = None
If passed, will cause single files to be subdivided into nplanes separate images.
Otherwise, each file is taken to represent one image.
npartitions : int, optional, default = None
Number of partitions for computational engine,
if None will use default for engine.
labels : array, optional, default = None
Labels for records. If provided, should be one-dimensional.
discard_extra : boolean, optional, default = False
If True and nplanes doesn't divide by the number of pages in a multi-page tiff, the reminder will
be discarded and a warning will be shown. If False, it will raise an error
"""
from tifffile import TiffFile
if nplanes is not None and nplanes <= 0:
raise ValueError('nplanes must be positive if passed, got %d' % nplanes)
def getarray(idx_buffer_filename):
idx, buf, fname = idx_buffer_filename
fbuf = BytesIO(buf)
tfh = TiffFile(fbuf)
ary = tfh.asarray()
pageCount = ary.shape[0]
if nplanes is not None:
extra = pageCount % nplanes
if extra:
if discard_extra:
pageCount = pageCount - extra
logging.getLogger('thunder').warn('Ignored %d pages in file %s' % (extra, fname))
else:
raise ValueError("nplanes '%d' does not evenly divide '%d in file %s'" % (nplanes, pageCount,
fname))
values = [ary[i:(i+nplanes)] for i in range(0, pageCount, nplanes)]
else:
values = [ary]
tfh.close()
if ary.ndim == 3:
values = [val.squeeze() for val in values]
nvals = len(values)
keys = [(idx*nvals + timepoint,) for timepoint in range(nvals)]
return zip(keys, values)
recount = False if nplanes is None else True
data = frompath(path, accessor=getarray, ext=ext, start=start, stop=stop,
recursive=recursive, npartitions=npartitions, recount=recount,
labels=labels, engine=engine, credentials=credentials)
if engine is not None and npartitions is not None and data.npartitions() < npartitions:
data = data.repartition(npartitions)
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:frompng; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ext; 7, string:'png'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:start; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:stop; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:recursive; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:npartitions; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:labels; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:engine; 25, None; 26, default_parameter; 26, 27; 26, 28; 27, identifier:credentials; 28, None; 29, block; 29, 30; 29, 32; 29, 38; 29, 66; 30, expression_statement; 30, 31; 31, comment; 32, import_from_statement; 32, 33; 32, 36; 33, dotted_name; 33, 34; 33, 35; 34, identifier:scipy; 35, identifier:misc; 36, dotted_name; 36, 37; 37, identifier:imread; 38, function_definition; 38, 39; 38, 40; 38, 42; 39, function_name:getarray; 40, parameters; 40, 41; 41, identifier:idx_buffer_filename; 42, block; 42, 43; 42, 50; 42, 57; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 49; 45, pattern_list; 45, 46; 45, 47; 45, 48; 46, identifier:idx; 47, identifier:buf; 48, identifier:_; 49, identifier:idx_buffer_filename; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:fbuf; 53, call; 53, 54; 53, 55; 54, identifier:BytesIO; 55, argument_list; 55, 56; 56, identifier:buf; 57, expression_statement; 57, 58; 58, yield; 58, 59; 59, expression_list; 59, 60; 59, 62; 60, tuple; 60, 61; 61, identifier:idx; 62, call; 62, 63; 62, 64; 63, identifier:imread; 64, argument_list; 64, 65; 65, identifier:fbuf; 66, return_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:frompath; 69, argument_list; 69, 70; 69, 71; 69, 74; 69, 77; 69, 80; 69, 83; 69, 86; 69, 89; 69, 92; 69, 95; 70, identifier:path; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:accessor; 73, identifier:getarray; 74, keyword_argument; 74, 75; 74, 76; 75, identifier:ext; 76, identifier:ext; 77, keyword_argument; 77, 78; 77, 79; 78, identifier:start; 79, identifier:start; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:stop; 82, identifier:stop; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:recursive; 85, identifier:recursive; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:npartitions; 88, identifier:npartitions; 89, keyword_argument; 89, 90; 89, 91; 90, identifier:labels; 91, identifier:labels; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:engine; 94, identifier:engine; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:credentials; 97, identifier:credentials | def frompng(path, ext='png', start=None, stop=None, recursive=False, npartitions=None, labels=None, engine=None, credentials=None):
"""
Load images from PNG files.
Parameters
----------
path : str
Path to data files or directory, specified as either a local filesystem path
or in a URI-like format, including scheme. May include a single '*' wildcard character.
ext : string, optional, default = 'tif'
Extension required on data files to be loaded.
start, stop : nonnegative int, optional, default = None
Indices of the first and last-plus-one file to load, relative to the sorted
filenames matching `path` and `ext`. Interpreted using python slice indexing conventions.
recursive : boolean, optional, default = False
If true, will recursively descend directories from path, loading all files
with an extension matching 'ext'.
npartitions : int, optional, default = None
Number of partitions for computational engine,
if None will use default for engine.
labels : array, optional, default = None
Labels for records. If provided, should be one-dimensional.
"""
from scipy.misc import imread
def getarray(idx_buffer_filename):
idx, buf, _ = idx_buffer_filename
fbuf = BytesIO(buf)
yield (idx,), imread(fbuf)
return frompath(path, accessor=getarray, ext=ext, start=start,
stop=stop, recursive=recursive, npartitions=npartitions,
labels=labels, engine=engine, credentials=credentials) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ext; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:start; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:stop; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:recursive; 16, False; 17, block; 17, 18; 17, 20; 17, 36; 17, 56; 17, 65; 18, expression_statement; 18, 19; 19, comment; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:files; 23, conditional_expression:if; 23, 24; 23, 29; 23, 31; 24, call; 24, 25; 24, 26; 25, identifier:listflat; 26, argument_list; 26, 27; 26, 28; 27, identifier:path; 28, identifier:ext; 29, not_operator; 29, 30; 30, identifier:recursive; 31, call; 31, 32; 31, 33; 32, identifier:listrecursive; 33, argument_list; 33, 34; 33, 35; 34, identifier:path; 35, identifier:ext; 36, if_statement; 36, 37; 36, 43; 37, comparison_operator:<; 37, 38; 37, 42; 38, call; 38, 39; 38, 40; 39, identifier:len; 40, argument_list; 40, 41; 41, identifier:files; 42, integer:1; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:FileNotFoundError; 47, argument_list; 47, 48; 48, binary_operator:%; 48, 49; 48, 50; 49, string:'Cannot find files of type "%s" in %s'; 50, tuple; 50, 51; 50, 55; 51, conditional_expression:if; 51, 52; 51, 53; 51, 54; 52, identifier:ext; 53, identifier:ext; 54, string:'*'; 55, identifier:path; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:files; 59, call; 59, 60; 59, 61; 60, identifier:select; 61, argument_list; 61, 62; 61, 63; 61, 64; 62, identifier:files; 63, identifier:start; 64, identifier:stop; 65, return_statement; 65, 66; 66, identifier:files | def list(path, ext=None, start=None, stop=None, recursive=False):
"""
Get sorted list of file paths matching path and extension
"""
files = listflat(path, ext) if not recursive else listrecursive(path, ext)
if len(files) < 1:
raise FileNotFoundError('Cannot find files of type "%s" in %s'
% (ext if ext else '*', path))
files = select(files, start, stop)
return files |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:path; 5, default_parameter; 5, 6; 5, 7; 6, identifier:filename; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:start; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:stop; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:recursive; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:directories; 19, False; 20, block; 20, 21; 20, 23; 20, 30; 20, 41; 20, 114; 20, 123; 20, 145; 20, 151; 20, 160; 21, expression_statement; 21, 22; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:path; 26, call; 26, 27; 26, 28; 27, identifier:uri_to_path; 28, argument_list; 28, 29; 29, identifier:path; 30, if_statement; 30, 31; 30, 35; 31, boolean_operator:and; 31, 32; 31, 34; 32, not_operator; 32, 33; 33, identifier:filename; 34, identifier:recursive; 35, block; 35, 36; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 39; 38, identifier:listrecursive; 39, argument_list; 39, 40; 40, identifier:path; 41, if_statement; 41, 42; 41, 43; 41, 87; 42, identifier:filename; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 53; 44, 66; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:os; 49, identifier:path; 50, identifier:isdir; 51, argument_list; 51, 52; 52, identifier:path; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:path; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:os; 61, identifier:path; 62, identifier:join; 63, argument_list; 63, 64; 63, 65; 64, identifier:path; 65, identifier:filename; 66, else_clause; 66, 67; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:path; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:os; 75, identifier:path; 76, identifier:join; 77, argument_list; 77, 78; 77, 86; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:os; 82, identifier:path; 83, identifier:dirname; 84, argument_list; 84, 85; 85, identifier:path; 86, identifier:filename; 87, else_clause; 87, 88; 88, block; 88, 89; 89, if_statement; 89, 90; 89, 101; 90, boolean_operator:and; 90, 91; 90, 99; 91, call; 91, 92; 91, 97; 92, attribute; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:os; 95, identifier:path; 96, identifier:isdir; 97, argument_list; 97, 98; 98, identifier:path; 99, not_operator; 99, 100; 100, identifier:directories; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:path; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:os; 109, identifier:path; 110, identifier:join; 111, argument_list; 111, 112; 111, 113; 112, identifier:path; 113, string:"*"; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:files; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:glob; 120, identifier:glob; 121, argument_list; 121, 122; 122, identifier:path; 123, if_statement; 123, 124; 123, 126; 124, not_operator; 124, 125; 125, identifier:directories; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:files; 130, list_comprehension; 130, 131; 130, 132; 130, 135; 131, identifier:fpath; 132, for_in_clause; 132, 133; 132, 134; 133, identifier:fpath; 134, identifier:files; 135, if_clause; 135, 136; 136, not_operator; 136, 137; 137, call; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:os; 141, identifier:path; 142, identifier:isdir; 143, argument_list; 143, 144; 144, identifier:fpath; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:files; 149, identifier:sort; 150, argument_list; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:files; 154, call; 154, 155; 154, 156; 155, identifier:select; 156, argument_list; 156, 157; 156, 158; 156, 159; 157, identifier:files; 158, identifier:start; 159, identifier:stop; 160, return_statement; 160, 161; 161, identifier:files | def list(path, filename=None, start=None, stop=None, recursive=False, directories=False):
"""
List files specified by dataPath.
Datapath may include a single wildcard ('*') in the filename specifier.
Returns sorted list of absolute path strings.
"""
path = uri_to_path(path)
if not filename and recursive:
return listrecursive(path)
if filename:
if os.path.isdir(path):
path = os.path.join(path, filename)
else:
path = os.path.join(os.path.dirname(path), filename)
else:
if os.path.isdir(path) and not directories:
path = os.path.join(path, "*")
files = glob.glob(path)
if not directories:
files = [fpath for fpath in files if not os.path.isdir(fpath)]
files.sort()
files = select(files, start, stop)
return files |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:list; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:self; 5, identifier:path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:filename; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:start; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:stop; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:recursive; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:directories; 20, False; 21, block; 21, 22; 21, 24; 21, 44; 21, 66; 21, 72; 21, 81; 22, expression_statement; 22, 23; 23, comment; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, pattern_list; 26, 27; 26, 28; 27, identifier:storageScheme; 28, identifier:keys; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:getkeys; 33, argument_list; 33, 34; 33, 35; 33, 38; 33, 41; 34, identifier:path; 35, keyword_argument; 35, 36; 35, 37; 36, identifier:filename; 37, identifier:filename; 38, keyword_argument; 38, 39; 38, 40; 39, identifier:directories; 40, identifier:directories; 41, keyword_argument; 41, 42; 41, 43; 42, identifier:recursive; 43, identifier:recursive; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:keys; 47, list_comprehension; 47, 48; 47, 63; 48, binary_operator:+; 48, 49; 48, 60; 49, binary_operator:+; 49, 50; 49, 59; 50, binary_operator:+; 50, 51; 50, 54; 51, binary_operator:+; 51, 52; 51, 53; 52, identifier:storageScheme; 53, string:":///"; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:key; 57, identifier:bucket; 58, identifier:name; 59, string:"/"; 60, attribute; 60, 61; 60, 62; 61, identifier:key; 62, identifier:name; 63, for_in_clause; 63, 64; 63, 65; 64, identifier:key; 65, identifier:keys; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:keys; 70, identifier:sort; 71, argument_list; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:keys; 75, call; 75, 76; 75, 77; 76, identifier:select; 77, argument_list; 77, 78; 77, 79; 77, 80; 78, identifier:keys; 79, identifier:start; 80, identifier:stop; 81, return_statement; 81, 82; 82, identifier:keys | def list(self, path, filename=None, start=None, stop=None, recursive=False, directories=False):
"""
List objects specified by path.
Returns sorted list of 'gs://' or 's3n://' URIs.
"""
storageScheme, keys = self.getkeys(
path, filename=filename, directories=directories, recursive=recursive)
keys = [storageScheme + ":///" + key.bucket.name + "/" + key.name for key in keys]
keys.sort()
keys = select(keys, start, stop)
return keys |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:validate_v3_svc_catalog_endpoint_data; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:expected; 6, identifier:actual; 7, block; 7, 8; 7, 10; 7, 19; 7, 36; 7, 169; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:log; 16, identifier:debug; 17, argument_list; 17, 18; 18, string:'Validating v3 service catalog endpoint data...'; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:log; 25, identifier:debug; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, string:'actual: {}'; 30, identifier:format; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 34; 33, identifier:repr; 34, argument_list; 34, 35; 35, identifier:actual; 36, for_statement; 36, 37; 36, 40; 36, 46; 37, pattern_list; 37, 38; 37, 39; 38, identifier:k; 39, identifier:v; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:six; 43, identifier:iteritems; 44, argument_list; 44, 45; 45, identifier:expected; 46, block; 46, 47; 47, if_statement; 47, 48; 47, 51; 47, 160; 48, comparison_operator:in; 48, 49; 48, 50; 49, identifier:k; 50, identifier:actual; 51, block; 51, 52; 51, 67; 51, 84; 51, 113; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:l_expected; 55, call; 55, 56; 55, 57; 56, identifier:sorted; 57, argument_list; 57, 58; 57, 59; 58, identifier:v; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:key; 61, lambda; 61, 62; 61, 64; 62, lambda_parameters; 62, 63; 63, identifier:x; 64, subscript; 64, 65; 64, 66; 65, identifier:x; 66, string:'interface'; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:l_actual; 70, call; 70, 71; 70, 72; 71, identifier:sorted; 72, argument_list; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:actual; 75, identifier:k; 76, keyword_argument; 76, 77; 76, 78; 77, identifier:key; 78, lambda; 78, 79; 78, 81; 79, lambda_parameters; 79, 80; 80, identifier:x; 81, subscript; 81, 82; 81, 83; 82, identifier:x; 83, string:'interface'; 84, if_statement; 84, 85; 84, 94; 85, comparison_operator:!=; 85, 86; 85, 90; 86, call; 86, 87; 86, 88; 87, identifier:len; 88, argument_list; 88, 89; 89, identifier:l_actual; 90, call; 90, 91; 90, 92; 91, identifier:len; 92, argument_list; 92, 93; 93, identifier:l_expected; 94, block; 94, 95; 95, return_statement; 95, 96; 96, parenthesized_expression; 96, 97; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, concatenated_string; 99, 100; 99, 101; 100, string:"endpoint {} has differing number of interfaces "; 101, string:" - expected({}), actual({})"; 102, identifier:format; 103, argument_list; 103, 104; 103, 105; 103, 109; 104, identifier:k; 105, call; 105, 106; 105, 107; 106, identifier:len; 107, argument_list; 107, 108; 108, identifier:l_expected; 109, call; 109, 110; 109, 111; 110, identifier:len; 111, argument_list; 111, 112; 112, identifier:l_actual; 113, for_statement; 113, 114; 113, 117; 113, 122; 114, pattern_list; 114, 115; 114, 116; 115, identifier:i_expected; 116, identifier:i_actual; 117, call; 117, 118; 117, 119; 118, identifier:zip; 119, argument_list; 119, 120; 119, 121; 120, identifier:l_expected; 121, identifier:l_actual; 122, block; 122, 123; 122, 139; 122, 149; 123, expression_statement; 123, 124; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:log; 129, identifier:debug; 130, argument_list; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, string:"checking interface {}"; 134, identifier:format; 135, argument_list; 135, 136; 136, subscript; 136, 137; 136, 138; 137, identifier:i_expected; 138, string:'interface'; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:ret; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:_validate_dict_data; 146, argument_list; 146, 147; 146, 148; 147, identifier:i_expected; 148, identifier:i_actual; 149, if_statement; 149, 150; 149, 151; 150, identifier:ret; 151, block; 151, 152; 152, return_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:endpoint_error; 157, argument_list; 157, 158; 157, 159; 158, identifier:k; 159, identifier:ret; 160, else_clause; 160, 161; 161, block; 161, 162; 162, return_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, string:"endpoint {} does not exist"; 166, identifier:format; 167, argument_list; 167, 168; 168, identifier:k; 169, return_statement; 169, 170; 170, identifier:ret | def validate_v3_svc_catalog_endpoint_data(self, expected, actual):
"""Validate the keystone v3 catalog endpoint data.
Validate a list of dictinaries that make up the keystone v3 service
catalogue.
It is in the form of:
{u'identity': [{u'id': u'48346b01c6804b298cdd7349aadb732e',
u'interface': u'admin',
u'region': u'RegionOne',
u'region_id': u'RegionOne',
u'url': u'http://10.5.5.224:35357/v3'},
{u'id': u'8414f7352a4b47a69fddd9dbd2aef5cf',
u'interface': u'public',
u'region': u'RegionOne',
u'region_id': u'RegionOne',
u'url': u'http://10.5.5.224:5000/v3'},
{u'id': u'd5ca31440cc24ee1bf625e2996fb6a5b',
u'interface': u'internal',
u'region': u'RegionOne',
u'region_id': u'RegionOne',
u'url': u'http://10.5.5.224:5000/v3'}],
u'key-manager': [{u'id': u'68ebc17df0b045fcb8a8a433ebea9e62',
u'interface': u'public',
u'region': u'RegionOne',
u'region_id': u'RegionOne',
u'url': u'http://10.5.5.223:9311'},
{u'id': u'9cdfe2a893c34afd8f504eb218cd2f9d',
u'interface': u'internal',
u'region': u'RegionOne',
u'region_id': u'RegionOne',
u'url': u'http://10.5.5.223:9311'},
{u'id': u'f629388955bc407f8b11d8b7ca168086',
u'interface': u'admin',
u'region': u'RegionOne',
u'region_id': u'RegionOne',
u'url': u'http://10.5.5.223:9312'}]}
Note, that an added complication is that the order of admin, public,
internal against 'interface' in each region.
Thus, the function sorts the expected and actual lists using the
interface key as a sort key, prior to the comparison.
"""
self.log.debug('Validating v3 service catalog endpoint data...')
self.log.debug('actual: {}'.format(repr(actual)))
for k, v in six.iteritems(expected):
if k in actual:
l_expected = sorted(v, key=lambda x: x['interface'])
l_actual = sorted(actual[k], key=lambda x: x['interface'])
if len(l_actual) != len(l_expected):
return ("endpoint {} has differing number of interfaces "
" - expected({}), actual({})"
.format(k, len(l_expected), len(l_actual)))
for i_expected, i_actual in zip(l_expected, l_actual):
self.log.debug("checking interface {}"
.format(i_expected['interface']))
ret = self._validate_dict_data(i_expected, i_actual)
if ret:
return self.endpoint_error(k, ret)
else:
return "endpoint {} does not exist".format(k)
return ret |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:ordered; 3, parameters; 3, 4; 4, identifier:orderme; 5, block; 5, 6; 5, 8; 5, 21; 5, 27; 5, 73; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 15; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:isinstance; 12, argument_list; 12, 13; 12, 14; 13, identifier:orderme; 14, identifier:dict; 15, block; 15, 16; 16, raise_statement; 16, 17; 17, call; 17, 18; 17, 19; 18, identifier:ValueError; 19, argument_list; 19, 20; 20, string:'argument must be a dict type'; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:result; 24, call; 24, 25; 24, 26; 25, identifier:OrderedDict; 26, argument_list; 27, for_statement; 27, 28; 27, 31; 27, 48; 28, pattern_list; 28, 29; 28, 30; 29, identifier:k; 30, identifier:v; 31, call; 31, 32; 31, 33; 32, identifier:sorted; 33, argument_list; 33, 34; 33, 40; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:six; 37, identifier:iteritems; 38, argument_list; 38, 39; 39, identifier:orderme; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:key; 42, lambda; 42, 43; 42, 45; 43, lambda_parameters; 43, 44; 44, identifier:x; 45, subscript; 45, 46; 45, 47; 46, identifier:x; 47, integer:0; 48, block; 48, 49; 49, if_statement; 49, 50; 49, 55; 49, 65; 50, call; 50, 51; 50, 52; 51, identifier:isinstance; 52, argument_list; 52, 53; 52, 54; 53, identifier:v; 54, identifier:dict; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 61; 58, subscript; 58, 59; 58, 60; 59, identifier:result; 60, identifier:k; 61, call; 61, 62; 61, 63; 62, identifier:ordered; 63, argument_list; 63, 64; 64, identifier:v; 65, else_clause; 65, 66; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:result; 71, identifier:k; 72, identifier:v; 73, return_statement; 73, 74; 74, identifier:result | def ordered(orderme):
"""Converts the provided dictionary into a collections.OrderedDict.
The items in the returned OrderedDict will be inserted based on the
natural sort order of the keys. Nested dictionaries will also be sorted
in order to ensure fully predictable ordering.
:param orderme: the dict to order
:return: collections.OrderedDict
:raises: ValueError: if `orderme` isn't a dict instance.
"""
if not isinstance(orderme, dict):
raise ValueError('argument must be a dict type')
result = OrderedDict()
for k, v in sorted(six.iteritems(orderme), key=lambda x: x[0]):
if isinstance(v, dict):
result[k] = ordered(v)
else:
result[k] = v
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:q; 6, default_parameter; 6, 7; 6, 8; 7, identifier:start; 8, integer:1; 9, default_parameter; 9, 10; 9, 11; 10, identifier:num; 11, integer:10; 12, default_parameter; 12, 13; 12, 14; 13, identifier:sortField; 14, string:"username"; 15, default_parameter; 15, 16; 15, 17; 16, identifier:sortOrder; 17, string:"asc"; 18, block; 18, 19; 18, 21; 18, 43; 18, 49; 19, expression_statement; 19, 20; 20, comment; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:params; 24, dictionary; 24, 25; 24, 28; 24, 31; 24, 34; 24, 37; 24, 40; 25, pair; 25, 26; 25, 27; 26, string:"f"; 27, string:"json"; 28, pair; 28, 29; 28, 30; 29, string:"q"; 30, identifier:q; 31, pair; 31, 32; 31, 33; 32, string:"start"; 33, identifier:start; 34, pair; 34, 35; 34, 36; 35, string:"num"; 36, identifier:num; 37, pair; 37, 38; 37, 39; 38, string:"sortField"; 39, identifier:sortField; 40, pair; 40, 41; 40, 42; 41, string:"sortOrder"; 42, identifier:sortOrder; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:url; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_url; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_get; 54, argument_list; 54, 55; 54, 58; 54, 61; 54, 66; 54, 71; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:url; 57, identifier:url; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:param_dict; 60, identifier:params; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:securityHandler; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:_securityHandler; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:proxy_url; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_proxy_url; 71, keyword_argument; 71, 72; 71, 73; 72, identifier:proxy_port; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:_proxy_port | def search(self,
q,
start=1,
num=10,
sortField="username",
sortOrder="asc"):
"""
The User Search operation searches for users in the portal. The
search index is updated whenever users are created, updated, or
deleted. There can be a lag between the time that the user is
updated and the time when it's reflected in the search results. The
results only contain users that the calling user has permissions to
see. Users can control this visibility by changing the access
property of their user.
Inputs:
q -The query string to search the users against.
start - The number of the first entry in the result set response.
The index number is 1-based. The default value of start is
1 (for example, the first search result). The start
parameter, along with the num parameter can be used to
paginate the search results.
num - The maximum number of results to be included in the result
set response. The default value is 10, and the maximum
allowed value is 100. The start parameter, along with the num
parameter can be used to paginate the search results. The
actual number of returned results may be less than num. This
happens when the number of results remaining after start is
less than num.
sortField - Field to sort by. The allowed field names are username
and created.
sortOrder - Describes whether the returned results are in ascending
or descending order. Default is ascending.
Values: asc | desc
"""
params = {
"f" : "json",
"q" : q,
"start" : start,
"num" : num,
"sortField" : sortField,
"sortOrder" : sortOrder
}
url = self._url
return self._get(
url = url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 55; 2, function_name:exportImage; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 3, 37; 3, 40; 3, 43; 3, 46; 3, 49; 3, 52; 4, identifier:self; 5, identifier:bbox; 6, identifier:imageSR; 7, identifier:bboxSR; 8, default_parameter; 8, 9; 8, 10; 9, identifier:size; 10, list:[400,400]; 10, 11; 10, 12; 11, integer:400; 12, integer:400; 13, default_parameter; 13, 14; 13, 15; 14, identifier:time; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:format; 18, string:"jpgpng"; 19, default_parameter; 19, 20; 19, 21; 20, identifier:pixelType; 21, string:"UNKNOWN"; 22, default_parameter; 22, 23; 22, 24; 23, identifier:noData; 24, None; 25, default_parameter; 25, 26; 25, 27; 26, identifier:noDataInterpretation; 27, string:"esriNoDataMatchAny"; 28, default_parameter; 28, 29; 28, 30; 29, identifier:interpolation; 30, None; 31, default_parameter; 31, 32; 31, 33; 32, identifier:compression; 33, None; 34, default_parameter; 34, 35; 34, 36; 35, identifier:compressionQuality; 36, integer:75; 37, default_parameter; 37, 38; 37, 39; 38, identifier:bandIds; 39, None; 40, default_parameter; 40, 41; 40, 42; 41, identifier:moasiacRule; 42, None; 43, default_parameter; 43, 44; 43, 45; 44, identifier:renderingRule; 45, string:""; 46, default_parameter; 46, 47; 46, 48; 47, identifier:f; 48, string:"json"; 49, default_parameter; 49, 50; 49, 51; 50, identifier:saveFolder; 51, None; 52, default_parameter; 52, 53; 52, 54; 53, identifier:saveFile; 54, None; 55, block; 55, 56; 55, 58; 55, 88; 55, 96; 55, 109; 55, 127; 55, 133; 55, 141; 55, 147; 55, 162; 55, 173; 55, 191; 55, 214; 55, 230; 55, 241; 55, 252; 55, 268; 55, 291; 55, 302; 55, 308; 56, expression_statement; 56, 57; 57, comment; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:params; 61, dictionary; 61, 62; 61, 65; 61, 68; 61, 71; 61, 82; 61, 85; 62, pair; 62, 63; 62, 64; 63, string:"bbox"; 64, identifier:bbox; 65, pair; 65, 66; 65, 67; 66, string:"imageSR"; 67, identifier:imageSR; 68, pair; 68, 69; 68, 70; 69, string:"bboxSR"; 70, identifier:bboxSR; 71, pair; 71, 72; 71, 73; 72, string:"size"; 73, binary_operator:%; 73, 74; 73, 75; 74, string:"%s %s"; 75, tuple; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:size; 78, integer:0; 79, subscript; 79, 80; 79, 81; 80, identifier:size; 81, integer:1; 82, pair; 82, 83; 82, 84; 83, string:"pixelType"; 84, identifier:pixelType; 85, pair; 85, 86; 85, 87; 86, string:"compressionQuality"; 87, identifier:compressionQuality; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:url; 91, binary_operator:+; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:_url; 95, string:"/exportImage"; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:__allowedFormat; 99, list:["jpgpng", "png",
"png8", "png24",
"jpg", "bmp",
"gif", "tiff",
"png32"]; 99, 100; 99, 101; 99, 102; 99, 103; 99, 104; 99, 105; 99, 106; 99, 107; 99, 108; 100, string:"jpgpng"; 101, string:"png"; 102, string:"png8"; 103, string:"png24"; 104, string:"jpg"; 105, string:"bmp"; 106, string:"gif"; 107, string:"tiff"; 108, string:"png32"; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:__allowedPixelTypes; 112, list:[
"C128", "C64", "F32",
"F64", "S16", "S32",
"S8", "U1", "U16",
"U2", "U32", "U4",
"U8", "UNKNOWN"
]; 112, 113; 112, 114; 112, 115; 112, 116; 112, 117; 112, 118; 112, 119; 112, 120; 112, 121; 112, 122; 112, 123; 112, 124; 112, 125; 112, 126; 113, string:"C128"; 114, string:"C64"; 115, string:"F32"; 116, string:"F64"; 117, string:"S16"; 118, string:"S32"; 119, string:"S8"; 120, string:"U1"; 121, string:"U16"; 122, string:"U2"; 123, string:"U32"; 124, string:"U4"; 125, string:"U8"; 126, string:"UNKNOWN"; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:__allowednoDataInt; 130, list:[
"esriNoDataMatchAny",
"esriNoDataMatchAll"
]; 130, 131; 130, 132; 131, string:"esriNoDataMatchAny"; 132, string:"esriNoDataMatchAll"; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:__allowedInterpolation; 136, list:[
"RSP_BilinearInterpolation",
"RSP_CubicConvolution",
"RSP_Majority",
"RSP_NearestNeighbor"
]; 136, 137; 136, 138; 136, 139; 136, 140; 137, string:"RSP_BilinearInterpolation"; 138, string:"RSP_CubicConvolution"; 139, string:"RSP_Majority"; 140, string:"RSP_NearestNeighbor"; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:__allowedCompression; 144, list:[
"JPEG", "LZ77"
]; 144, 145; 144, 146; 145, string:"JPEG"; 146, string:"LZ77"; 147, if_statement; 147, 148; 147, 153; 148, call; 148, 149; 148, 150; 149, identifier:isinstance; 150, argument_list; 150, 151; 150, 152; 151, identifier:moasiacRule; 152, identifier:MosaicRuleObject; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:params; 158, string:"moasiacRule"; 159, attribute; 159, 160; 159, 161; 160, identifier:moasiacRule; 161, identifier:value; 162, if_statement; 162, 163; 162, 166; 163, comparison_operator:in; 163, 164; 163, 165; 164, identifier:format; 165, identifier:__allowedFormat; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, subscript; 169, 170; 169, 171; 170, identifier:params; 171, string:'format'; 172, identifier:format; 173, if_statement; 173, 174; 173, 181; 174, call; 174, 175; 174, 176; 175, identifier:isinstance; 176, argument_list; 176, 177; 176, 178; 177, identifier:time; 178, attribute; 178, 179; 178, 180; 179, identifier:datetime; 180, identifier:datetime; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:params; 186, string:'time'; 187, call; 187, 188; 187, 189; 188, identifier:local_time_to_online; 189, argument_list; 189, 190; 190, identifier:time; 191, if_statement; 191, 192; 191, 207; 192, boolean_operator:and; 192, 193; 192, 201; 192, 202; 193, boolean_operator:and; 193, 194; 193, 197; 193, 198; 194, comparison_operator:is; 194, 195; 194, 196; 195, identifier:interpolation; 196, None; 197, line_continuation:\; 198, comparison_operator:in; 198, 199; 198, 200; 199, identifier:interpolation; 200, identifier:__allowedInterpolation; 201, line_continuation:\; 202, call; 202, 203; 202, 204; 203, identifier:isinstance; 204, argument_list; 204, 205; 204, 206; 205, identifier:interpolation; 206, identifier:str; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 210, subscript; 210, 211; 210, 212; 211, identifier:params; 212, string:'interpolation'; 213, identifier:interpolation; 214, if_statement; 214, 215; 214, 223; 215, boolean_operator:and; 215, 216; 215, 219; 215, 220; 216, comparison_operator:is; 216, 217; 216, 218; 217, identifier:pixelType; 218, None; 219, line_continuation:\; 220, comparison_operator:in; 220, 221; 220, 222; 221, identifier:pixelType; 222, identifier:__allowedPixelTypes; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:params; 228, string:'pixelType'; 229, identifier:pixelType; 230, if_statement; 230, 231; 230, 234; 231, comparison_operator:in; 231, 232; 231, 233; 232, identifier:noDataInterpretation; 233, identifier:__allowedInterpolation; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 240; 237, subscript; 237, 238; 237, 239; 238, identifier:params; 239, string:'noDataInterpretation'; 240, identifier:noDataInterpretation; 241, if_statement; 241, 242; 241, 245; 242, comparison_operator:is; 242, 243; 242, 244; 243, identifier:noData; 244, None; 245, block; 245, 246; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:params; 250, string:'noData'; 251, identifier:noData; 252, if_statement; 252, 253; 252, 261; 253, boolean_operator:and; 253, 254; 253, 257; 253, 258; 254, comparison_operator:is; 254, 255; 254, 256; 255, identifier:compression; 256, None; 257, line_continuation:\; 258, comparison_operator:in; 258, 259; 258, 260; 259, identifier:compression; 260, identifier:__allowedCompression; 261, block; 261, 262; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 267; 264, subscript; 264, 265; 264, 266; 265, identifier:params; 266, string:'compression'; 267, identifier:compression; 268, if_statement; 268, 269; 268, 279; 269, boolean_operator:and; 269, 270; 269, 273; 269, 274; 270, comparison_operator:is; 270, 271; 270, 272; 271, identifier:bandIds; 272, None; 273, line_continuation:\; 274, call; 274, 275; 274, 276; 275, identifier:isinstance; 276, argument_list; 276, 277; 276, 278; 277, identifier:bandIds; 278, identifier:list; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 285; 282, subscript; 282, 283; 282, 284; 283, identifier:params; 284, string:'bandIds'; 285, call; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, string:","; 288, identifier:join; 289, argument_list; 289, 290; 290, identifier:bandIds; 291, if_statement; 291, 292; 291, 295; 292, comparison_operator:is; 292, 293; 292, 294; 293, identifier:renderingRule; 294, None; 295, block; 295, 296; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 301; 298, subscript; 298, 299; 298, 300; 299, identifier:params; 300, string:'renderingRule'; 301, identifier:renderingRule; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 307; 304, subscript; 304, 305; 304, 306; 305, identifier:params; 306, string:"f"; 307, identifier:f; 308, if_statement; 308, 309; 308, 312; 308, 340; 308, 382; 309, comparison_operator:==; 309, 310; 309, 311; 310, identifier:f; 311, string:"json"; 312, block; 312, 313; 313, return_statement; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:self; 317, identifier:_get; 318, argument_list; 318, 319; 318, 322; 318, 325; 318, 330; 318, 335; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:url; 321, identifier:url; 322, keyword_argument; 322, 323; 322, 324; 323, identifier:param_dict; 324, identifier:params; 325, keyword_argument; 325, 326; 325, 327; 326, identifier:securityHandler; 327, attribute; 327, 328; 327, 329; 328, identifier:self; 329, identifier:_securityHandler; 330, keyword_argument; 330, 331; 330, 332; 331, identifier:proxy_port; 332, attribute; 332, 333; 332, 334; 333, identifier:self; 334, identifier:_proxy_port; 335, keyword_argument; 335, 336; 335, 337; 336, identifier:proxy_url; 337, attribute; 337, 338; 337, 339; 338, identifier:self; 339, identifier:_proxy_url; 340, elif_clause; 340, 341; 340, 344; 341, comparison_operator:==; 341, 342; 341, 343; 342, identifier:f; 343, string:"image"; 344, block; 344, 345; 344, 380; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 348; 347, identifier:result; 348, call; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:self; 351, identifier:_get; 352, argument_list; 352, 353; 352, 356; 352, 359; 352, 364; 352, 369; 352, 374; 352, 377; 353, keyword_argument; 353, 354; 353, 355; 354, identifier:url; 355, identifier:url; 356, keyword_argument; 356, 357; 356, 358; 357, identifier:param_dict; 358, identifier:params; 359, keyword_argument; 359, 360; 359, 361; 360, identifier:securityHandler; 361, attribute; 361, 362; 361, 363; 362, identifier:self; 363, identifier:_securityHandler; 364, keyword_argument; 364, 365; 364, 366; 365, identifier:proxy_url; 366, attribute; 366, 367; 366, 368; 367, identifier:self; 368, identifier:_proxy_url; 369, keyword_argument; 369, 370; 369, 371; 370, identifier:proxy_port; 371, attribute; 371, 372; 371, 373; 372, identifier:self; 373, identifier:_proxy_port; 374, keyword_argument; 374, 375; 374, 376; 375, identifier:out_folder; 376, identifier:saveFolder; 377, keyword_argument; 377, 378; 377, 379; 378, identifier:file_name; 379, identifier:saveFile; 380, return_statement; 380, 381; 381, identifier:result; 382, elif_clause; 382, 383; 382, 386; 383, comparison_operator:==; 383, 384; 383, 385; 384, identifier:f; 385, string:"kmz"; 386, block; 386, 387; 387, return_statement; 387, 388; 388, call; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:self; 391, identifier:_get; 392, argument_list; 392, 393; 392, 396; 392, 399; 392, 404; 392, 409; 392, 414; 392, 417; 393, keyword_argument; 393, 394; 393, 395; 394, identifier:url; 395, identifier:url; 396, keyword_argument; 396, 397; 396, 398; 397, identifier:param_dict; 398, identifier:params; 399, keyword_argument; 399, 400; 399, 401; 400, identifier:securityHandler; 401, attribute; 401, 402; 401, 403; 402, identifier:self; 403, identifier:_securityHandler; 404, keyword_argument; 404, 405; 404, 406; 405, identifier:proxy_url; 406, attribute; 406, 407; 406, 408; 407, identifier:self; 408, identifier:_proxy_url; 409, keyword_argument; 409, 410; 409, 411; 410, identifier:proxy_port; 411, attribute; 411, 412; 411, 413; 412, identifier:self; 413, identifier:_proxy_port; 414, keyword_argument; 414, 415; 414, 416; 415, identifier:out_folder; 416, identifier:saveFolder; 417, keyword_argument; 417, 418; 417, 419; 418, identifier:file_name; 419, identifier:saveFile | def exportImage(self,
bbox,
imageSR,
bboxSR,
size=[400,400],
time=None,
format="jpgpng",
pixelType="UNKNOWN",
noData=None,
noDataInterpretation="esriNoDataMatchAny",
interpolation=None,
compression=None,
compressionQuality=75,
bandIds=None,
moasiacRule=None,
renderingRule="",
f="json",
saveFolder=None,
saveFile=None
):
"""
The exportImage operation is performed on an image service resource
The result of this operation is an image resource. This resource
provides information about the exported image, such as its URL,
extent, width, and height.
In addition to the usual response formats of HTML and JSON, you can
also request the image format while performing this operation. When
you perform an export with the image format , the server responds
by directly streaming the image bytes to the client. With this
approach, you don't get any information associated with the
exported image other than the image itself.
Inputs:
bbox - The extent (bounding box) of the exported image. Unless
the bboxSR parameter has been specified, the bbox is
assumed to be in the spatial reference of the image
service.
imageSR - The spatial reference of the exported image.
bboxSR - The spatial reference of the bbox.
size - The size (width * height) of the exported image in
pixels. If size is not specified, an image with a default
size of 400 * 400 will be exported.
time - The time instant or the time extent of the exported image.
format - The format of the exported image. The default format is
jpgpng.
Values: jpgpng | png | png8 | png24 | jpg | bmp | gif |
tiff | png32
pixelType - The pixel type, also known as data type, pertains to
the type of values stored in the raster, such as
signed integer, unsigned integer, or floating point.
Integers are whole numbers, whereas floating points
have decimals.
noDate - The pixel value representing no information.
noDataInterpretation - Interpretation of the noData setting. The
default is esriNoDataMatchAny when noData is
a number, and esriNoDataMatchAll when noData
is a comma-delimited string:
esriNoDataMatchAny | esriNoDataMatchAll.
interpolation - The resampling process of extrapolating the
pixel values while transforming the raster
dataset when it undergoes warping or when it
changes coordinate space.
compression - Controls how to compress the image when exporting
to TIFF format: None, JPEG, LZ77. It does not
control compression on other formats.
compressionQuality - Controls how much loss the image will be
subjected to by the compression algorithm.
Valid value ranges of compression quality
are from 0 to 100.
bandIds - If there are multiple bands, you can specify a single
band to export, or you can change the band combination
(red, green, blue) by specifying the band number. Band
number is 0 based.
mosaicRule - Specifies the mosaic rule when defining how
individual images should be mosaicked. When a mosaic
rule is not specified, the default mosaic rule of
the image service will be used (as advertised in
the root resource: defaultMosaicMethod,
mosaicOperator, sortField, sortValue).
renderingRule - Specifies the rendering rule for how the
requested image should be rendered.
f - The response format. default is json
Values: json | image | kmz
"""
params = {
"bbox" : bbox,
"imageSR": imageSR,
"bboxSR": bboxSR,
"size" : "%s %s" % (size[0], size[1]),
"pixelType" : pixelType,
"compressionQuality" : compressionQuality,
}
url = self._url + "/exportImage"
__allowedFormat = ["jpgpng", "png",
"png8", "png24",
"jpg", "bmp",
"gif", "tiff",
"png32"]
__allowedPixelTypes = [
"C128", "C64", "F32",
"F64", "S16", "S32",
"S8", "U1", "U16",
"U2", "U32", "U4",
"U8", "UNKNOWN"
]
__allowednoDataInt = [
"esriNoDataMatchAny",
"esriNoDataMatchAll"
]
__allowedInterpolation = [
"RSP_BilinearInterpolation",
"RSP_CubicConvolution",
"RSP_Majority",
"RSP_NearestNeighbor"
]
__allowedCompression = [
"JPEG", "LZ77"
]
if isinstance(moasiacRule,MosaicRuleObject):
params["moasiacRule"] = moasiacRule.value
if format in __allowedFormat:
params['format'] = format
if isinstance(time, datetime.datetime):
params['time'] = local_time_to_online(time)
if interpolation is not None and \
interpolation in __allowedInterpolation and \
isinstance(interpolation, str):
params['interpolation'] = interpolation
if pixelType is not None and \
pixelType in __allowedPixelTypes:
params['pixelType'] = pixelType
if noDataInterpretation in __allowedInterpolation:
params['noDataInterpretation'] = noDataInterpretation
if noData is not None:
params['noData'] = noData
if compression is not None and \
compression in __allowedCompression:
params['compression'] = compression
if bandIds is not None and \
isinstance(bandIds, list):
params['bandIds'] = ",".join(bandIds)
if renderingRule is not None:
params['renderingRule'] = renderingRule
params["f" ] = f
if f == "json":
return self._get(url=url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_port=self._proxy_port,
proxy_url=self._proxy_url)
elif f == "image":
result = self._get(url=url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port,
out_folder=saveFolder,
file_name=saveFile)
return result
elif f == "kmz":
return self._get(url=url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port,
out_folder=saveFolder,
file_name=saveFile) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 2, function_name:measure; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, identifier:fromGeometry; 6, identifier:toGeometry; 7, identifier:measureOperation; 8, default_parameter; 8, 9; 8, 10; 9, identifier:geometryType; 10, string:"esriGeometryPoint"; 11, default_parameter; 11, 12; 11, 13; 12, identifier:pixelSize; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:mosaicRule; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:linearUnit; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:angularUnit; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:areaUnit; 25, None; 26, block; 26, 27; 26, 29; 26, 37; 26, 56; 26, 68; 26, 80; 26, 92; 26, 104; 26, 116; 27, expression_statement; 27, 28; 28, comment; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:url; 32, binary_operator:+; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_url; 36, string:"/measure"; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:params; 40, dictionary; 40, 41; 40, 44; 40, 47; 40, 50; 40, 53; 41, pair; 41, 42; 41, 43; 42, string:"f"; 43, string:"json"; 44, pair; 44, 45; 44, 46; 45, string:"fromGeometry"; 46, identifier:fromGeometry; 47, pair; 47, 48; 47, 49; 48, string:"toGeometry"; 49, identifier:toGeometry; 50, pair; 50, 51; 50, 52; 51, string:"geometryType"; 52, identifier:geometryType; 53, pair; 53, 54; 53, 55; 54, string:"measureOperation"; 55, identifier:measureOperation; 56, if_statement; 56, 57; 56, 61; 57, not_operator; 57, 58; 58, comparison_operator:is; 58, 59; 58, 60; 59, identifier:pixelSize; 60, None; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, subscript; 64, 65; 64, 66; 65, identifier:params; 66, string:"pixelSize"; 67, identifier:pixelSize; 68, if_statement; 68, 69; 68, 73; 69, not_operator; 69, 70; 70, comparison_operator:is; 70, 71; 70, 72; 71, identifier:mosaicRule; 72, None; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, subscript; 76, 77; 76, 78; 77, identifier:params; 78, string:"mosaicRule"; 79, identifier:mosaicRule; 80, if_statement; 80, 81; 80, 85; 81, not_operator; 81, 82; 82, comparison_operator:is; 82, 83; 82, 84; 83, identifier:linearUnit; 84, None; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 91; 88, subscript; 88, 89; 88, 90; 89, identifier:params; 90, string:"linearUnit"; 91, identifier:linearUnit; 92, if_statement; 92, 93; 92, 97; 93, not_operator; 93, 94; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:angularUnit; 96, None; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:params; 102, string:"angularUnit"; 103, identifier:angularUnit; 104, if_statement; 104, 105; 104, 109; 105, not_operator; 105, 106; 106, comparison_operator:is; 106, 107; 106, 108; 107, identifier:areaUnit; 108, None; 109, block; 109, 110; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, subscript; 112, 113; 112, 114; 113, identifier:params; 114, string:"areaUnit"; 115, identifier:areaUnit; 116, return_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:_get; 121, argument_list; 121, 122; 121, 125; 121, 128; 121, 133; 121, 138; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:url; 124, identifier:url; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:param_dict; 127, identifier:params; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:securityHandler; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:_securityHandler; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:proxy_url; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:_proxy_url; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:proxy_port; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:_proxy_port | def measure(self,fromGeometry,toGeometry,measureOperation,
geometryType="esriGeometryPoint",pixelSize=None,mosaicRule=None,
linearUnit=None,angularUnit=None,areaUnit=None):
"""
The measure operation is performed on an image service resource. It
lets a user measure distance, direction, area, perimeter, and height
from an image service. The result of this operation includes the name
of the raster dataset being used, sensor name, and measured values.
The measure operation can be supported by image services from raster
datasets and mosaic datasets. Spatial reference is required to perform
basic measurement (distance, area, and so on). Sensor metadata (geodata
transformation) needs to be present in the data source used by an image
service to enable height measurement (for example, imagery with RPCs).
The mosaic dataset or service needs to include DEM to perform 3D measure.
Users can provide arguments to the measure operation as query parameters.
Inputs:
fromGeometry - A geometry that defines the "from" location of the
measurement. The structure of the geometry is the same as the structure
of the JSON geometry objects returned by the ArcGIS REST API. In addition
to the JSON structures, for points, you can specify the geometry with a
simple comma-separated syntax.
By default, the geometry is assumed to be in the spatial reference of
the image service. You can specify a different spatial reference by
using the JSON structure syntax for geometries.
toGeometry - A geometry that defines the "to" location of the measurement.
The type of geometry must be the same as fromGeometry. The structure of
the geometry is the same as the structure of the JSON geometry objects
returned by the ArcGIS REST API. In addition to the JSON structures, for
points, you can specify the geometry with a simple comma-separated syntax.
By default, the geometry is assumed to be in the spatial reference of
the image service. You can specify a different spatial reference by
using the JSON structure syntax for geometries.
geometryType - The type of geometry specified by the fromGeometry and
toGeometry parameters. The geometry type can be a point, polygon, or
envelope. The default geometry type is point.
Values: esriGeometryPoint | esriGeometryPolygon | esriGeometryEnvelope
measureOperation - Specifies the type of measure being performed.
Values: esriMensurationPoint | esriMensurationDistanceAndAngle |
esriMensurationAreaAndPerimeter | esriMensurationHeightFromBaseAndTop |
esriMensurationHeightFromBaseAndTopShadow |
esriMensurationHeightFromTopAndTopShadow | esriMensurationCentroid |
esriMensurationPoint3D | esriMensurationDistanceAndAngle3D |
esriMensurationAreaAndPerimeter3D | esriMensurationCentroid3D
pixelSize - The pixel level (resolution) being measured. If pixel size
is not specified, pixelSize will default to the base resolution of the
image service. The raster at the specified pixel size in the mosaic
dataset will be used for measurement.
The structure of the pixelSize parameter is the same as the structure
of the point object returned by the ArcGIS REST API. In addition to the
JSON structure, you can specify the pixel size with a simple
comma-separated syntax.
mosaicRule - Specifies the mosaic rule when defining how individual
images should be mosaicked. When a mosaic rule is not specified, the
default mosaic rule of the image service will be used (as advertised
in the root resource: defaultMosaicMethod, mosaicOperator, sortField,
sortValue). The first visible image is used by measure.
linearUnit - The linear unit in which height, length, or perimeters
will be calculated. It can be any of the following esriUnits constant.
If the unit is not specified, the default is esriMeters. The list of
valid esriUnits constants include:
esriInches | esriFeet | esriYards | esriMiles | esriNauticalMiles |
esriMillimeters | esriCentimeters | esriDecimeters | esriMeters |
esriKilometers
angularUnit - The angular unit in which directions of line segments
will be calculated. It can be one of the following esriDirectionUnits
constants: esriDURadians | esriDUDecimalDegrees
If the unit is not specified, the default is esriDUDecimalDegrees.
areaUnit - The area unit in which areas of polygons will be calculated.
It can be any esriAreaUnits constant. If the unit is not specified, the
default is esriSquareMeters. The list of valid esriAreaUnits constants
include:
esriSquareInches | esriSquareFeet | esriSquareYards | esriAcres |
esriSquareMiles | esriSquareMillimeters | esriSquareCentimeters |
esriSquareDecimeters | esriSquareMeters | esriAres | esriHectares |
esriSquareKilometers
"""
url = self._url + "/measure"
params = {
"f" : "json",
"fromGeometry" : fromGeometry,
"toGeometry": toGeometry,
"geometryType": geometryType,
"measureOperation": measureOperation
}
if not pixelSize is None:
params["pixelSize"] = pixelSize
if not mosaicRule is None:
params["mosaicRule"] = mosaicRule
if not linearUnit is None:
params["linearUnit"] = linearUnit
if not angularUnit is None:
params["angularUnit"] = angularUnit
if not areaUnit is None:
params["areaUnit"] = areaUnit
return self._get(url=url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:computeStatisticsHistograms; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 4, identifier:self; 5, identifier:geometry; 6, identifier:geometryType; 7, default_parameter; 7, 8; 7, 9; 8, identifier:mosaicRule; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:renderingRule; 12, None; 13, default_parameter; 13, 14; 13, 15; 14, identifier:pixelSize; 15, None; 16, block; 16, 17; 16, 19; 16, 27; 16, 40; 16, 52; 16, 64; 16, 76; 17, expression_statement; 17, 18; 18, comment; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:url; 22, binary_operator:+; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:_url; 26, string:"/computeStatisticsHistograms"; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:params; 30, dictionary; 30, 31; 30, 34; 30, 37; 31, pair; 31, 32; 31, 33; 32, string:"f"; 33, string:"json"; 34, pair; 34, 35; 34, 36; 35, string:"geometry"; 36, identifier:geometry; 37, pair; 37, 38; 37, 39; 38, string:"geometryType"; 39, identifier:geometryType; 40, if_statement; 40, 41; 40, 45; 41, not_operator; 41, 42; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:mosaicRule; 44, None; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:params; 50, string:"mosaicRule"; 51, identifier:mosaicRule; 52, if_statement; 52, 53; 52, 57; 53, not_operator; 53, 54; 54, comparison_operator:is; 54, 55; 54, 56; 55, identifier:renderingRule; 56, None; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 63; 60, subscript; 60, 61; 60, 62; 61, identifier:params; 62, string:"renderingRule"; 63, identifier:renderingRule; 64, if_statement; 64, 65; 64, 69; 65, not_operator; 65, 66; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:pixelSize; 68, None; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, subscript; 72, 73; 72, 74; 73, identifier:params; 74, string:"pixelSize"; 75, identifier:pixelSize; 76, return_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:_get; 81, argument_list; 81, 82; 81, 85; 81, 88; 81, 93; 81, 98; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:url; 84, identifier:url; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:param_dict; 87, identifier:params; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:securityHandler; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:_securityHandler; 93, keyword_argument; 93, 94; 93, 95; 94, identifier:proxy_url; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:_proxy_url; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:proxy_port; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:_proxy_port | def computeStatisticsHistograms(self,geometry,geometryType,mosaicRule=None,
renderingRule=None,pixelSize=None):
"""
The computeStatisticsHistograms operation is performed on an image service
resource. This operation is supported by any image service published with
mosaic datasets or a raster dataset. The result of this operation contains
both statistics and histograms computed from the given extent.
Inputs:
geometry - A geometry that defines the geometry within which the histogram
is computed. The geometry can be an envelope or a polygon. The structure of
the geometry is the same as the structure of the JSON geometry objects
returned by the ArcGIS REST API.
geometryType - The type of geometry specified by the geometry parameter.
The geometry type can be an envelope or polygon.
Values: esriGeometryEnvelope | esriGeometryPolygon
mosaicRule - Specifies the mosaic rule when defining how individual
images should be mosaicked. When a mosaic rule is not specified, the
default mosaic rule of the image service will be used (as advertised
in the root resource: defaultMosaicMethod, mosaicOperator, sortField,
sortValue).
renderingRule - Specifies the rendering rule for how the requested
image should be rendered.
pixelSize - The pixel level being used (or the resolution being looked at).
If pixel size is not specified, then pixelSize will default to the base
resolution of the dataset. The raster at the specified pixel size in the
mosaic dataset will be used for histogram calculation.
The structure of the pixelSize parameter is the same as the structure of
the point object returned by the ArcGIS REST API. In addition to the JSON
structure, you can specify the pixel size with a simple comma-separated syntax.
"""
url = self._url + "/computeStatisticsHistograms"
params = {
"f" : "json",
"geometry" : geometry,
"geometryType": geometryType
}
if not mosaicRule is None:
params["mosaicRule"] = mosaicRule
if not renderingRule is None:
params["renderingRule"] = renderingRule
if not pixelSize is None:
params["pixelSize"] = pixelSize
return self._get(url=url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:users; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:start; 7, integer:1; 8, default_parameter; 8, 9; 8, 10; 9, identifier:num; 10, integer:10; 11, default_parameter; 11, 12; 11, 13; 12, identifier:sortField; 13, string:"fullName"; 14, default_parameter; 14, 15; 14, 16; 15, identifier:sortOrder; 16, string:"asc"; 17, default_parameter; 17, 18; 17, 19; 18, identifier:role; 19, None; 20, block; 20, 21; 20, 23; 20, 27; 20, 35; 20, 48; 20, 60; 20, 72; 20, 84; 20, 91; 20, 120; 20, 249; 20, 255; 21, expression_statement; 21, 22; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:users; 26, list:[]; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:url; 30, binary_operator:+; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_url; 34, string:"/users"; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:params; 38, dictionary; 38, 39; 38, 42; 38, 45; 39, pair; 39, 40; 39, 41; 40, string:"f"; 41, string:"json"; 42, pair; 42, 43; 42, 44; 43, string:"start"; 44, identifier:start; 45, pair; 45, 46; 45, 47; 46, string:"num"; 47, identifier:num; 48, if_statement; 48, 49; 48, 53; 49, not_operator; 49, 50; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:role; 52, None; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:params; 58, string:'role'; 59, identifier:role; 60, if_statement; 60, 61; 60, 65; 61, not_operator; 61, 62; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:sortField; 64, None; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:params; 70, string:'sortField'; 71, identifier:sortField; 72, if_statement; 72, 73; 72, 77; 73, not_operator; 73, 74; 74, comparison_operator:is; 74, 75; 74, 76; 75, identifier:sortOrder; 76, None; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:params; 82, string:'sortOrder'; 83, identifier:sortOrder; 84, import_from_statement; 84, 85; 84, 89; 85, relative_import; 85, 86; 85, 87; 86, import_prefix; 87, dotted_name; 87, 88; 88, identifier:_community; 89, dotted_name; 89, 90; 90, identifier:Community; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:res; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:_post; 98, argument_list; 98, 99; 98, 102; 98, 105; 98, 110; 98, 115; 99, keyword_argument; 99, 100; 99, 101; 100, identifier:url; 101, identifier:url; 102, keyword_argument; 102, 103; 102, 104; 103, identifier:param_dict; 104, identifier:params; 105, keyword_argument; 105, 106; 105, 107; 106, identifier:securityHandler; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:_securityHandler; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:proxy_url; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:_proxy_url; 115, keyword_argument; 115, 116; 115, 117; 116, identifier:proxy_port; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:_proxy_port; 120, if_statement; 120, 121; 120, 124; 121, comparison_operator:in; 121, 122; 121, 123; 122, string:"users"; 123, identifier:res; 124, block; 124, 125; 125, if_statement; 125, 126; 125, 134; 126, comparison_operator:>; 126, 127; 126, 133; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, subscript; 130, 131; 130, 132; 131, identifier:res; 132, string:'users'; 133, integer:0; 134, block; 134, 135; 134, 146; 134, 203; 134, 227; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:parsed; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:urlparse; 141, identifier:urlparse; 142, argument_list; 142, 143; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:_url; 146, if_statement; 146, 147; 146, 162; 146, 189; 147, comparison_operator:==; 147, 148; 147, 160; 148, call; 148, 149; 148, 158; 149, attribute; 149, 150; 149, 157; 150, call; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:parsed; 154, identifier:netloc; 155, identifier:lower; 156, argument_list; 157, identifier:find; 158, argument_list; 158, 159; 159, string:'arcgis.com'; 160, unary_operator:-; 160, 161; 161, integer:1; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:cURL; 166, binary_operator:%; 166, 167; 166, 168; 167, string:"%s://%s/%s/sharing/rest/community"; 168, tuple; 168, 169; 168, 172; 168, 175; 169, attribute; 169, 170; 169, 171; 170, identifier:parsed; 171, identifier:scheme; 172, attribute; 172, 173; 172, 174; 173, identifier:parsed; 174, identifier:netloc; 175, subscript; 175, 176; 175, 188; 176, call; 176, 177; 176, 186; 177, attribute; 177, 178; 177, 185; 178, subscript; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:parsed; 181, identifier:path; 182, slice; 182, 183; 182, 184; 183, integer:1; 184, colon; 185, identifier:split; 186, argument_list; 186, 187; 187, string:'/'; 188, integer:0; 189, else_clause; 189, 190; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:cURL; 194, binary_operator:%; 194, 195; 194, 196; 195, string:"%s://%s/sharing/rest/community"; 196, tuple; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:parsed; 199, identifier:scheme; 200, attribute; 200, 201; 200, 202; 201, identifier:parsed; 202, identifier:netloc; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:com; 206, call; 206, 207; 206, 208; 207, identifier:Community; 208, argument_list; 208, 209; 208, 212; 208, 217; 208, 222; 209, keyword_argument; 209, 210; 209, 211; 210, identifier:url; 211, identifier:cURL; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:securityHandler; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:_securityHandler; 217, keyword_argument; 217, 218; 217, 219; 218, identifier:proxy_url; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:_proxy_url; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:proxy_port; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:_proxy_port; 227, for_statement; 227, 228; 227, 229; 227, 232; 228, identifier:r; 229, subscript; 229, 230; 229, 231; 230, identifier:res; 231, string:'users'; 232, block; 232, 233; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:users; 237, identifier:append; 238, argument_list; 238, 239; 239, call; 239, 240; 239, 245; 240, attribute; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:com; 243, identifier:users; 244, identifier:user; 245, argument_list; 245, 246; 246, subscript; 246, 247; 246, 248; 247, identifier:r; 248, string:"username"; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 254; 251, subscript; 251, 252; 251, 253; 252, identifier:res; 253, string:'users'; 254, identifier:users; 255, return_statement; 255, 256; 256, identifier:res | def users(self,
start=1,
num=10,
sortField="fullName",
sortOrder="asc",
role=None):
"""
Lists all the members of the organization. The start and num paging
parameters are supported.
Inputs:
start - The number of the first entry in the result set response.
The index number is 1-based.
The default value of start is 1 (that is, the first
search result).
The start parameter, along with the num parameter, can
be used to paginate the search results.
num - The maximum number of results to be included in the result
set response.
The default value is 10, and the maximum allowed value is
100.The start parameter, along with the num parameter, can
be used to paginate the search results.
sortField - field to sort on
sortOrder - asc or desc on the sortField
role - name of the role or role id to search
Output:
list of User classes
"""
users = []
url = self._url + "/users"
params = {
"f" : "json",
"start" : start,
"num" : num
}
if not role is None:
params['role'] = role
if not sortField is None:
params['sortField'] = sortField
if not sortOrder is None:
params['sortOrder'] = sortOrder
from ._community import Community
res = self._post(url=url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port)
if "users" in res:
if len(res['users']) > 0:
parsed = urlparse.urlparse(self._url)
if parsed.netloc.lower().find('arcgis.com') == -1:
cURL = "%s://%s/%s/sharing/rest/community" % (parsed.scheme,
parsed.netloc,
parsed.path[1:].split('/')[0])
else:
cURL = "%s://%s/sharing/rest/community" % (parsed.scheme,
parsed.netloc)
com = Community(url=cURL,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port)
for r in res['users']:
users.append(
com.users.user(r["username"])
)
res['users'] = users
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 36; 2, function_name:find; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 4, identifier:self; 5, identifier:text; 6, default_parameter; 6, 7; 6, 8; 7, identifier:magicKey; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sourceCountry; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:bbox; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:location; 17, None; 18, default_parameter; 18, 19; 18, 20; 19, identifier:distance; 20, float:3218.69; 21, default_parameter; 21, 22; 21, 23; 22, identifier:outSR; 23, integer:102100; 24, default_parameter; 24, 25; 24, 26; 25, identifier:category; 26, None; 27, default_parameter; 27, 28; 27, 29; 28, identifier:outFields; 29, string:"*"; 30, default_parameter; 30, 31; 30, 32; 31, identifier:maxLocations; 32, integer:20; 33, default_parameter; 33, 34; 33, 35; 34, identifier:forStorage; 35, False; 36, block; 36, 37; 36, 39; 37, expression_statement; 37, 38; 38, comment; 39, if_statement; 39, 40; 39, 49; 39, 253; 40, call; 40, 41; 40, 42; 41, identifier:isinstance; 42, argument_list; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:_securityHandler; 46, tuple; 46, 47; 46, 48; 47, identifier:AGOLTokenSecurityHandler; 48, identifier:OAuthSecurityHandler; 49, block; 49, 50; 49, 58; 49, 69; 49, 81; 49, 93; 49, 105; 49, 159; 49, 171; 49, 183; 49, 202; 49, 214; 49, 226; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:url; 53, binary_operator:+; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_url; 57, string:"/find"; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:params; 61, dictionary; 61, 62; 61, 65; 61, 68; 62, pair; 62, 63; 62, 64; 63, string:"f"; 64, string:"json"; 65, pair; 65, 66; 65, 67; 66, string:"text"; 67, identifier:text; 68, comment; 69, if_statement; 69, 70; 69, 74; 70, not_operator; 70, 71; 71, comparison_operator:is; 71, 72; 71, 73; 72, identifier:magicKey; 73, None; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:params; 79, string:'magicKey'; 80, identifier:magicKey; 81, if_statement; 81, 82; 81, 86; 82, not_operator; 82, 83; 83, comparison_operator:is; 83, 84; 83, 85; 84, identifier:sourceCountry; 85, None; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:params; 91, string:'sourceCountry'; 92, identifier:sourceCountry; 93, if_statement; 93, 94; 93, 98; 94, not_operator; 94, 95; 95, comparison_operator:is; 95, 96; 95, 97; 96, identifier:bbox; 97, None; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:params; 103, string:'bbox'; 104, identifier:bbox; 105, if_statement; 105, 106; 105, 110; 106, not_operator; 106, 107; 107, comparison_operator:is; 107, 108; 107, 109; 108, identifier:location; 109, None; 110, block; 110, 111; 110, 126; 110, 147; 111, if_statement; 111, 112; 111, 117; 112, call; 112, 113; 112, 114; 113, identifier:isinstance; 114, argument_list; 114, 115; 114, 116; 115, identifier:location; 116, identifier:Point; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 123; 120, subscript; 120, 121; 120, 122; 121, identifier:params; 122, string:'location'; 123, attribute; 123, 124; 123, 125; 124, identifier:location; 125, identifier:asDictionary; 126, if_statement; 126, 127; 126, 132; 127, call; 127, 128; 127, 129; 128, identifier:isinstance; 129, argument_list; 129, 130; 129, 131; 130, identifier:location; 131, identifier:list; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:params; 137, string:'location'; 138, binary_operator:%; 138, 139; 138, 140; 139, string:"%s,%s"; 140, tuple; 140, 141; 140, 144; 141, subscript; 141, 142; 141, 143; 142, identifier:location; 143, integer:0; 144, subscript; 144, 145; 144, 146; 145, identifier:location; 146, integer:1; 147, if_statement; 147, 148; 147, 152; 148, not_operator; 148, 149; 149, comparison_operator:is; 149, 150; 149, 151; 150, identifier:distance; 151, None; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:params; 157, string:'distance'; 158, identifier:distance; 159, if_statement; 159, 160; 159, 164; 160, not_operator; 160, 161; 161, comparison_operator:is; 161, 162; 161, 163; 162, identifier:outSR; 163, None; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:params; 169, string:'outSR'; 170, identifier:outSR; 171, if_statement; 171, 172; 171, 176; 172, not_operator; 172, 173; 173, comparison_operator:is; 173, 174; 173, 175; 174, identifier:category; 175, None; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 182; 179, subscript; 179, 180; 179, 181; 180, identifier:params; 181, string:'category'; 182, identifier:category; 183, if_statement; 183, 184; 183, 187; 183, 194; 184, comparison_operator:is; 184, 185; 184, 186; 185, identifier:outFields; 186, None; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, subscript; 190, 191; 190, 192; 191, identifier:params; 192, string:'outFields'; 193, string:"*"; 194, else_clause; 194, 195; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 201; 198, subscript; 198, 199; 198, 200; 199, identifier:params; 200, string:'outFields'; 201, identifier:outFields; 202, if_statement; 202, 203; 202, 207; 203, not_operator; 203, 204; 204, comparison_operator:is; 204, 205; 204, 206; 205, identifier:maxLocations; 206, None; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 210, subscript; 210, 211; 210, 212; 211, identifier:params; 212, string:'maxLocations'; 213, identifier:maxLocations; 214, if_statement; 214, 215; 214, 219; 215, not_operator; 215, 216; 216, comparison_operator:is; 216, 217; 216, 218; 217, identifier:forStorage; 218, None; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:params; 224, string:'forStorage'; 225, identifier:forStorage; 226, return_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:_post; 231, argument_list; 231, 232; 231, 235; 231, 238; 231, 243; 231, 248; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:url; 234, identifier:url; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:param_dict; 237, identifier:params; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:securityHandler; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:_securityHandler; 243, keyword_argument; 243, 244; 243, 245; 244, identifier:proxy_url; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:_proxy_url; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:proxy_port; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:_proxy_port; 253, else_clause; 253, 254; 254, block; 254, 255; 255, raise_statement; 255, 256; 256, call; 256, 257; 256, 258; 257, identifier:Exception; 258, argument_list; 258, 259; 259, string:"This function works on the ArcGIS Online World Geocoder" | def find(self,
text,
magicKey=None,
sourceCountry=None,
bbox=None,
location=None,
distance=3218.69,
outSR=102100,
category=None,
outFields="*",
maxLocations=20,
forStorage=False):
"""
The find operation geocodes one location per request; the input
address is specified in a single parameter.
Inputs:
text - Specifies the location to be geocoded. This can be a
street address, place name, postal code, or POI.
magicKey - The find operation retrieves results quicker when you
pass in valid text and magicKey values than when you don't pass
in magicKey. However, to get these advantages, you need to make
a prior request to suggest, which provides a magicKey. This may
or may not be relevant to your workflow.
sourceCountry - A value representing the country. Providing this
value increases geocoding speed. Acceptable values include the
full country name in English or the official language of the
country, the ISO 3166-1 2-digit country code, or the
ISO 3166-1 3-digit country code.
bbox - A set of bounding box coordinates that limit the search
area to a specific region. This is especially useful for
applications in which a user will search for places and
addresses only within the current map extent.
location - Defines an origin point location that is used with
the distance parameter to sort geocoding candidates based upon
their proximity to the location. The distance parameter
specifies the radial distance from the location in meters. The
priority of candidates within this radius is boosted relative
to those outside the radius.
distance - Specifies the radius of an area around a point
location which is used to boost the rank of geocoding
candidates so that candidates closest to the location are
returned first. The distance value is in meters.
outSR - The spatial reference of the x/y coordinates returned by
a geocode request. This is useful for applications using a map
with a spatial reference different than that of the geocode
service.
category - A place or address type which can be used to filter
find results. The parameter supports input of single category
values or multiple comma-separated values. The category
parameter can be passed in a request with or without the text
parameter.
outFields - The list of fields to be returned in the response.
maxLocation - The maximum number of locations to be returned by
a search, up to the maximum number allowed by the service. If
not specified, then one location will be returned.
forStorage - Specifies whether the results of the operation will
be persisted. The default value is false, which indicates the
results of the operation can't be stored, but they can be
temporarily displayed on a map for instance. If you store the
results, in a database for example, you need to set this
parameter to true.
"""
if isinstance(self._securityHandler, (AGOLTokenSecurityHandler, OAuthSecurityHandler)):
url = self._url + "/find"
params = {
"f" : "json",
"text" : text,
#"token" : self._securityHandler.token
}
if not magicKey is None:
params['magicKey'] = magicKey
if not sourceCountry is None:
params['sourceCountry'] = sourceCountry
if not bbox is None:
params['bbox'] = bbox
if not location is None:
if isinstance(location, Point):
params['location'] = location.asDictionary
if isinstance(location, list):
params['location'] = "%s,%s" % (location[0], location[1])
if not distance is None:
params['distance'] = distance
if not outSR is None:
params['outSR'] = outSR
if not category is None:
params['category'] = category
if outFields is None:
params['outFields'] = "*"
else:
params['outFields'] = outFields
if not maxLocations is None:
params['maxLocations'] = maxLocations
if not forStorage is None:
params['forStorage'] = forStorage
return self._post(url=url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port)
else:
raise Exception("This function works on the ArcGIS Online World Geocoder") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:self; 5, identifier:q; 6, default_parameter; 6, 7; 6, 8; 7, identifier:t; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:focus; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:bbox; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:start; 17, integer:1; 18, default_parameter; 18, 19; 18, 20; 19, identifier:num; 20, integer:10; 21, default_parameter; 21, 22; 21, 23; 22, identifier:sortField; 23, None; 24, default_parameter; 24, 25; 24, 26; 25, identifier:sortOrder; 26, string:"asc"; 27, default_parameter; 27, 28; 27, 29; 28, identifier:useSecurity; 29, True; 30, block; 30, 31; 30, 33; 30, 61; 30, 83; 30, 95; 30, 107; 30, 136; 30, 147; 30, 158; 31, expression_statement; 31, 32; 32, comment; 33, if_statement; 33, 34; 33, 42; 33, 51; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_url; 39, identifier:endswith; 40, argument_list; 40, 41; 41, string:"/rest"; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:url; 46, binary_operator:+; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_url; 50, string:"/search"; 51, else_clause; 51, 52; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:url; 56, binary_operator:+; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_url; 60, string:"/rest/search"; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:params; 64, dictionary; 64, 65; 64, 68; 64, 71; 64, 74; 64, 77; 64, 80; 65, pair; 65, 66; 65, 67; 66, string:"f"; 67, string:"json"; 68, pair; 68, 69; 68, 70; 69, string:"q"; 70, identifier:q; 71, pair; 71, 72; 71, 73; 72, string:"sortOrder"; 73, identifier:sortOrder; 74, pair; 74, 75; 74, 76; 75, string:"num"; 76, identifier:num; 77, pair; 77, 78; 77, 79; 78, string:"start"; 79, identifier:start; 80, pair; 80, 81; 80, 82; 81, string:'restrict'; 82, identifier:useSecurity; 83, if_statement; 83, 84; 83, 88; 84, not_operator; 84, 85; 85, comparison_operator:is; 85, 86; 85, 87; 86, identifier:focus; 87, None; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:params; 93, string:'focus'; 94, identifier:focus; 95, if_statement; 95, 96; 95, 100; 96, not_operator; 96, 97; 97, comparison_operator:is; 97, 98; 97, 99; 98, identifier:t; 99, None; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:params; 105, string:'t'; 106, identifier:t; 107, if_statement; 107, 108; 107, 125; 108, boolean_operator:and; 108, 109; 108, 117; 108, 118; 109, boolean_operator:and; 109, 110; 109, 111; 109, 112; 110, identifier:useSecurity; 111, line_continuation:\; 112, comparison_operator:is; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:_securityHandler; 116, None; 117, line_continuation:\; 118, comparison_operator:==; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:_securityHandler; 123, identifier:method; 124, string:"token"; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:params; 130, string:"token"; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:_securityHandler; 135, identifier:token; 136, if_statement; 136, 137; 136, 140; 137, comparison_operator:is; 137, 138; 137, 139; 138, identifier:sortField; 139, None; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, subscript; 143, 144; 143, 145; 144, identifier:params; 145, string:'sortField'; 146, identifier:sortField; 147, if_statement; 147, 148; 147, 151; 148, comparison_operator:is; 148, 149; 148, 150; 149, identifier:bbox; 150, None; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:params; 156, string:'bbox'; 157, identifier:bbox; 158, return_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:_get; 163, argument_list; 163, 164; 163, 167; 163, 170; 163, 175; 163, 180; 164, keyword_argument; 164, 165; 164, 166; 165, identifier:url; 166, identifier:url; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:param_dict; 169, identifier:params; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:securityHandler; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:_securityHandler; 175, keyword_argument; 175, 176; 175, 177; 176, identifier:proxy_url; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:_proxy_url; 180, keyword_argument; 180, 181; 180, 182; 181, identifier:proxy_port; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:_proxy_port | def search(self,
q,
t=None,
focus=None,
bbox=None,
start=1,
num=10,
sortField=None,
sortOrder="asc",
useSecurity=True):
"""
This operation searches for content items in the portal. The
searches are performed against a high performance index that
indexes the most popular fields of an item. See the Search
reference page for information on the fields and the syntax of the
query.
The search index is updated whenever users add, update, or delete
content. There can be a lag between the time that the content is
updated and the time when it's reflected in the search results.
The results of a search only contain items that the user has
permission to access.
Inputs:
q - The query string used to search
t - type of content to search for.
focus - another content filter. Ex: files
bbox - The bounding box for a spatial search defined as minx,
miny, maxx, or maxy. Search requires q, bbox, or both.
Spatial search is an overlaps/intersects function of the
query bbox and the extent of the document.
Documents that have no extent (e.g., mxds, 3dds, lyr)
will not be found when doing a bbox search.
Document extent is assumed to be in the WGS84 geographic
coordinate system.
start - The number of the first entry in the result set
response. The index number is 1-based.
The default value of start is 1 (that is, the first
search result).
The start parameter, along with the num parameter, can
be used to paginate the search results.
num - The maximum number of results to be included in the result
set response.
The default value is 10, and the maximum allowed value is
100.
The start parameter, along with the num parameter, can be
used to paginate the search results.
sortField - Field to sort by. You can also sort by multiple
fields (comma separated) for an item.
The allowed sort field names are title, created,
type, owner, modified, avgRating, numRatings,
numComments, and numViews.
sortOrder - Describes whether the results return in ascending or
descending order. Default is ascending.
Values: asc | desc
useSecurity - boolean value that determines if the security
handler object's token will be appended on the
search call. If the value is set to False, then
the search will be performed without
authentication. This means only items that have
been shared with everyone on AGOL or portal site
will be found. If it is set to True, then all
items the user has permission to see based on the
query passed will be returned.
Output:
returns a list of dictionary
"""
if self._url.endswith("/rest"):
url = self._url + "/search"
else:
url = self._url + "/rest/search"
params = {
"f" : "json",
"q" : q,
"sortOrder" : sortOrder,
"num" : num,
"start" : start,
'restrict' : useSecurity
}
if not focus is None:
params['focus'] = focus
if not t is None:
params['t'] = t
if useSecurity and \
self._securityHandler is not None and \
self._securityHandler.method == "token":
params["token"] = self._securityHandler.token
if sortField is not None:
params['sortField'] = sortField
if bbox is not None:
params['bbox'] = bbox
return self._get(url=url,
param_dict=params,
securityHandler=self._securityHandler,
proxy_url=self._proxy_url,
proxy_port=self._proxy_port) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_models; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 32; 5, 40; 5, 47; 5, 51; 5, 55; 5, 141; 5, 150; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:model_names; 11, list_comprehension; 11, 12; 11, 15; 11, 24; 12, attribute; 12, 13; 12, 14; 13, identifier:table; 14, identifier:name; 15, for_in_clause; 15, 16; 15, 17; 16, identifier:table; 17, attribute; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:Base; 22, identifier:metadata; 23, identifier:sorted_tables; 24, if_clause; 24, 25; 25, comparison_operator:in; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:table; 28, identifier:name; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:models; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:logger; 36, identifier:debug; 37, argument_list; 37, 38; 37, 39; 38, string:"Unsorted models: %s"; 39, identifier:model_names; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:model_count; 43, call; 43, 44; 43, 45; 44, identifier:len; 45, argument_list; 45, 46; 46, identifier:model_names; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:swapped; 50, True; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:sort_round; 54, integer:0; 55, while_statement; 55, 56; 55, 57; 56, identifier:swapped; 57, block; 57, 58; 57, 62; 57, 71; 57, 75; 57, 127; 57, 128; 57, 137; 58, expression_statement; 58, 59; 59, augmented_assignment:+=; 59, 60; 59, 61; 60, identifier:sort_round; 61, integer:1; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:logger; 66, identifier:debug; 67, argument_list; 67, 68; 67, 69; 67, 70; 68, string:'Sorting round: %d (%s)'; 69, identifier:sort_round; 70, identifier:model_names; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:sorted_models; 74, list:[]; 75, for_statement; 75, 76; 75, 77; 75, 81; 76, identifier:i; 77, call; 77, 78; 77, 79; 78, identifier:range; 79, argument_list; 79, 80; 80, identifier:model_count; 81, block; 81, 82; 81, 92; 81, 93; 81, 111; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:model; 85, subscript; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:models; 89, subscript; 89, 90; 89, 91; 90, identifier:model_names; 91, identifier:i; 92, comment; 93, for_statement; 93, 94; 93, 95; 93, 98; 94, identifier:foreign_model_name; 95, attribute; 95, 96; 95, 97; 96, identifier:model; 97, identifier:foreign_models; 98, block; 98, 99; 99, if_statement; 99, 100; 99, 103; 100, comparison_operator:not; 100, 101; 100, 102; 101, identifier:foreign_model_name; 102, identifier:sorted_models; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:sorted_models; 108, identifier:append; 109, argument_list; 109, 110; 110, identifier:foreign_model_name; 111, if_statement; 111, 112; 111, 117; 112, comparison_operator:not; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:model; 115, identifier:name; 116, identifier:sorted_models; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:sorted_models; 122, identifier:append; 123, argument_list; 123, 124; 124, attribute; 124, 125; 124, 126; 125, identifier:model; 126, identifier:name; 127, comment; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:==; 129, 130; 129, 131; 130, identifier:model_names; 131, identifier:sorted_models; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:swapped; 136, False; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:model_names; 140, identifier:sorted_models; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:logger; 145, identifier:debug; 146, argument_list; 146, 147; 146, 148; 146, 149; 147, string:"Sorted models: %s (%d rounds)"; 148, identifier:model_names; 149, identifier:sort_round; 150, return_statement; 150, 151; 151, identifier:model_names | def sort_models(self):
"""Sorts the database models appropriately based on their relationships so that we load our data
in the appropriate order.
Returns:
A sorted list containing the names of the models.
"""
model_names = [
table.name for table in self.Base.metadata.sorted_tables if table.name in self.models
]
logger.debug("Unsorted models: %s", model_names)
model_count = len(model_names)
swapped = True
sort_round = 0
while swapped:
sort_round += 1
logger.debug('Sorting round: %d (%s)', sort_round, model_names)
sorted_models = []
for i in range(model_count):
model = self.models[model_names[i]]
# check if this model has any dependencies which haven't been taken care of in this round
for foreign_model_name in model.foreign_models:
if foreign_model_name not in sorted_models:
sorted_models.append(foreign_model_name)
if model.name not in sorted_models:
sorted_models.append(model.name)
# we're done here (no changes after this sorting round)
if model_names == sorted_models:
swapped = False
model_names = sorted_models
logger.debug("Sorted models: %s (%d rounds)", model_names, sort_round)
return model_names |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:keyed_helper; 3, parameters; 3, 4; 4, identifier:helper; 5, block; 5, 6; 5, 8; 5, 139; 5, 145; 6, expression_statement; 6, 7; 7, comment; 8, decorated_definition; 8, 9; 8, 14; 9, decorator; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:wraps; 12, argument_list; 12, 13; 13, identifier:helper; 14, function_definition; 14, 15; 14, 16; 14, 30; 15, function_name:wrapper; 16, parameters; 16, 17; 16, 20; 16, 23; 16, 26; 16, 28; 17, default_parameter; 17, 18; 17, 19; 18, identifier:instance; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:key; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:attr; 25, None; 26, list_splat_pattern; 26, 27; 27, identifier:args; 28, dictionary_splat_pattern; 28, 29; 29, identifier:kwargs; 30, block; 30, 31; 30, 55; 30, 69; 30, 82; 30, 108; 30, 109; 30, 110; 30, 137; 31, if_statement; 31, 32; 31, 42; 31, 43; 32, comparison_operator:==; 32, 33; 32, 40; 33, call; 33, 34; 33, 35; 34, identifier:set; 35, argument_list; 35, 36; 36, tuple; 36, 37; 36, 38; 36, 39; 37, identifier:instance; 38, identifier:key; 39, identifier:attr; 40, set; 40, 41; 41, None; 42, comment; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:ValueError; 47, argument_list; 47, 48; 48, binary_operator:%; 48, 49; 48, 52; 49, concatenated_string; 49, 50; 49, 51; 50, string:"If called directly, helper function '%s' requires either a model"; 51, string:" instance, or a 'key' or 'attr' keyword argument."; 52, attribute; 52, 53; 52, 54; 53, identifier:helper; 54, identifier:__name__; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:instance; 58, None; 59, block; 59, 60; 60, return_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:helper; 63, argument_list; 63, 64; 63, 65; 63, 67; 64, identifier:instance; 65, list_splat; 65, 66; 66, identifier:args; 67, dictionary_splat; 67, 68; 68, identifier:kwargs; 69, if_statement; 69, 70; 69, 77; 70, boolean_operator:and; 70, 71; 70, 74; 71, comparison_operator:is; 71, 72; 71, 73; 72, identifier:key; 73, None; 74, comparison_operator:is; 74, 75; 74, 76; 75, identifier:attr; 76, None; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:attr; 81, string:'self'; 82, if_statement; 82, 83; 82, 84; 83, identifier:attr; 84, block; 84, 85; 85, if_statement; 85, 86; 85, 89; 85, 97; 86, comparison_operator:==; 86, 87; 86, 88; 87, identifier:attr; 88, string:'self'; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:key; 93, lambda; 93, 94; 93, 96; 94, lambda_parameters; 94, 95; 95, identifier:obj; 96, identifier:obj; 97, else_clause; 97, 98; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:key; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:operator; 105, identifier:attrgetter; 106, argument_list; 106, 107; 107, identifier:attr; 108, comment; 109, comment; 110, decorated_definition; 110, 111; 110, 116; 111, decorator; 111, 112; 112, call; 112, 113; 112, 114; 113, identifier:wraps; 114, argument_list; 114, 115; 115, identifier:helper; 116, function_definition; 116, 117; 116, 118; 116, 124; 117, function_name:helper_wrapper; 118, parameters; 118, 119; 118, 120; 118, 122; 119, identifier:instance; 120, list_splat_pattern; 120, 121; 121, identifier:args; 122, dictionary_splat_pattern; 122, 123; 123, identifier:kwargs; 124, block; 124, 125; 125, return_statement; 125, 126; 126, call; 126, 127; 126, 128; 127, identifier:helper; 128, argument_list; 128, 129; 128, 133; 128, 135; 129, call; 129, 130; 129, 131; 130, identifier:key; 131, argument_list; 131, 132; 132, identifier:instance; 133, list_splat; 133, 134; 134, identifier:args; 135, dictionary_splat; 135, 136; 136, identifier:kwargs; 137, return_statement; 137, 138; 138, identifier:helper_wrapper; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:wrapper; 143, identifier:_is_wrapped; 144, True; 145, return_statement; 145, 146; 146, identifier:wrapper | def keyed_helper(helper):
"""
Decorator for helper functions that operate on direct values instead of model instances.
A keyed helper is one that can be used normally in the view's own custom callbacks, but also
supports direct access in the column declaration, such as in the example:
datatable_options = {
'columns': [
('Field Name', 'fieldname', make_boolean_checkmark(key=attrgetter('fieldname'))),
],
}
With the help of a ``sort``-style ``key`` argument, the helper can receive all the information
it requires in advance, so that the view doesn't have to go through the trouble of declaring
a custom callback method that simply returns the value of the ``make_boolean_checkmark()``
helper.
If the attribute being fetched is identical to the one pointed to in the column declaration,
even the ``key`` argument can be omitted:
('Field Name', 'fieldname', make_boolean_checkmark)),
"""
@wraps(helper)
def wrapper(instance=None, key=None, attr=None, *args, **kwargs):
if set((instance, key, attr)) == {None}:
# helper was called in place with neither important arg
raise ValueError("If called directly, helper function '%s' requires either a model"
" instance, or a 'key' or 'attr' keyword argument." % helper.__name__)
if instance is not None:
return helper(instance, *args, **kwargs)
if key is None and attr is None:
attr = 'self'
if attr:
if attr == 'self':
key = lambda obj: obj
else:
key = operator.attrgetter(attr)
# Helper is used directly in the columns declaration. A new callable is
# returned to take the place of a callback.
@wraps(helper)
def helper_wrapper(instance, *args, **kwargs):
return helper(key(instance), *args, **kwargs)
return helper_wrapper
wrapper._is_wrapped = True
return wrapper |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:find_bin; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:x; 6, block; 6, 7; 6, 9; 6, 22; 6, 37; 6, 71; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:x; 12, call; 12, 13; 12, 21; 13, attribute; 13, 14; 13, 20; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:np; 17, identifier:asarray; 18, argument_list; 18, 19; 19, identifier:x; 20, identifier:flatten; 21, argument_list; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:right; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:np; 28, identifier:digitize; 29, argument_list; 29, 30; 29, 31; 29, 34; 30, identifier:x; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:bins; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:right; 36, True; 37, if_statement; 37, 38; 37, 50; 38, comparison_operator:==; 38, 39; 38, 44; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:right; 42, identifier:max; 43, argument_list; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:bins; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 63; 53, subscript; 53, 54; 53, 55; 54, identifier:right; 55, comparison_operator:==; 55, 56; 55, 57; 56, identifier:right; 57, call; 57, 58; 57, 59; 58, identifier:len; 59, argument_list; 59, 60; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:bins; 63, binary_operator:-; 63, 64; 63, 70; 64, call; 64, 65; 64, 66; 65, identifier:len; 66, argument_list; 66, 67; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:bins; 70, integer:1; 71, return_statement; 71, 72; 72, identifier:right | def find_bin(self, x):
"""
Sort input or inputs according to the current bin estimate
Parameters
----------
x : array or numeric
a value or array of values to fit within the estimated
bins
Returns
-------
a bin index or array of bin indices that classify the input into one of
the classifiers' bins.
Note that this differs from similar functionality in
numpy.digitize(x, classi.bins, right=True).
This will always provide the closest bin, so data "outside" the classifier,
above and below the max/min breaks, will be classified into the nearest bin.
numpy.digitize returns k+1 for data greater than the greatest bin, but retains 0
for data below the lowest bin.
"""
x = np.asarray(x).flatten()
right = np.digitize(x, self.bins, right=True)
if right.max() == len(self.bins):
right[right == len(self.bins)] = len(self.bins) - 1
return right |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 24; 1, 30; 2, function_name:filter_by_size; 3, parameters; 3, 4; 3, 8; 3, 16; 3, 20; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:feat_dir; 6, type; 6, 7; 7, identifier:Path; 8, typed_parameter; 8, 9; 8, 10; 9, identifier:prefixes; 10, type; 10, 11; 11, generic_type; 11, 12; 11, 13; 12, identifier:List; 13, type_parameter; 13, 14; 14, type; 14, 15; 15, identifier:str; 16, typed_parameter; 16, 17; 16, 18; 17, identifier:feat_type; 18, type; 18, 19; 19, identifier:str; 20, typed_parameter; 20, 21; 20, 22; 21, identifier:max_samples; 22, type; 22, 23; 23, identifier:int; 24, type; 24, 25; 25, generic_type; 25, 26; 25, 27; 26, identifier:List; 27, type_parameter; 27, 28; 28, type; 28, 29; 29, identifier:str; 30, block; 30, 31; 30, 33; 30, 34; 30, 46; 30, 60; 31, expression_statement; 31, 32; 32, comment; 33, comment; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:prefix_lens; 37, call; 37, 38; 37, 39; 38, identifier:get_prefix_lens; 39, argument_list; 39, 40; 39, 44; 39, 45; 40, call; 40, 41; 40, 42; 41, identifier:Path; 42, argument_list; 42, 43; 43, identifier:feat_dir; 44, identifier:prefixes; 45, identifier:feat_type; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:prefixes; 49, list_comprehension; 49, 50; 49, 51; 49, 56; 50, identifier:prefix; 51, for_in_clause; 51, 52; 51, 55; 52, pattern_list; 52, 53; 52, 54; 53, identifier:prefix; 54, identifier:length; 55, identifier:prefix_lens; 56, if_clause; 56, 57; 57, comparison_operator:<=; 57, 58; 57, 59; 58, identifier:length; 59, identifier:max_samples; 60, return_statement; 60, 61; 61, identifier:prefixes | def filter_by_size(feat_dir: Path, prefixes: List[str], feat_type: str,
max_samples: int) -> List[str]:
""" Sorts the files by their length and returns those with less
than or equal to max_samples length. Returns the filename prefixes of
those files. The main job of the method is to filter, but the sorting
may give better efficiency when doing dynamic batching unless it gets
shuffled downstream.
"""
# TODO Tell the user what utterances we are removing.
prefix_lens = get_prefix_lens(Path(feat_dir), prefixes, feat_type)
prefixes = [prefix for prefix, length in prefix_lens
if length <= max_samples]
return prefixes |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 1, 34; 2, function_name:sort_annotations; 3, parameters; 3, 4; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:annotations; 6, type; 6, 7; 7, generic_type; 7, 8; 7, 9; 8, identifier:List; 9, type_parameter; 9, 10; 10, type; 10, 11; 11, generic_type; 11, 12; 11, 13; 12, identifier:Tuple; 13, type_parameter; 13, 14; 13, 16; 13, 18; 14, type; 14, 15; 15, identifier:int; 16, type; 16, 17; 17, identifier:int; 18, type; 18, 19; 19, identifier:str; 20, type; 20, 21; 21, generic_type; 21, 22; 21, 23; 22, identifier:List; 23, type_parameter; 23, 24; 24, type; 24, 25; 25, generic_type; 25, 26; 25, 27; 26, identifier:Tuple; 27, type_parameter; 27, 28; 27, 30; 27, 32; 28, type; 28, 29; 29, identifier:int; 30, type; 30, 31; 31, identifier:int; 32, type; 32, 33; 33, identifier:str; 34, block; 34, 35; 34, 37; 35, expression_statement; 35, 36; 36, comment; 37, return_statement; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:sorted; 40, argument_list; 40, 41; 40, 42; 41, identifier:annotations; 42, keyword_argument; 42, 43; 42, 44; 43, identifier:key; 44, lambda; 44, 45; 44, 47; 45, lambda_parameters; 45, 46; 46, identifier:x; 47, subscript; 47, 48; 47, 49; 48, identifier:x; 49, integer:0 | def sort_annotations(annotations: List[Tuple[int, int, str]]
) -> List[Tuple[int, int, str]]:
""" Sorts the annotations by their start_time. """
return sorted(annotations, key=lambda x: x[0]) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:default_sort_key; 3, parameters; 3, 4; 3, 5; 4, identifier:item; 5, default_parameter; 5, 6; 5, 7; 6, identifier:order; 7, None; 8, block; 8, 9; 8, 11; 8, 19; 8, 28; 8, 35; 8, 51; 8, 204; 9, expression_statement; 9, 10; 10, comment; 11, import_from_statement; 11, 12; 11, 15; 11, 17; 12, dotted_name; 12, 13; 12, 14; 13, identifier:sympy; 14, identifier:core; 15, dotted_name; 15, 16; 16, identifier:S; 17, dotted_name; 17, 18; 18, identifier:Basic; 19, import_from_statement; 19, 20; 19, 24; 19, 26; 20, dotted_name; 20, 21; 20, 22; 20, 23; 21, identifier:sympy; 22, identifier:core; 23, identifier:sympify; 24, dotted_name; 24, 25; 25, identifier:sympify; 26, dotted_name; 26, 27; 27, identifier:SympifyError; 28, import_from_statement; 28, 29; 28, 33; 29, dotted_name; 29, 30; 29, 31; 29, 32; 30, identifier:sympy; 31, identifier:core; 32, identifier:compatibility; 33, dotted_name; 33, 34; 34, identifier:iterable; 35, if_statement; 35, 36; 35, 41; 36, call; 36, 37; 36, 38; 37, identifier:isinstance; 38, argument_list; 38, 39; 38, 40; 39, identifier:item; 40, identifier:Basic; 41, block; 41, 42; 42, return_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:item; 46, identifier:sort_key; 47, argument_list; 47, 48; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:order; 50, identifier:order; 51, if_statement; 51, 52; 51, 59; 51, 149; 52, call; 52, 53; 52, 54; 53, identifier:iterable; 54, argument_list; 54, 55; 54, 56; 55, identifier:item; 56, keyword_argument; 56, 57; 56, 58; 57, identifier:exclude; 58, identifier:string_types; 59, block; 59, 60; 59, 108; 59, 122; 59, 133; 60, if_statement; 60, 61; 60, 66; 60, 79; 60, 94; 61, call; 61, 62; 61, 63; 62, identifier:isinstance; 63, argument_list; 63, 64; 63, 65; 64, identifier:item; 65, identifier:dict; 66, block; 66, 67; 66, 75; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:args; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:item; 73, identifier:items; 74, argument_list; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:unordered; 78, True; 79, elif_clause; 79, 80; 79, 85; 80, call; 80, 81; 80, 82; 81, identifier:isinstance; 82, argument_list; 82, 83; 82, 84; 83, identifier:item; 84, identifier:set; 85, block; 85, 86; 85, 90; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:args; 89, identifier:item; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:unordered; 93, True; 94, else_clause; 94, 95; 94, 96; 95, comment; 96, block; 96, 97; 96, 104; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:args; 100, call; 100, 101; 100, 102; 101, identifier:list; 102, argument_list; 102, 103; 103, identifier:item; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:unordered; 107, False; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:args; 111, list_comprehension; 111, 112; 111, 119; 112, call; 112, 113; 112, 114; 113, identifier:default_sort_key; 114, argument_list; 114, 115; 114, 116; 115, identifier:arg; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:order; 118, identifier:order; 119, for_in_clause; 119, 120; 119, 121; 120, identifier:arg; 121, identifier:args; 122, if_statement; 122, 123; 122, 124; 122, 125; 123, identifier:unordered; 124, comment; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:args; 129, call; 129, 130; 129, 131; 130, identifier:sorted; 131, argument_list; 131, 132; 132, identifier:args; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, pattern_list; 135, 136; 135, 137; 136, identifier:cls_index; 137, identifier:args; 138, expression_list; 138, 139; 138, 140; 139, integer:10; 140, tuple; 140, 141; 140, 145; 141, call; 141, 142; 141, 143; 142, identifier:len; 143, argument_list; 143, 144; 144, identifier:args; 145, call; 145, 146; 145, 147; 146, identifier:tuple; 147, argument_list; 147, 148; 148, identifier:args; 149, else_clause; 149, 150; 150, block; 150, 151; 150, 189; 150, 190; 151, if_statement; 151, 152; 151, 158; 152, not_operator; 152, 153; 153, call; 153, 154; 153, 155; 154, identifier:isinstance; 155, argument_list; 155, 156; 155, 157; 156, identifier:item; 157, identifier:string_types; 158, block; 158, 159; 159, try_statement; 159, 160; 159, 168; 159, 173; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:item; 164, call; 164, 165; 164, 166; 165, identifier:sympify; 166, argument_list; 166, 167; 167, identifier:item; 168, except_clause; 168, 169; 168, 170; 168, 171; 169, identifier:SympifyError; 170, comment; 171, block; 171, 172; 172, pass_statement; 173, else_clause; 173, 174; 174, block; 174, 175; 174, 188; 175, if_statement; 175, 176; 175, 181; 175, 182; 176, call; 176, 177; 176, 178; 177, identifier:isinstance; 178, argument_list; 178, 179; 178, 180; 179, identifier:item; 180, identifier:Basic; 181, comment; 182, block; 182, 183; 183, return_statement; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:default_sort_key; 186, argument_list; 186, 187; 187, identifier:item; 188, comment; 189, comment; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 195; 192, pattern_list; 192, 193; 192, 194; 193, identifier:cls_index; 194, identifier:args; 195, expression_list; 195, 196; 195, 197; 196, integer:0; 197, tuple; 197, 198; 197, 199; 198, integer:1; 199, tuple; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:str; 202, argument_list; 202, 203; 203, identifier:item; 204, return_statement; 204, 205; 205, expression_list; 205, 206; 205, 214; 205, 215; 205, 222; 206, tuple; 206, 207; 206, 208; 206, 209; 207, identifier:cls_index; 208, integer:0; 209, attribute; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:item; 212, identifier:__class__; 213, identifier:__name__; 214, identifier:args; 215, call; 215, 216; 215, 221; 216, attribute; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:S; 219, identifier:One; 220, identifier:sort_key; 221, argument_list; 222, attribute; 222, 223; 222, 224; 223, identifier:S; 224, identifier:One | def default_sort_key(item, order=None):
"""Return a key that can be used for sorting.
The key has the structure:
(class_key, (len(args), args), exponent.sort_key(), coefficient)
This key is supplied by the sort_key routine of Basic objects when
``item`` is a Basic object or an object (other than a string) that
sympifies to a Basic object. Otherwise, this function produces the
key.
The ``order`` argument is passed along to the sort_key routine and is
used to determine how the terms *within* an expression are ordered.
(See examples below) ``order`` options are: 'lex', 'grlex', 'grevlex',
and reversed values of the same (e.g. 'rev-lex'). The default order
value is None (which translates to 'lex').
Examples
========
>>> from sympy import S, I, default_sort_key
>>> from sympy.core.function import UndefinedFunction
>>> from sympy.abc import x
The following are equivalent ways of getting the key for an object:
>>> x.sort_key() == default_sort_key(x)
True
Here are some examples of the key that is produced:
>>> default_sort_key(UndefinedFunction('f'))
((0, 0, 'UndefinedFunction'), (1, ('f',)), ((1, 0, 'Number'),
(0, ()), (), 1), 1)
>>> default_sort_key('1')
((0, 0, 'str'), (1, ('1',)), ((1, 0, 'Number'), (0, ()), (), 1), 1)
>>> default_sort_key(S.One)
((1, 0, 'Number'), (0, ()), (), 1)
>>> default_sort_key(2)
((1, 0, 'Number'), (0, ()), (), 2)
While sort_key is a method only defined for SymPy objects,
default_sort_key will accept anything as an argument so it is
more robust as a sorting key. For the following, using key=
lambda i: i.sort_key() would fail because 2 doesn't have a sort_key
method; that's why default_sort_key is used. Note, that it also
handles sympification of non-string items likes ints:
>>> a = [2, I, -I]
>>> sorted(a, key=default_sort_key)
[2, -I, I]
The returned key can be used anywhere that a key can be specified for
a function, e.g. sort, min, max, etc...:
>>> a.sort(key=default_sort_key); a[0]
2
>>> min(a, key=default_sort_key)
2
Note
----
The key returned is useful for getting items into a canonical order
that will be the same across platforms. It is not directly useful for
sorting lists of expressions:
>>> a, b = x, 1/x
Since ``a`` has only 1 term, its value of sort_key is unaffected by
``order``:
>>> a.sort_key() == a.sort_key('rev-lex')
True
If ``a`` and ``b`` are combined then the key will differ because there
are terms that can be ordered:
>>> eq = a + b
>>> eq.sort_key() == eq.sort_key('rev-lex')
False
>>> eq.as_ordered_terms()
[x, 1/x]
>>> eq.as_ordered_terms('rev-lex')
[1/x, x]
But since the keys for each of these terms are independent of ``order``'s
value, they don't sort differently when they appear separately in a list:
>>> sorted(eq.args, key=default_sort_key)
[1/x, x]
>>> sorted(eq.args, key=lambda i: default_sort_key(i, order='rev-lex'))
[1/x, x]
The order of terms obtained when using these keys is the order that would
be obtained if those terms were *factors* in a product.
See Also
========
sympy.core.expr.as_ordered_factors, sympy.core.expr.as_ordered_terms
"""
from sympy.core import S, Basic
from sympy.core.sympify import sympify, SympifyError
from sympy.core.compatibility import iterable
if isinstance(item, Basic):
return item.sort_key(order=order)
if iterable(item, exclude=string_types):
if isinstance(item, dict):
args = item.items()
unordered = True
elif isinstance(item, set):
args = item
unordered = True
else:
# e.g. tuple, list
args = list(item)
unordered = False
args = [default_sort_key(arg, order=order) for arg in args]
if unordered:
# e.g. dict, set
args = sorted(args)
cls_index, args = 10, (len(args), tuple(args))
else:
if not isinstance(item, string_types):
try:
item = sympify(item)
except SympifyError:
# e.g. lambda x: x
pass
else:
if isinstance(item, Basic):
# e.g int -> Integer
return default_sort_key(item)
# e.g. UndefinedFunction
# e.g. str
cls_index, args = 0, (1, (str(item),))
return (cls_index, 0, item.__class__.__name__
), args, S.One.sort_key(), S.One |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:uintersect1d; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:arr1; 5, identifier:arr2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:assume_unique; 8, False; 9, block; 9, 10; 9, 12; 9, 25; 9, 35; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:v; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:np; 18, identifier:intersect1d; 19, argument_list; 19, 20; 19, 21; 19, 22; 20, identifier:arr1; 21, identifier:arr2; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:assume_unique; 24, identifier:assume_unique; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:v; 28, call; 28, 29; 28, 30; 29, identifier:_validate_numpy_wrapper_units; 30, argument_list; 30, 31; 30, 32; 31, identifier:v; 32, list:[arr1, arr2]; 32, 33; 32, 34; 33, identifier:arr1; 34, identifier:arr2; 35, return_statement; 35, 36; 36, identifier:v | def uintersect1d(arr1, arr2, assume_unique=False):
"""Find the sorted unique elements of the two input arrays.
A wrapper around numpy.intersect1d that preserves units. All input arrays
must have the same units. See the documentation of numpy.intersect1d for
full details.
Examples
--------
>>> from unyt import cm
>>> A = [1, 2, 3]*cm
>>> B = [2, 3, 4]*cm
>>> uintersect1d(A, B)
unyt_array([2, 3], 'cm')
"""
v = np.intersect1d(arr1, arr2, assume_unique=assume_unique)
v = _validate_numpy_wrapper_units(v, [arr1, arr2])
return v |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:argsort; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 12; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:axis; 7, unary_operator:-; 7, 8; 8, integer:1; 9, default_parameter; 9, 10; 9, 11; 10, identifier:kind; 11, string:"quicksort"; 12, default_parameter; 12, 13; 12, 14; 13, identifier:order; 14, None; 15, block; 15, 16; 15, 18; 16, expression_statement; 16, 17; 17, comment; 18, return_statement; 18, 19; 19, call; 19, 20; 19, 30; 20, attribute; 20, 21; 20, 29; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:view; 25, argument_list; 25, 26; 26, attribute; 26, 27; 26, 28; 27, identifier:np; 28, identifier:ndarray; 29, identifier:argsort; 30, argument_list; 30, 31; 30, 32; 30, 33; 31, identifier:axis; 32, identifier:kind; 33, identifier:order | def argsort(self, axis=-1, kind="quicksort", order=None):
"""
Returns the indices that would sort the array.
See the documentation of ndarray.argsort for details about the keyword
arguments.
Example
-------
>>> from unyt import km
>>> data = [3, 8, 7]*km
>>> print(np.argsort(data))
[0 2 1]
>>> print(data.argsort())
[0 2 1]
"""
return self.view(np.ndarray).argsort(axis, kind, order) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:serve; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:info; 5, identifier:host; 6, identifier:port; 7, identifier:reload; 8, identifier:debugger; 9, identifier:eager_loading; 10, identifier:with_threads; 11, block; 11, 12; 11, 14; 11, 15; 11, 16; 11, 25; 11, 34; 11, 40; 11, 48; 11, 60; 11, 72; 11, 82; 11, 94; 11, 118; 11, 123; 11, 137; 12, expression_statement; 12, 13; 13, string:'''
Runs a local udata development server.
This local server is recommended for development purposes only but it
can also be used for simple intranet deployments.
By default it will not support any sort of concurrency at all
to simplify debugging.
This can be changed with the --with-threads option which will enable basic
multithreading.
The reloader and debugger are by default enabled if the debug flag of
Flask is enabled and disabled otherwise.
'''; 14, comment; 15, comment; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:logger; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:logging; 22, identifier:getLogger; 23, argument_list; 23, 24; 24, string:'werkzeug'; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:logger; 29, identifier:setLevel; 30, argument_list; 30, 31; 31, attribute; 31, 32; 31, 33; 32, identifier:logging; 33, identifier:INFO; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:logger; 38, identifier:handlers; 39, list:[]; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:debug; 43, subscript; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:current_app; 46, identifier:config; 47, string:'DEBUG'; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:is; 49, 50; 49, 51; 50, identifier:reload; 51, None; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:reload; 56, call; 56, 57; 56, 58; 57, identifier:bool; 58, argument_list; 58, 59; 59, identifier:debug; 60, if_statement; 60, 61; 60, 64; 61, comparison_operator:is; 61, 62; 61, 63; 62, identifier:debugger; 63, None; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:debugger; 68, call; 68, 69; 68, 70; 69, identifier:bool; 70, argument_list; 70, 71; 71, identifier:debug; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:is; 73, 74; 73, 75; 74, identifier:eager_loading; 75, None; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:eager_loading; 80, not_operator; 80, 81; 81, identifier:reload; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:app; 85, call; 85, 86; 85, 87; 86, identifier:DispatchingApp; 87, argument_list; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:info; 90, identifier:load_app; 91, keyword_argument; 91, 92; 91, 93; 92, identifier:use_eager_loading; 93, identifier:eager_loading; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:settings; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:os; 101, identifier:environ; 102, identifier:get; 103, argument_list; 103, 104; 103, 105; 104, string:'UDATA_SETTINGS'; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:os; 109, identifier:path; 110, identifier:join; 111, argument_list; 111, 112; 111, 117; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:os; 115, identifier:getcwd; 116, argument_list; 117, string:'udata.cfg'; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:extra_files; 121, list:[settings]; 121, 122; 122, identifier:settings; 123, if_statement; 123, 124; 123, 125; 124, identifier:reload; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:extra_files; 130, identifier:extend; 131, argument_list; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:assets; 135, identifier:manifests_paths; 136, argument_list; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:run_simple; 140, argument_list; 140, 141; 140, 142; 140, 143; 140, 144; 140, 147; 140, 150; 140, 153; 141, identifier:host; 142, identifier:port; 143, identifier:app; 144, keyword_argument; 144, 145; 144, 146; 145, identifier:use_reloader; 146, identifier:reload; 147, keyword_argument; 147, 148; 147, 149; 148, identifier:use_debugger; 149, identifier:debugger; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:threaded; 152, identifier:with_threads; 153, keyword_argument; 153, 154; 153, 155; 154, identifier:extra_files; 155, identifier:extra_files | def serve(info, host, port, reload, debugger, eager_loading, with_threads):
'''
Runs a local udata development server.
This local server is recommended for development purposes only but it
can also be used for simple intranet deployments.
By default it will not support any sort of concurrency at all
to simplify debugging.
This can be changed with the --with-threads option which will enable basic
multithreading.
The reloader and debugger are by default enabled if the debug flag of
Flask is enabled and disabled otherwise.
'''
# Werkzeug logger is special and is required
# with this configuration for development server
logger = logging.getLogger('werkzeug')
logger.setLevel(logging.INFO)
logger.handlers = []
debug = current_app.config['DEBUG']
if reload is None:
reload = bool(debug)
if debugger is None:
debugger = bool(debug)
if eager_loading is None:
eager_loading = not reload
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
settings = os.environ.get('UDATA_SETTINGS',
os.path.join(os.getcwd(), 'udata.cfg'))
extra_files = [settings]
if reload:
extra_files.extend(assets.manifests_paths())
run_simple(host, port, app, use_reloader=reload,
use_debugger=debugger, threaded=with_threads,
extra_files=extra_files) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:get_enabled_plugins; 3, parameters; 4, block; 4, 5; 4, 7; 4, 21; 4, 35; 4, 67; 5, expression_statement; 5, 6; 6, string:'''
Returns enabled preview plugins.
Plugins are sorted, defaults come last
'''; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:plugins; 10, call; 10, 11; 10, 20; 11, attribute; 11, 12; 11, 19; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:entrypoints; 15, identifier:get_enabled; 16, argument_list; 16, 17; 16, 18; 17, string:'udata.preview'; 18, identifier:current_app; 19, identifier:values; 20, argument_list; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:valid; 24, list_comprehension; 24, 25; 24, 26; 24, 29; 25, identifier:p; 26, for_in_clause; 26, 27; 26, 28; 27, identifier:p; 28, identifier:plugins; 29, if_clause; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:issubclass; 32, argument_list; 32, 33; 32, 34; 33, identifier:p; 34, identifier:PreviewPlugin; 35, for_statement; 35, 36; 35, 37; 35, 38; 36, identifier:plugin; 37, identifier:plugins; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 43; 40, comparison_operator:not; 40, 41; 40, 42; 41, identifier:plugin; 42, identifier:valid; 43, block; 43, 44; 43, 50; 43, 59; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:clsname; 47, attribute; 47, 48; 47, 49; 48, identifier:plugin; 49, identifier:__name__; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:msg; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, string:'{0} is not a valid preview plugin'; 56, identifier:format; 57, argument_list; 57, 58; 58, identifier:clsname; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:warnings; 63, identifier:warn; 64, argument_list; 64, 65; 64, 66; 65, identifier:msg; 66, identifier:PreviewWarning; 67, return_statement; 67, 68; 68, list_comprehension; 68, 69; 68, 72; 69, call; 69, 70; 69, 71; 70, identifier:p; 71, argument_list; 72, for_in_clause; 72, 73; 72, 74; 73, identifier:p; 74, call; 74, 75; 74, 76; 75, identifier:sorted; 76, argument_list; 76, 77; 76, 78; 77, identifier:valid; 78, keyword_argument; 78, 79; 78, 80; 79, identifier:key; 80, lambda; 80, 81; 80, 83; 81, lambda_parameters; 81, 82; 82, identifier:p; 83, conditional_expression:if; 83, 84; 83, 85; 83, 88; 84, integer:1; 85, attribute; 85, 86; 85, 87; 86, identifier:p; 87, identifier:fallback; 88, integer:0 | def get_enabled_plugins():
'''
Returns enabled preview plugins.
Plugins are sorted, defaults come last
'''
plugins = entrypoints.get_enabled('udata.preview', current_app).values()
valid = [p for p in plugins if issubclass(p, PreviewPlugin)]
for plugin in plugins:
if plugin not in valid:
clsname = plugin.__name__
msg = '{0} is not a valid preview plugin'.format(clsname)
warnings.warn(msg, PreviewWarning)
return [p() for p in sorted(valid, key=lambda p: 1 if p.fallback else 0)] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:extract_sort; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:params; 6, block; 6, 7; 6, 9; 6, 19; 6, 31; 6, 55; 7, expression_statement; 7, 8; 8, string:'''Extract and build sort query from parameters'''; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:sorts; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:params; 15, identifier:pop; 16, argument_list; 16, 17; 16, 18; 17, string:'sort'; 18, list:[]; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:sorts; 22, conditional_expression:if; 22, 23; 22, 25; 22, 30; 23, list:[sorts]; 23, 24; 24, identifier:sorts; 25, call; 25, 26; 25, 27; 26, identifier:isinstance; 27, argument_list; 27, 28; 27, 29; 28, identifier:sorts; 29, identifier:basestring; 30, identifier:sorts; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:sorts; 34, list_comprehension; 34, 35; 34, 52; 35, conditional_expression:if; 35, 36; 35, 43; 35, 49; 36, tuple; 36, 37; 36, 42; 37, subscript; 37, 38; 37, 39; 38, identifier:s; 39, slice; 39, 40; 39, 41; 40, integer:1; 41, colon; 42, string:'desc'; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:s; 46, identifier:startswith; 47, argument_list; 47, 48; 48, string:'-'; 49, tuple; 49, 50; 49, 51; 50, identifier:s; 51, string:'asc'; 52, for_in_clause; 52, 53; 52, 54; 53, identifier:s; 54, identifier:sorts; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:sorts; 60, list_comprehension; 60, 61; 60, 71; 60, 76; 61, dictionary; 61, 62; 62, pair; 62, 63; 62, 70; 63, subscript; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:adapter; 68, identifier:sorts; 69, identifier:s; 70, identifier:d; 71, for_in_clause; 71, 72; 71, 75; 72, pattern_list; 72, 73; 72, 74; 73, identifier:s; 74, identifier:d; 75, identifier:sorts; 76, if_clause; 76, 77; 77, comparison_operator:in; 77, 78; 77, 79; 78, identifier:s; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:adapter; 83, identifier:sorts | def extract_sort(self, params):
'''Extract and build sort query from parameters'''
sorts = params.pop('sort', [])
sorts = [sorts] if isinstance(sorts, basestring) else sorts
sorts = [(s[1:], 'desc')
if s.startswith('-') else (s, 'asc')
for s in sorts]
self.sorts = [
{self.adapter.sorts[s]: d}
for s, d in sorts if s in self.adapter.sorts
] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:ancestors_objects; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 12; 5, 46; 5, 60; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:ancestors_objects; 11, list:[]; 12, for_statement; 12, 13; 12, 14; 12, 17; 13, identifier:ancestor; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:ancestors; 17, block; 17, 18; 17, 39; 18, try_statement; 18, 19; 18, 33; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:ancestor_object; 23, call; 23, 24; 23, 29; 24, attribute; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:GeoZone; 27, identifier:objects; 28, identifier:get; 29, argument_list; 29, 30; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:id; 32, identifier:ancestor; 33, except_clause; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:GeoZone; 36, identifier:DoesNotExist; 37, block; 37, 38; 38, continue_statement; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:ancestors_objects; 43, identifier:append; 44, argument_list; 44, 45; 45, identifier:ancestor_object; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:ancestors_objects; 50, identifier:sort; 51, argument_list; 51, 52; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:key; 54, lambda; 54, 55; 54, 57; 55, lambda_parameters; 55, 56; 56, identifier:a; 57, attribute; 57, 58; 57, 59; 58, identifier:a; 59, identifier:name; 60, return_statement; 60, 61; 61, identifier:ancestors_objects | def ancestors_objects(self):
"""Ancestors objects sorted by name."""
ancestors_objects = []
for ancestor in self.ancestors:
try:
ancestor_object = GeoZone.objects.get(id=ancestor)
except GeoZone.DoesNotExist:
continue
ancestors_objects.append(ancestor_object)
ancestors_objects.sort(key=lambda a: a.name)
return ancestors_objects |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:check_for_territories; 3, parameters; 3, 4; 4, identifier:query; 5, block; 5, 6; 5, 8; 5, 24; 5, 32; 5, 40; 5, 48; 5, 55; 5, 219; 5, 226; 5, 227; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 21; 9, boolean_operator:or; 9, 10; 9, 12; 10, not_operator; 10, 11; 11, identifier:query; 12, not_operator; 12, 13; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:current_app; 17, identifier:config; 18, identifier:get; 19, argument_list; 19, 20; 20, string:'ACTIVATE_TERRITORIES'; 21, block; 21, 22; 22, return_statement; 22, 23; 23, list:[]; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:dbqs; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:db; 30, identifier:Q; 31, argument_list; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:query; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:query; 38, identifier:lower; 39, argument_list; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:is_digit; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:query; 46, identifier:isdigit; 47, argument_list; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:query_length; 51, call; 51, 52; 51, 53; 52, identifier:len; 53, argument_list; 53, 54; 54, identifier:query; 55, for_statement; 55, 56; 55, 57; 55, 65; 56, identifier:level; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:current_app; 61, identifier:config; 62, identifier:get; 63, argument_list; 63, 64; 64, string:'HANDLED_LEVELS'; 65, block; 65, 66; 65, 73; 65, 84; 65, 214; 65, 215; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:==; 67, 68; 67, 69; 68, identifier:level; 69, string:'country'; 70, block; 70, 71; 70, 72; 71, continue_statement; 72, comment; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:q; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:db; 79, identifier:Q; 80, argument_list; 80, 81; 81, keyword_argument; 81, 82; 81, 83; 82, identifier:level; 83, identifier:level; 84, if_statement; 84, 85; 84, 102; 84, 103; 84, 115; 84, 138; 84, 185; 84, 211; 85, parenthesized_expression; 85, 86; 86, boolean_operator:and; 86, 87; 86, 94; 87, boolean_operator:and; 87, 88; 87, 91; 88, comparison_operator:==; 88, 89; 88, 90; 89, identifier:query_length; 90, integer:2; 91, comparison_operator:==; 91, 92; 91, 93; 92, identifier:level; 93, string:'fr:departement'; 94, parenthesized_expression; 94, 95; 95, boolean_operator:or; 95, 96; 95, 97; 96, identifier:is_digit; 97, comparison_operator:in; 97, 98; 97, 99; 98, identifier:query; 99, tuple; 99, 100; 99, 101; 100, string:'2a'; 101, string:'2b'; 102, comment; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, augmented_assignment:&=; 105, 106; 105, 107; 106, identifier:q; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:db; 110, identifier:Q; 111, argument_list; 111, 112; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:code; 114, identifier:query; 115, elif_clause; 115, 116; 115, 125; 115, 126; 116, boolean_operator:and; 116, 117; 116, 124; 117, boolean_operator:and; 117, 118; 117, 121; 118, comparison_operator:==; 118, 119; 118, 120; 119, identifier:query_length; 120, integer:3; 121, comparison_operator:==; 121, 122; 121, 123; 122, identifier:level; 123, string:'fr:departement'; 124, identifier:is_digit; 125, comment; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, augmented_assignment:&=; 128, 129; 128, 130; 129, identifier:q; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:db; 133, identifier:Q; 134, argument_list; 134, 135; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:code; 137, identifier:query; 138, elif_clause; 138, 139; 138, 163; 138, 164; 139, boolean_operator:and; 139, 140; 139, 147; 140, boolean_operator:and; 140, 141; 140, 144; 141, comparison_operator:==; 141, 142; 141, 143; 142, identifier:query_length; 143, integer:5; 144, comparison_operator:==; 144, 145; 144, 146; 145, identifier:level; 146, string:'fr:commune'; 147, parenthesized_expression; 147, 148; 148, boolean_operator:or; 148, 149; 148, 157; 149, boolean_operator:or; 149, 150; 149, 151; 150, identifier:is_digit; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:query; 154, identifier:startswith; 155, argument_list; 155, 156; 156, string:'2a'; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:query; 160, identifier:startswith; 161, argument_list; 161, 162; 162, string:'2b'; 163, comment; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, augmented_assignment:&=; 166, 167; 166, 168; 167, identifier:q; 168, binary_operator:|; 168, 169; 168, 177; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:db; 172, identifier:Q; 173, argument_list; 173, 174; 174, keyword_argument; 174, 175; 174, 176; 175, identifier:code; 176, identifier:query; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:db; 180, identifier:Q; 181, argument_list; 181, 182; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:keys__postal__contains; 184, identifier:query; 185, elif_clause; 185, 186; 185, 189; 185, 190; 186, comparison_operator:>=; 186, 187; 186, 188; 187, identifier:query_length; 188, integer:4; 189, comment; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, augmented_assignment:&=; 192, 193; 192, 194; 193, identifier:q; 194, binary_operator:|; 194, 195; 194, 203; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:db; 198, identifier:Q; 199, argument_list; 199, 200; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:name__istartswith; 202, identifier:query; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:db; 206, identifier:Q; 207, argument_list; 207, 208; 208, keyword_argument; 208, 209; 208, 210; 209, identifier:name__iexact; 210, identifier:query; 211, else_clause; 211, 212; 212, block; 212, 213; 213, continue_statement; 214, comment; 215, expression_statement; 215, 216; 216, augmented_assignment:|=; 216, 217; 216, 218; 217, identifier:dbqs; 218, identifier:q; 219, if_statement; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:dbqs; 222, identifier:empty; 223, block; 223, 224; 224, return_statement; 224, 225; 225, list:[]; 226, comment; 227, return_statement; 227, 228; 228, call; 228, 229; 228, 237; 229, attribute; 229, 230; 229, 236; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:GeoZone; 233, identifier:objects; 234, argument_list; 234, 235; 235, identifier:dbqs; 236, identifier:order_by; 237, argument_list; 237, 238; 237, 239; 238, string:'-population'; 239, string:'-area' | def check_for_territories(query):
"""
Return a geozone queryset of territories given the `query`.
Results are sorted by population and area (biggest first).
"""
if not query or not current_app.config.get('ACTIVATE_TERRITORIES'):
return []
dbqs = db.Q()
query = query.lower()
is_digit = query.isdigit()
query_length = len(query)
for level in current_app.config.get('HANDLED_LEVELS'):
if level == 'country':
continue # Level not fully handled yet.
q = db.Q(level=level)
if (query_length == 2 and level == 'fr:departement' and
(is_digit or query in ('2a', '2b'))):
# Counties + Corsica.
q &= db.Q(code=query)
elif query_length == 3 and level == 'fr:departement' and is_digit:
# French DROM-COM.
q &= db.Q(code=query)
elif query_length == 5 and level == 'fr:commune' and (
is_digit or query.startswith('2a') or query.startswith('2b')):
# INSEE code then postal codes with Corsica exceptions.
q &= db.Q(code=query) | db.Q(keys__postal__contains=query)
elif query_length >= 4:
# Check names starting with query or exact match.
q &= db.Q(name__istartswith=query) | db.Q(name__iexact=query)
else:
continue
# Meta Q object, ready to be passed to a queryset.
dbqs |= q
if dbqs.empty:
return []
# Sort matching results by population and area.
return GeoZone.objects(dbqs).order_by('-population', '-area') |
Subsets and Splits