-
Notifications
You must be signed in to change notification settings - Fork 2
GOATS-961 GOATS-983: Add clone target and observation serializers. #465
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
Merged
davner
merged 2 commits into
main
from
GOATS-961_GOATS-983/clone-target-observation-serializers
Oct 21, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
""" | ||
Clone Observation Serializer for the GPP module. | ||
""" | ||
|
||
__all__ = ["CloneObservationSerializer"] | ||
|
||
from typing import Any | ||
|
||
from gpp_client.api.enums import ( | ||
CloudExtinctionPreset, | ||
ImageQualityPreset, | ||
PosAngleConstraintMode, | ||
SkyBackground, | ||
WaterVapor, | ||
) | ||
from rest_framework import serializers | ||
|
||
from .utils import normalize | ||
|
||
|
||
class CloneObservationSerializer(serializers.Serializer): | ||
""" | ||
Serializer for cloning observation data. | ||
|
||
This serializer processes hidden input fields related to observation cloning, such | ||
as observation ID, observing mode, and various constraints. | ||
""" | ||
|
||
hiddenObservationIdInput = serializers.CharField( | ||
required=False, allow_blank=True, allow_null=True | ||
) | ||
hiddenObservingModeInput = serializers.CharField( | ||
required=False, allow_blank=True, allow_null=True | ||
) | ||
observerNotesTextarea = serializers.CharField( | ||
required=False, allow_blank=True, allow_null=True | ||
) | ||
imageQualitySelect = serializers.ChoiceField( | ||
choices=[c.value for c in ImageQualityPreset], required=False, allow_blank=False | ||
) | ||
cloudExtinctionSelect = serializers.ChoiceField( | ||
choices=[c.value for c in CloudExtinctionPreset], | ||
required=False, | ||
allow_blank=False, | ||
) | ||
skyBackgroundSelect = serializers.ChoiceField( | ||
choices=[c.value for c in SkyBackground], required=False, allow_blank=False | ||
) | ||
waterVaporSelect = serializers.ChoiceField( | ||
choices=[c.value for c in WaterVapor], required=False, allow_blank=False | ||
) | ||
posAngleConstraintModeSelect = serializers.ChoiceField( | ||
choices=[c.value for c in PosAngleConstraintMode], | ||
required=False, | ||
allow_blank=False, | ||
) | ||
posAngleConstraintAngleInput = serializers.FloatField( | ||
required=False, allow_null=True, min_value=0.0, max_value=360.0 | ||
) | ||
|
||
def to_internal_value(self, data: dict[str, Any]) -> dict[str, Any]: | ||
""" | ||
Normalize blank strings to ``None`` before standard processing because this is | ||
form data. | ||
|
||
Parameters | ||
---------- | ||
data : dict[str, Any] | ||
The input data from the form. | ||
|
||
Returns | ||
------- | ||
dict[str, Any] | ||
The normalized internal value dictionary. | ||
""" | ||
normalized_data = {key: normalize(value) for key, value in data.items()} | ||
return super().to_internal_value(normalized_data) | ||
|
||
def validate(self, data: dict[str, Any]) -> dict[str, Any]: | ||
""" | ||
Perform cross-field validation and build the structured data for the clone | ||
observation. | ||
|
||
Parameters | ||
---------- | ||
data : dict[str, Any] | ||
The validated data dictionary. | ||
|
||
Returns | ||
------- | ||
dict[str, Any] | ||
The validated data dictionary. | ||
""" | ||
# Assign observation ID and observing mode if provided. | ||
self._observation_id = data.get("hiddenObservationIdInput") | ||
self._observing_mode = data.get("hiddenObservingModeInput") | ||
|
||
mode = data.get("posAngleConstraintModeSelect") | ||
angle = data.get("posAngleConstraintAngleInput") | ||
|
||
# Validate that angle is provided if mode requires it. | ||
if mode in { | ||
PosAngleConstraintMode.FIXED.value, | ||
PosAngleConstraintMode.ALLOW_FLIP.value, | ||
PosAngleConstraintMode.PARALLACTIC_OVERRIDE.value, | ||
}: | ||
if angle is None: | ||
raise serializers.ValidationError( | ||
{ | ||
"Position Angle Input": ( | ||
"This angle is required for the selected mode." | ||
) | ||
} | ||
) | ||
|
||
return { | ||
"observerNotes": data.get("observerNotesTextarea"), | ||
"constraintSet": { | ||
"imageQuality": data.get("imageQualitySelect"), | ||
"cloudExtinction": data.get("cloudExtinctionSelect"), | ||
"skyBackground": data.get("skyBackgroundSelect"), | ||
"waterVapor": data.get("waterVaporSelect"), | ||
# Placeholder for other serializer field. | ||
"elevationRange": None, | ||
}, | ||
"posAngleConstraint": { | ||
"mode": mode, | ||
"angle": {"degrees": angle}, | ||
}, | ||
# Placeholder for other serializer field. | ||
"observingMode": None, | ||
} | ||
|
||
@property | ||
def observation_id(self) -> str | None: | ||
return getattr(self, "_observation_id", None) | ||
|
||
@property | ||
def observing_mode(self) -> str | None: | ||
return getattr(self, "_observing_mode", None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
""" | ||
Clone Target Serializer for the GPP module. | ||
""" | ||
|
||
__all__ = ["CloneTargetSerializer"] | ||
|
||
from typing import Any | ||
|
||
from rest_framework import serializers | ||
|
||
from .utils import normalize | ||
|
||
|
||
class CloneTargetSerializer(serializers.Serializer): | ||
"""Serializer for cloning target data. | ||
|
||
This serializer processes hidden input fields related to target cloning, such as | ||
target ID, radial velocity, parallax, and proper motion. | ||
""" | ||
|
||
hiddenTargetIdInput = serializers.CharField( | ||
required=False, allow_null=True, allow_blank=True | ||
) | ||
radialVelocityInput = serializers.FloatField(required=False, allow_null=True) | ||
parallaxInput = serializers.FloatField(required=False, allow_null=True) | ||
uRaInput = serializers.FloatField(required=False, allow_null=True) | ||
uDecInput = serializers.FloatField(required=False, allow_null=True) | ||
|
||
def to_internal_value(self, data: dict[str, Any]) -> dict[str, Any]: | ||
""" | ||
Normalize blank strings to ``None`` before standard processing because this is | ||
form data. | ||
|
||
Parameters | ||
---------- | ||
data : dict[str, Any] | ||
The input data from the form. | ||
|
||
Returns | ||
------- | ||
dict[str, Any] | ||
The normalized internal value dictionary. | ||
""" | ||
normalized_data = {key: normalize(value) for key, value in data.items()} | ||
return super().to_internal_value(normalized_data) | ||
|
||
def validate(self, data: dict[str, Any]) -> dict[str, Any]: | ||
""" | ||
Perform cross-field validation and build the structured data for the clone | ||
target. | ||
|
||
Parameters | ||
---------- | ||
data : dict[str, Any] | ||
The validated data dictionary. | ||
|
||
Returns | ||
------- | ||
dict[str, Any] | ||
The validated data dictionary. | ||
|
||
Notes | ||
----- | ||
- RA and Dec are set to dummy values as they are not modified via the ToO form. | ||
- The epoch is set to a standard value of "J2000". | ||
""" | ||
# Assign target ID if provided. | ||
self._target_id = data.get("hiddenTargetIdInput") | ||
|
||
return { | ||
"sidereal": { | ||
"radialVelocity": { | ||
"kilometersPerSecond": data.get("radialVelocityInput") | ||
}, | ||
"parallax": {"milliarcseconds": data.get("parallaxInput")}, | ||
"properMotion": { | ||
"ra": {"milliarcsecondsPerYear": data.get("uRaInput")}, | ||
"dec": {"milliarcsecondsPerYear": data.get("uDecInput")}, | ||
}, | ||
# RA and Dec are not modified via TOO form, set to dummy values. | ||
"ra": {"degrees": None}, | ||
"dec": {"degrees": None}, | ||
# Use standard epoch. | ||
"epoch": "J2000", | ||
}, | ||
# Placeholder for other serializer field. | ||
"sourceProfile": None, | ||
} | ||
|
||
@property | ||
def target_id(self) -> str | None: | ||
return getattr(self, "_target_id", None) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.