Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHuwe committed May 1, 2024
1 parent fb16aba commit 89a34e5
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 75 deletions.
9 changes: 1 addition & 8 deletions src/roman_datamodels/datamodels/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def __new__(cls, init=None, **kwargs):
return super().__new__(cls)

def __init__(self, init=None, **kwargs):
# print(f"\n\n\n\nXXX type(init.meta.file_date) = {type(init.meta.file_date)}")
if isinstance(init, self.__class__):
# Due to __new__ above, this is already initialized.
return
Expand All @@ -128,11 +127,7 @@ def __init__(self, init=None, **kwargs):
raise ValidationError(
f"TaggedObjectNode: {init.__class__.__name__} is not of the type expected. Expected {expected}"
)
# print(f"\n\n\n\nXXX init = {init}")
# print(f"\n\n\n\nXXX init.meta.file_date = {init.meta.file_date}")
# print(f"\n\n\n\nXXX type(init.meta.file_date) = {type(init.meta.file_date)}")
# print(f"\n\n\n\nXXX init.meta.file_date.tag = {init.meta.file_date.tag}")
# print(f"\n\n\n\nXXX init.meta.file_date._tag = {init.meta.file_date._tag}")

with validate.nuke_validation():
self._instance = init
af = asdf.AsdfFile()
Expand Down Expand Up @@ -261,11 +256,9 @@ def shape(self):
return self._shape

def __setattr__(self, attr, value):
# print(f"XXX Setting model value for ({attr})")
if attr.startswith("_"):
self.__dict__[attr] = value
else:
# print(f"XXX Setting model value for ({attr})")
setattr(self._instance, attr, value)

def __getattr__(self, attr):
Expand Down
4 changes: 0 additions & 4 deletions src/roman_datamodels/datamodels/_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ def __init_subclass__(cls, **kwargs):

class _RomanDataModel(_DataModel):
def __init__(self, init=None, **kwargs):
# print(f"\n\n\n\nXXX 0 _RomanDataModel type(init.meta.file_date) = {type(init.meta.file_date)}")

super().__init__(init, **kwargs)

# print(f"\n\n\n\nXXX 1 _RomanDataModel type(init.meta.file_date) = {type(init.meta.file_date)}")

if init is not None:
self.meta.model_type = self.__class__.__name__

Expand Down
10 changes: 2 additions & 8 deletions src/roman_datamodels/maker_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _get_node_maker(node_class):
-------
maker function for node class
"""
print(f"\nXXX node_class = {node_class}")

if node_class.__name__ in SPECIAL_MAKERS:
method_name = SPECIAL_MAKERS[node_class.__name__]
else:
Expand All @@ -62,8 +62,6 @@ def _get_node_maker(node_class):

if method_name not in globals():
raise ValueError(f"Maker utility: {method_name} not implemented for class {node_class.__name__}")

print(f"\nXXX method_name = {method_name}")

return globals()[method_name]

Expand All @@ -84,7 +82,6 @@ def mk_node(node_class, **kwargs):
-------
`roman_datamodels.stnode.TaggedObjectNode`
"""
print("\nXXX Making node!")

return _get_node_maker(node_class)(**kwargs)

Expand All @@ -105,8 +102,5 @@ def mk_datamodel(model_class, **kwargs):
-------
`roman_datamodels.datamodels.Datamodel`
"""
print(f"\n\nXXX model_class = {model_class}\n\n")
# print(f"\n\nXXX NODE_REGISTRY[model_class] = {NODE_REGISTRY[model_class]}\n\n")
print(f"\n\nXXX kwargs = {kwargs}\n\n")
# print(f"\n\nXXX mk_node(NODE_REGISTRY[model_class], **kwargs) = {mk_node(NODE_REGISTRY[model_class], **kwargs)}\n\n")

return model_class(mk_node(NODE_REGISTRY[model_class], **kwargs))
4 changes: 1 addition & 3 deletions src/roman_datamodels/maker_utils/_basic_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def mk_file_date(**kwargs):
-------
roman_datamodels.stnode.FileDate
"""
print("XXX REAL FileDate")

return stnode.FileDate(kwargs.get("file_date", time.Time("2020-01-01T00:00:00.0", format="isot", scale="utc")))


