pysus 0.4.0__py3.6-linux-x86_64.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. EGG-INFO/PKG-INFO +30 -0
  2. EGG-INFO/SOURCES.txt +75 -0
  3. EGG-INFO/dependency_links.txt +1 -0
  4. EGG-INFO/native_libs.txt +2 -0
  5. EGG-INFO/not-zip-safe +1 -0
  6. EGG-INFO/requires.txt +7 -0
  7. EGG-INFO/top_level.txt +2 -0
  8. __pycache__/_readdbc.cpython-36.pyc +0 -0
  9. _readdbc.abi3.so +0 -0
  10. _readdbc.py +7 -0
  11. pysus/__init__.py +2 -0
  12. pysus/__pycache__/__init__.cpython-36.pyc +0 -0
  13. pysus/online_data/CIHA.py +62 -0
  14. pysus/online_data/CNES.py +24 -0
  15. pysus/online_data/SIA.py +92 -0
  16. pysus/online_data/SIH.py +61 -0
  17. pysus/online_data/SIM.py +155 -0
  18. pysus/online_data/__init__.py +22 -0
  19. pysus/online_data/__pycache__/CIHA.cpython-36.pyc +0 -0
  20. pysus/online_data/__pycache__/CNES.cpython-36.pyc +0 -0
  21. pysus/online_data/__pycache__/SIA.cpython-36.pyc +0 -0
  22. pysus/online_data/__pycache__/SIH.cpython-36.pyc +0 -0
  23. pysus/online_data/__pycache__/SIM.cpython-36.pyc +0 -0
  24. pysus/online_data/__pycache__/__init__.cpython-36.pyc +0 -0
  25. pysus/online_data/__pycache__/sinasc.cpython-36.pyc +0 -0
  26. pysus/online_data/sinasc.py +44 -0
  27. pysus/preprocessing/__init__.py +8 -0
  28. pysus/preprocessing/__pycache__/__init__.cpython-36.pyc +0 -0
  29. pysus/preprocessing/__pycache__/decoders.cpython-36.pyc +0 -0
  30. pysus/preprocessing/__pycache__/sinan.cpython-36.pyc +0 -0
  31. pysus/preprocessing/decoders.py +96 -0
  32. pysus/preprocessing/sinan.py +103 -0
  33. pysus/tests/__init__.py +8 -0
  34. pysus/tests/__pycache__/__init__.cpython-36.pyc +0 -0
  35. pysus/tests/__pycache__/test_decoders.cpython-36.pyc +0 -0
  36. pysus/tests/__pycache__/test_sinan.cpython-36.pyc +0 -0
  37. pysus/tests/__pycache__/test_utilities.cpython-36.pyc +0 -0
  38. pysus/tests/test_data/__init__.py +6 -0
  39. pysus/tests/test_data/__pycache__/__init__.cpython-36.pyc +0 -0
  40. pysus/tests/test_data/__pycache__/test_ciha.cpython-36.pyc +0 -0
  41. pysus/tests/test_data/__pycache__/test_sia.cpython-36.pyc +0 -0
  42. pysus/tests/test_data/__pycache__/test_sih.cpython-36.pyc +0 -0
  43. pysus/tests/test_data/__pycache__/test_sim.cpython-36.pyc +0 -0
  44. pysus/tests/test_data/__pycache__/test_sinasc.cpython-36.pyc +0 -0
  45. pysus/tests/test_data/test_ciha.py +23 -0
  46. pysus/tests/test_data/test_sia.py +25 -0
  47. pysus/tests/test_data/test_sih.py +18 -0
  48. pysus/tests/test_data/test_sim.py +41 -0
  49. pysus/tests/test_data/test_sinasc.py +20 -0
  50. pysus/tests/test_decoders.py +38 -0
  51. pysus/tests/test_sinan.py +35 -0
  52. pysus/tests/test_utilities.py +18 -0
  53. pysus/utilities/__init__.py +6 -0
  54. pysus/utilities/__pycache__/__init__.cpython-36.pyc +0 -0
  55. pysus/utilities/__pycache__/_build_readdbc.cpython-36.pyc +0 -0
  56. pysus/utilities/__pycache__/readdbc.cpython-36.pyc +0 -0
  57. pysus/utilities/_build_readdbc.py +32 -0
  58. pysus/utilities/_readdbc.c +897 -0
  59. pysus/utilities/_readdbc.cpython-36m-x86_64-linux-gnu.so +0 -0
  60. pysus/utilities/_readdbc.o +0 -0
  61. pysus/utilities/blast.c +982 -0
  62. pysus/utilities/blast.h +75 -0
  63. pysus/utilities/blast.o +0 -0
  64. pysus/utilities/readdbc.py +52 -0
