tspng 0.0.1__tar.gz

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.
@@ -0,0 +1,40 @@
1
+ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3
+
4
+ name: Python package
5
+
6
+ on:
7
+ push:
8
+ branches: [ "main" ]
9
+ pull_request:
10
+ branches: [ "main" ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ python-version: ["3.8", "3.9", "3.10"]
20
+
21
+ steps:
22
+ - uses: actions/checkout@v3
23
+ - name: Set up Python ${{ matrix.python-version }}
24
+ uses: actions/setup-python@v3
25
+ with:
26
+ python-version: ${{ matrix.python-version }}
27
+ - name: Install dependencies
28
+ run: |
29
+ python -m pip install --upgrade pip
30
+ python -m pip install flake8 pytest
31
+ if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32
+ - name: Lint with flake8
33
+ run: |
34
+ # stop the build if there are Python syntax errors or undefined names
35
+ flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
36
+ # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37
+ flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38
+ - name: Test with pytest
39
+ run: |
40
+ pytest
tspng-0.0.1/.gitignore ADDED
@@ -0,0 +1,160 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
@@ -0,0 +1,3 @@
1
+ ## 0.0.1 (2023-07-11)
2
+
3
+ Initial release
tspng-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2023 Theia Scientific, LLC. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
tspng-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.1
2
+ Name: tspng
3
+ Version: 0.0.1
4
+ Summary: A Python package for manipulating PNG files exported or imported using the Theia web application
5
+ Project-URL: Homepage, https://github.com/Theia-Scientific/theia-png
6
+ Project-URL: Bug Tracker, https://github.com/Theia-Scientific/theia-png/issues
7
+ Author-email: Theia Scientific <support@theiascientific.com>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.7
13
+ Provides-Extra: dev
14
+ Requires-Dist: build; extra == 'dev'
15
+ Requires-Dist: twine; extra == 'dev'
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Theia PNG
19
+
20
+ [![CI](https://github.com/Theia-Scientific/theia-png/actions/workflows/python-package.yml/badge.svg)](https://github.com/Theia-Scientific/theia-png/actions/workflows/python-package.yml)
21
+ [![Google Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1iC5KLoQUY4D54D9SH4YB2pJ0rTXXq2Fs?usp=sharing)
22
+
23
+ A Python package for manipulating PNG files exported or imported using the
24
+ Theia web application. These files have data embedded in the PNG in a [COCO JSON format] compatible form. This package unpacks and makes the data readily usable.
25
+
26
+ ## Quick Start
27
+
28
+ 1. Create a virtual environment.
29
+
30
+ ```sh
31
+ python3 -m venv .venv
32
+ ```
33
+
34
+ 2. Activate the virtual environment.
35
+
36
+ ```sh
37
+ source .venv/bin/activate
38
+ ```
39
+
40
+ 3. Install tspng.
41
+
42
+ ```sh
43
+ python3 -m pip install tspng
44
+ ```
45
+
46
+ 4. Create a `png_dump.py` script to extract inference results from a PNG file,
47
+
48
+ ```python
49
+ import json
50
+
51
+ from tspng.extraction import extract
52
+
53
+ print(json.dumps(extract(PATH_TO_FILE), indent=2))
54
+ ```
55
+
56
+ where `PATH_TO_FILE` is replaced with the path to a `.ts.png` file on disk.
57
+
58
+ 5. Run the `png_dump.py` script.
59
+
60
+ ```sh
61
+ $ python3 ./png_dump.py
62
+ {
63
+ "info": {
64
+ "description": "Theiascope image",
65
+ "url": "http://www.theiascientific.com",
66
+ "version": "1.0",
67
+ "year": 2023,
68
+ "contributor": "Theia Scientific, LLC",
69
+ "date_created": "2023-05-10 19:22:47.722802+00:00"
70
+ },
71
+ "licenses": {
72
+ "url": "http://www.theiascientific.com",
73
+ "id": 1,
74
+ "name": "Proprietary"
75
+ },
76
+ "images": [
77
+ {
78
+ "license": 1,
79
+ "file_name": "20230510T192247Z.722_crimson-notebook (PML).ts.png",
80
+ "height": 512,
81
+ "width": 512,
82
+ "date_captured": "2023-05-10 19:22:47.722802+00:00",
83
+ "id": 3783,
84
+ "field_of_view": [
85
+ 0,
86
+ 0,
87
+ 512,
88
+ 512
89
+ ],
90
+ "scale_bar": {
91
+ "dimensions": [
92
+ 25,
93
+ 501,
94
+ 128,
95
+ 1
96
+ ],
97
+ "length": 100.0,
98
+ "units_abbr": "nm",
99
+ "units_name": "nanometers"
100
+ }
101
+ }
102
+ ],
103
+ "annotations": [...], // Omitted for clarity
104
+ "models": [
105
+ {
106
+ "id": 17,
107
+ "configuration": {
108
+ "image_processing": {
109
+ "brightness": 0,
110
+ "clahe": false,
111
+ "contrast": 1.0,
112
+ "gamma": 1.0,
113
+ "gray": false,
114
+ "invert": false
115
+ },
116
+ "max_concurrency": 2,
117
+ "num_cpus": 0,
118
+ "num_gpus": 1.0,
119
+ "box_nms_thresh": 0.7,
120
+ "crop_n_layers": 0,
121
+ "crop_nms_thresh": 0.7,
122
+ "crop_overlap_ratio": 0.3413333333333333,
123
+ "crop_n_points_downscale_factor": 1,
124
+ "min_mask_region_area": 0,
125
+ "points_per_side": 32,
126
+ "points_per_batch": 64,
127
+ "pred_iou_thresh": 0.88,
128
+ "stability_score_thresh": 0.95,
129
+ "stability_score_offset": 1.0,
130
+ "weights_file": {
131
+ "filename": "sam_vit_b_01ec64.pth",
132
+ "version": "default",
133
+ "path": "/sam/vit-b"
134
+ }
135
+ },
136
+ "created": "2023-05-09 19:46:18.309323+00:00",
137
+ "family": "SAM",
138
+ "name": "vit-b",
139
+ "pid": 1
140
+ }
141
+ ],
142
+ "categories": [
143
+ {
144
+ "supercategory": "defect",
145
+ "id": 1,
146
+ "name": ""
147
+ }
148
+ ]
149
+ }
150
+ ```
151
+
152
+ ## Contributing
153
+
154
+ 1. Clone this repository.
155
+
156
+ ```sh
157
+ git clone https://github.com/Theia-Scientific/theia-png.git && cd theia-png
158
+ ```
159
+
160
+ 2. Install the dependencies.
161
+
162
+ ```sh
163
+ python3 -m pip install .[dev]
164
+ ```
165
+
166
+ 3. Build the package.
167
+
168
+ ```sh
169
+ python3 -m build
170
+ ```
171
+
172
+ ## Testing
173
+
174
+ Testing is divided into unit and integration tests. Unit tests are located in
175
+ the package source code tree and are defined on a per-module basis with a
176
+ `test_<module>.py` format, while the integration tests are defined in the
177
+ `tests` directory.
178
+
179
+ ## License
180
+
181
+ - [LICENSE](https://github.com/Theia-Scientific/theia-png/blob/main/LICENSE).
182
+
183
+ ## Acknowledgments
184
+
185
+ This material is based upon work supported by the U.S. Department of Energy, Office of Nuclear Energy under Award Number DE-SC0021529.
186
+
187
+ [coco json format]: https://cocodataset.org/#format-data
tspng-0.0.1/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # Theia PNG
2
+
3
+ [![CI](https://github.com/Theia-Scientific/theia-png/actions/workflows/python-package.yml/badge.svg)](https://github.com/Theia-Scientific/theia-png/actions/workflows/python-package.yml)
4
+ [![Google Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1iC5KLoQUY4D54D9SH4YB2pJ0rTXXq2Fs?usp=sharing)
5
+
6
+ A Python package for manipulating PNG files exported or imported using the
7
+ Theia web application. These files have data embedded in the PNG in a [COCO JSON format] compatible form. This package unpacks and makes the data readily usable.
8
+
9
+ ## Quick Start
10
+
11
+ 1. Create a virtual environment.
12
+
13
+ ```sh
14
+ python3 -m venv .venv
15
+ ```
16
+
17
+ 2. Activate the virtual environment.
18
+
19
+ ```sh
20
+ source .venv/bin/activate
21
+ ```
22
+
23
+ 3. Install tspng.
24
+
25
+ ```sh
26
+ python3 -m pip install tspng
27
+ ```
28
+
29
+ 4. Create a `png_dump.py` script to extract inference results from a PNG file,
30
+
31
+ ```python
32
+ import json
33
+
34
+ from tspng.extraction import extract
35
+
36
+ print(json.dumps(extract(PATH_TO_FILE), indent=2))
37
+ ```
38
+
39
+ where `PATH_TO_FILE` is replaced with the path to a `.ts.png` file on disk.
40
+
41
+ 5. Run the `png_dump.py` script.
42
+
43
+ ```sh
44
+ $ python3 ./png_dump.py
45
+ {
46
+ "info": {
47
+ "description": "Theiascope image",
48
+ "url": "http://www.theiascientific.com",
49
+ "version": "1.0",
50
+ "year": 2023,
51
+ "contributor": "Theia Scientific, LLC",
52
+ "date_created": "2023-05-10 19:22:47.722802+00:00"
53
+ },
54
+ "licenses": {
55
+ "url": "http://www.theiascientific.com",
56
+ "id": 1,
57
+ "name": "Proprietary"
58
+ },
59
+ "images": [
60
+ {
61
+ "license": 1,
62
+ "file_name": "20230510T192247Z.722_crimson-notebook (PML).ts.png",
63
+ "height": 512,
64
+ "width": 512,
65
+ "date_captured": "2023-05-10 19:22:47.722802+00:00",
66
+ "id": 3783,
67
+ "field_of_view": [
68
+ 0,
69
+ 0,
70
+ 512,
71
+ 512
72
+ ],
73
+ "scale_bar": {
74
+ "dimensions": [
75
+ 25,
76
+ 501,
77
+ 128,
78
+ 1
79
+ ],
80
+ "length": 100.0,
81
+ "units_abbr": "nm",
82
+ "units_name": "nanometers"
83
+ }
84
+ }
85
+ ],
86
+ "annotations": [...], // Omitted for clarity
87
+ "models": [
88
+ {
89
+ "id": 17,
90
+ "configuration": {
91
+ "image_processing": {
92
+ "brightness": 0,
93
+ "clahe": false,
94
+ "contrast": 1.0,
95
+ "gamma": 1.0,
96
+ "gray": false,
97
+ "invert": false
98
+ },
99
+ "max_concurrency": 2,
100
+ "num_cpus": 0,
101
+ "num_gpus": 1.0,
102
+ "box_nms_thresh": 0.7,
103
+ "crop_n_layers": 0,
104
+ "crop_nms_thresh": 0.7,
105
+ "crop_overlap_ratio": 0.3413333333333333,
106
+ "crop_n_points_downscale_factor": 1,
107
+ "min_mask_region_area": 0,
108
+ "points_per_side": 32,
109
+ "points_per_batch": 64,
110
+ "pred_iou_thresh": 0.88,
111
+ "stability_score_thresh": 0.95,
112
+ "stability_score_offset": 1.0,
113
+ "weights_file": {
114
+ "filename": "sam_vit_b_01ec64.pth",
115
+ "version": "default",
116
+ "path": "/sam/vit-b"
117
+ }
118
+ },
119
+ "created": "2023-05-09 19:46:18.309323+00:00",
120
+ "family": "SAM",
121
+ "name": "vit-b",
122
+ "pid": 1
123
+ }
124
+ ],
125
+ "categories": [
126
+ {
127
+ "supercategory": "defect",
128
+ "id": 1,
129
+ "name": ""
130
+ }
131
+ ]
132
+ }
133
+ ```
134
+
135
+ ## Contributing
136
+
137
+ 1. Clone this repository.
138
+
139
+ ```sh
140
+ git clone https://github.com/Theia-Scientific/theia-png.git && cd theia-png
141
+ ```
142
+
143
+ 2. Install the dependencies.
144
+
145
+ ```sh
146
+ python3 -m pip install .[dev]
147
+ ```
148
+
149
+ 3. Build the package.
150
+
151
+ ```sh
152
+ python3 -m build
153
+ ```
154
+
155
+ ## Testing
156
+
157
+ Testing is divided into unit and integration tests. Unit tests are located in
158
+ the package source code tree and are defined on a per-module basis with a
159
+ `test_<module>.py` format, while the integration tests are defined in the
160
+ `tests` directory.
161
+
162
+ ## License
163
+
164
+ - [LICENSE](https://github.com/Theia-Scientific/theia-png/blob/main/LICENSE).
165
+
166
+ ## Acknowledgments
167
+
168
+ This material is based upon work supported by the U.S. Department of Energy, Office of Nuclear Energy under Award Number DE-SC0021529.
169
+
170
+ [coco json format]: https://cocodataset.org/#format-data
@@ -0,0 +1,25 @@
1
+ [project]
2
+ name = "tspng"
3
+ version = "0.0.1"
4
+ authors = [
5
+ { name="Theia Scientific", email="support@theiascientific.com" },
6
+ ]
7
+ description = "A Python package for manipulating PNG files exported or imported using the Theia web application"
8
+ readme = "README.md"
9
+ requires-python = ">=3.7"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Operating System :: OS Independent",
14
+ ]
15
+
16
+ [project.urls]
17
+ "Homepage" = "https://github.com/Theia-Scientific/theia-png"
18
+ "Bug Tracker" = "https://github.com/Theia-Scientific/theia-png/issues"
19
+
20
+ [build-system]
21
+ requires = ["hatchling"]
22
+ build-backend = "hatchling.build"
23
+
24
+ [project.optional-dependencies]
25
+ dev = ["build","twine"]
@@ -0,0 +1 @@
1
+ Pillow==7.0.0
tspng-0.0.1/setup.py ADDED
@@ -0,0 +1,51 @@
1
+ import setuptools
2
+
3
+ with open("README.md", "r") as fh:
4
+ long_description = fh.read()
5
+
6
+ setuptools.setup(
7
+ # Here is the module name.
8
+ name="tspng",
9
+
10
+ # version of the module
11
+ version="0.0.1",
12
+
13
+ # Name of Author
14
+ author="Theia Scientific",
15
+
16
+ # your Email address
17
+ author_email="support@theiascientific.com",
18
+
19
+ # #Small Description about module
20
+ # description="adding number",
21
+
22
+ # long_description=long_description,
23
+
24
+ # Specifying that we are using markdown file for description
25
+ long_description=long_description,
26
+ long_description_content_type="text/markdown",
27
+
28
+ # Any link to reach this module, ***if*** you have any webpage or github profile
29
+ # url="https://github.com/username/",
30
+ packages=setuptools.find_packages(),
31
+
32
+
33
+ # if module has dependencies i.e. if your package rely on other package at pypi.org
34
+ # then you must add there, in order to download every requirement of package
35
+
36
+
37
+
38
+ install_requires=[
39
+ "Pillow"
40
+ ],
41
+
42
+
43
+ license="MIT",
44
+
45
+ # classifiers like program is suitable for python3, just leave as it is.
46
+ classifiers=[
47
+ "Programming Language :: Python :: 3",
48
+ "License :: OSI Approved :: MIT License",
49
+ "Operating System :: OS Independent",
50
+ ],
51
+ )
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env python3
2
+
3
+ def test_hello_world():
4
+ print('Hello World!')
@@ -0,0 +1,5 @@
1
+ import os
2
+
3
+ DEFAULT_MIME_TYPE="application/vnd.theiascope.io+json"
4
+
5
+ MIME_TYPE = os.getenv("TSPNG_MIME_TYPE") or DEFAULT_MIME_TYPE
@@ -0,0 +1,15 @@
1
+ #import statements
2
+ from PIL import Image
3
+ from tspng import MIME_TYPE
4
+
5
+ import json
6
+ import os
7
+
8
+ def extract(path,mime_type=MIME_TYPE):
9
+ #open
10
+ abs_path=os.path.abspath(path)
11
+ im=Image.open(abs_path)
12
+ meta=im.text
13
+ #load
14
+ dict=json.loads(meta[mime_type])
15
+ return dict
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from tspng.extraction import extract
4
+
5
+ def test_hello_world():
6
+ print('Hello World!')
7
+
8
+ def test_extract():
9
+ test_data = extract('tests/assets/example_file.ts.png')
10
+ assert list(test_data.keys())==['info','licenses','images','annotations','models','categories']