Expand Down Expand Up @@ -104,13 +104,11 @@ def mk_basic_meta(**kwargs):
-------
dict (defined by the basic-1.0.0 schema)
"""
print("XXX Making REAL BASIC")
meta = {}
meta["calibration_software_version"] = mk_calibration_software_version(**kwargs)
meta["sdf_software_version"] = mk_sdf_software_version(**kwargs)
meta["filename"] = mk_filename(**kwargs)
meta["file_date"] = mk_file_date(**kwargs)
print(f"XXX type(meta[file_date]) = {type(meta["file_date"])}")
meta["model_type"] = mk_model_type(**kwargs)
meta["origin"] = mk_origin(**kwargs)
meta["prd_software_version"] = mk_prd_software_version(**kwargs)
Expand Down
4 changes: 0 additions & 4 deletions src/roman_datamodels/maker_utils/_common_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ def mk_common_meta(**kwargs):
dict (defined by the common-1.0.0 schema)
"""
meta = mk_basic_meta(**kwargs)
print(f"XXX common meta type(meta[file_date]) = {type(meta["file_date"])}")
meta["aperture"] = mk_aperture(**kwargs.get("aperture", {}))
meta["cal_step"] = mk_l2_cal_step(**kwargs.get("cal_step", {}))
meta["coordinates"] = mk_coordinates(**kwargs.get("coordinates", {}))
Expand Down Expand Up @@ -529,9 +528,6 @@ def mk_photometry_meta(**kwargs):
meta["photometry"] = mk_photometry(**kwargs.get("photometry", {}))
meta["outlier_detection"] = mk_outlier_detection(**kwargs.get("outlier_detection", {}))

print(f"XXX photometry meta type(meta[file_date]) = {type(meta["file_date"])}")


return meta


Expand Down
4 changes: 0 additions & 4 deletions src/roman_datamodels/maker_utils/_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,8 @@ def mk_level2_image(*, shape=(4088, 4088), n_groups=8, filepath=None, **kwargs):

wfi_image = stnode.WfiImage()

# print(f"XXX make l2 type(wfi_image[meta][file_date]) = {type(wfi_image["meta"]["file_date"])}")

wfi_image["meta"] = mk_photometry_meta(**kwargs.get("meta", {}))

# print(f"XXX make l2 type(wfi_image[meta][file_date]) = {type(wfi_image["meta"]["file_date"])}")

