Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light update #37

Merged
merged 7 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ and the release date, in year-month-day format (see examples below).
Unreleased
----------


0.10.0 (2024-05-28)
-------------------

Added
^^^^^
- image_records.py - Added various light_on_x columns to record the state of the
lights in ImageRecord objects.

Changed
^^^^^^^
- create_raw.py - For the get_lights() function, session is now optional, and by default,
the get_lights() function now relies on the values in the passed ImageRecord, but if
given a session, the values in the light_records table will override what is in the
ImageRecord.

0.9.2 (2024-04-15)
------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.9.2
current_version = 0.10.0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
Expand Down
2 changes: 1 addition & 1 deletion src/vipersci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """vipersci Developers"""
__email__ = "[email protected]"
__version__ = "0.9.2"
__version__ = "0.10.0"
67 changes: 67 additions & 0 deletions src/vipersci/vis/db/image_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ class ImageRecord(Base):
doc="The absolute path (POSIX style) that contains the Array_2D_Image "
"that this metadata refers to.",
)
haz1LightState = synonym("light_on_hfp")
haz2LightState = synonym("light_on_hap")
haz3LightState = synonym("light_on_hfs")
haz4LightState = synonym("light_on_has")
haz5LightState = synonym("light_on_hcp")
haz6LightState = synonym("light_on_hcs")
icer_byte_quota = mapped_column(
Integer,
doc="The byteQuota value during onboard ICER compression. In the returned "
Expand Down Expand Up @@ -200,6 +206,46 @@ class ImageRecord(Base):
# There is a sensor in the camera body (PT1000) which is apparently not
# connected (sigh). And there is also a sensor external to each camera
# body (AD590), need to track down its Yamcs feed.
light_on_hfp = mapped_column(
Boolean,
nullable=True,
doc="haz1LightState as reported by image metadata.",
)
light_on_hap = mapped_column(
Boolean,
nullable=True,
doc="haz2LightState as reported by image metadata.",
)
light_on_hfs = mapped_column(
Boolean,
nullable=True,
doc="haz3LightState as reported by image metadata.",
)
light_on_has = mapped_column(
Boolean,
nullable=True,
doc="haz4LightState as reported by image metadata.",
)
light_on_hcp = mapped_column(
Boolean,
nullable=True,
doc="haz5LightState as reported by image metadata.",
)
light_on_hcs = mapped_column(
Boolean,
nullable=True,
doc="haz6LightState as reported by image metadata.",
)
light_on_nl = mapped_column(
Boolean,
nullable=True,
doc="navLeftLightState as reported by image metadata.",
)
light_on_nr = mapped_column(
Boolean,
nullable=True,
doc="navRightLightState as reported by image metadata.",
)
lines = mapped_column(
Integer,
nullable=False,
Expand All @@ -211,6 +257,8 @@ class ImageRecord(Base):
nullable=False,
doc="The TIME_TAG from the MCSE Image Header.",
)
navLeftLightState = synonym("light_on_nl")
navRightLightState = synonym("light_on_nr")
# mcam_id, The MCAM_ID from the MCSE Image Header is not returned to the ground.
offset = mapped_column(
Integer,
Expand Down Expand Up @@ -640,6 +688,25 @@ def validate_pga_gain(self, key, value):
def validate_datetime_asutc(self, key, value):
return vld.validate_datetime_asutc(key, value)

@validates(
"light_on_hap",
"light_on_has",
"light_on_hcp",
"light_on_hcs",
"light_on_hfp",
"light_on_hfs",
"light_on_nl",
"light_on_nr",
)
def validate_lights(self, key, value):
if isinstance(value, str):
if value.casefold() == "on":
return True
elif value.casefold() == "off":
return False

return bool(value)

@validates("output_image_mask")
def validate_output_image_mask(self, key, value):
try:
Expand Down
11 changes: 11 additions & 0 deletions src/vipersci/vis/db/light_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
"haz3": "HazLight Fore Starboard",
}

luminaire_shortnames = dict(
hfp="haz1",
hap="haz2",
hfs="haz3",
has="haz4",
hcp="haz5",
hcs="haz6",
nl="navLeft",
nr="navRight",
)


class LightRecord(Base):
"""An object to represent rows in the light_records table for VIS. Each row
Expand Down
50 changes: 30 additions & 20 deletions src/vipersci/vis/pds/create_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@

import vipersci
from vipersci.vis.db.image_records import ImageRecord, ProcessingStage
from vipersci.vis.db.light_records import LightRecord, luminaire_names
from vipersci.vis.db.light_records import (
LightRecord,
luminaire_names,
luminaire_shortnames,
)
from vipersci.vis.create_image import tif_info
from vipersci.vis.pds import lids, write_xml
from vipersci.pds import pid as pds
Expand Down Expand Up @@ -153,7 +157,7 @@ def main():
}

# This allows values in these dicts to override the hard-coded values above.
metadata.update(label_dict(ir, get_lights(ir, session)))
metadata.update(label_dict(ir, get_lights(ir)))
if args.dburl.startswith("sqlite://"):
for c in ir.__table__.columns:
dt = getattr(ir, c.name)
Expand Down Expand Up @@ -266,27 +270,33 @@ def main():
# self.__call__(d, im)


def get_lights(ir: ImageRecord, session: Session):
def get_lights(ir: ImageRecord, session: Union[Session, None] = None):
# If session is given, values in the ImageRecord are ignored.
lights = {k: False for k in luminaire_names.values()}
for light in lights:
prev_stmt = (
select(LightRecord)
.where(
and_(
LightRecord.name == light,
LightRecord.datetime < ir.start_time,
for short in luminaire_shortnames:
light_name = luminaire_names[luminaire_shortnames[short]]
light_col = getattr(ir, f"light_on_{short}")
if session is not None:
prev_stmt = (
select(LightRecord)
.where(
and_(
LightRecord.name == light_name,
LightRecord.datetime < ir.start_time,
)
)
.order_by(LightRecord.datetime.desc())
)
.order_by(LightRecord.datetime.desc())
)
prev_light = session.scalars(prev_stmt).first()

if (
prev_light is not None
and prev_light.on
and ir.start_time - prev_light.datetime < timedelta(seconds=10)
):
lights[light] = True
prev_light = session.scalars(prev_stmt).first()

if (
prev_light is not None
and prev_light.on
and ir.start_time - prev_light.datetime < timedelta(seconds=10)
):
lights[light_name] = True
elif light_col is not None:
lights[light_name] = light_col

return lights

Expand Down
13 changes: 13 additions & 0 deletions tests/test_create_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def setUp(self) -> None:
immediateDownloadInfo=10,
instrument_name="NavCam Left",
instrument_temperature=0,
light_on_hap=None,
light_on_has=None,
light_on_hcp=None,
light_on_hcs=None,
light_on_hfp=None,
light_on_hfs=None,
light_on_nl=None,
light_on_nr=None,
lines=2048,
lobt=1700921056,
offset=0,
Expand Down Expand Up @@ -140,6 +148,11 @@ def test_get_lights(self):
t = cr.get_lights(self.ir, self.session)
self.assertEqual(truth, t)

# Now, no session
t = cr.get_lights(self.ir, None)
all_false = {k: False for k in luminaire_names.values()}
self.assertEqual(all_false, t)

def test_label_dict(self):
d = cr.label_dict(self.ir, cr.get_lights(self.ir, self.session))
self.assertEqual(
Expand Down
3 changes: 3 additions & 0 deletions tests/test_density_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ class TestDensityHeatmap(unittest.TestCase):
def test_density_heatmap_3x3_uniform(self):
self.uniform_density_heatmap_runner((3, 3), processes=1)

@unittest.skip("for speedup")
def test_density_heatmap_30x50_uniform(self):
self.uniform_density_heatmap_runner((30, 50), processes=8)

@unittest.skip("for speedup")
def test_density_heatmap_31x17_uniform(self):
self.uniform_density_heatmap_runner((31, 17), processes=8)

@unittest.skip("for speedup")
def test_density_heatmap_100x100_uniform(self):
self.uniform_density_heatmap_runner((100, 100), processes=8)

Expand Down
24 changes: 16 additions & 8 deletions tests/test_image_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ def setUp(self):
exposure_duration=111,
file_creation_datetime=datetime.now(timezone.utc),
file_path="/path/to/dummy",
hazlight_aft_port_on=False,
hazlight_aft_starboard_on=False,
hazlight_center_port_on=False,
hazlight_center_starboard_on=False,
hazlight_fore_port_on=False,
hazlight_fore_starboard_on=False,
light_on_hap=False,
light_on_has=False,
light_on_hcp=False,
light_on_hcs=False,
light_on_hfp=False,
light_on_hfs=False,
light_on_nl=False,
light_on_nr=False,
icer_byte_quota=493448,
image_id=0,
instrument_name="NavCam Left",
Expand All @@ -91,8 +93,6 @@ def setUp(self):
md5_checksum="dummychecksum",
minLoss=0,
mission_phase="Test",
navlight_left_on=False,
navlight_right_on=False,
offset=16324,
# onboard_compression_ratio=5,
onboard_compression_type="ICER",
Expand Down Expand Up @@ -283,12 +283,20 @@ def test_fromyamcs(self):
"cameraId": 0,
"captureId": 1,
"exposureTime": 111,
"haz1LightState": "OFF",
"haz2LightState": "OFF",
"haz3LightState": "OFF",
"haz4LightState": "OFF",
"haz5LightState": "OFF",
"haz6LightState": "OFF",
"imageDepth": 1,
"imageHeight": 2048,
"imageId": 0,
"imageWidth": 2048,
"immediateDownloadInfo": 10,
"lobt": 1700921056,
"navLeftLightState": "ON",
"navRightLightState": "ON",
"offset": 0,
"outputImageMask": 16,
"outputImageType": "JBIG2_IMAGE",
Expand Down