@@ -0,0 +1,75 @@
1
+ /* blast.h -- interface for blast.c
2
+ Copyright (C) 2003, 2012 Mark Adler
3
+ version 1.2, 24 Oct 2012
4
+
5
+ This software is provided 'as-is', without any express or implied
6
+ warranty. In no event will the author be held liable for any damages
7
+ arising from the use of this software.
8
+
9
+ Permission is granted to anyone to use this software for any purpose,
10
+ including commercial applications, and to alter it and redistribute it
11
+ freely, subject to the following restrictions:
12
+
13
+ 1. The origin of this software must not be misrepresented; you must not
14
+ claim that you wrote the original software. If you use this software
15
+ in a product, an acknowledgment in the product documentation would be
16
+ appreciated but is not required.
17
+ 2. Altered source versions must be plainly marked as such, and must not be
18
+ misrepresented as being the original software.
19
+ 3. This notice may not be removed or altered from any source distribution.
20
+
21
+ Mark Adler madler@alumni.caltech.edu
22
+ */
23
+
24
+
25
+ /*
26
+ * blast() decompresses the PKWare Data Compression Library (DCL) compressed
27
+ * format. It provides the same functionality as the explode() function in
28
+ * that library. (Note: PKWare overused the "implode" verb, and the format
29
+ * used by their library implode() function is completely different and
30
+ * incompatible with the implode compression method supported by PKZIP.)
31
+ *
32
+ * The binary mode for stdio functions should be used to assure that the
33
+ * compressed data is not corrupted when read or written. For example:
34
+ * fopen(..., "rb") and fopen(..., "wb").
35
+ */
36
+
37
+
38
+ typedef unsigned (*blast_in)(void *how, unsigned char **buf);
39
+ typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len);
40
+ /* Definitions for input/output functions passed to blast(). See below for
41
+ * what the provided functions need to do.
42
+ */
43
+
44
+
45
+ int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow);
46
+ /* Decompress input to output using the provided infun() and outfun() calls.
47
+ * On success, the return value of blast() is zero. If there is an error in
48
+ * the source data, i.e. it is not in the proper format, then a negative value
49
+ * is returned. If there is not enough input available or there is not enough
50
+ * output space, then a positive error is returned.
51
+ *
52
+ * The input function is invoked: len = infun(how, &buf), where buf is set by
53
+ * infun() to point to the input buffer, and infun() returns the number of
54
+ * available bytes there. If infun() returns zero, then blast() returns with
55
+ * an input error. (blast() only asks for input if it needs it.) inhow is for
56
+ * use by the application to pass an input descriptor to infun(), if desired.
57
+ *
58
+ * The output function is invoked: err = outfun(how, buf, len), where the bytes
59
+ * to be written are buf[0..len-1]. If err is not zero, then blast() returns
60
+ * with an output error. outfun() is always called with len <= 4096. outhow
61
+ * is for use by the application to pass an output descriptor to outfun(), if
62
+ * desired.
63
+ *
64
+ * The return codes are:
65
+ *
66
+ * 2: ran out of input before completing decompression
67
+ * 1: output error before completing decompression
68
+ * 0: successful decompression
69
+ * -1: literal flag not zero or one
70
+ * -2: dictionary size not in 4..6
71
+ * -3: distance is too far back
72
+ *
73
+ * At the bottom of blast.c is an example program that uses blast() that can be
74
+ * compiled to produce a command-line decompression filter by defining TEST.
75
+ */
Binary file
@@ -0,0 +1,52 @@
1
+ u"""
2
+ Created on 16/08/16
3
+ by fccoelho
4
+ license: GPL V3 or Later
5
+ """
6
+ import os
7
+ from tempfile import NamedTemporaryFile
8
+ from io import BytesIO
9
+ import pandas as pd
10
+ from dbfread import DBF
11
+
12
+ from pysus.utilities._readdbc import ffi, lib
13
+
14
+
15
+ def read_dbc(filename, encoding='utf-8'):
16
+ """
17
+ Opens a DATASUS .dbc file and return its contents as a pandas
18
+ Dataframe.
19
+ :param filename: .dbc filename
20
+ :param encoding: encoding of the data
21
+ :return: Pandas Dataframe.
22
+ """
23
+ if isinstance(filename, str):
24
+ filename = filename.encode()
25
+ with NamedTemporaryFile(delete=False) as tf:
26
+ dbc2dbf(filename, tf.name.encode())
27
+ dbf = DBF(tf.name, encoding=encoding)
28
+ df = pd.DataFrame(list(dbf))
29
+ os.unlink(tf.name)
30
+
31
+ return df
32
+
33
+
34
+ def dbc2dbf(infile, outfile):
35
+ """
36
+ Converts a DATASUS dbc file to a DBF database.
37
+ :param infile: .dbc file name
38
+ :param outfile: name of the .dbf file to be created.
39
+ """
40
+ if isinstance(infile, str):
41
+ infile = infile.encode()
42
+ if isinstance(outfile, str):
43
+ outfile = outfile.encode()
44
+ p = ffi.new('char[]', os.path.abspath(infile))
45
+ q = ffi.new('char[]', os.path.abspath(outfile))
46
+
47
+ lib.dbc2dbf([p], [q])
48
+
49
+ # print(os.path.exists(outfile))
50
+
51
+
52
+