# add border reference pixel arrays
wfi_image["border_ref_pix_left"] = kwargs.get(
"border_ref_pix_left", u.Quantity(np.zeros((n_groups, shape[0] + 8, 4), dtype=np.float32), u.DN, dtype=np.float32)
Expand Down
12 changes: 1 addition & 11 deletions src/roman_datamodels/maker_utils/_fps_common_meta.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import numpy as np
from astropy import coordinates, time
from astropy import units as u
from astropy.modeling import models
from astropy.table import QTable
from gwcs import coordinate_frames
from gwcs.wcs import WCS
from astropy import time

from roman_datamodels import stnode

from ._base import NONUM, NOSTR
from ._fps_basic_meta import mk_fps_basic_meta

# from ._ground import mk_base_exposure, mk_base_guidestar
# from ._tagged_nodes import mk_photometry, mk_resample


def mk_fps_exposure(**kwargs):
Expand Down Expand Up @@ -136,4 +127,3 @@ def mk_fps_ref_file(**kwargs):
ref_file["crds"] = kwargs.get("crds", {"sw_version": "12.3.1", "context_used": "roman_0815.pmap"})

return ref_file

1 change: 0 additions & 1 deletion src/roman_datamodels/maker_utils/_tvac_basic_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def mk_tvac_basic_meta(**kwargs):
-------
dict (defined by the tvac/basic-1.0.0 schema)
"""
print("XXX Making TVAC BASIC")
meta = {}
meta["calibration_software_version"] = mk_tvac_calibration_software_version(**kwargs)
meta["sdf_software_version"] = mk_tvac_sdf_software_version(**kwargs)
Expand Down
13 changes: 1 addition & 12 deletions src/roman_datamodels/maker_utils/_tvac_common_meta.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import numpy as np
from astropy import coordinates, time
from astropy import units as u
from astropy.modeling import models
from astropy.table import QTable
from gwcs import coordinate_frames
from gwcs.wcs import WCS
from astropy import time

from roman_datamodels import stnode

from ._base import NONUM, NOSTR
from ._tvac_basic_meta import mk_tvac_basic_meta

# from ._ground import mk_base_exposure, mk_base_guidestar
# from ._tagged_nodes import mk_photometry, mk_resample


def mk_tvac_exposure(**kwargs):
"""
Expand Down Expand Up @@ -136,4 +126,3 @@ def mk_tvac_ref_file(**kwargs):
ref_file["crds"] = kwargs.get("crds", {"sw_version": "12.3.1", "context_used": "roman_0815.pmap"})

return ref_file

11 changes: 0 additions & 11 deletions src/roman_datamodels/stnode/_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,14 @@ def load_schema_from_uri(schema_uri):
if "reference_files" in schema_uri:
schema_path = BASE_SCHEMA_PATH / "reference_files" / filename
elif "/fps/tagged_scalars" in schema_uri:
print(f"XXXX FPS TAGGED SCALARS schema_uri = {schema_uri}")
schema_path = BASE_SCHEMA_PATH / "fps/tagged_scalars" / filename
elif "/fps/" in schema_uri:
print(f"XXXX FPX schema_uri = {schema_uri}")
schema_path = BASE_SCHEMA_PATH / "fps" / filename
elif "/tvac/tagged_scalars" in schema_uri:
print(f"XXXX TVAC TAGGED SCALARS schema_uri = {schema_uri}")
schema_path = BASE_SCHEMA_PATH / "tvac/tagged_scalars" / filename
elif "/tvac/" in schema_uri:
print(f"XXXX TVAC schema_uri = {schema_uri}")
schema_path = BASE_SCHEMA_PATH / "tvac" / filename
elif "tagged_scalars" in schema_uri:
print(f"XXXX REAL TAGGED SCALARS schema_uri = {schema_uri}")
schema_path = BASE_SCHEMA_PATH / "tagged_scalars" / filename
else:
schema_path = BASE_SCHEMA_PATH / filename
Expand Down Expand Up @@ -123,9 +118,6 @@ def scalar_factory(tag):
class_name = class_name_from_tag_uri(tag["tag_uri"])
schema = load_schema_from_uri(tag["schema_uri"])

print(f"XXXX scalar_factory tag[schema_uri] = {tag["schema_uri"]}")
print(f"XXXX scalar_factory schema = {schema}")

# TaggedScalarNode subclasses are really subclasses of the type of the scalar,
# with the TaggedScalarNode as a mixin. This is because the TaggedScalarNode
# is supposed to be the scalar, but it needs to be serializable under a specific
Expand Down Expand Up @@ -162,9 +154,6 @@ def node_factory(tag):
class_name = class_name_from_tag_uri(tag["tag_uri"])
schema = load_schema_from_uri(tag["schema_uri"])

print(f"XXXX node_factory tag[schema_uri] = {tag["schema_uri"]}")
print(f"XXXX node_factory schema = {schema}")

if "type" in schema:
# Determine if the class is a TaggedObjectNode or TaggedListNode based on the
# type defined in the schema:
Expand Down
9 changes: 1 addition & 8 deletions src/roman_datamodels/stnode/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def ctx(self):
@staticmethod
def _convert_to_scalar(key, value):
"""Find and wrap scalars in the appropriate class, if its a tagged one."""
print(f"XXX converting ({key},{value}) to scalar")

if key in SCALAR_NODE_CLASSES_BY_KEY:
value = SCALAR_NODE_CLASSES_BY_KEY[key](value)

Expand Down Expand Up @@ -226,8 +226,6 @@ def __setattr__(self, key, value):
Permit assigning dict keys as attributes.
"""

print(f"XXX Setting node value for ({key}, {value}) with tag ({self._tag})")

# Private keys should just be in the normal __dict__
if key[0] != "_":

Expand Down Expand Up @@ -316,20 +314,17 @@ def __getitem__(self, key):
def __setitem__(self, key, value):
"""Dictionary style access set data"""

print(f"XXX Before converting to scalar ({key},{value}) with tag ({self._tag})")
# Convert the value to a tagged scalar if necessary
if self._tag and "/tvac" in self._tag:
value = self._convert_to_scalar("tvac_"+key, value)
elif self._tag and "/fps" in self._tag:
value = self._convert_to_scalar("fps_"+key, value)
else:
value = self._convert_to_scalar(key, value)
print(f"XXX After converting to scalar ({key},{value}) with tag ({self._tag})")

# If the value is a dictionary, loop over its keys and convert them to tagged scalars
if isinstance(value, dict):
for sub_key, sub_value in value.items():
print(f"XXX Looping over subkeys!")
# value[sub_key] = self._convert_to_scalar(sub_key, sub_value)
if self._tag and "/tvac" in self._tag:
value[sub_key] = self._convert_to_scalar("tvac_"+sub_key, sub_value)
Expand All @@ -338,8 +333,6 @@ def __setitem__(self, key, value):
else:
value[sub_key] = self._convert_to_scalar(sub_key, sub_value)

print(f"XXX After loop ({key},{value}) with tag ({self._tag})")

self._data[key] = value

def __delitem__(self, key):
Expand Down
1 change: 0 additions & 1 deletion src/roman_datamodels/stnode/_tagged.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def __init_subclass__(cls, **kwargs) -> None:
Register any subclasses of this class in the SCALAR_NODE_CLASSES_BY_TAG
and SCALAR_NODE_CLASSES_BY_KEY registry.
"""
print(f"XXX TaggedScalarNode init cls._tag = {cls._tag}")
super().__init_subclass__(**kwargs)
if cls.__name__ != "TaggedScalarNode":
if cls._tag in SCALAR_NODE_CLASSES_BY_TAG:
Expand Down

0 comments on commit 89a34e5

Please sign in to comment.