fctpd 0.1.0__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.
- fctpd-0.1.0/LICENSE +24 -0
- fctpd-0.1.0/PKG-INFO +111 -0
- fctpd-0.1.0/README.md +93 -0
- fctpd-0.1.0/pyproject.toml +23 -0
- fctpd-0.1.0/setup.cfg +4 -0
- fctpd-0.1.0/setup.py +3 -0
- fctpd-0.1.0/src/fctpd/__init__.py +11 -0
- fctpd-0.1.0/src/fctpd/enums.py +31 -0
- fctpd-0.1.0/src/fctpd/fetcher.py +123 -0
- fctpd-0.1.0/src/fctpd/field_map.py +104 -0
- fctpd-0.1.0/src/fctpd/fields.py +212 -0
- fctpd-0.1.0/src/fctpd/fpb_reader.py +102 -0
- fctpd-0.1.0/src/fctpd/fpb_writer.py +156 -0
- fctpd-0.1.0/src/fctpd/fph_reader.py +323 -0
- fctpd-0.1.0/src/fctpd/fph_writer.py +191 -0
- fctpd-0.1.0/src/fctpd/header.py +151 -0
- fctpd-0.1.0/src/fctpd/marshaler.py +100 -0
- fctpd-0.1.0/src/fctpd/projection.py +89 -0
- fctpd-0.1.0/src/fctpd/reader.py +77 -0
- fctpd-0.1.0/src/fctpd/timing.py +53 -0
- fctpd-0.1.0/src/fctpd/uid.py +27 -0
- fctpd-0.1.0/src/fctpd/unmarshaler.py +90 -0
- fctpd-0.1.0/src/fctpd/writer.py +105 -0
- fctpd-0.1.0/src/fctpd.egg-info/PKG-INFO +111 -0
- fctpd-0.1.0/src/fctpd.egg-info/SOURCES.txt +26 -0
- fctpd-0.1.0/src/fctpd.egg-info/dependency_links.txt +1 -0
- fctpd-0.1.0/src/fctpd.egg-info/requires.txt +3 -0
- fctpd-0.1.0/src/fctpd.egg-info/top_level.txt +1 -0
fctpd-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
fctpd-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fctpd
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Tools for FPH/FPB, CT projection data formats for the modern compute environment.
|
|
5
|
+
Author-email: "J. Genender, J. Hoffman" <johnmarianhoffman@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://gitlab.com/hoffman-lab/fct/fpb-py
|
|
7
|
+
Project-URL: Issues, https://gitlab.com/hoffman-lab/fct/fpb-py/-/work_items
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: pympler
|
|
16
|
+
Requires-Dist: requests
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# FPB-py
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Getting started
|
|
24
|
+
|
|
25
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
26
|
+
|
|
27
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
28
|
+
|
|
29
|
+
## Add your files
|
|
30
|
+
|
|
31
|
+
* [Create](https://docs.gitlab.com/user/project/repository/web_editor/#create-a-file) or [upload](https://docs.gitlab.com/user/project/repository/web_editor/#upload-a-file) files
|
|
32
|
+
* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
cd existing_repo
|
|
36
|
+
git remote add origin https://gitlab.com/hoffman-lab/fct/fpb-py.git
|
|
37
|
+
git branch -M main
|
|
38
|
+
git push -uf origin main
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Integrate with your tools
|
|
42
|
+
|
|
43
|
+
* [Set up project integrations](https://gitlab.com/hoffman-lab/fct/fpb-py/-/settings/integrations)
|
|
44
|
+
|
|
45
|
+
## Collaborate with your team
|
|
46
|
+
|
|
47
|
+
* [Invite team members and collaborators](https://docs.gitlab.com/user/project/members/)
|
|
48
|
+
* [Create a new merge request](https://docs.gitlab.com/user/project/merge_requests/creating_merge_requests/)
|
|
49
|
+
* [Automatically close issues from merge requests](https://docs.gitlab.com/user/project/issues/managing_issues/#closing-issues-automatically)
|
|
50
|
+
* [Enable merge request approvals](https://docs.gitlab.com/user/project/merge_requests/approvals/)
|
|
51
|
+
* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
|
52
|
+
|
|
53
|
+
## Test and Deploy
|
|
54
|
+
|
|
55
|
+
Use the built-in continuous integration in GitLab.
|
|
56
|
+
|
|
57
|
+
* [Get started with GitLab CI/CD](https://docs.gitlab.com/ci/quick_start/)
|
|
58
|
+
* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/user/application_security/sast/)
|
|
59
|
+
* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/topics/autodevops/requirements/)
|
|
60
|
+
* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/user/clusters/agent/)
|
|
61
|
+
* [Set up protected environments](https://docs.gitlab.com/ci/environments/protected_environments/)
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
# Editing this README
|
|
66
|
+
|
|
67
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
68
|
+
|
|
69
|
+
## Suggestions for a good README
|
|
70
|
+
|
|
71
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
72
|
+
|
|
73
|
+
## Name
|
|
74
|
+
Choose a self-explaining name for your project.
|
|
75
|
+
|
|
76
|
+
## Description
|
|
77
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
78
|
+
|
|
79
|
+
## Badges
|
|
80
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
81
|
+
|
|
82
|
+
## Visuals
|
|
83
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
87
|
+
|
|
88
|
+
## Usage
|
|
89
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
90
|
+
|
|
91
|
+
## Support
|
|
92
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
93
|
+
|
|
94
|
+
## Roadmap
|
|
95
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
96
|
+
|
|
97
|
+
## Contributing
|
|
98
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
99
|
+
|
|
100
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
101
|
+
|
|
102
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
103
|
+
|
|
104
|
+
## Authors and acknowledgment
|
|
105
|
+
Show your appreciation to those who have contributed to the project.
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
For open source projects, say how it is licensed.
|
|
109
|
+
|
|
110
|
+
## Project status
|
|
111
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
fctpd-0.1.0/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# FPB-py
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
8
|
+
|
|
9
|
+
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
10
|
+
|
|
11
|
+
## Add your files
|
|
12
|
+
|
|
13
|
+
* [Create](https://docs.gitlab.com/user/project/repository/web_editor/#create-a-file) or [upload](https://docs.gitlab.com/user/project/repository/web_editor/#upload-a-file) files
|
|
14
|
+
* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
cd existing_repo
|
|
18
|
+
git remote add origin https://gitlab.com/hoffman-lab/fct/fpb-py.git
|
|
19
|
+
git branch -M main
|
|
20
|
+
git push -uf origin main
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Integrate with your tools
|
|
24
|
+
|
|
25
|
+
* [Set up project integrations](https://gitlab.com/hoffman-lab/fct/fpb-py/-/settings/integrations)
|
|
26
|
+
|
|
27
|
+
## Collaborate with your team
|
|
28
|
+
|
|
29
|
+
* [Invite team members and collaborators](https://docs.gitlab.com/user/project/members/)
|
|
30
|
+
* [Create a new merge request](https://docs.gitlab.com/user/project/merge_requests/creating_merge_requests/)
|
|
31
|
+
* [Automatically close issues from merge requests](https://docs.gitlab.com/user/project/issues/managing_issues/#closing-issues-automatically)
|
|
32
|
+
* [Enable merge request approvals](https://docs.gitlab.com/user/project/merge_requests/approvals/)
|
|
33
|
+
* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
|
34
|
+
|
|
35
|
+
## Test and Deploy
|
|
36
|
+
|
|
37
|
+
Use the built-in continuous integration in GitLab.
|
|
38
|
+
|
|
39
|
+
* [Get started with GitLab CI/CD](https://docs.gitlab.com/ci/quick_start/)
|
|
40
|
+
* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/user/application_security/sast/)
|
|
41
|
+
* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/topics/autodevops/requirements/)
|
|
42
|
+
* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/user/clusters/agent/)
|
|
43
|
+
* [Set up protected environments](https://docs.gitlab.com/ci/environments/protected_environments/)
|
|
44
|
+
|
|
45
|
+
***
|
|
46
|
+
|
|
47
|
+
# Editing this README
|
|
48
|
+
|
|
49
|
+
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
|
50
|
+
|
|
51
|
+
## Suggestions for a good README
|
|
52
|
+
|
|
53
|
+
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
|
54
|
+
|
|
55
|
+
## Name
|
|
56
|
+
Choose a self-explaining name for your project.
|
|
57
|
+
|
|
58
|
+
## Description
|
|
59
|
+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
60
|
+
|
|
61
|
+
## Badges
|
|
62
|
+
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
|
63
|
+
|
|
64
|
+
## Visuals
|
|
65
|
+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
72
|
+
|
|
73
|
+
## Support
|
|
74
|
+
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
75
|
+
|
|
76
|
+
## Roadmap
|
|
77
|
+
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
State if you are open to contributions and what your requirements are for accepting them.
|
|
81
|
+
|
|
82
|
+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
|
83
|
+
|
|
84
|
+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
|
85
|
+
|
|
86
|
+
## Authors and acknowledgment
|
|
87
|
+
Show your appreciation to those who have contributed to the project.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
For open source projects, say how it is licensed.
|
|
91
|
+
|
|
92
|
+
## Project status
|
|
93
|
+
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools"]
|
|
3
|
+
build-backend = "setuptools.build_meta:__legacy__"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fctpd"
|
|
7
|
+
description = "Tools for FPH/FPB, CT projection data formats for the modern compute environment."
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "J. Genender, J. Hoffman", email = "johnmarianhoffman@gmail.com" }
|
|
10
|
+
]
|
|
11
|
+
version = "0.1.0"
|
|
12
|
+
requires-python = ">= 3.9"
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Science/Research",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
]
|
|
19
|
+
dependencies = ["numpy", "pympler", "requests"]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://gitlab.com/hoffman-lab/fct/fpb-py"
|
|
23
|
+
Issues = "https://gitlab.com/hoffman-lab/fct/fpb-py/-/work_items"
|
fctpd-0.1.0/setup.cfg
ADDED
fctpd-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .enums import AnonymizationLevel, PixelEncoding, WriteMode
|
|
2
|
+
from .field_map import FieldMap
|
|
3
|
+
from .fpb_reader import FPBReader
|
|
4
|
+
from .fpb_writer import FPBWriter
|
|
5
|
+
from .fph_reader import FPHReader
|
|
6
|
+
from .fph_writer import FPHWriter
|
|
7
|
+
from .header import Header
|
|
8
|
+
from .marshaler import ProjectionMarshaler
|
|
9
|
+
from .projection import Projection
|
|
10
|
+
from .unmarshaler import ProjectionUnmarshaler
|
|
11
|
+
from .writer import WriteOptions
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class AnonymizationLevel(Enum):
|
|
5
|
+
"""
|
|
6
|
+
AnonymizationLevel describes how a Reader or Writer should treat
|
|
7
|
+
the sensitive entry collection.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
High = 0
|
|
11
|
+
Medium = 1
|
|
12
|
+
Low = 2
|
|
13
|
+
NA = 3
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class PixelEncoding(Enum):
|
|
17
|
+
"""
|
|
18
|
+
PixelEncoding describes how a Writer should serialize pixel data.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
F32 = 0
|
|
22
|
+
U16 = 1
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class WriteMode(Enum):
|
|
26
|
+
"""
|
|
27
|
+
WriteMode describes how an FPHWriter writes its projection data.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
Single = 0
|
|
31
|
+
Multi = 1
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
from . import fields
|
|
2
|
+
from .field_map import FieldMap
|
|
3
|
+
from requests import get, Response
|
|
4
|
+
from typing import Any
|
|
5
|
+
from urllib.parse import ParseResult, urlparse
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SelfValue(Any):
|
|
10
|
+
def __init__(self, offset: int, range: int | None) -> None:
|
|
11
|
+
self._offset: int = offset
|
|
12
|
+
self._range: int | None = range
|
|
13
|
+
|
|
14
|
+
@property
|
|
15
|
+
def offset(self) -> int:
|
|
16
|
+
return self._offset
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def range(self) -> int | None:
|
|
20
|
+
return self._range
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Fetcher:
|
|
24
|
+
def __init__(self) -> None:
|
|
25
|
+
return
|
|
26
|
+
|
|
27
|
+
def fetch(self, val: Any) -> Any:
|
|
28
|
+
"""
|
|
29
|
+
Fetch either standard and URI-linked data from an input value.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
- val (Any): Value to parse.
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
-------
|
|
37
|
+
- data (Any): Data linked by the value.
|
|
38
|
+
"""
|
|
39
|
+
# If we don't have a FieldMap, there's nothing to fetch
|
|
40
|
+
if not isinstance(val, FieldMap) and not isinstance(val, dict):
|
|
41
|
+
return val
|
|
42
|
+
|
|
43
|
+
# If the URI is absent, we cannot treat the value as a
|
|
44
|
+
# URI-addressed value; simply return it
|
|
45
|
+
if fields.URI not in val:
|
|
46
|
+
return val
|
|
47
|
+
|
|
48
|
+
# Set the byte offset and range
|
|
49
|
+
uri: str = val[fields.URI]
|
|
50
|
+
offset: int = val[fields.ByteOffset] if fields.ByteOffset in val else 0
|
|
51
|
+
range: int | None = val[fields.ByteRange] if fields.ByteRange in val else None
|
|
52
|
+
|
|
53
|
+
# Validate whether the URI is valid
|
|
54
|
+
uri_parse: ParseResult = urlparse(uri)
|
|
55
|
+
if not uri_parse.scheme:
|
|
56
|
+
raise ValueError("invalid URI-addressed value: URI is invalid")
|
|
57
|
+
|
|
58
|
+
# Match on the scheme
|
|
59
|
+
match uri_parse.scheme:
|
|
60
|
+
case "file":
|
|
61
|
+
return self._fetch_file(uri_parse.path, offset, range)
|
|
62
|
+
|
|
63
|
+
case "http" | "https":
|
|
64
|
+
return self._fetch_http(uri, offset, range)
|
|
65
|
+
|
|
66
|
+
case "self":
|
|
67
|
+
return SelfValue(offset, range)
|
|
68
|
+
|
|
69
|
+
case _:
|
|
70
|
+
raise NotImplementedError(
|
|
71
|
+
f"URI scheme {uri_parse.scheme} not supported"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def _fetch_file(self, path: str, offset: int, range: int | None) -> bytes:
|
|
75
|
+
"""
|
|
76
|
+
Internal fetch function for local files.
|
|
77
|
+
|
|
78
|
+
Parameters
|
|
79
|
+
----------
|
|
80
|
+
- path (str): Local file path to data.
|
|
81
|
+
- offset (int): File byte offset to data.
|
|
82
|
+
- range: (int | None): Size of byte data to read.
|
|
83
|
+
"""
|
|
84
|
+
# Check the path exists and is a file
|
|
85
|
+
if not os.path.exists(path) or os.path.isdir(path):
|
|
86
|
+
raise FileNotFoundError
|
|
87
|
+
|
|
88
|
+
# Adjust the range
|
|
89
|
+
if range is None:
|
|
90
|
+
range = os.path.getsize(path)
|
|
91
|
+
|
|
92
|
+
# Load the file pointer into memory
|
|
93
|
+
with open(path, "rb", buffering=0) as f:
|
|
94
|
+
f.seek(offset, os.SEEK_SET)
|
|
95
|
+
data: bytes = f.read(range)
|
|
96
|
+
f.close()
|
|
97
|
+
|
|
98
|
+
return data
|
|
99
|
+
|
|
100
|
+
def _fetch_http(self, uri: str, offset: int, range: int | None) -> bytes:
|
|
101
|
+
"""
|
|
102
|
+
Internal fetch function for HTTP/HTTPS.
|
|
103
|
+
|
|
104
|
+
Parameters
|
|
105
|
+
----------
|
|
106
|
+
- uri (str): HTTP-schemed URI to data.
|
|
107
|
+
- offset (int): File byte offset to data.
|
|
108
|
+
- range: (int | None): Size of byte data to read.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
# Get the range header
|
|
112
|
+
range_hdr: dict[str, str] = (
|
|
113
|
+
{"Range": f"bytes={offset}-"}
|
|
114
|
+
if range is None
|
|
115
|
+
else {"Range": f"bytes={offset}-{offset+range}"}
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Perform the request
|
|
119
|
+
resp: Response = get(uri, headers=range_hdr)
|
|
120
|
+
resp.raise_for_status()
|
|
121
|
+
|
|
122
|
+
# Return the response body
|
|
123
|
+
return resp.content
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
from . import fields
|
|
2
|
+
from .enums import AnonymizationLevel
|
|
3
|
+
from .timing import date
|
|
4
|
+
from .uid import generate_accession_number, generate_uid
|
|
5
|
+
from numpy import number
|
|
6
|
+
from re import match
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FieldMap(dict[str, Any]):
|
|
11
|
+
"""
|
|
12
|
+
FieldMap is a hash map with string-valued keys and
|
|
13
|
+
any-valued values.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, entries: dict[str, Any] | None = None) -> None:
|
|
17
|
+
"""
|
|
18
|
+
Constructor for a FieldMap object.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
- entries (dict[str, Any]): Entries to initialize the FieldMap
|
|
23
|
+
with [default: `{}`].
|
|
24
|
+
"""
|
|
25
|
+
super().__init__({} if entries is None else entries)
|
|
26
|
+
|
|
27
|
+
def anonymized(self, anon_level: AnonymizationLevel) -> FieldMap:
|
|
28
|
+
"""
|
|
29
|
+
Returns an anonymized copy of the FieldMap object.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
- anon_level (AnonymizationLevel): Degree of anonymization to apply
|
|
34
|
+
to the copied FieldMap.
|
|
35
|
+
|
|
36
|
+
Returns
|
|
37
|
+
-------
|
|
38
|
+
- anon_fm (FieldMap): Anonymized FieldMap object.
|
|
39
|
+
"""
|
|
40
|
+
# Iterate through sensitive fields and anonymize
|
|
41
|
+
anon_fm: FieldMap = FieldMap()
|
|
42
|
+
for fld in fields.SensitiveFields:
|
|
43
|
+
# Skip fields that are absent
|
|
44
|
+
if fld not in self:
|
|
45
|
+
continue
|
|
46
|
+
|
|
47
|
+
# Switch on anonymization level
|
|
48
|
+
val = self.pop(fld)
|
|
49
|
+
match anon_level:
|
|
50
|
+
case AnonymizationLevel.High:
|
|
51
|
+
# Leave the entry out
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
case AnonymizationLevel.Medium:
|
|
55
|
+
# Switch on the value type
|
|
56
|
+
match val:
|
|
57
|
+
case str():
|
|
58
|
+
anon_fm[fld] = ""
|
|
59
|
+
case number():
|
|
60
|
+
anon_fm[fld] = 0
|
|
61
|
+
|
|
62
|
+
case AnonymizationLevel.Low:
|
|
63
|
+
# Switch on the value type
|
|
64
|
+
match val:
|
|
65
|
+
case str():
|
|
66
|
+
anon_fm[fld] = _anonymize_string_field(fld, val)
|
|
67
|
+
case number():
|
|
68
|
+
anon_fm[fld] = 0
|
|
69
|
+
|
|
70
|
+
case AnonymizationLevel.NA:
|
|
71
|
+
# Reinstate the entry
|
|
72
|
+
anon_fm[fld] = val
|
|
73
|
+
|
|
74
|
+
return anon_fm
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _anonymize_string_field(fld: str, val: str) -> str:
|
|
78
|
+
"""
|
|
79
|
+
Internal string anonymization function.
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
----------
|
|
83
|
+
- fld (str): Name of the entry.
|
|
84
|
+
- val (str): String-typed value associated with the entry.
|
|
85
|
+
|
|
86
|
+
Returns
|
|
87
|
+
-------
|
|
88
|
+
- anonymized string value (str)
|
|
89
|
+
"""
|
|
90
|
+
lower: str = fld.lower()
|
|
91
|
+
if "date" in lower:
|
|
92
|
+
return date()
|
|
93
|
+
elif "pregnan" in lower:
|
|
94
|
+
return "PregnancyUnknown"
|
|
95
|
+
elif "uid" in lower:
|
|
96
|
+
return generate_uid()
|
|
97
|
+
elif "time" in lower:
|
|
98
|
+
return "0.000"
|
|
99
|
+
elif fld == fields.AccessionNumber:
|
|
100
|
+
return generate_accession_number()
|
|
101
|
+
elif match(r"[\w+]Y", val):
|
|
102
|
+
return "000Y"
|
|
103
|
+
else:
|
|
104
|
+
return "ANON"
|