Skip to content

Commit be5034f

Browse files
committed
more cleanup
1 parent f6ebbd9 commit be5034f

File tree

7 files changed

+1213
-913
lines changed

7 files changed

+1213
-913
lines changed

notebooks/Your_first_ASDF_converter.ipynb

Lines changed: 986 additions & 225 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[project]
2+
name = "mfconverter"
3+
description = "TODO"
4+
version='0.1.0'
5+
requires-python = ">=3.9"
6+
dependencies = [
7+
"asdf >=2.8",
8+
]
9+
10+
[build-system]
11+
requires = ["setuptools >=61", "setuptools_scm[toml] >=3.4"]
12+
build-backend = "setuptools.build_meta"
13+
14+
[project.entry-points."asdf.extensions"]
15+
mfconverter = "mfconverter.extensions:get_extensions"
16+
17+
[tool.setuptools.packages.find]
18+
where = ["src"]

notebooks/Your_first_ASDF_converter/src/mfconverter/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from asdf.extension import Converter
2+
3+
class PhotoIDConverter(Converter):
4+
tags = ["asdf://stsci.edu/example-project/tags/photo_id-*"]
5+
types = ["mfconverter.photo_id.PhotoID"]
6+
# The above registers the tag that the converter is used for, as well as
7+
# associating the class that the converter is used for.
8+
9+
# This method converts from the Python object to yaml
10+
def to_yaml_tree(self, obj, tags, ctx):
11+
# The yaml conversion expects a dictionary returned
12+
node = {}
13+
node['first_name'] = obj.first_name
14+
node['last_name'] = obj.last_name
15+
node['photo'] = obj.photo
16+
return node
17+
18+
# This method converts from yaml to the Python object
19+
def from_yaml_tree(self, node, tag, ctx):
20+
from .photo_id import PhotoID # Deferred import to avoid always importing
21+
# when ASDF gets entry points.
22+
return PhotoID(node['last_name'],
23+
node['first_name'],
24+
node['photo'])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from asdf.extension import Extension
2+
from .converter import PhotoIDConverter
3+
4+
class MFExtension(Extension):
5+
extension_uri = "asdf://stsci.edu/example-project/photo_id-1.0.0"
6+
tags = ["asdf://stsci.edu/example-project/tags/photo_id-1.0.0"]
7+
converters = [PhotoIDConverter()]
8+
9+
# The following will be called by ASDF when looking for ASDF entry points
10+
def get_extensions():
11+
return [MFExtension()]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class PhotoID:
2+
"Holds Photo ID information"
3+
4+
def __init__(self, last_name, first_name, photo):
5+
"expects a monochromatic numpy array for photo"
6+
self.last_name = last_name
7+
self.first_name = first_name
8+
self.photo = photo
9+
10+
def name(self):
11+
return self.last_name + ', ' + self.first_name

0 commit comments

Comments
 (0)