content
stringlengths 1
1.04M
| input_ids
sequencelengths 1
786k
| ratio_char_token
float64 0.38
14.2
| token_count
int64 1
786k
|
---|---|---|---|
#!/usr/bin/env python2
# -*- encoding: utf-8 -*-
# Gimp Markup Builder
# author: duangsuse
# date: Thu May 02 2019 CST
from os import linesep
from Util import stream_join
class MarkupBuilder:
''' Gimp Markup SGML builder '''
def __init__(self, indent = -1, nl = linesep, buffer = str):
self.marks = buffer()
self.tag_stack = list()
self.nl = nl
self.indent = indent
self.last_spaces = 0
self.revert_last_indent_size = 0
self.last_is_text = False
'''
Indent rules:
when starting new tag, write last spaces, last spaces += indent
if new tag is not text tag start (inner is just text), write newline
when leaving tag, last spaces -= indent
'''
def useindent(self): return self.indent != -1
indented = property(useindent)
def wnewline(self):
''' see use_indent'''
self.marks += self.nl
def windent(self):
''' see use_indent'''
wrote = 0
for _ in range(0, self.last_spaces):
self.marks += ' '
wrote += 1 # dummy?
return wrote
def cancel_indent(self):
''' cancel last indent '''
if self.indented: self.marks = self.marks[:-self.revert_last_indent_size]
def do_indent(self, entering = True):
''' Write indent, increase last_spaces, saving wrote spaces and newline to revert_last_indent_size '''
def do():
self.wnewline()
if (entering):
self.last_spaces += self.indent
else: self.last_spaces -= self.indent
self.revert_last_indent_size = self.windent() +1
if self.indented: do()
def do_last_indent(self, *args, **kwargs):
''' write indenting for last block '''
self.last_spaces -= self.indent
self.do_indent(*args, **kwargs)
self.last_spaces += self.indent
def begin(self, tag, attrs = {}):
'''
Make a tag with name and attributes
Attribute name, value and tag name is escaped
'''
self.last_is_text = False
attrst = str()
tagscape = self.escape(tag)
ary = list(stream_join(attrs.keys(), attrs.values())) if attrs.__class__ is dict else list(attrs)
if len(attrs) != 0:
for n in range(0, len(ary), 2):
attrst += self.escape(str(ary[n]))
attrst += '='
#print(ary)
#print(n)
attrst += "\"%s\"" % self.escape(str(ary[n+1]))
self.marks += '<' + tagscape
if len(attrs) != 0: self.marks += ' '
self.marks += attrst + '>'
# always write indents for next line
# makes its possible to drop last indent (text tag)
self.do_indent()
self.tag_stack.append(tagscape)
return self
def make(self): return self.marks
def tag(self, *args, **kwargs):
r'''
EDSL using __close__ with syntax
create nodes like:
with xml.tag('span', {color: '#66ccff'}):
xml % 'Q \w\ Q'
'''
self.last_is_text = False
class TagBuilder:
def __init__(self, xml):
self.xml = xml
def __enter__(self):
self.xml.begin(*args, attrs = kwargs)
def __exit__(self, *lveinfo):
self.xml.end()
return TagBuilder(self)
def text(self, content):
''' append text content '''
self.last_is_text = True
if self.indented: self.cancel_indent()
self.marks += self.escape(content)
return self
#@staticmethod
#def test():
# m = MarkupBuilder()
# m > 'html'
# m > 'head'
# m > 'title'
# m < 'Hello World'
# m <= 2
# m > 'body'
# m > 'text'
# with m.tag("b"):
# m < 'String'
# m >= ['a', {'id': 'str'}]
# m < '|sg.'
# m <= 4
# return m
def end(self):
''' delimites last tag '''
if not self.last_is_text: # cancel indentation
#print(self.indent, self.tag_stack)
self.cancel_indent()
self.do_indent(False)
self.marks += '</' + self.tag_stack.pop() + '>'
self.do_indent(False)
self.last_is_text = False
# Not cared by Markup indent emitter
def raw(self, raw):
''' write raw text (unescaped) '''
self.marks += raw
return self
def rawtag(self, rawtext):
''' append unescaped raw <> text '''
self.marks += '<'
self.marks += rawtext
self.marks += '>'
def _escape(self, xml):
'''
Escape XML string
' is replaced with '
" is replaced with "
& is replaced with &
< is replaced with <
> is replaced with >
'''
escapes = frozenset("'\"&<>")
replacement = { '\'': 'apos', '"': 'quot', '&': 'amp', '<': 'lt', '>': 'gt' }
if len(xml) < 1: return
output = str()
for i in range(0, len(xml)):
char = xml[i]
if (char in escapes):
output += '&'
output += replacement[char]
output += ';'
else: output += char
return output
escape = classmethod(_escape)
def __str__(self):
''' M(marks)..[tag stack] '''
return 'M(' + self.marks + ')..' + str(self.tag_stack)
__lt__ = text # chain
__gt__ = begin # chain
__add__ = raw # chain
def __contains__(self, tag):
''' is tag inside enclosing tags ? '''
return tag in self.tag_stack
def __ge__(self, tag_attr):
''' xml >= ['markup', {'name': 'abcs'}] '''
mark = tag_attr[0]
attr = tag_attr[1]
self.begin(mark, attr)
def __le__(self, n = 1):
''' Leave (close) N tags '''
while n > 0:
self.end()
n -= 1
| [
2,
48443,
14629,
14,
8800,
14,
24330,
21015,
17,
198,
2,
532,
9,
12,
21004,
25,
3384,
69,
12,
23,
532,
9,
12,
198,
198,
2,
402,
11011,
2940,
929,
35869,
198,
2,
1772,
25,
7043,
27725,
1904,
198,
2,
3128,
25,
26223,
1737,
7816,
13130,
46429,
198,
198,
6738,
28686,
1330,
3951,
538,
198,
198,
6738,
7273,
346,
1330,
4269,
62,
22179,
198,
198,
4871,
2940,
929,
32875,
25,
198,
220,
705,
7061,
402,
11011,
2940,
929,
26147,
5805,
27098,
705,
7061,
198,
220,
825,
11593,
15003,
834,
7,
944,
11,
33793,
796,
532,
16,
11,
299,
75,
796,
3951,
538,
11,
11876,
796,
965,
2599,
198,
220,
220,
220,
2116,
13,
14306,
796,
11876,
3419,
198,
220,
220,
220,
2116,
13,
12985,
62,
25558,
796,
1351,
3419,
628,
220,
220,
220,
2116,
13,
21283,
796,
299,
75,
198,
220,
220,
220,
2116,
13,
521,
298,
796,
33793,
198,
220,
220,
220,
2116,
13,
12957,
62,
2777,
2114,
796,
657,
628,
220,
220,
220,
2116,
13,
260,
1851,
62,
12957,
62,
521,
298,
62,
7857,
796,
657,
628,
220,
220,
220,
2116,
13,
12957,
62,
271,
62,
5239,
796,
10352,
628,
220,
705,
7061,
198,
220,
1423,
298,
3173,
25,
628,
220,
618,
3599,
649,
7621,
11,
3551,
938,
9029,
11,
938,
9029,
15853,
33793,
198,
220,
611,
649,
7621,
318,
407,
2420,
7621,
923,
357,
5083,
318,
655,
2420,
828,
3551,
649,
1370,
198,
220,
618,
4305,
7621,
11,
938,
9029,
48185,
33793,
198,
220,
705,
7061,
198,
220,
825,
779,
521,
298,
7,
944,
2599,
1441,
2116,
13,
521,
298,
14512,
532,
16,
198,
220,
773,
4714,
796,
3119,
7,
1904,
521,
298,
8,
198,
220,
825,
266,
3605,
1370,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
766,
779,
62,
521,
298,
7061,
6,
198,
220,
220,
220,
2116,
13,
14306,
15853,
2116,
13,
21283,
198,
220,
825,
2344,
298,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
766,
779,
62,
521,
298,
7061,
6,
198,
220,
220,
220,
2630,
796,
657,
198,
220,
220,
220,
329,
4808,
287,
2837,
7,
15,
11,
2116,
13,
12957,
62,
2777,
2114,
2599,
198,
220,
220,
220,
220,
220,
2116,
13,
14306,
15853,
705,
705,
198,
220,
220,
220,
220,
220,
2630,
15853,
352,
1303,
31548,
30,
198,
220,
220,
220,
1441,
2630,
198,
220,
825,
14241,
62,
521,
298,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
14241,
938,
33793,
705,
7061,
198,
220,
220,
220,
611,
2116,
13,
521,
4714,
25,
2116,
13,
14306,
796,
2116,
13,
14306,
58,
21912,
944,
13,
260,
1851,
62,
12957,
62,
521,
298,
62,
7857,
60,
198,
220,
825,
466,
62,
521,
298,
7,
944,
11,
8218,
796,
6407,
2599,
198,
220,
220,
220,
705,
7061,
19430,
33793,
11,
2620,
938,
62,
2777,
2114,
11,
8914,
2630,
9029,
290,
649,
1370,
284,
34052,
62,
12957,
62,
521,
298,
62,
7857,
705,
7061,
198,
220,
220,
220,
825,
466,
33529,
198,
220,
220,
220,
220,
220,
2116,
13,
675,
413,
1370,
3419,
198,
220,
220,
220,
220,
220,
611,
357,
298,
1586,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
12957,
62,
2777,
2114,
15853,
2116,
13,
521,
298,
198,
220,
220,
220,
220,
220,
2073,
25,
2116,
13,
12957,
62,
2777,
2114,
48185,
2116,
13,
521,
298,
198,
220,
220,
220,
220,
220,
2116,
13,
260,
1851,
62,
12957,
62,
521,
298,
62,
7857,
796,
2116,
13,
7972,
298,
3419,
1343,
16,
198,
220,
220,
220,
611,
2116,
13,
521,
4714,
25,
466,
3419,
628,
220,
825,
466,
62,
12957,
62,
521,
298,
7,
944,
11,
1635,
22046,
11,
12429,
46265,
22046,
2599,
198,
220,
220,
220,
705,
7061,
3551,
33793,
278,
329,
938,
2512,
705,
7061,
198,
220,
220,
220,
2116,
13,
12957,
62,
2777,
2114,
48185,
2116,
13,
521,
298,
198,
220,
220,
220,
2116,
13,
4598,
62,
521,
298,
46491,
22046,
11,
12429,
46265,
22046,
8,
198,
220,
220,
220,
2116,
13,
12957,
62,
2777,
2114,
15853,
2116,
13,
521,
298,
628,
220,
825,
2221,
7,
944,
11,
7621,
11,
708,
3808,
796,
23884,
2599,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
6889,
257,
7621,
351,
1438,
290,
12608,
628,
220,
220,
220,
3460,
4163,
1438,
11,
1988,
290,
7621,
1438,
318,
13537,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
2116,
13,
12957,
62,
271,
62,
5239,
796,
10352,
198,
220,
220,
220,
708,
81,
301,
796,
965,
3419,
198,
220,
220,
220,
7621,
6794,
796,
2116,
13,
41915,
7,
12985,
8,
628,
220,
220,
220,
257,
563,
796,
1351,
7,
5532,
62,
22179,
7,
1078,
3808,
13,
13083,
22784,
708,
3808,
13,
27160,
3419,
4008,
611,
708,
3808,
13,
834,
4871,
834,
318,
8633,
2073,
1351,
7,
1078,
3808,
8,
198,
220,
220,
220,
611,
18896,
7,
1078,
3808,
8,
14512,
657,
25,
198,
220,
220,
220,
220,
220,
329,
299,
287,
2837,
7,
15,
11,
18896,
7,
560,
828,
362,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
708,
81,
301,
15853,
2116,
13,
41915,
7,
2536,
7,
560,
58,
77,
60,
4008,
198,
220,
220,
220,
220,
220,
220,
220,
708,
81,
301,
15853,
705,
11639,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
4798,
7,
560,
8,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
4798,
7,
77,
8,
198,
220,
220,
220,
220,
220,
220,
220,
708,
81,
301,
15853,
366,
7879,
4,
82,
7879,
1,
4064,
2116,
13,
41915,
7,
2536,
7,
560,
58,
77,
10,
16,
60,
4008,
628,
220,
220,
220,
2116,
13,
14306,
15853,
705,
27,
6,
1343,
7621,
6794,
198,
220,
220,
220,
611,
18896,
7,
1078,
3808,
8,
14512,
657,
25,
2116,
13,
14306,
15853,
705,
705,
198,
220,
220,
220,
2116,
13,
14306,
15853,
708,
81,
301,
1343,
705,
29,
6,
628,
220,
220,
220,
1303,
1464,
3551,
773,
658,
329,
1306,
1627,
198,
220,
220,
220,
1303,
1838,
663,
1744,
284,
4268,
938,
33793,
357,
5239,
7621,
8,
198,
220,
220,
220,
2116,
13,
4598,
62,
521,
298,
3419,
628,
220,
220,
220,
2116,
13,
12985,
62,
25558,
13,
33295,
7,
12985,
6794,
8,
198,
220,
220,
220,
1441,
2116,
628,
220,
825,
787,
7,
944,
2599,
1441,
2116,
13,
14306,
628,
220,
825,
7621,
7,
944,
11,
1635,
22046,
11,
12429,
46265,
22046,
2599,
198,
220,
220,
220,
374,
7061,
6,
198,
220,
220,
220,
412,
5258,
43,
1262,
11593,
19836,
834,
351,
15582,
628,
220,
220,
220,
2251,
13760,
588,
25,
198,
220,
220,
220,
351,
35555,
13,
12985,
10786,
12626,
3256,
1391,
8043,
25,
705,
2,
2791,
535,
487,
6,
92,
2599,
198,
220,
220,
220,
220,
220,
35555,
4064,
705,
48,
3467,
86,
59,
1195,
6,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
2116,
13,
12957,
62,
271,
62,
5239,
796,
10352,
198,
220,
220,
220,
1398,
17467,
32875,
25,
198,
220,
220,
220,
220,
220,
825,
11593,
15003,
834,
7,
944,
11,
35555,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
19875,
796,
35555,
198,
220,
220,
220,
220,
220,
825,
11593,
9255,
834,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
19875,
13,
27471,
46491,
22046,
11,
708,
3808,
796,
479,
86,
22046,
8,
198,
220,
220,
220,
220,
220,
825,
11593,
37023,
834,
7,
944,
11,
1635,
75,
303,
10951,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
19875,
13,
437,
3419,
198,
220,
220,
220,
1441,
17467,
32875,
7,
944,
8,
628,
220,
825,
2420,
7,
944,
11,
2695,
2599,
198,
220,
220,
220,
705,
7061,
24443,
2420,
2695,
705,
7061,
198,
220,
220,
220,
2116,
13,
12957,
62,
271,
62,
5239,
796,
6407,
198,
220,
220,
220,
611,
2116,
13,
521,
4714,
25,
2116,
13,
66,
21130,
62,
521,
298,
3419,
198,
220,
220,
220,
2116,
13,
14306,
15853,
2116,
13,
41915,
7,
11299,
8,
198,
220,
220,
220,
1441,
2116,
628,
220,
1303,
31,
12708,
24396,
198,
220,
1303,
4299,
1332,
33529,
198,
220,
1303,
220,
285,
796,
2940,
929,
32875,
3419,
198,
220,
1303,
220,
285,
1875,
705,
6494,
6,
198,
220,
1303,
220,
285,
1875,
705,
2256,
6,
198,
220,
1303,
220,
285,
1875,
705,
7839,
6,
198,
220,
1303,
220,
285,
1279,
705,
15496,
2159,
6,
198,
220,
1303,
220,
285,
19841,
362,
198,
220,
1303,
220,
285,
1875,
705,
2618,
6,
198,
220,
1303,
220,
285,
1875,
705,
5239,
6,
198,
220,
1303,
220,
351,
285,
13,
12985,
7203,
65,
1,
2599,
198,
220,
1303,
220,
220,
220,
285,
1279,
705,
10100,
6,
198,
220,
1303,
220,
285,
18189,
37250,
64,
3256,
1391,
6,
312,
10354,
705,
2536,
6,
92,
60,
198,
220,
1303,
220,
285,
1279,
705,
91,
45213,
2637,
198,
220,
1303,
220,
285,
19841,
604,
198,
220,
1303,
220,
1441,
285,
628,
220,
825,
886,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
46728,
2737,
938,
7621,
705,
7061,
198,
220,
220,
220,
611,
407,
2116,
13,
12957,
62,
271,
62,
5239,
25,
1303,
14241,
33793,
341,
198,
220,
220,
220,
220,
220,
1303,
4798,
7,
944,
13,
521,
298,
11,
2116,
13,
12985,
62,
25558,
8,
198,
220,
220,
220,
220,
220,
2116,
13,
66,
21130,
62,
521,
298,
3419,
198,
220,
220,
220,
220,
220,
2116,
13,
4598,
62,
521,
298,
7,
25101,
8,
628,
220,
220,
220,
2116,
13,
14306,
15853,
705,
3556,
6,
1343,
2116,
13,
12985,
62,
25558,
13,
12924,
3419,
1343,
705,
29,
6,
198,
220,
220,
220,
2116,
13,
4598,
62,
521,
298,
7,
25101,
8,
198,
220,
220,
220,
2116,
13,
12957,
62,
271,
62,
5239,
796,
10352,
628,
220,
1303,
1892,
19951,
416,
2940,
929,
33793,
795,
1967,
198,
220,
825,
8246,
7,
944,
11,
8246,
2599,
198,
220,
220,
220,
705,
7061,
3551,
8246,
2420,
357,
403,
3798,
5813,
8,
705,
7061,
198,
220,
220,
220,
2116,
13,
14306,
15853,
8246,
198,
220,
220,
220,
1441,
2116,
628,
220,
825,
8246,
12985,
7,
944,
11,
8246,
5239,
2599,
198,
220,
220,
220,
705,
7061,
24443,
555,
3798,
5813,
8246,
1279,
29,
2420,
705,
7061,
198,
220,
220,
220,
2116,
13,
14306,
15853,
705,
27,
6,
198,
220,
220,
220,
2116,
13,
14306,
15853,
8246,
5239,
198,
220,
220,
220,
2116,
13,
14306,
15853,
705,
29,
6,
628,
220,
825,
4808,
41915,
7,
944,
11,
35555,
2599,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
14473,
23735,
4731,
628,
220,
220,
220,
705,
318,
6928,
351,
1222,
499,
418,
26,
198,
220,
220,
220,
366,
318,
6928,
351,
1222,
421,
313,
26,
198,
220,
220,
220,
1222,
318,
6928,
351,
1222,
696,
26,
198,
220,
220,
220,
1279,
318,
6928,
351,
1222,
2528,
26,
198,
220,
220,
220,
1875,
318,
6928,
351,
1222,
13655,
26,
198,
220,
220,
220,
705,
7061,
198,
220,
220,
220,
32695,
796,
8400,
8247,
316,
7203,
6,
7879,
5,
27,
29,
4943,
198,
220,
220,
220,
9014,
796,
1391,
705,
59,
7061,
25,
705,
499,
418,
3256,
705,
1,
10354,
705,
421,
313,
3256,
705,
5,
10354,
705,
696,
3256,
705,
27,
10354,
705,
2528,
3256,
705,
29,
10354,
705,
13655,
6,
1782,
628,
220,
220,
220,
611,
18896,
7,
19875,
8,
1279,
352,
25,
1441,
198,
220,
220,
220,
5072,
796,
965,
3419,
198,
220,
220,
220,
329,
1312,
287,
2837,
7,
15,
11,
18896,
7,
19875,
8,
2599,
198,
220,
220,
220,
220,
220,
1149,
796,
35555,
58,
72,
60,
198,
220,
220,
220,
220,
220,
611,
357,
10641,
287,
32695,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
5072,
15853,
705,
5,
6,
198,
220,
220,
220,
220,
220,
220,
220,
5072,
15853,
9014,
58,
10641,
60,
198,
220,
220,
220,
220,
220,
220,
220,
5072,
15853,
705,
26,
6,
198,
220,
220,
220,
220,
220,
2073,
25,
5072,
15853,
1149,
198,
220,
220,
220,
1441,
5072,
628,
220,
6654,
796,
1398,
24396,
28264,
41915,
8,
628,
220,
825,
11593,
2536,
834,
7,
944,
2599,
198,
220,
220,
220,
705,
7061,
337,
7,
14306,
8,
492,
58,
12985,
8931,
60,
705,
7061,
198,
220,
220,
220,
1441,
705,
44,
10786,
1343,
2116,
13,
14306,
1343,
705,
8,
492,
6,
1343,
965,
7,
944,
13,
12985,
62,
25558,
8,
628,
220,
11593,
2528,
834,
796,
2420,
1303,
6333,
198,
220,
11593,
13655,
834,
796,
2221,
1303,
6333,
198,
220,
11593,
2860,
834,
796,
8246,
1303,
6333,
628,
220,
825,
11593,
3642,
1299,
834,
7,
944,
11,
7621,
2599,
198,
220,
220,
220,
705,
7061,
318,
7621,
2641,
13507,
2752,
15940,
5633,
705,
7061,
198,
220,
220,
220,
1441,
7621,
287,
2116,
13,
12985,
62,
25558,
628,
220,
825,
11593,
469,
834,
7,
944,
11,
7621,
62,
35226,
2599,
198,
220,
220,
220,
705,
7061,
35555,
18189,
37250,
4102,
929,
3256,
1391,
6,
3672,
10354,
705,
397,
6359,
6,
92,
60,
705,
7061,
198,
220,
220,
220,
1317,
796,
7621,
62,
35226,
58,
15,
60,
198,
220,
220,
220,
708,
81,
796,
7621,
62,
35226,
58,
16,
60,
198,
220,
220,
220,
2116,
13,
27471,
7,
4102,
11,
708,
81,
8,
628,
220,
825,
11593,
293,
834,
7,
944,
11,
299,
796,
352,
2599,
198,
220,
220,
220,
705,
7061,
17446,
357,
19836,
8,
399,
15940,
705,
7061,
198,
220,
220,
220,
981,
299,
1875,
657,
25,
198,
220,
220,
220,
220,
220,
2116,
13,
437,
3419,
198,
220,
220,
220,
220,
220,
299,
48185,
352,
628
] | 2.354493 | 2,237 |
from pkg_resources import DistributionNotFound, get_distribution, parse_version
try:
import psycopg2 # noqa: F401
except ImportError:
raise ImportError(
'No module named psycopg2. Please install either '
'psycopg2 or psycopg2-binary package for CPython '
'or psycopg2cffi for Pypy.'
)
for package in ['psycopg2', 'psycopg2-binary', 'psycopg2cffi']:
try:
if get_distribution(package).parsed_version < parse_version('2.5'):
raise ImportError('Minimum required version for psycopg2 is 2.5')
break
except DistributionNotFound:
pass
__version__ = get_distribution('hs-sqlalchemy-redshift').version
from sqlalchemy.dialects import registry
registry.register("redshift", "sqlalchemy_redshift.dialect", "RedshiftDialect")
registry.register(
"redshift.psycopg2", "sqlalchemy_redshift.dialect", "RedshiftDialect"
)
| [
6738,
279,
10025,
62,
37540,
1330,
27484,
3673,
21077,
11,
651,
62,
17080,
3890,
11,
21136,
62,
9641,
198,
198,
28311,
25,
198,
220,
220,
220,
1330,
17331,
22163,
70,
17,
220,
1303,
645,
20402,
25,
376,
21844,
198,
16341,
17267,
12331,
25,
198,
220,
220,
220,
5298,
17267,
12331,
7,
198,
220,
220,
220,
220,
220,
220,
220,
705,
2949,
8265,
3706,
17331,
22163,
70,
17,
13,
4222,
2721,
2035,
705,
198,
220,
220,
220,
220,
220,
220,
220,
705,
13764,
22163,
70,
17,
393,
17331,
22163,
70,
17,
12,
39491,
5301,
329,
16932,
7535,
705,
198,
220,
220,
220,
220,
220,
220,
220,
705,
273,
17331,
22163,
70,
17,
66,
487,
72,
329,
350,
4464,
88,
2637,
198,
220,
220,
220,
1267,
198,
198,
1640,
5301,
287,
37250,
13764,
22163,
70,
17,
3256,
705,
13764,
22163,
70,
17,
12,
39491,
3256,
705,
13764,
22163,
70,
17,
66,
487,
72,
6,
5974,
198,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
611,
651,
62,
17080,
3890,
7,
26495,
737,
79,
945,
276,
62,
9641,
1279,
21136,
62,
9641,
10786,
17,
13,
20,
6,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
5298,
17267,
12331,
10786,
44046,
2672,
2196,
329,
17331,
22163,
70,
17,
318,
362,
13,
20,
11537,
198,
220,
220,
220,
220,
220,
220,
220,
2270,
198,
220,
220,
220,
2845,
27484,
3673,
21077,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1208,
198,
198,
834,
9641,
834,
796,
651,
62,
17080,
3890,
10786,
11994,
12,
25410,
282,
26599,
12,
445,
30846,
27691,
9641,
198,
198,
6738,
44161,
282,
26599,
13,
38969,
478,
82,
1330,
20478,
198,
198,
2301,
4592,
13,
30238,
7203,
445,
30846,
1600,
366,
25410,
282,
26599,
62,
445,
30846,
13,
38969,
478,
1600,
366,
7738,
30846,
24400,
478,
4943,
198,
2301,
4592,
13,
30238,
7,
198,
220,
220,
220,
366,
445,
30846,
13,
13764,
22163,
70,
17,
1600,
366,
25410,
282,
26599,
62,
445,
30846,
13,
38969,
478,
1600,
366,
7738,
30846,
24400,
478,
1,
198,
8,
198
] | 2.594203 | 345 |
# -*- coding: utf-8 -*-
def message(age: int = 0, name: str = 'stranger') -> str:
return f'Hello {name}, you are {age} years old'
| [
2,
532,
9,
12,
19617,
25,
3384,
69,
12,
23,
532,
9,
12,
198,
4299,
3275,
7,
496,
25,
493,
796,
657,
11,
1438,
25,
965,
796,
705,
2536,
2564,
11537,
4613,
965,
25,
198,
220,
220,
220,
1441,
277,
6,
15496,
1391,
3672,
5512,
345,
389,
1391,
496,
92,
812,
1468,
6,
198
] | 2.481481 | 54 |
"""
This module contains the top level API for managing the project/file templates.
"""
import json
import logging
import os
import re
from binaryornot.check import is_binary
from hackedit.app import settings
def create(template, dest_dir, answers):
"""
Creates a file/project from the specified template, at the specified directory.
:param template: Template data.
:param dest_dir: Destination directory where to create the file/project
:param answers: Dict of answers for substitution variables
"""
def get_paths(root, path, src_dir, dest_dir):
src_path = os.path.join(root, path)
rel_path = os.path.relpath(src_path, src_dir)
dst_path = os.path.join(dest_dir, rel_path)
return src_path, dst_path
def get_file_encoding(path):
if is_binary(path):
return 'binary'
try:
encodings = template['encodings']
except KeyError:
encodings = ['utf-8', 'cp1252']
for encoding in encodings:
try:
with open(path, encoding=encoding) as f:
f.read()
except UnicodeDecodeError:
continue
else:
return encoding
def open_file(path, encoding, to_write=None):
if encoding == 'binary':
if to_write is None:
mode = 'rb'
else:
mode = 'wb'
encoding = None
else:
if to_write is None:
mode = 'r'
else:
mode = 'w'
content = None
with open(path, mode, encoding=encoding) as f:
if to_write is not None:
f.write(to_write)
else:
content = f.read()
return content
def subsitute_vars(string):
for var, value in answers.items():
string = re.sub('@%s@' % var, value, string)
return string
ret_val = []
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
src_dir = template['path']
for root, dirs, files in os.walk(src_dir):
for file in files:
if file == 'template.json' or file.endswith('.pyc'):
continue
src, dst = get_paths(root, file, src_dir, dest_dir)
dst = subsitute_vars(dst)
encoding = get_file_encoding(src)
try:
content = open_file(src, encoding)
except OSError:
_logger().exception('failed to open file: %r', src)
if encoding != 'binary':
content = subsitute_vars(content)
if file == 'btpad_btn_img_0.png':
print(len(content), encoding)
try:
open_file(dst, encoding, to_write=content)
except PermissionError:
_logger().exception('failed to write file: %r', dst)
else:
ret_val.append(dst)
assert open_file(dst, encoding) == content
for directory in dirs:
src, dst = get_paths(root, directory, src_dir, dest_dir)
dst = subsitute_vars(dst)
try:
os.mkdir(dst)
except PermissionError:
_logger().exception('failed to create directory: %r', dst)
return ret_val
def get_sources():
"""
Returns the template sources (directory associated with a label).
"""
s = settings.load()
tmpl_sources = s.value('_templates/sources', '[]')
tmpl_sources = json.loads(tmpl_sources)
return sorted(tmpl_sources, key=lambda x: x['label'])
def add_source(label, path):
"""
Adds a template source
:param label: Name of the template source.
:param path: Path of the template source.
"""
tmpl_sources = get_sources()
tmpl_sources.append({'label': label, 'path': path})
s = settings.load()
s.setValue('_templates/sources', json.dumps(tmpl_sources))
def rm_source(label):
"""
Removes the specified template source.
:param label: Name of the template source to remove.
"""
tmpl_sources = get_sources()
for src in tmpl_sources:
if src['label'] == label:
tmpl_sources.remove(src)
s = settings.load()
s.setValue('_templates/sources', json.dumps(tmpl_sources))
def clear_sources():
"""
Clear template sources.
"""
s = settings.load()
s.setValue('_templates/sources', json.dumps([]))
def get_template(source, template):
"""
Returns the specified template data.
"""
for t in get_templates(source_filter=source):
if t['name'] == template:
return t
return None
def _logger():
return logging.getLogger(__name__)
if __name__ == '__main__':
clear_sources()
add_source('COBOL', '/home/colin/Documents/hackedit-cobol/hackedit_cobol/templates')
add_source('Python', '/home/colin/Documents/hackedit-python/hackedit_python/templates')
for tmpl in get_templates():
print(json.dumps(tmpl, indent=4, sort_keys=True))
| [
37811,
198,
1212,
8265,
4909,
262,
1353,
1241,
7824,
329,
11149,
262,
1628,
14,
7753,
24019,
13,
198,
37811,
198,
11748,
33918,
198,
11748,
18931,
198,
11748,
28686,
198,
11748,
302,
198,
198,
6738,
13934,
1211,
313,
13,
9122,
1330,
318,
62,
39491,
198,
198,
6738,
19957,
270,
13,
1324,
1330,
6460,
628,
198,
4299,
2251,
7,
28243,
11,
2244,
62,
15908,
11,
7429,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
7921,
274,
257,
2393,
14,
16302,
422,
262,
7368,
11055,
11,
379,
262,
7368,
8619,
13,
628,
220,
220,
220,
1058,
17143,
11055,
25,
37350,
1366,
13,
198,
220,
220,
220,
1058,
17143,
2244,
62,
15908,
25,
45657,
8619,
810,
284,
2251,
262,
2393,
14,
16302,
198,
220,
220,
220,
1058,
17143,
7429,
25,
360,
713,
286,
7429,
329,
32097,
9633,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
825,
651,
62,
6978,
82,
7,
15763,
11,
3108,
11,
12351,
62,
15908,
11,
2244,
62,
15908,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
12351,
62,
6978,
796,
28686,
13,
6978,
13,
22179,
7,
15763,
11,
3108,
8,
198,
220,
220,
220,
220,
220,
220,
220,
823,
62,
6978,
796,
28686,
13,
6978,
13,
2411,
6978,
7,
10677,
62,
6978,
11,
12351,
62,
15908,
8,
198,
220,
220,
220,
220,
220,
220,
220,
29636,
62,
6978,
796,
28686,
13,
6978,
13,
22179,
7,
16520,
62,
15908,
11,
823,
62,
6978,
8,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
12351,
62,
6978,
11,
29636,
62,
6978,
628,
220,
220,
220,
825,
651,
62,
7753,
62,
12685,
7656,
7,
6978,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
611,
318,
62,
39491,
7,
6978,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1441,
705,
39491,
6,
198,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2207,
375,
654,
796,
11055,
17816,
12685,
375,
654,
20520,
198,
220,
220,
220,
220,
220,
220,
220,
2845,
7383,
12331,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2207,
375,
654,
796,
37250,
40477,
12,
23,
3256,
705,
13155,
1065,
4309,
20520,
628,
220,
220,
220,
220,
220,
220,
220,
329,
21004,
287,
2207,
375,
654,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
351,
1280,
7,
6978,
11,
21004,
28,
12685,
7656,
8,
355,
277,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
277,
13,
961,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2845,
34371,
10707,
1098,
12331,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2555,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1441,
21004,
628,
220,
220,
220,
825,
1280,
62,
7753,
7,
6978,
11,
21004,
11,
284,
62,
13564,
28,
14202,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
611,
21004,
6624,
705,
39491,
10354,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
284,
62,
13564,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4235,
796,
705,
26145,
6,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4235,
796,
705,
39346,
6,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
21004,
796,
6045,
198,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
284,
62,
13564,
318,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4235,
796,
705,
81,
6,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4235,
796,
705,
86,
6,
198,
220,
220,
220,
220,
220,
220,
220,
2695,
796,
6045,
198,
220,
220,
220,
220,
220,
220,
220,
351,
1280,
7,
6978,
11,
4235,
11,
21004,
28,
12685,
7656,
8,
355,
277,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
284,
62,
13564,
318,
407,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
277,
13,
13564,
7,
1462,
62,
13564,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2695,
796,
277,
13,
961,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
2695,
628,
220,
220,
220,
825,
6352,
3678,
62,
85,
945,
7,
8841,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
329,
1401,
11,
1988,
287,
7429,
13,
23814,
33529,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4731,
796,
302,
13,
7266,
10786,
31,
4,
82,
31,
6,
4064,
1401,
11,
1988,
11,
4731,
8,
198,
220,
220,
220,
220,
220,
220,
220,
1441,
4731,
628,
220,
220,
220,
1005,
62,
2100,
796,
17635,
628,
220,
220,
220,
611,
407,
28686,
13,
6978,
13,
1069,
1023,
7,
16520,
62,
15908,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
28686,
13,
76,
4335,
17062,
7,
16520,
62,
15908,
8,
198,
220,
220,
220,
12351,
62,
15908,
796,
11055,
17816,
6978,
20520,
198,
220,
220,
220,
329,
6808,
11,
288,
17062,
11,
3696,
287,
28686,
13,
11152,
7,
10677,
62,
15908,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
329,
2393,
287,
3696,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
2393,
6624,
705,
28243,
13,
17752,
6,
393,
2393,
13,
437,
2032,
342,
7,
4458,
9078,
66,
6,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2555,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
12351,
11,
29636,
796,
651,
62,
6978,
82,
7,
15763,
11,
2393,
11,
12351,
62,
15908,
11,
2244,
62,
15908,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
29636,
796,
6352,
3678,
62,
85,
945,
7,
67,
301,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
21004,
796,
651,
62,
7753,
62,
12685,
7656,
7,
10677,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2695,
796,
1280,
62,
7753,
7,
10677,
11,
21004,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2845,
440,
5188,
81,
1472,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
1069,
4516,
10786,
47904,
284,
1280,
2393,
25,
4064,
81,
3256,
12351,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
21004,
14512,
705,
39491,
10354,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2695,
796,
6352,
3678,
62,
85,
945,
7,
11299,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
2393,
6624,
705,
18347,
15636,
62,
46118,
62,
9600,
62,
15,
13,
11134,
10354,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3601,
7,
11925,
7,
11299,
828,
21004,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1280,
62,
7753,
7,
67,
301,
11,
21004,
11,
284,
62,
13564,
28,
11299,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2845,
2448,
3411,
12331,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
1069,
4516,
10786,
47904,
284,
3551,
2393,
25,
4064,
81,
3256,
29636,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1005,
62,
2100,
13,
33295,
7,
67,
301,
8,
628,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
6818,
1280,
62,
7753,
7,
67,
301,
11,
21004,
8,
6624,
2695,
628,
220,
220,
220,
220,
220,
220,
220,
329,
8619,
287,
288,
17062,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
12351,
11,
29636,
796,
651,
62,
6978,
82,
7,
15763,
11,
8619,
11,
12351,
62,
15908,
11,
2244,
62,
15908,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
29636,
796,
6352,
3678,
62,
85,
945,
7,
67,
301,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
28686,
13,
28015,
15908,
7,
67,
301,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2845,
2448,
3411,
12331,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4808,
6404,
1362,
22446,
1069,
4516,
10786,
47904,
284,
2251,
8619,
25,
4064,
81,
3256,
29636,
8,
198,
220,
220,
220,
1441,
1005,
62,
2100,
628,
198,
4299,
651,
62,
82,
2203,
33529,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
16409,
262,
11055,
4237,
357,
34945,
3917,
351,
257,
6167,
737,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
264,
796,
6460,
13,
2220,
3419,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
796,
264,
13,
8367,
10786,
62,
11498,
17041,
14,
82,
2203,
3256,
705,
21737,
11537,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
796,
33918,
13,
46030,
7,
17209,
489,
62,
82,
2203,
8,
198,
220,
220,
220,
1441,
23243,
7,
17209,
489,
62,
82,
2203,
11,
1994,
28,
50033,
2124,
25,
2124,
17816,
18242,
6,
12962,
628,
198,
4299,
751,
62,
10459,
7,
18242,
11,
3108,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
34333,
257,
11055,
2723,
628,
220,
220,
220,
1058,
17143,
6167,
25,
6530,
286,
262,
11055,
2723,
13,
198,
220,
220,
220,
1058,
17143,
3108,
25,
10644,
286,
262,
11055,
2723,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
796,
651,
62,
82,
2203,
3419,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
13,
33295,
15090,
6,
18242,
10354,
6167,
11,
705,
6978,
10354,
3108,
30072,
198,
220,
220,
220,
264,
796,
6460,
13,
2220,
3419,
198,
220,
220,
220,
264,
13,
2617,
11395,
10786,
62,
11498,
17041,
14,
82,
2203,
3256,
33918,
13,
67,
8142,
7,
17209,
489,
62,
82,
2203,
4008,
628,
198,
4299,
42721,
62,
10459,
7,
18242,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
3982,
5241,
262,
7368,
11055,
2723,
13,
628,
220,
220,
220,
1058,
17143,
6167,
25,
6530,
286,
262,
11055,
2723,
284,
4781,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
796,
651,
62,
82,
2203,
3419,
198,
220,
220,
220,
329,
12351,
287,
256,
76,
489,
62,
82,
2203,
25,
198,
220,
220,
220,
220,
220,
220,
220,
611,
12351,
17816,
18242,
20520,
6624,
6167,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
256,
76,
489,
62,
82,
2203,
13,
28956,
7,
10677,
8,
198,
220,
220,
220,
264,
796,
6460,
13,
2220,
3419,
198,
220,
220,
220,
264,
13,
2617,
11395,
10786,
62,
11498,
17041,
14,
82,
2203,
3256,
33918,
13,
67,
8142,
7,
17209,
489,
62,
82,
2203,
4008,
628,
198,
4299,
1598,
62,
82,
2203,
33529,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
11459,
11055,
4237,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
264,
796,
6460,
13,
2220,
3419,
198,
220,
220,
220,
264,
13,
2617,
11395,
10786,
62,
11498,
17041,
14,
82,
2203,
3256,
33918,
13,
67,
8142,
7,
21737,
4008,
628,
198,
198,
4299,
651,
62,
28243,
7,
10459,
11,
11055,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
16409,
262,
7368,
11055,
1366,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
329,
256,
287,
651,
62,
11498,
17041,
7,
10459,
62,
24455,
28,
10459,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
611,
256,
17816,
3672,
20520,
6624,
11055,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1441,
256,
198,
220,
220,
220,
1441,
6045,
628,
198,
4299,
4808,
6404,
1362,
33529,
198,
220,
220,
220,
1441,
18931,
13,
1136,
11187,
1362,
7,
834,
3672,
834,
8,
628,
198,
361,
11593,
3672,
834,
6624,
705,
834,
12417,
834,
10354,
198,
220,
220,
220,
1598,
62,
82,
2203,
3419,
198,
220,
220,
220,
751,
62,
10459,
10786,
8220,
33,
3535,
3256,
220,
31051,
11195,
14,
4033,
259,
14,
38354,
14,
71,
6021,
270,
12,
66,
672,
349,
14,
71,
6021,
270,
62,
66,
672,
349,
14,
11498,
17041,
11537,
198,
220,
220,
220,
751,
62,
10459,
10786,
37906,
3256,
31051,
11195,
14,
4033,
259,
14,
38354,
14,
71,
6021,
270,
12,
29412,
14,
71,
6021,
270,
62,
29412,
14,
11498,
17041,
11537,
198,
220,
220,
220,
329,
256,
76,
489,
287,
651,
62,
11498,
17041,
33529,
198,
220,
220,
220,
220,
220,
220,
220,
3601,
7,
17752,
13,
67,
8142,
7,
17209,
489,
11,
33793,
28,
19,
11,
3297,
62,
13083,
28,
17821,
4008,
198
] | 2.157648 | 2,347 |
"""
Convert video format x to MP4/H.264.
"""
import os
import sys
import logging
from .videometainfo import VideoMetaInfo
from .utils import sizeof_fmt, time_fmt, find_files, check_dependencies, call, ffmpeg
logger = logging.getLogger(__name__)
class VideoToMP4:
"""To Mp4"""
SUPPORTED_EXTENSIONS = ".wmv, .avi, .mkv, .mov, .flv"
RULES = {
".wmv": "-c:v libx264 -crf 19 ",
".avi":
"-vf yadif=1 -c:v h264_nvenc -preset slow -tune film -crf 17",
".mkv": "-c copy",
".mov": "-vcodec h264 -acodec aac -strict -2 -crf 19 ",
".flv": " -r 20 ",
}
def process(self, video_file: str):
"""Convert video files to MP4 container format."""
name = os.path.splitext(video_file)[0]
ext = os.path.splitext(video_file)[1]
new_name = f"{name}.mp4"
if os.path.exists(new_name):
logger.info(f"Skipping file {new_name} already exists!")
elif ext not in VideoToMP4.RULES:
logger.error(f"Skipping unsupported type {ext}!")
else:
print(f'Convert {ext} to MP4 {new_name} ... ')
meta_info = VideoMetaInfo(video_file)
rule = VideoToMP4.RULES[ext]
flags = "-movflags +faststart -pix_fmt yuv420p"
ffmpeg(
f'-i "{video_file}" {flags} {rule} -metadata date="{meta_info.original_date}" "{new_name}"'
)
def file(self, filename: str) -> None:
logger.debug(f"converting file {filename}")
self.process(filename)
def directory(self, path: str, extension: str) -> int:
files = find_files(path, extension)
if len(files) < 1:
print("No matching files found in directory!", file=sys.stderr)
else:
for f in files:
self.file(f)
| [
37811,
198,
3103,
1851,
2008,
5794,
2124,
284,
4904,
19,
14,
39,
13,
18897,
13,
198,
37811,
198,
198,
11748,
28686,
198,
11748,
25064,
198,
11748,
18931,
198,
198,
6738,
764,
85,
485,
908,
391,
6513,
1330,
7623,
48526,
12360,
198,
6738,
764,
26791,
1330,
39364,
62,
69,
16762,
11,
640,
62,
69,
16762,
11,
1064,
62,
16624,
11,
2198,
62,
45841,
3976,
11,
869,
11,
31246,
43913,
198,
198,
6404,
1362,
796,
18931,
13,
1136,
11187,
1362,
7,
834,
3672,
834,
8,
628,
198,
4871,
7623,
2514,
7378,
19,
25,
198,
220,
220,
220,
37227,
2514,
337,
79,
19,
37811,
198,
220,
220,
220,
43333,
1961,
62,
13918,
16938,
11053,
796,
27071,
26377,
85,
11,
764,
15820,
11,
764,
28015,
85,
11,
764,
76,
709,
11,
764,
2704,
85,
1,
198,
220,
220,
220,
371,
6239,
1546,
796,
1391,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
26377,
85,
1298,
27444,
66,
25,
85,
9195,
87,
18897,
532,
6098,
69,
678,
33172,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
15820,
1298,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27444,
85,
69,
331,
324,
361,
28,
16,
532,
66,
25,
85,
289,
18897,
62,
77,
574,
66,
532,
18302,
316,
3105,
532,
83,
1726,
2646,
532,
6098,
69,
1596,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
28015,
85,
1298,
27444,
66,
4866,
1600,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
76,
709,
1298,
27444,
85,
19815,
721,
289,
18897,
532,
330,
375,
721,
257,
330,
532,
301,
2012,
532,
17,
532,
6098,
69,
678,
33172,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
27071,
2704,
85,
1298,
366,
532,
81,
1160,
33172,
198,
220,
220,
220,
220,
220,
220,
220,
1782,
628,
220,
220,
220,
825,
1429,
7,
944,
11,
2008,
62,
7753,
25,
965,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
3103,
1851,
2008,
3696,
284,
4904,
19,
9290,
5794,
526,
15931,
628,
220,
220,
220,
220,
220,
220,
220,
1438,
796,
28686,
13,
6978,
13,
22018,
578,
742,
7,
15588,
62,
7753,
38381,
15,
60,
198,
220,
220,
220,
220,
220,
220,
220,
1070,
796,
28686,
13,
6978,
13,
22018,
578,
742,
7,
15588,
62,
7753,
38381,
16,
60,
198,
220,
220,
220,
220,
220,
220,
220,
649,
62,
3672,
796,
277,
1,
90,
3672,
27422,
3149,
19,
1,
198,
220,
220,
220,
220,
220,
220,
220,
611,
28686,
13,
6978,
13,
1069,
1023,
7,
3605,
62,
3672,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
49706,
13,
10951,
7,
69,
1,
50,
4106,
2105,
2393,
1391,
3605,
62,
3672,
92,
1541,
7160,
2474,
8,
198,
220,
220,
220,
220,
220,
220,
220,
1288,
361,
1070,
407,
287,
7623,
2514,
7378,
19,
13,
49,
6239,
1546,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
49706,
13,
18224,
7,
69,
1,
50,
4106,
2105,
24222,
2099,
1391,
2302,
92,
2474,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3601,
7,
69,
6,
3103,
1851,
1391,
2302,
92,
284,
4904,
19,
1391,
3605,
62,
3672,
92,
2644,
705,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
13634,
62,
10951,
796,
7623,
48526,
12360,
7,
15588,
62,
7753,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3896,
796,
7623,
2514,
7378,
19,
13,
49,
6239,
1546,
58,
2302,
60,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
9701,
796,
27444,
76,
709,
33152,
1343,
7217,
9688,
532,
79,
844,
62,
69,
16762,
331,
14795,
27211,
79,
1,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
31246,
43913,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
277,
29001,
72,
45144,
15588,
62,
7753,
36786,
1391,
33152,
92,
1391,
25135,
92,
532,
38993,
3128,
2625,
90,
28961,
62,
10951,
13,
14986,
62,
4475,
36786,
45144,
3605,
62,
3672,
92,
30543,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1267,
628,
220,
220,
220,
825,
2393,
7,
944,
11,
29472,
25,
965,
8,
4613,
6045,
25,
198,
220,
220,
220,
220,
220,
220,
220,
49706,
13,
24442,
7,
69,
1,
1102,
48820,
2393,
1391,
34345,
92,
4943,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
14681,
7,
34345,
8,
628,
220,
220,
220,
825,
8619,
7,
944,
11,
3108,
25,
965,
11,
7552,
25,
965,
8,
4613,
493,
25,
198,
220,
220,
220,
220,
220,
220,
220,
3696,
796,
1064,
62,
16624,
7,
6978,
11,
7552,
8,
198,
220,
220,
220,
220,
220,
220,
220,
611,
18896,
7,
16624,
8,
1279,
352,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3601,
7203,
2949,
12336,
3696,
1043,
287,
8619,
40754,
2393,
28,
17597,
13,
301,
1082,
81,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
329,
277,
287,
3696,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
7753,
7,
69,
8,
198
] | 2.045455 | 902 |
from setuptools import setup
setup(
name='parasol',
dependency_links=[
],
install_requires=[
]
)
| [
6738,
900,
37623,
10141,
1330,
9058,
198,
40406,
7,
198,
220,
220,
220,
1438,
11639,
1845,
292,
349,
3256,
198,
220,
220,
220,
20203,
62,
28751,
41888,
198,
220,
220,
220,
16589,
198,
220,
220,
220,
2721,
62,
47911,
41888,
198,
220,
220,
220,
2361,
198,
8,
198
] | 2.4375 | 48 |
# Generated by Django 3.2.8 on 2021-11-02 12:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0006_auto_20211102_1928'),
]
operations = [
migrations.RemoveField(
model_name='profile',
name='skill',
),
migrations.AddField(
model_name='profile',
name='tags',
field=models.ManyToManyField(blank=True, to='app.Tag'),
),
migrations.DeleteModel(
name='Skill',
),
]
| [
2,
2980,
515,
416,
37770,
513,
13,
17,
13,
23,
319,
33448,
12,
1157,
12,
2999,
1105,
25,
3510,
198,
198,
6738,
42625,
14208,
13,
9945,
1330,
15720,
602,
11,
4981,
628,
198,
4871,
36991,
7,
76,
3692,
602,
13,
44,
4254,
2599,
628,
220,
220,
220,
20086,
796,
685,
198,
220,
220,
220,
220,
220,
220,
220,
19203,
1324,
3256,
705,
830,
21,
62,
23736,
62,
19004,
1157,
15377,
62,
1129,
2078,
33809,
198,
220,
220,
220,
2361,
628,
220,
220,
220,
4560,
796,
685,
198,
220,
220,
220,
220,
220,
220,
220,
15720,
602,
13,
27914,
15878,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2746,
62,
3672,
11639,
13317,
3256,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1438,
11639,
42401,
3256,
198,
220,
220,
220,
220,
220,
220,
220,
10612,
198,
220,
220,
220,
220,
220,
220,
220,
15720,
602,
13,
4550,
15878,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2746,
62,
3672,
11639,
13317,
3256,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1438,
11639,
31499,
3256,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2214,
28,
27530,
13,
7085,
2514,
7085,
15878,
7,
27190,
28,
17821,
11,
284,
11639,
1324,
13,
24835,
33809,
198,
220,
220,
220,
220,
220,
220,
220,
10612,
198,
220,
220,
220,
220,
220,
220,
220,
15720,
602,
13,
38727,
17633,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1438,
11639,
35040,
3256,
198,
220,
220,
220,
220,
220,
220,
220,
10612,
198,
220,
220,
220,
2361,
198
] | 2.057971 | 276 |
import csv
import io
import json
import logging
import os
import warnings
from collections import defaultdict
from ..utils.exceptions import OasisException
from ..utils.log import oasis_log
from .files import GENERAL_SETTINGS_FILE, GUL_SUMMARIES_FILE, IL_SUMMARIES_FILE, MODEL_SETTINGS_FILE
def _get_summaries(summary_file):
"""
Get a list representation of a summary file.
"""
summaries_dict = defaultdict(lambda: {'leccalc': {}})
with io.open(summary_file, 'r', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
id = int(row[0])
if row[1].startswith('leccalc'):
summaries_dict[id]['leccalc'][row[1]] = row[2].lower() == 'true'
else:
summaries_dict[id][row[1]] = row[2].lower() == 'true'
summaries = list()
for id in sorted(summaries_dict):
summaries_dict[id]['id'] = id
summaries.append(summaries_dict[id])
return summaries
def read_analysis_settings(analysis_settings_fp, il_files_exist=False,
ri_files_exist=False):
"""Read the analysis settings file"""
# Load analysis_settings file
try:
# Load as a json
with io.open(analysis_settings_fp, 'r', encoding='utf-8') as f:
analysis_settings = json.load(f)
# Extract the analysis_settings part within the json
if analysis_settings.get('analysis_settings'):
analysis_settings = analysis_settings['analysis_settings']
except (IOError, TypeError, ValueError):
raise OasisException('Invalid analysis settings file or file path: {}.'.format(
analysis_settings_fp))
# Reset il_output if the files are not there
if not il_files_exist or 'il_output' not in analysis_settings:
# No insured loss output
analysis_settings['il_output'] = False
analysis_settings['il_summaries'] = []
# Same for ri_output
if not ri_files_exist or 'ri_output' not in analysis_settings:
# No reinsured loss output
analysis_settings['ri_output'] = False
analysis_settings['ri_summaries'] = []
# If we want ri_output, we will need il_output, which needs il_files
if analysis_settings['ri_output'] and not analysis_settings['il_output']:
if not il_files_exist:
warnings.warn("ri_output selected, but il files not found")
analysis_settings['ri_output'] = False
analysis_settings['ri_summaries'] = []
else:
analysis_settings['il_output'] = True
# guard - Check if at least one output type is selected
if not any([
analysis_settings['gul_output'] if 'gul_output' in analysis_settings else False,
analysis_settings['il_output'] if 'il_output' in analysis_settings else False,
analysis_settings['ri_output'] if 'ri_output' in analysis_settings else False,
]):
raise OasisException(
'No valid output settings in: {}'.format(analysis_settings_fp))
return analysis_settings
| [
11748,
269,
21370,
198,
11748,
33245,
198,
11748,
33918,
198,
11748,
18931,
198,
11748,
28686,
198,
11748,
14601,
198,
198,
6738,
17268,
1330,
4277,
11600,
198,
198,
6738,
11485,
26791,
13,
1069,
11755,
1330,
440,
17765,
16922,
198,
6738,
11485,
26791,
13,
6404,
1330,
267,
17765,
62,
6404,
198,
6738,
764,
16624,
1330,
41877,
62,
28480,
51,
20754,
62,
25664,
11,
402,
6239,
62,
50,
5883,
40569,
11015,
62,
25664,
11,
14639,
62,
50,
5883,
40569,
11015,
62,
25664,
11,
19164,
3698,
62,
28480,
51,
20754,
62,
25664,
628,
198,
4299,
4808,
1136,
62,
82,
13929,
3166,
7,
49736,
62,
7753,
2599,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
3497,
257,
1351,
10552,
286,
257,
10638,
2393,
13,
198,
220,
220,
220,
37227,
198,
220,
220,
220,
30114,
3166,
62,
11600,
796,
4277,
11600,
7,
50033,
25,
1391,
6,
293,
535,
282,
66,
10354,
1391,
11709,
8,
628,
220,
220,
220,
351,
33245,
13,
9654,
7,
49736,
62,
7753,
11,
705,
81,
3256,
21004,
11639,
40477,
12,
23,
11537,
355,
269,
21370,
7753,
25,
198,
220,
220,
220,
220,
220,
220,
220,
9173,
796,
269,
21370,
13,
46862,
7,
40664,
7753,
8,
198,
220,
220,
220,
220,
220,
220,
220,
329,
5752,
287,
9173,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4686,
796,
493,
7,
808,
58,
15,
12962,
628,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
5752,
58,
16,
4083,
9688,
2032,
342,
10786,
293,
535,
282,
66,
6,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30114,
3166,
62,
11600,
58,
312,
7131,
6,
293,
535,
282,
66,
6,
7131,
808,
58,
16,
11907,
796,
5752,
58,
17,
4083,
21037,
3419,
6624,
705,
7942,
6,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
30114,
3166,
62,
11600,
58,
312,
7131,
808,
58,
16,
11907,
796,
5752,
58,
17,
4083,
21037,
3419,
6624,
705,
7942,
6,
628,
220,
220,
220,
30114,
3166,
796,
1351,
3419,
198,
220,
220,
220,
329,
4686,
287,
23243,
7,
82,
13929,
3166,
62,
11600,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
30114,
3166,
62,
11600,
58,
312,
7131,
6,
312,
20520,
796,
4686,
198,
220,
220,
220,
220,
220,
220,
220,
30114,
3166,
13,
33295,
7,
82,
13929,
3166,
62,
11600,
58,
312,
12962,
628,
220,
220,
220,
1441,
30114,
3166,
628,
198,
198,
4299,
1100,
62,
20930,
62,
33692,
7,
20930,
62,
33692,
62,
46428,
11,
4229,
62,
16624,
62,
38476,
28,
25101,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
374,
72,
62,
16624,
62,
38476,
28,
25101,
2599,
198,
220,
220,
220,
37227,
5569,
262,
3781,
6460,
2393,
37811,
628,
198,
220,
220,
220,
1303,
8778,
3781,
62,
33692,
2393,
198,
220,
220,
220,
1949,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
8778,
355,
257,
33918,
198,
220,
220,
220,
220,
220,
220,
220,
351,
33245,
13,
9654,
7,
20930,
62,
33692,
62,
46428,
11,
705,
81,
3256,
21004,
11639,
40477,
12,
23,
11537,
355,
277,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
796,
33918,
13,
2220,
7,
69,
8,
628,
220,
220,
220,
220,
220,
220,
220,
1303,
29677,
262,
3781,
62,
33692,
636,
1626,
262,
33918,
198,
220,
220,
220,
220,
220,
220,
220,
611,
3781,
62,
33692,
13,
1136,
10786,
20930,
62,
33692,
6,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
796,
3781,
62,
33692,
17816,
20930,
62,
33692,
20520,
628,
220,
220,
220,
2845,
357,
9399,
12331,
11,
5994,
12331,
11,
11052,
12331,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
5298,
440,
17765,
16922,
10786,
44651,
3781,
6460,
2393,
393,
2393,
3108,
25,
23884,
2637,
13,
18982,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
62,
46428,
4008,
628,
220,
220,
220,
1303,
30027,
4229,
62,
22915,
611,
262,
3696,
389,
407,
612,
198,
220,
220,
220,
611,
407,
4229,
62,
16624,
62,
38476,
393,
705,
346,
62,
22915,
6,
407,
287,
3781,
62,
33692,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
1400,
31977,
2994,
5072,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
346,
62,
22915,
20520,
796,
10352,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
346,
62,
82,
13929,
3166,
20520,
796,
17635,
628,
220,
220,
220,
1303,
16766,
329,
374,
72,
62,
22915,
198,
220,
220,
220,
611,
407,
374,
72,
62,
16624,
62,
38476,
393,
705,
380,
62,
22915,
6,
407,
287,
3781,
62,
33692,
25,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
1400,
302,
28409,
2994,
5072,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
22915,
20520,
796,
10352,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
82,
13929,
3166,
20520,
796,
17635,
628,
220,
220,
220,
1303,
1002,
356,
765,
374,
72,
62,
22915,
11,
356,
481,
761,
4229,
62,
22915,
11,
543,
2476,
4229,
62,
16624,
198,
220,
220,
220,
611,
3781,
62,
33692,
17816,
380,
62,
22915,
20520,
290,
407,
3781,
62,
33692,
17816,
346,
62,
22915,
6,
5974,
198,
220,
220,
220,
220,
220,
220,
220,
611,
407,
4229,
62,
16624,
62,
38476,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
14601,
13,
40539,
7203,
380,
62,
22915,
6163,
11,
475,
4229,
3696,
407,
1043,
4943,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
22915,
20520,
796,
10352,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
82,
13929,
3166,
20520,
796,
17635,
198,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
346,
62,
22915,
20520,
796,
6407,
628,
220,
220,
220,
1303,
4860,
532,
6822,
611,
379,
1551,
530,
5072,
2099,
318,
6163,
198,
220,
220,
220,
611,
407,
597,
26933,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
70,
377,
62,
22915,
20520,
611,
705,
70,
377,
62,
22915,
6,
287,
3781,
62,
33692,
2073,
10352,
11,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
346,
62,
22915,
20520,
611,
705,
346,
62,
22915,
6,
287,
3781,
62,
33692,
2073,
10352,
11,
198,
220,
220,
220,
220,
220,
220,
220,
3781,
62,
33692,
17816,
380,
62,
22915,
20520,
611,
705,
380,
62,
22915,
6,
287,
3781,
62,
33692,
2073,
10352,
11,
198,
220,
220,
220,
2361,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
5298,
440,
17765,
16922,
7,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
705,
2949,
4938,
5072,
6460,
287,
25,
23884,
4458,
18982,
7,
20930,
62,
33692,
62,
46428,
4008,
628,
220,
220,
220,
1441,
3781,
62,
33692,
198
] | 2.533773 | 1,214 |
#!/usr/bin/env python
#--------------------------------------------------------------------------------
#Changes the sky coordinates (x,y,z) to the disk coordinates (x_d,y_d,z_d)
#The x axis is the rotation axis
def FUN_rotation(x,y,z):
x_d = x
y_d = y*np.cos(inc) - z*np.sin(inc)
z_d = y*np.sin(inc) + z*np.cos(inc)
return x_d,y_d,z_d
#--------------------------------------------------------------------------------
#Radiative transfer equation
def FUN_intensity(I,z,x,y,optde):
x_d,y_d,z_d = FUN_rotation(x,y,z)
density = EQ_density(x_d,y_d,z_d)
amax = EQ_amax(x_d,y_d,z_d)
opa = function_ext(amax)
S = funcion_S([z_d,y_d,x_d])
# print ('x,y,z', x,y,z)
# print (S, x_d, y_d, z_d)
# print (optde(z))
dIdz = -S*opa*density*np.exp(-optde(z)) #z es la variable de integracion (debe ser evaluada en cualquier punto)
return dIdz
#--------------------------------------------------------------------------------
#Optical depth
def FUN_tau(tt,z,x,y):
x_d,y_d,z_d = FUN_rotation(x,y,z)
density = EQ_density(x_d,y_d,z_d)
amax = EQ_amax(x_d,y_d,z_d)
opa = function_ext(amax)
dtau = -opa*density
return dtau
#--------------------------------------------------------------------------------
def FUN_tau_zaxis(tt,z,x,y):
x_d,y_d,z_d = x,y,z
density = EQ_density(x_d,y_d,z_d)
amax = EQ_amax(x_d,y_d,z_d)
opa = function_ext(amax)
dtau = -opa*density
return dtau
#--------------------------------------------------------------------------------
#Black body radiation
def FUN_BB(nu,T):
# B = 2.*hP*nu**3/clight**2/( np.exp(hP*nu/kB/T) - 1.)
B = 1./( np.exp(hP*nu/kB/T) - 1.)
return B
#--------------------------------------------------------------------------------
def FUN_limits_mult(xx,yy):
Hout = EQ_Height(Rout)
lim_z = Rout*np.sin(inc) + 2.*Hout*np.cos(inc) #Based on the geometry of the disk
lim_y = Rout*np.cos(inc) + 2.*Hout*np.sin(inc) #Based on the geometry of the disk
z_arr = np.linspace(1.1*lim_z, -1.1*lim_z, 200)
z_crit = []
if ((np.abs(xx) <=Rout) and (np.abs(yy) <= lim_y)):
xd,yd,zd = FUN_rotation(xx,yy,z_arr)
crit = np.zeros((len(z_arr)))
###############################################################################
#Funciona pero podria ser optimizado
###############################################################################
for ii in range(len(z_arr)): #Crea un vector de densidad en la linea de vision
if (EQ_density(xd,yd[ii],zd[ii]) == 0.):
crit[ii] = 0
else:
crit[ii] = 1
for ii in range(len(z_arr)): #Ve los indices donde cambia de 0 a algun valor, o de algun valor a 0 (fronteras)
if ( (ii != 0) and (crit[ii] - crit[ii-1] != 0 )):
z_crit.append(z_arr[ii])
elif(ii == 0 and crit[0] == 1):
z_crit.append(z_arr[0])
###############################################################################
return z_crit
#--------------------------------------------------------------------------------
def FUN_creates_source_function(x_array,y_array):
#Arrays and limits
Hout = EQ_Height(Rout)
z_array = np.linspace(-2.*Hout, 2.*Hout, 200)
Sfunction = np.zeros((len(z_array),len(y_array),len(x_array)))
Temfunction = np.zeros((len(z_array),len(y_array),len(x_array)))
op_depth_p = np.zeros((len(y_array),len(x_array)))
#Computes the optical depth (perpendicular to the disk midplane)
for j in range(len(y_array)):
for i in range(len(x_array)):
if(x_array[i] == 0. and y_array[j] == 0.):
Sfunction[:,j,i] = 0.
Temfunction[:,j,i] = 0.
else:
rad = np.sqrt(x_array[i]**2 + y_array[j]**2)
Hscale = EQ_Height(rad)
z_integ = np.linspace(2.*Hscale,-2.*Hscale,200)
sol = odeint(FUN_tau_zaxis,0.,z_integ,args=(x_array[i],y_array[j])).T[0]
op_depth_p[j][i] = sol[len(z_integ)-1]
inter_opt = interpolate.interp1d(z_integ,sol,kind='linear', bounds_error=False,fill_value=0.)
for k in range(len(z_array)):
amax = EQ_amax(x_array[i],y_array[j],z_array[k])
albedo = function_alb(amax)
##########Temperature##########
Omega2 = Ggrav*Mstar/(rad*AU)**3
Teff4 = 3.*Mdot*Omega2/8./np.pi/sigmaB
Tacc4 = 3./4.*(7.*inter_opt(abs(z_array[k])) + 2./3.)*Teff4
Tirr4 = Tstar**4./4.*(Rstar/rad/AU)**2*np.exp(-7.*inter_opt(abs(z_array[k]))/phi_angle)
Temfunction[k,j,i] = (Tacc4 + Tirr4)**(0.25)
#Temfunction[k,j,i] = EQ_temperature(x_array[i],y_array[j],z_array[k])
###############################
Sfunction[k,j,i] = FUN_BB(nu,Temfunction[k,j,i])*(1.+ albedo*FUN_f(inter_opt(z_array[k]),op_depth_p[j][i],albedo))
#Crea funcion fuente y temperatura en 3D
funcion_S = RegularGridInterpolator((z_array, y_array, x_array), Sfunction,bounds_error=False,fill_value=None)
funcion_T = RegularGridInterpolator((z_array, y_array, x_array), Temfunction,bounds_error=False,fill_value=None)
return funcion_S, funcion_T
#--------------------------------------------------------------------------------
def FUN_f(t,tau,alb):
eps = np.sqrt(1.-alb)
fff = np.exp(-np.sqrt(3.)*eps*t) + np.exp(np.sqrt(3.)*eps*(t-tau))
fff = fff/( np.exp(-np.sqrt(3.)*eps*tau)*(eps-1.) - (eps+1.) )
return fff
#--------------------------------------------------------------------------------
#Lee las tablas de opacidad DSHARP
#Load opacities
with np.load('default_opacities_smooth.npz') as d:
a_w = d['a']
gsca_w = d['g']
lam_w = d['lam']
k_abs_w = d['k_abs']
k_sca_w = d['k_sca']
lam_avgs = wl
# We split the opacities within the range of frequency to make the calculations faster
k_abs_w = k_abs_w[(0.9*lam_avgs<lam_w) & (1.1*lam_avgs>lam_w),:]
k_sca_w = k_sca_w[(0.9*lam_avgs<lam_w) & (1.1*lam_avgs>lam_w),:]
k_sca_w = k_sca_w*(1. - gsca_w[(0.9*lam_avgs<lam_w) & (1.1*lam_avgs>lam_w),:])
lam_w = lam_w[(0.9*lam_avgs<lam_w) & (1.1*lam_avgs>lam_w)]
opac_grid = opacity.size_average_opacity(lam_avgs, a_w, lam_w, k_abs_w.T, k_sca_w.T, q=3.5, plot=True)
function_ext = interpolate.interp1d(a_w, opac_grid['ka'][:]+opac_grid['ks'][:],kind='cubic')
function_alb = interpolate.interp1d(a_w, opac_grid['ks'][:]/(opac_grid['ka'][:]+opac_grid['ks'][:]),kind='cubic')
if not scattering:
function_alb = interpolate.interp1d(a_w, np.zeros((np.shape(opac_grid['ks'][:]))),kind='cubic')
| [
2,
48443,
14629,
14,
8800,
14,
24330,
21015,
198,
198,
2,
10097,
1783,
198,
2,
29238,
262,
6766,
22715,
357,
87,
11,
88,
11,
89,
8,
284,
262,
11898,
22715,
357,
87,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
8,
198,
2,
464,
2124,
16488,
318,
262,
13179,
16488,
198,
4299,
29397,
62,
10599,
341,
7,
87,
11,
88,
11,
89,
2599,
198,
220,
220,
220,
2124,
62,
67,
796,
2124,
220,
220,
220,
220,
198,
220,
220,
220,
331,
62,
67,
796,
331,
9,
37659,
13,
6966,
7,
1939,
8,
532,
1976,
9,
37659,
13,
31369,
7,
1939,
8,
198,
220,
220,
220,
1976,
62,
67,
796,
331,
9,
37659,
13,
31369,
7,
1939,
8,
1343,
1976,
9,
37659,
13,
6966,
7,
1939,
8,
198,
220,
220,
220,
1441,
2124,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
198,
198,
2,
10097,
1783,
198,
2,
49,
9189,
876,
4351,
16022,
198,
4299,
29397,
62,
47799,
7,
40,
11,
89,
11,
87,
11,
88,
11,
8738,
2934,
2599,
198,
220,
220,
220,
2124,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
796,
29397,
62,
10599,
341,
7,
87,
11,
88,
11,
89,
8,
198,
220,
220,
220,
12109,
796,
36529,
62,
43337,
7,
87,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
8,
198,
220,
220,
220,
716,
897,
796,
36529,
62,
321,
897,
7,
87,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
8,
198,
220,
220,
220,
1034,
64,
796,
2163,
62,
2302,
7,
321,
897,
8,
198,
220,
220,
220,
311,
796,
25439,
295,
62,
50,
26933,
89,
62,
67,
11,
88,
62,
67,
11,
87,
62,
67,
12962,
198,
2,
220,
220,
220,
3601,
19203,
87,
11,
88,
11,
89,
3256,
2124,
11,
88,
11,
89,
8,
198,
2,
220,
220,
220,
3601,
357,
50,
11,
2124,
62,
67,
11,
331,
62,
67,
11,
1976,
62,
67,
8,
198,
2,
220,
220,
220,
3601,
357,
8738,
2934,
7,
89,
4008,
198,
220,
220,
220,
288,
7390,
89,
796,
532,
50,
9,
26186,
9,
43337,
9,
37659,
13,
11201,
32590,
8738,
2934,
7,
89,
4008,
1303,
89,
1658,
8591,
7885,
390,
4132,
11510,
295,
357,
2934,
1350,
1055,
5418,
84,
4763,
551,
269,
723,
421,
959,
4000,
1462,
8,
198,
220,
220,
220,
1441,
288,
7390,
89,
198,
198,
2,
10097,
1783,
198,
2,
27871,
605,
6795,
198,
4299,
29397,
62,
83,
559,
7,
926,
11,
89,
11,
87,
11,
88,
2599,
198,
220,
220,
220,
2124,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
796,
29397,
62,
10599,
341,
7,
87,
11,
88,
11,
89,
8,
198,
220,
220,
220,
12109,
796,
36529,
62,
43337,
7,
87,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
8,
198,
220,
220,
220,
716,
897,
796,
36529,
62,
321,
897,
7,
87,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
8,
198,
220,
220,
220,
1034,
64,
796,
2163,
62,
2302,
7,
321,
897,
8,
198,
220,
220,
220,
288,
83,
559,
796,
532,
26186,
9,
43337,
198,
220,
220,
220,
1441,
288,
83,
559,
198,
198,
2,
10097,
1783,
198,
4299,
29397,
62,
83,
559,
62,
89,
22704,
7,
926,
11,
89,
11,
87,
11,
88,
2599,
198,
220,
220,
220,
2124,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
796,
2124,
11,
88,
11,
89,
198,
220,
220,
220,
12109,
796,
36529,
62,
43337,
7,
87,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
8,
198,
220,
220,
220,
716,
897,
796,
36529,
62,
321,
897,
7,
87,
62,
67,
11,
88,
62,
67,
11,
89,
62,
67,
8,
198,
220,
220,
220,
1034,
64,
796,
2163,
62,
2302,
7,
321,
897,
8,
198,
220,
220,
220,
288,
83,
559,
796,
532,
26186,
9,
43337,
198,
220,
220,
220,
1441,
288,
83,
559,
198,
198,
2,
10097,
1783,
198,
2,
9915,
1767,
11881,
198,
4299,
29397,
62,
15199,
7,
28803,
11,
51,
2599,
198,
2,
220,
220,
220,
347,
796,
362,
15885,
71,
47,
9,
28803,
1174,
18,
14,
565,
432,
1174,
17,
29006,
45941,
13,
11201,
7,
71,
47,
9,
28803,
14,
38841,
14,
51,
8,
532,
352,
2014,
198,
220,
220,
220,
347,
796,
352,
19571,
7,
45941,
13,
11201,
7,
71,
47,
9,
28803,
14,
38841,
14,
51,
8,
532,
352,
2014,
198,
220,
220,
220,
1441,
347,
198,
198,
2,
10097,
1783,
198,
4299,
29397,
62,
49196,
62,
16680,
7,
5324,
11,
22556,
2599,
198,
220,
220,
220,
367,
448,
796,
36529,
62,
23106,
7,
49,
448,
8,
198,
220,
220,
220,
1761,
62,
89,
796,
39602,
9,
37659,
13,
31369,
7,
1939,
8,
1343,
362,
15885,
39,
448,
9,
37659,
13,
6966,
7,
1939,
8,
1303,
15001,
319,
262,
22939,
286,
262,
11898,
198,
220,
220,
220,
1761,
62,
88,
796,
39602,
9,
37659,
13,
6966,
7,
1939,
8,
1343,
362,
15885,
39,
448,
9,
37659,
13,
31369,
7,
1939,
8,
220,
1303,
15001,
319,
262,
22939,
286,
262,
11898,
628,
220,
220,
220,
1976,
62,
3258,
796,
45941,
13,
21602,
10223,
7,
16,
13,
16,
9,
2475,
62,
89,
11,
532,
16,
13,
16,
9,
2475,
62,
89,
11,
939,
8,
628,
220,
220,
220,
1976,
62,
22213,
796,
17635,
628,
220,
220,
220,
611,
14808,
37659,
13,
8937,
7,
5324,
8,
19841,
49,
448,
8,
290,
357,
37659,
13,
8937,
7,
22556,
8,
19841,
1761,
62,
88,
8,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
2124,
67,
11,
5173,
11,
89,
67,
796,
29397,
62,
10599,
341,
7,
5324,
11,
22556,
11,
89,
62,
3258,
8,
198,
220,
220,
220,
220,
220,
220,
220,
1955,
796,
45941,
13,
9107,
418,
19510,
11925,
7,
89,
62,
3258,
22305,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
29113,
29113,
7804,
4242,
2235,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
37,
19524,
32792,
583,
78,
24573,
7496,
1055,
6436,
528,
4533,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
29113,
29113,
7804,
4242,
2235,
220,
220,
220,
220,
220,
220,
220,
220,
198,
220,
220,
220,
220,
220,
220,
220,
329,
21065,
287,
2837,
7,
11925,
7,
89,
62,
3258,
8,
2599,
1303,
12443,
64,
555,
15879,
390,
29509,
32482,
551,
8591,
1627,
64,
390,
5761,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
357,
36,
48,
62,
43337,
7,
24954,
11,
5173,
58,
4178,
4357,
89,
67,
58,
4178,
12962,
6624,
657,
47308,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1955,
58,
4178,
60,
796,
657,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1955,
58,
4178,
60,
796,
352,
198,
220,
220,
220,
220,
198,
220,
220,
220,
220,
220,
220,
220,
329,
21065,
287,
2837,
7,
11925,
7,
89,
62,
3258,
8,
2599,
1303,
26979,
22346,
36525,
288,
14378,
269,
4131,
544,
390,
657,
257,
435,
7145,
1188,
273,
11,
267,
390,
435,
7145,
1188,
273,
257,
657,
357,
69,
1313,
353,
292,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
357,
357,
4178,
14512,
657,
8,
290,
357,
22213,
58,
4178,
60,
532,
1955,
58,
4178,
12,
16,
60,
14512,
657,
1267,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1976,
62,
22213,
13,
33295,
7,
89,
62,
3258,
58,
4178,
12962,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1288,
361,
7,
4178,
6624,
657,
290,
1955,
58,
15,
60,
6624,
352,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1976,
62,
22213,
13,
33295,
7,
89,
62,
3258,
58,
15,
12962,
198,
220,
220,
220,
220,
220,
220,
220,
1303,
29113,
29113,
7804,
4242,
2235,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
198,
220,
220,
220,
1441,
1976,
62,
22213,
198,
198,
2,
10097,
1783,
198,
4299,
29397,
62,
20123,
274,
62,
10459,
62,
8818,
7,
87,
62,
18747,
11,
88,
62,
18747,
2599,
198,
220,
220,
220,
1303,
3163,
20477,
290,
7095,
198,
220,
220,
220,
367,
448,
796,
36529,
62,
23106,
7,
49,
448,
8,
198,
220,
220,
220,
1976,
62,
18747,
796,
45941,
13,
21602,
10223,
32590,
17,
15885,
39,
448,
11,
362,
15885,
39,
448,
11,
939,
8,
198,
220,
220,
220,
311,
8818,
796,
45941,
13,
9107,
418,
19510,
11925,
7,
89,
62,
18747,
828,
11925,
7,
88,
62,
18747,
828,
11925,
7,
87,
62,
18747,
22305,
198,
220,
220,
220,
5825,
8818,
796,
45941,
13,
9107,
418,
19510,
11925,
7,
89,
62,
18747,
828,
11925,
7,
88,
62,
18747,
828,
11925,
7,
87,
62,
18747,
22305,
220,
220,
220,
220,
198,
220,
220,
220,
1034,
62,
18053,
62,
79,
796,
45941,
13,
9107,
418,
19510,
11925,
7,
88,
62,
18747,
828,
11925,
7,
87,
62,
18747,
22305,
628,
220,
220,
220,
1303,
7293,
1769,
262,
18480,
6795,
357,
525,
37038,
13174,
284,
262,
11898,
3095,
14382,
8,
198,
220,
220,
220,
329,
474,
287,
2837,
7,
11925,
7,
88,
62,
18747,
8,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
329,
1312,
287,
2837,
7,
11925,
7,
87,
62,
18747,
8,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
7,
87,
62,
18747,
58,
72,
60,
6624,
657,
13,
290,
331,
62,
18747,
58,
73,
60,
6624,
657,
47308,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
311,
8818,
58,
45299,
73,
11,
72,
60,
796,
657,
13,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
5825,
8818,
58,
45299,
73,
11,
72,
60,
796,
657,
13,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2073,
25,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
2511,
796,
45941,
13,
31166,
17034,
7,
87,
62,
18747,
58,
72,
60,
1174,
17,
1343,
331,
62,
18747,
58,
73,
60,
1174,
17,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
367,
9888,
796,
36529,
62,
23106,
7,
6335,
8,
628,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1976,
62,
18908,
796,
45941,
13,
21602,
10223,
7,
17,
15885,
39,
9888,
12095,
17,
15885,
39,
9888,
11,
2167,
8,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1540,
796,
267,
2934,
600,
7,
42296,
62,
83,
559,
62,
89,
22704,
11,
15,
1539,
89,
62,
18908,
11,
22046,
16193,
87,
62,
18747,
58,
72,
4357,
88,
62,
18747,
58,
73,
12962,
737,
51,
58,
15,
60,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1034,
62,
18053,
62,
79,
58,
73,
7131,
72,
60,
796,
1540,
58,
11925,
7,
89,
62,
18908,
13219,
16,
60,
628,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
987,
62,
8738,
796,
39555,
378,
13,
3849,
79,
16,
67,
7,
89,
62,
18908,
11,
34453,
11,
11031,
11639,
29127,
3256,
22303,
62,
18224,
28,
25101,
11,
20797,
62,
8367,
28,
15,
2014,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
329,
479,
287,
2837,
7,
11925,
7,
89,
62,
18747,
8,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
716,
897,
796,
36529,
62,
321,
897,
7,
87,
62,
18747,
58,
72,
4357,
88,
62,
18747,
58,
73,
4357,
89,
62,
18747,
58,
74,
12962,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
435,
3077,
78,
796,
2163,
62,
282,
65,
7,
321,
897,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
7804,
2,
42492,
7804,
2235,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
19839,
17,
796,
402,
70,
4108,
9,
44,
7364,
29006,
6335,
9,
26830,
8,
1174,
18,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1665,
487,
19,
796,
513,
15885,
44,
26518,
9,
46,
13731,
17,
14,
23,
19571,
37659,
13,
14415,
14,
82,
13495,
33,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
309,
4134,
19,
796,
513,
19571,
19,
15885,
7,
22,
15885,
3849,
62,
8738,
7,
8937,
7,
89,
62,
18747,
58,
74,
60,
4008,
1343,
362,
19571,
18,
2014,
9,
6767,
487,
19,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
39847,
81,
19,
796,
309,
7364,
1174,
19,
19571,
19,
15885,
7,
49,
7364,
14,
6335,
14,
26830,
8,
1174,
17,
9,
37659,
13,
11201,
32590,
22,
15885,
3849,
62,
8738,
7,
8937,
7,
89,
62,
18747,
58,
74,
60,
4008,
14,
34846,
62,
9248,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
5825,
8818,
58,
74,
11,
73,
11,
72,
60,
796,
357,
51,
4134,
19,
1343,
39847,
81,
19,
8,
1174,
7,
15,
13,
1495,
8,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
12966,
8818,
58,
74,
11,
73,
11,
72,
60,
796,
36529,
62,
11498,
21069,
7,
87,
62,
18747,
58,
72,
4357,
88,
62,
18747,
58,
73,
4357,
89,
62,
18747,
58,
74,
12962,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
14468,
7804,
4242,
2235,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
311,
8818,
58,
74,
11,
73,
11,
72,
60,
796,
29397,
62,
15199,
7,
28803,
11,
12966,
8818,
58,
74,
11,
73,
11,
72,
12962,
9,
7,
16,
13,
10,
435,
3077,
78,
9,
42296,
62,
69,
7,
3849,
62,
8738,
7,
89,
62,
18747,
58,
74,
46570,
404,
62,
18053,
62,
79,
58,
73,
7131,
72,
4357,
282,
3077,
78,
4008,
628,
220,
220,
220,
1303,
12443,
64,
25439,
295,
14035,
21872,
331,
4124,
2541,
64,
551,
513,
35,
198,
220,
220,
220,
25439,
295,
62,
50,
796,
23603,
41339,
9492,
16104,
1352,
19510,
89,
62,
18747,
11,
331,
62,
18747,
11,
2124,
62,
18747,
828,
311,
8818,
11,
65,
3733,
62,
18224,
28,
25101,
11,
20797,
62,
8367,
28,
14202,
8,
198,
220,
220,
220,
25439,
295,
62,
51,
796,
23603,
41339,
9492,
16104,
1352,
19510,
89,
62,
18747,
11,
331,
62,
18747,
11,
2124,
62,
18747,
828,
5825,
8818,
11,
65,
3733,
62,
18224,
28,
25101,
11,
20797,
62,
8367,
28,
14202,
8,
198,
220,
220,
220,
1441,
25439,
295,
62,
50,
11,
25439,
295,
62,
51,
198,
198,
2,
10097,
1783,
198,
4299,
29397,
62,
69,
7,
83,
11,
83,
559,
11,
282,
65,
2599,
198,
220,
220,
220,
304,
862,
796,
45941,
13,
31166,
17034,
7,
16,
7874,
282,
65,
8,
198,
220,
220,
220,
277,
487,
796,
45941,
13,
11201,
32590,
37659,
13,
31166,
17034,
7,
18,
2014,
9,
25386,
9,
83,
8,
1343,
45941,
13,
11201,
7,
37659,
13,
31166,
17034,
7,
18,
2014,
9,
25386,
9,
7,
83,
12,
83,
559,
4008,
198,
220,
220,
220,
277,
487,
796,
277,
487,
29006,
45941,
13,
11201,
32590,
37659,
13,
31166,
17034,
7,
18,
2014,
9,
25386,
9,
83,
559,
27493,
7,
25386,
12,
16,
2014,
532,
357,
25386,
10,
16,
2014,
1267,
198,
220,
220,
220,
1441,
277,
487,
198,
198,
2,
10097,
1783,
198,
2,
24338,
39990,
7400,
21921,
390,
1034,
330,
32482,
360,
9693,
36035,
198,
2,
8912,
1034,
330,
871,
198,
4480,
45941,
13,
2220,
10786,
12286,
62,
404,
330,
871,
62,
5796,
5226,
13,
37659,
89,
11537,
355,
288,
25,
198,
220,
220,
220,
257,
62,
86,
220,
220,
220,
220,
796,
288,
17816,
64,
20520,
198,
220,
220,
220,
308,
1416,
64,
62,
86,
220,
796,
288,
17816,
70,
20520,
198,
220,
220,
220,
30592,
62,
86,
220,
220,
796,
288,
17816,
2543,
20520,
198,
220,
220,
220,
479,
62,
8937,
62,
86,
796,
288,
17816,
74,
62,
8937,
20520,
198,
220,
220,
220,
479,
62,
1416,
64,
62,
86,
796,
288,
17816,
74,
62,
1416,
64,
20520,
198,
198,
2543,
62,
615,
14542,
796,
266,
75,
198,
2,
775,
6626,
262,
1034,
330,
871,
1626,
262,
2837,
286,
8373,
284,
787,
262,
16765,
5443,
198,
74,
62,
8937,
62,
86,
796,
479,
62,
8937,
62,
86,
58,
7,
15,
13,
24,
9,
2543,
62,
615,
14542,
27,
2543,
62,
86,
8,
1222,
357,
16,
13,
16,
9,
2543,
62,
615,
14542,
29,
2543,
62,
86,
828,
47715,
198,
74,
62,
1416,
64,
62,
86,
796,
479,
62,
1416,
64,
62,
86,
58,
7,
15,
13,
24,
9,
2543,
62,
615,
14542,
27,
2543,
62,
86,
8,
1222,
357,
16,
13,
16,
9,
2543,
62,
615,
14542,
29,
2543,
62,
86,
828,
47715,
198,
74,
62,
1416,
64,
62,
86,
796,
479,
62,
1416,
64,
62,
86,
9,
7,
16,
13,
532,
220,
308,
1416,
64,
62,
86,
58,
7,
15,
13,
24,
9,
2543,
62,
615,
14542,
27,
2543,
62,
86,
8,
1222,
357,
16,
13,
16,
9,
2543,
62,
615,
14542,
29,
2543,
62,
86,
828,
25,
12962,
198,
2543,
62,
86,
796,
30592,
62,
86,
58,
7,
15,
13,
24,
9,
2543,
62,
615,
14542,
27,
2543,
62,
86,
8,
1222,
357,
16,
13,
16,
9,
2543,
62,
615,
14542,
29,
2543,
62,
86,
15437,
198,
198,
404,
330,
62,
25928,
796,
45912,
13,
7857,
62,
23913,
62,
404,
4355,
7,
2543,
62,
615,
14542,
11,
257,
62,
86,
11,
30592,
62,
86,
11,
479,
62,
8937,
62,
86,
13,
51,
11,
479,
62,
1416,
64,
62,
86,
13,
51,
11,
10662,
28,
18,
13,
20,
11,
7110,
28,
17821,
8,
628,
198,
8818,
62,
2302,
796,
39555,
378,
13,
3849,
79,
16,
67,
7,
64,
62,
86,
11,
1034,
330,
62,
25928,
17816,
4914,
6,
7131,
47715,
10,
404,
330,
62,
25928,
17816,
591,
6,
7131,
25,
4357,
11031,
11639,
66,
549,
291,
11537,
198,
8818,
62,
282,
65,
796,
39555,
378,
13,
3849,
79,
16,
67,
7,
64,
62,
86,
11,
1034,
330,
62,
25928,
17816,
591,
6,
7131,
47715,
29006,
404,
330,
62,
25928,
17816,
4914,
6,
7131,
47715,
10,
404,
330,
62,
25928,
17816,
591,
6,
7131,
25,
46570,
11031,
11639,
66,
549,
291,
11537,
198,
361,
407,
45765,
25,
198,
220,
220,
220,
2163,
62,
282,
65,
796,
39555,
378,
13,
3849,
79,
16,
67,
7,
64,
62,
86,
11,
45941,
13,
9107,
418,
19510,
37659,
13,
43358,
7,
404,
330,
62,
25928,
17816,
591,
6,
7131,
47715,
4008,
828,
11031,
11639,
66,
549,
291,
11537,
198
] | 2.08665 | 3,266 |
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 16 18:06:05 2021
@author: jhask
"""
import csv
import pandas as pd
import numpy as np
import re
import scipy.io as sio
import os
# Map MCM names to TUV labels
j_vals_dict= dict({
'O3 -> O2 + O(1D)':'J1',
'O3 -> O2 + O(3P)':'J2',
'H2O2 -> 2 OH':'J3',
'NO2 -> NO + O(3P)':'J4',
'NO3 -> NO + O2':'J5',
'NO3 -> NO2 + O(3P)':'J6',
'HNO2 -> OH + NO':'J7',
'HNO3 -> OH + NO2':'J8',
'CH2O -> H + HCO':'J11',
'CH2O -> H2 + CO':'J12',
'CH3CHO -> CH3 + HCO':'J13',
'C2H5CHO -> C2H5 + HCO':'J14',
'CH2=C(CH3)CHO -> Products':'J18',
'CH3COCH3 -> CH3CO + CH3':'J21',
'CH3COCH2CH3 -> CH3CO + CH2CH3':'J22',
'CH3COCH=CH2 -> Products':'J23',
'CHOCHO -> H2 + 2CO':'J31',
'CHOCHO -> CH2O + CO':'J32',
'CHOCHO -> HCO + HCO':'J33',
'CH3COCHO -> CH3CO + HCO':'J34',
'CH3COCOCH3 -> Products':'J35',
'CH3OOH -> CH3O + OH':'J41',
'CH3ONO2 -> CH3O + NO2':'J51',
'C2H5ONO2 -> C2H5O + NO2':'J52',
'n-C3H7ONO2 -> C3H7O + NO2':'J53',
'CH3CHONO2CH3 -> CH3CHOCH3 + NO2':'J54',
'C(CH3)3(ONO2) -> C(CH3)3(O.) + NO2':'J55',
'CH3COCH2(ONO2) -> CH3COCH2(O.) + NO2':'J56',
'CH2(OH)COCH3 -> CH3CO + CH2(OH)':'Jn10',
'CH2=CHCHO -> Products':'Jn11',
'CH3CO(OONO2) -> CH3CO(OO) + NO2':'Jn14',
'CH3CO(OONO2) -> CH3CO(O) + NO3':'Jn15',
'CH3(OONO2) -> CH3(OO) + NO2':'Jn16',
'CH3(OONO2) -> CH3(OO) + NO2':'Jn17',
'N2O5 -> NO3 + NO2':'Jn19',
'N2O5 -> NO3 + NO + O(3P)':'Jn20',
'HNO4 -> HO2 + NO2':'Jn21'})
#TUV output file.
file= 'C:/Users/jhask/OneDrive/Documents/MATLAB/F0AM/Setups/SOAS_RCIM/foam_6_29_out.txt'
with open(file, "r",errors="ignore") as f: # read line by line.
reader = csv.reader(f, delimiter="\t")
# Initialize vars we fill in reading the file.
ln_num = 0; map_cols=dict({})
in_species_list=False;
pass_go=False
for row in reader:
line = " ".join(row) # read line by line.
hdrs= [key for key in list(j_vals_dict.keys()) if key in line]
if len(hdrs) > 0 :
headers= re.search(r"[\d]*[\=\w]", line)
print(line, hdrs, j_vals_dict[ hdrs[:][0]])
if headers: map_cols[headers.group()]=j_vals_dict[ hdrs[:][0]]
if (pass_go is True) and ('------' not in line ):
# Append the j-values to the dataframe at this point in time.
splt= [float(item) for item in line.split(" ") if item !='']
df.loc[len(df)]=np.array(splt)
if 'time, hrs. sza, deg.' in line:
pass_go=True
df=pd.DataFrame(columns= ['time', 'sza']+ list(map_cols.values()))
to_mat={name: col.values for name, col in df.items()}
filename= os.path.join('C:/Users/jhask/OneDrive/Documents/MATLAB/F0AM/Setups/SOAS_RCIM/'+'F0AM_tuv.mat')
sio.savemat(filename, to_mat)
print(filename)
| [
2,
532,
9,
12,
19617,
25,
3384,
69,
12,
23,
532,
9,
12,
201,
198,
37811,
201,
198,
41972,
319,
3300,
7653,
1467,
1248,
25,
3312,
25,
2713,
33448,
201,
198,
201,
198,
31,
9800,
25,
474,
71,
2093,
201,
198,
37811,
201,
198,
11748,
269,
21370,
220,
201,
198,
11748,
19798,
292,
355,
279,
67,
201,
198,
11748,
299,
32152,
355,
45941,
220,
201,
198,
11748,
302,
201,
198,
11748,
629,
541,
88,
13,
952,
355,
264,
952,
220,
201,
198,
11748,
28686,
220,
201,
198,
201,
198,
2,
9347,
13122,
44,
3891,
284,
309,
31667,
14722,
220,
201,
198,
73,
62,
12786,
62,
11600,
28,
8633,
15090,
201,
198,
6,
46,
18,
4613,
440,
17,
1343,
440,
7,
16,
35,
8,
10354,
6,
41,
16,
3256,
201,
198,
6,
46,
18,
4613,
440,
17,
1343,
440,
7,
18,
47,
8,
10354,
6,
41,
17,
3256,
201,
198,
6,
39,
17,
46,
17,
4613,
362,
18723,
10354,
6,
41,
18,
3256,
201,
198,
6,
15285,
17,
4613,
8005,
1343,
440,
7,
18,
47,
8,
10354,
6,
41,
19,
3256,
201,
198,
6,
15285,
18,
4613,
8005,
1343,
440,
17,
10354,
6,
41,
20,
3256,
201,
198,
6,
15285,
18,
4613,
8005,
17,
1343,
440,
7,
18,
47,
8,
10354,
6,
41,
21,
3256,
201,
198,
6,
39,
15285,
17,
4613,
18723,
1343,
8005,
10354,
6,
41,
22,
3256,
201,
198,
6,
39,
15285,
18,
4613,
18723,
1343,
8005,
17,
10354,
6,
41,
23,
3256,
201,
198,
6,
3398,
17,
46,
4613,
367,
1343,
367,
8220,
10354,
6,
41,
1157,
3256,
201,
198,
6,
3398,
17,
46,
4613,
367,
17,
1343,
7375,
10354,
6,
41,
1065,
3256,
201,
198,
6,
3398,
18,
44899,
4613,
5870,
18,
1343,
367,
8220,
10354,
6,
41,
1485,
3256,
201,
198,
6,
34,
17,
39,
20,
44899,
4613,
327,
17,
39,
20,
1343,
367,
8220,
10354,
6,
41,
1415,
3256,
201,
198,
6,
3398,
17,
28,
34,
7,
3398,
18,
8,
44899,
4613,
18675,
10354,
6,
41,
1507,
3256,
201,
198,
6,
3398,
18,
8220,
3398,
18,
4613,
5870,
18,
8220,
1343,
5870,
18,
10354,
6,
41,
2481,
3256,
201,
198,
6,
3398,
18,
8220,
3398,
17,
3398,
18,
4613,
5870,
18,
8220,
1343,
5870,
17,
3398,
18,
10354,
6,
41,
1828,
3256,
201,
198,
6,
3398,
18,
8220,
3398,
28,
3398,
17,
4613,
18675,
10354,
6,
41,
1954,
3256,
201,
198,
6,
44899,
44899,
4613,
367,
17,
1343,
362,
8220,
10354,
6,
41,
3132,
3256,
201,
198,
6,
44899,
44899,
4613,
5870,
17,
46,
1343,
7375,
10354,
6,
41,
2624,
3256,
201,
198,
6,
44899,
44899,
4613,
367,
8220,
1343,
367,
8220,
10354,
6,
41,
2091,
3256,
201,
198,
6,
3398,
18,
8220,
44899,
4613,
5870,
18,
8220,
1343,
367,
8220,
10354,
6,
41,
2682,
3256,
201,
198,
6,
3398,
18,
34,
4503,
46,
3398,
18,
4613,
18675,
10354,
6,
41,
2327,
3256,
201,
198,
6,
3398,
18,
6684,
39,
4613,
5870,
18,
46,
1343,
18723,
10354,
6,
41,
3901,
3256,
201,
198,
6,
3398,
18,
1340,
46,
17,
4613,
5870,
18,
46,
1343,
8005,
17,
10354,
6,
41,
4349,
3256,
201,
198,
6,
34,
17,
39,
20,
1340,
46,
17,
4613,
327,
17,
39,
20,
46,
1343,
8005,
17,
10354,
6,
41,
4309,
3256,
201,
198,
6,
77,
12,
34,
18,
39,
22,
1340,
46,
17,
4613,
327,
18,
39,
22,
46,
1343,
8005,
17,
10354,
6,
41,
4310,
3256,
201,
198,
6,
3398,
18,
3398,
1340,
46,
17,
3398,
18,
4613,
5870,
18,
44899,
3398,
18,
1343,
8005,
17,
10354,
6,
41,
4051,
3256,
201,
198,
6,
34,
7,
3398,
18,
8,
18,
7,
1340,
46,
17,
8,
4613,
327,
7,
3398,
18,
8,
18,
7,
46,
2014,
1343,
8005,
17,
10354,
6,
41,
2816,
3256,
201,
198,
6,
3398,
18,
8220,
3398,
17,
7,
1340,
46,
17,
8,
4613,
5870,
18,
8220,
3398,
17,
7,
46,
2014,
1343,
8005,
17,
10354,
6,
41,
3980,
3256,
201,
198,
6,
3398,
17,
7,
12096,
8,
8220,
3398,
18,
4613,
5870,
18,
8220,
1343,
5870,
17,
7,
12096,
8,
10354,
6,
41,
77,
940,
3256,
201,
198,
6,
3398,
17,
28,
3398,
44899,
4613,
18675,
10354,
6,
41,
77,
1157,
3256,
201,
198,
6,
3398,
18,
8220,
7,
46,
1340,
46,
17,
8,
4613,
5870,
18,
8220,
7,
6684,
8,
1343,
8005,
17,
10354,
6,
41,
77,
1415,
3256,
201,
198,
6,
3398,
18,
8220,
7,
46,
1340,
46,
17,
8,
4613,
5870,
18,
8220,
7,
46,
8,
1343,
8005,
18,
10354,
6,
41,
77,
1314,
3256,
201,
198,
6,
3398,
18,
7,
46,
1340,
46,
17,
8,
4613,
5870,
18,
7,
6684,
8,
1343,
8005,
17,
10354,
6,
41,
77,
1433,
3256,
201,
198,
6,
3398,
18,
7,
46,
1340,
46,
17,
8,
4613,
5870,
18,
7,
6684,
8,
1343,
8005,
17,
10354,
6,
41,
77,
1558,
3256,
201,
198,
6,
45,
17,
46,
20,
4613,
8005,
18,
1343,
8005,
17,
10354,
6,
41,
77,
1129,
3256,
201,
198,
6,
45,
17,
46,
20,
4613,
8005,
18,
1343,
8005,
1343,
440,
7,
18,
47,
8,
10354,
6,
41,
77,
1238,
3256,
201,
198,
6,
39,
15285,
19,
4613,
40115,
17,
1343,
8005,
17,
10354,
6,
41,
77,
2481,
6,
30072,
201,
198,
201,
198,
201,
198,
2,
51,
31667,
5072,
2393,
13,
220,
201,
198,
7753,
28,
705,
34,
14079,
14490,
14,
73,
71,
2093,
14,
3198,
24825,
14,
38354,
14,
41636,
48780,
14,
37,
15,
2390,
14,
7248,
4739,
14,
15821,
1921,
62,
7397,
3955,
14,
6513,
321,
62,
21,
62,
1959,
62,
448,
13,
14116,
6,
201,
198,
201,
198,
4480,
1280,
7,
7753,
11,
366,
81,
1600,
48277,
2625,
46430,
4943,
355,
277,
25,
1303,
1100,
1627,
416,
1627,
13,
201,
198,
220,
220,
220,
9173,
796,
269,
21370,
13,
46862,
7,
69,
11,
46728,
2676,
2625,
59,
83,
4943,
201,
198,
220,
220,
220,
220,
201,
198,
220,
220,
220,
1303,
20768,
1096,
410,
945,
356,
6070,
287,
3555,
262,
2393,
13,
220,
201,
198,
220,
220,
220,
300,
77,
62,
22510,
796,
657,
26,
3975,
62,
4033,
82,
28,
11600,
15090,
30072,
201,
198,
220,
220,
220,
287,
62,
35448,
62,
4868,
28,
25101,
26,
220,
201,
198,
201,
198,
220,
220,
220,
1208,
62,
2188,
28,
25101,
201,
198,
220,
220,
220,
329,
5752,
287,
9173,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
1627,
796,
366,
27071,
22179,
7,
808,
8,
220,
1303,
1100,
1627,
416,
1627,
13,
220,
201,
198,
201,
198,
201,
198,
220,
220,
220,
220,
220,
220,
220,
289,
67,
3808,
28,
685,
2539,
220,
329,
1994,
287,
1351,
7,
73,
62,
12786,
62,
11600,
13,
13083,
28955,
611,
1994,
287,
1627,
60,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
611,
18896,
7,
31298,
3808,
8,
1875,
657,
1058,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
24697,
28,
302,
13,
12947,
7,
81,
17912,
59,
67,
60,
9,
58,
59,
28,
59,
86,
60,
1600,
1627,
8,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
3601,
7,
1370,
11,
289,
67,
3808,
11,
474,
62,
12786,
62,
11600,
58,
289,
67,
3808,
58,
25,
7131,
15,
11907,
8,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
24697,
25,
3975,
62,
4033,
82,
58,
50145,
13,
8094,
3419,
22241,
73,
62,
12786,
62,
11600,
58,
289,
67,
3808,
58,
25,
7131,
15,
11907,
201,
198,
201,
198,
220,
220,
220,
220,
220,
220,
220,
611,
357,
6603,
62,
2188,
318,
6407,
8,
290,
19203,
23031,
6,
407,
287,
1627,
15179,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
2034,
437,
262,
474,
12,
27160,
284,
262,
1366,
14535,
379,
428,
966,
287,
640,
13,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
4328,
83,
28,
685,
22468,
7,
9186,
8,
329,
2378,
287,
1627,
13,
35312,
7203,
366,
8,
611,
2378,
14512,
7061,
60,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
47764,
13,
17946,
58,
11925,
7,
7568,
15437,
28,
37659,
13,
18747,
7,
22018,
83,
8,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
611,
705,
2435,
11,
36201,
13,
220,
264,
4496,
11,
3396,
2637,
287,
1627,
25,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1208,
62,
2188,
28,
17821,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
47764,
28,
30094,
13,
6601,
19778,
7,
28665,
82,
28,
37250,
2435,
3256,
705,
82,
4496,
20520,
10,
1351,
7,
8899,
62,
4033,
82,
13,
27160,
3419,
4008,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
201,
198,
1462,
62,
6759,
34758,
3672,
25,
951,
13,
27160,
329,
1438,
11,
951,
287,
47764,
13,
23814,
3419,
92,
201,
198,
201,
198,
34345,
28,
28686,
13,
6978,
13,
22179,
10786,
34,
14079,
14490,
14,
73,
71,
2093,
14,
3198,
24825,
14,
38354,
14,
41636,
48780,
14,
37,
15,
2390,
14,
7248,
4739,
14,
15821,
1921,
62,
7397,
3955,
14,
6,
10,
6,
37,
15,
2390,
62,
83,
14795,
13,
6759,
11537,
201,
198,
82,
952,
13,
21928,
6759,
7,
34345,
11,
284,
62,
6759,
8,
201,
198,
220,
220,
220,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
4798,
7,
34345,
8,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198
] | 1.792441 | 1,614 |
'''
Imports
'''
from config import *
from newspaper import Article
import sys as sys
import pandas as pd
import csv
from collections import defaultdict
import re
'''
URL Extract
'''
columns = defaultdict(list)
with open('SecurityIDRBT.csv') as f:
reader = csv.DictReader(f) # read rows into a dictionary format
for row in reader: # read a row as {column1: value1, column2: value2,...}
for (k,v) in row.items(): # go over each column name and value
columns[k].append(v) # append the value into the appropriate list
url_list = [] # based on column name k
for element in range(len(columns['Body'])):
urls = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', columns['Body'][element])
for url in urls:
url_list.append(url)
'''
Find Unique URLs and filter with semantic search results
'''
url_unique = []
for element in url_list:
if element not in url_unique:
if element not in common_urls_http:
if element not in common_urls_https:
url_unique.append(element)
'''
Write it in a new CSV
'''
with open('url.csv', 'w',newline='') as myfile:
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
for word in url_unique:
wr.writerow([word])
| [
7061,
6,
201,
198,
3546,
3742,
201,
198,
7061,
6,
201,
198,
6738,
4566,
1330,
1635,
201,
198,
6738,
7533,
1330,
10172,
201,
198,
11748,
25064,
355,
25064,
201,
198,
11748,
19798,
292,
355,
279,
67,
220,
201,
198,
11748,
269,
21370,
201,
198,
6738,
17268,
1330,
4277,
11600,
201,
198,
11748,
302,
201,
198,
7061,
6,
201,
198,
21886,
29677,
201,
198,
7061,
6,
201,
198,
28665,
82,
796,
4277,
11600,
7,
4868,
8,
201,
198,
4480,
1280,
10786,
24074,
2389,
49,
19313,
13,
40664,
11537,
355,
277,
25,
201,
198,
220,
220,
220,
9173,
796,
269,
21370,
13,
35,
713,
33634,
7,
69,
8,
1303,
1100,
15274,
656,
257,
22155,
5794,
201,
198,
220,
220,
220,
329,
5752,
287,
9173,
25,
1303,
1100,
257,
5752,
355,
1391,
28665,
16,
25,
1988,
16,
11,
5721,
17,
25,
1988,
17,
42303,
92,
201,
198,
220,
220,
220,
220,
220,
220,
220,
329,
357,
74,
11,
85,
8,
287,
5752,
13,
23814,
33529,
1303,
467,
625,
1123,
5721,
1438,
290,
1988,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
15180,
58,
74,
4083,
33295,
7,
85,
8,
1303,
24443,
262,
1988,
656,
262,
5035,
1351,
201,
198,
6371,
62,
4868,
796,
17635,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
1303,
1912,
319,
5721,
1438,
479,
201,
198,
1640,
5002,
287,
2837,
7,
11925,
7,
28665,
82,
17816,
25842,
6,
12962,
2599,
201,
198,
220,
220,
220,
220,
220,
220,
220,
2956,
7278,
796,
302,
13,
19796,
439,
10786,
5450,
30,
1378,
7,
27514,
58,
12,
59,
86,
8183,
91,
7,
27514,
4,
58,
59,
6814,
12,
69,
32,
12,
37,
60,
90,
17,
92,
4008,
10,
3256,
15180,
17816,
25842,
6,
7131,
30854,
12962,
201,
198,
220,
220,
220,
220,
220,
220,
220,
329,
19016,
287,
2956,
7278,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
19016,
62,
4868,
13,
33295,
7,
6371,
8,
201,
198,
7061,
6,
201,
198,
16742,
30015,
32336,
290,
8106,
351,
37865,
2989,
2482,
201,
198,
7061,
6,
201,
198,
6371,
62,
34642,
796,
17635,
201,
198,
1640,
5002,
287,
19016,
62,
4868,
25,
201,
198,
220,
220,
220,
611,
5002,
407,
287,
19016,
62,
34642,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
611,
5002,
407,
287,
2219,
62,
6371,
82,
62,
4023,
25,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
611,
5002,
407,
287,
2219,
62,
6371,
82,
62,
5450,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
19016,
62,
34642,
13,
33295,
7,
30854,
8,
201,
198,
7061,
6,
201,
198,
16594,
340,
287,
257,
649,
44189,
201,
198,
7061,
6,
220,
220,
220,
220,
201,
198,
201,
198,
4480,
1280,
10786,
6371,
13,
40664,
3256,
705,
86,
3256,
3605,
1370,
28,
7061,
8,
355,
616,
7753,
25,
201,
198,
220,
220,
220,
1319,
796,
269,
21370,
13,
16002,
7,
1820,
7753,
11,
28411,
28,
40664,
13,
10917,
23051,
62,
7036,
8,
201,
198,
220,
220,
220,
329,
1573,
287,
19016,
62,
34642,
25,
201,
198,
220,
220,
220,
220,
220,
220,
220,
1319,
13,
16002,
322,
26933,
4775,
12962,
201,
198,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
220,
220,
220,
220,
220,
220,
220,
220,
201,
198,
220
] | 2.284014 | 588 |
# -*- coding: utf-8 -*-
# Copyright 2018, IBM.
#
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.
# pylint: disable=missing-docstring
from qiskit.mapper import _coupling
from .common import QiskitTestCase
class CouplingTest(QiskitTestCase):
def test_coupling_dict2list(self):
input_dict = {0: [1, 2], 1: [2]}
result = _coupling.coupling_dict2list(input_dict)
expected = [[0, 1], [0, 2], [1, 2]]
self.assertEqual(expected, result)
def test_coupling_dict2list_empty_dict(self):
self.assertIsNone(_coupling.coupling_dict2list({}))
def test_coupling_list2dict(self):
input_list = [[0, 1], [0, 2], [1, 2]]
result = _coupling.coupling_list2dict(input_list)
expected = {0: [1, 2], 1: [2]}
self.assertEqual(expected, result)
def test_coupling_list2dict_empty_list(self):
self.assertIsNone(_coupling.coupling_list2dict([]))
def test_empty_coupling_class(self):
coupling = _coupling.Coupling()
self.assertEqual(0, coupling.size())
self.assertEqual([], coupling.get_qubits())
self.assertEqual([], coupling.get_edges())
self.assertFalse(coupling.connected())
self.assertEqual("", str(coupling))
def test_coupling_str(self):
coupling_dict = {0: [1, 2], 1: [2]}
coupling = _coupling.Coupling(coupling_dict)
expected = ("qubits: q[0] @ 1, q[1] @ 2, q[2] @ 3\n"
"edges: q[0]-q[1], q[0]-q[2], q[1]-q[2]")
self.assertEqual(expected, str(coupling))
def test_coupling_compute_distance(self):
coupling_dict = {0: [1, 2], 1: [2]}
coupling = _coupling.Coupling(coupling_dict)
self.assertTrue(coupling.connected())
coupling.compute_distance()
qubits = coupling.get_qubits()
result = coupling.distance(qubits[0], qubits[1])
self.assertEqual(1, result)
def test_coupling_compute_distance_coupling_error(self):
coupling = _coupling.Coupling()
self.assertRaises(_coupling.CouplingError, coupling.compute_distance)
def test_add_qubit(self):
coupling = _coupling.Coupling()
self.assertEqual("", str(coupling))
coupling.add_qubit(('q', 0))
self.assertEqual("qubits: q[0] @ 1", str(coupling))
def test_add_qubit_not_tuple(self):
coupling = _coupling.Coupling()
self.assertRaises(_coupling.CouplingError, coupling.add_qubit, 'q0')
def test_add_qubit_tuple_incorrect_form(self):
coupling = _coupling.Coupling()
self.assertRaises(_coupling.CouplingError, coupling.add_qubit,
('q', '0'))
def test_add_edge(self):
coupling = _coupling.Coupling()
self.assertEqual("", str(coupling))
coupling.add_edge(("q", 0), ('q', 1))
expected = ("qubits: q[0] @ 1, q[1] @ 2\n"
"edges: q[0]-q[1]")
self.assertEqual(expected, str(coupling))
def test_distance_error(self):
"""Test distance method validation."""
graph = _coupling.Coupling({0: [1, 2], 1: [2]})
self.assertRaises(_coupling.CouplingError, graph.distance, ('q0', 0), ('q1', 1))
| [
2,
532,
9,
12,
19617,
25,
3384,
69,
12,
23,
532,
9,
12,
198,
198,
2,
15069,
2864,
11,
19764,
13,
198,
2,
198,
2,
770,
2723,
2438,
318,
11971,
739,
262,
24843,
13789,
11,
10628,
362,
13,
15,
1043,
287,
198,
2,
262,
38559,
24290,
13,
14116,
2393,
287,
262,
6808,
8619,
286,
428,
2723,
5509,
13,
198,
198,
2,
279,
2645,
600,
25,
15560,
28,
45688,
12,
15390,
8841,
628,
198,
6738,
10662,
1984,
270,
13,
76,
11463,
1330,
4808,
66,
280,
11347,
198,
6738,
764,
11321,
1330,
1195,
1984,
270,
14402,
20448,
628,
198,
4871,
15062,
11347,
14402,
7,
48,
1984,
270,
14402,
20448,
2599,
628,
220,
220,
220,
825,
1332,
62,
66,
280,
11347,
62,
11600,
17,
4868,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
5128,
62,
11600,
796,
1391,
15,
25,
685,
16,
11,
362,
4357,
352,
25,
685,
17,
48999,
198,
220,
220,
220,
220,
220,
220,
220,
1255,
796,
4808,
66,
280,
11347,
13,
66,
280,
11347,
62,
11600,
17,
4868,
7,
15414,
62,
11600,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2938,
796,
16410,
15,
11,
352,
4357,
685,
15,
11,
362,
4357,
685,
16,
11,
362,
11907,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7,
40319,
11,
1255,
8,
628,
220,
220,
220,
825,
1332,
62,
66,
280,
11347,
62,
11600,
17,
4868,
62,
28920,
62,
11600,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
3792,
14202,
28264,
66,
280,
11347,
13,
66,
280,
11347,
62,
11600,
17,
4868,
15090,
92,
4008,
628,
220,
220,
220,
825,
1332,
62,
66,
280,
11347,
62,
4868,
17,
11600,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
5128,
62,
4868,
796,
16410,
15,
11,
352,
4357,
685,
15,
11,
362,
4357,
685,
16,
11,
362,
11907,
198,
220,
220,
220,
220,
220,
220,
220,
1255,
796,
4808,
66,
280,
11347,
13,
66,
280,
11347,
62,
4868,
17,
11600,
7,
15414,
62,
4868,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2938,
796,
1391,
15,
25,
685,
16,
11,
362,
4357,
352,
25,
685,
17,
48999,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7,
40319,
11,
1255,
8,
628,
220,
220,
220,
825,
1332,
62,
66,
280,
11347,
62,
4868,
17,
11600,
62,
28920,
62,
4868,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
3792,
14202,
28264,
66,
280,
11347,
13,
66,
280,
11347,
62,
4868,
17,
11600,
7,
21737,
4008,
628,
220,
220,
220,
825,
1332,
62,
28920,
62,
66,
280,
11347,
62,
4871,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
796,
4808,
66,
280,
11347,
13,
34,
280,
11347,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7,
15,
11,
40204,
13,
7857,
28955,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
26933,
4357,
40204,
13,
1136,
62,
421,
9895,
28955,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
26933,
4357,
40204,
13,
1136,
62,
276,
3212,
28955,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
25101,
7,
66,
280,
11347,
13,
15236,
28955,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7203,
1600,
965,
7,
66,
280,
11347,
4008,
628,
220,
220,
220,
825,
1332,
62,
66,
280,
11347,
62,
2536,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
62,
11600,
796,
1391,
15,
25,
685,
16,
11,
362,
4357,
352,
25,
685,
17,
48999,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
796,
4808,
66,
280,
11347,
13,
34,
280,
11347,
7,
66,
280,
11347,
62,
11600,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2938,
796,
5855,
421,
9895,
25,
10662,
58,
15,
60,
2488,
352,
11,
10662,
58,
16,
60,
2488,
362,
11,
10662,
58,
17,
60,
2488,
513,
59,
77,
1,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
276,
3212,
25,
10662,
58,
15,
45297,
80,
58,
16,
4357,
10662,
58,
15,
45297,
80,
58,
17,
4357,
10662,
58,
16,
45297,
80,
58,
17,
60,
4943,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7,
40319,
11,
965,
7,
66,
280,
11347,
4008,
628,
220,
220,
220,
825,
1332,
62,
66,
280,
11347,
62,
5589,
1133,
62,
30246,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
62,
11600,
796,
1391,
15,
25,
685,
16,
11,
362,
4357,
352,
25,
685,
17,
48999,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
796,
4808,
66,
280,
11347,
13,
34,
280,
11347,
7,
66,
280,
11347,
62,
11600,
8,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
17821,
7,
66,
280,
11347,
13,
15236,
28955,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
13,
5589,
1133,
62,
30246,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
627,
9895,
796,
40204,
13,
1136,
62,
421,
9895,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
1255,
796,
40204,
13,
30246,
7,
421,
9895,
58,
15,
4357,
627,
9895,
58,
16,
12962,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7,
16,
11,
1255,
8,
628,
220,
220,
220,
825,
1332,
62,
66,
280,
11347,
62,
5589,
1133,
62,
30246,
62,
66,
280,
11347,
62,
18224,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
796,
4808,
66,
280,
11347,
13,
34,
280,
11347,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
21762,
2696,
28264,
66,
280,
11347,
13,
34,
280,
11347,
12331,
11,
40204,
13,
5589,
1133,
62,
30246,
8,
628,
220,
220,
220,
825,
1332,
62,
2860,
62,
421,
2545,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
796,
4808,
66,
280,
11347,
13,
34,
280,
11347,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7203,
1600,
965,
7,
66,
280,
11347,
4008,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
13,
2860,
62,
421,
2545,
7,
10786,
80,
3256,
657,
4008,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7203,
421,
9895,
25,
10662,
58,
15,
60,
2488,
352,
1600,
965,
7,
66,
280,
11347,
4008,
628,
220,
220,
220,
825,
1332,
62,
2860,
62,
421,
2545,
62,
1662,
62,
83,
29291,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
796,
4808,
66,
280,
11347,
13,
34,
280,
11347,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
21762,
2696,
28264,
66,
280,
11347,
13,
34,
280,
11347,
12331,
11,
40204,
13,
2860,
62,
421,
2545,
11,
705,
80,
15,
11537,
628,
220,
220,
220,
825,
1332,
62,
2860,
62,
421,
2545,
62,
83,
29291,
62,
1939,
47315,
62,
687,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
796,
4808,
66,
280,
11347,
13,
34,
280,
11347,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
21762,
2696,
28264,
66,
280,
11347,
13,
34,
280,
11347,
12331,
11,
40204,
13,
2860,
62,
421,
2545,
11,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
19203,
80,
3256,
705,
15,
6,
4008,
628,
220,
220,
220,
825,
1332,
62,
2860,
62,
14907,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
796,
4808,
66,
280,
11347,
13,
34,
280,
11347,
3419,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7203,
1600,
965,
7,
66,
280,
11347,
4008,
198,
220,
220,
220,
220,
220,
220,
220,
40204,
13,
2860,
62,
14907,
7,
7203,
80,
1600,
657,
828,
19203,
80,
3256,
352,
4008,
198,
220,
220,
220,
220,
220,
220,
220,
2938,
796,
5855,
421,
9895,
25,
10662,
58,
15,
60,
2488,
352,
11,
10662,
58,
16,
60,
2488,
362,
59,
77,
1,
198,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
220,
366,
276,
3212,
25,
10662,
58,
15,
45297,
80,
58,
16,
60,
4943,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
36,
13255,
7,
40319,
11,
965,
7,
66,
280,
11347,
4008,
628,
220,
220,
220,
825,
1332,
62,
30246,
62,
18224,
7,
944,
2599,
198,
220,
220,
220,
220,
220,
220,
220,
37227,
14402,
5253,
2446,
21201,
526,
15931,
198,
220,
220,
220,
220,
220,
220,
220,
4823,
796,
4808,
66,
280,
11347,
13,
34,
280,
11347,
15090,
15,
25,
685,
16,
11,
362,
4357,
352,
25,
685,
17,
60,
30072,
198,
220,
220,
220,
220,
220,
220,
220,
2116,
13,
30493,
21762,
2696,
28264,
66,
280,
11347,
13,
34,
280,
11347,
12331,
11,
4823,
13,
30246,
11,
19203,
80,
15,
3256,
657,
828,
19203,
80,
16,
3256,
352,
4008,
198
] | 2.157237 | 1,520 |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 34