Skip to content

Commit

Permalink
Merge pull request #1464 from gemini-hlsw/offset-for-gcals
Browse files Browse the repository at this point in the history
Moves telescope config from step config science to the step itself.
  • Loading branch information
rpiaggio authored Oct 30, 2024
2 parents 872cd37 + 0dffbc1 commit 536090a
Show file tree
Hide file tree
Showing 44 changed files with 672 additions and 535 deletions.
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ val http4sJdkHttpClientVersion = "0.9.1"
val jwtVersion = "5.0.0"
val logbackVersion = "1.5.11"
val log4catsVersion = "2.7.0"
val lucumaCatalogVersion = "0.48.5"
val lucumaItcVersion = "0.22.5"
val lucumaCoreVersion = "0.106.2"
val lucumaCatalogVersion = "0.48.6"
val lucumaItcVersion = "0.22.6"
val lucumaCoreVersion = "0.107.0"
val lucumaGraphQLRoutesVersion = "0.8.15"
val lucumaSsoVersion = "0.6.26"
val lucumaSsoVersion = "0.6.27"
val munitVersion = "0.7.29" // check test output if you attempt to update this
val munitCatsEffectVersion = "1.0.7" // check test output if you attempt to update this
val munitDisciplineVersion = "1.0.9" // check test output if you attempt to update this
Expand All @@ -32,7 +32,7 @@ val pprintVersion = "0.9.0"
val skunkVersion = "0.6.4"
val testcontainersScalaVersion = "0.40.14" // check test output if you attempt to update this

ThisBuild / tlBaseVersion := "0.15"
ThisBuild / tlBaseVersion := "0.16"
ThisBuild / scalaVersion := "3.5.1"
ThisBuild / crossScalaVersions := Seq("3.5.1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,9 @@ type GmosNorthStep {
"""
stepConfig: StepConfig!

"The telescope configuration at this step."
telescopeConfig: TelescopeConfig!

"""
Time estimate for this step's execution
"""
Expand Down Expand Up @@ -2509,6 +2512,9 @@ type GmosSouthStep {
"""
stepConfig: StepConfig!

"The telescope configuration at this step."
telescopeConfig: TelescopeConfig!

"""
Time estimate for this step's execution
"""
Expand Down Expand Up @@ -4067,11 +4073,12 @@ type RecordDatasetResult {

"Input parameters for creating a new GmosNorth StepRecord"
input RecordGmosNorthStepInput {
atomId: AtomId!
gmosNorth: GmosNorthDynamicInput!
stepConfig: StepConfigInput!
observeClass: ObserveClass!
generatedId: StepId
atomId: AtomId!
gmosNorth: GmosNorthDynamicInput!
stepConfig: StepConfigInput!
telescopeConfig: TelescopeConfigInput
observeClass: ObserveClass!
generatedId: StepId
}

"""
Expand Down Expand Up @@ -4106,11 +4113,12 @@ type RecordGmosNorthVisitResult {
Input parameters for creating a new GmosSouth StepRecord
"""
input RecordGmosSouthStepInput {
atomId: AtomId!
gmosSouth: GmosSouthDynamicInput!
stepConfig: StepConfigInput!
observeClass: ObserveClass!
generatedId: StepId
atomId: AtomId!
gmosSouth: GmosSouthDynamicInput!
stepConfig: StepConfigInput!
telescopeConfig: TelescopeConfigInput
observeClass: ObserveClass!
generatedId: StepId
}

"""
Expand Down Expand Up @@ -4156,15 +4164,6 @@ input RightAscensionInput {
Science step
"""
type Science implements StepConfig {
"""
Offset
"""
offset: Offset!

"""
Guide State (whether guiding is enabled for this step)
"""
guiding: GuideState!

"""
Step type is always SCIENCE.
Expand Down Expand Up @@ -4549,7 +4548,7 @@ input StepConfigInput {
"""
Science step creation option
"""
science: StepConfigScienceInput
science: Boolean

"""
Smart gcal creation option
Expand All @@ -4570,25 +4569,11 @@ input StepConfigGcalInput {
shutter: GcalShutter!
}

"""
Science step creation input
"""
input StepConfigScienceInput {
"""
offset position
"""
offset: OffsetInput!

"""
Whether guiding is enabled for this step (defaults to 'ENABLED').
"""
guiding: GuideState
}

"""
SmartGcal step creation input
"""
input StepConfigSmartGcalInput {

"""
Smart Gcal type
"""
Expand Down Expand Up @@ -4808,6 +4793,33 @@ input TargetPropertiesInput {
existence: Existence
}

type TelescopeConfig {
"""
Offset
"""
offset: Offset!

"""
Guide State (whether guiding is enabled for this step)
"""
guiding: GuideState!
}

"""
Science step creation input
"""
input TelescopeConfigInput {
"""
Offset position, which defaults to (0, 0) arcsec.
"""
offset: OffsetInput

"""
Whether guiding is enabled for this step (defaults to 'ENABLED').
"""
guiding: GuideState
}

"""
Time Accounting Categories. Each successful proposal is given one or more
time allocations and each allocation has a time accounting category.
Expand Down Expand Up @@ -10837,6 +10849,9 @@ type StepRecord {
"""
stepConfig: StepConfig!

"The telescope configuration for this step."
telescopeConfig: TelescopeConfig!

"The observe class of this step."
observeClass: ObserveClass!

Expand Down
7 changes: 4 additions & 3 deletions modules/schema/src/main/scala/lucuma/odb/json/sequence.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ import lucuma.core.model.sequence.SetupTime
import lucuma.core.model.sequence.Step
import lucuma.core.model.sequence.StepConfig
import lucuma.core.model.sequence.StepEstimate
import lucuma.core.model.sequence.TelescopeConfig
import lucuma.core.util.TimeSpan

import scala.collection.immutable.SortedSet

// (using Encoder[Offset], Encoder[TimeSpan], Encoder[Wavelength])

trait SequenceCodec {

import offset.decoder.given
Expand All @@ -57,10 +56,11 @@ trait SequenceCodec {
i <- c.downField("id").as[Step.Id]
d <- c.downField("instrumentConfig").as[D]
n <- c.downField("stepConfig").as[StepConfig]
t <- c.downField("telescopeConfig").as[TelescopeConfig]
e <- c.downField("estimate").as[StepEstimate]
o <- c.downField("observeClass").as[ObserveClass]
b <- c.downField("breakpoint").as[Breakpoint]
} yield Step(i, d, n, e, o, b)
} yield Step(i, d, n, t, e, o, b)
}

given [D: Encoder](using Encoder[Offset], Encoder[TimeSpan]): Encoder[Step[D]] =
Expand All @@ -69,6 +69,7 @@ trait SequenceCodec {
"id" -> a.id.asJson,
"instrumentConfig" -> a.instrumentConfig.asJson,
"stepConfig" -> a.stepConfig.asJson,
"telescopeConfig" -> a.telescopeConfig.asJson,
"estimate" -> a.estimate.asJson,
"observeClass" -> a.observeClass.asJson,
"breakpoint" -> a.breakpoint.asJson
Expand Down
96 changes: 41 additions & 55 deletions modules/schema/src/main/scala/lucuma/odb/json/stepconfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,100 +19,86 @@ import lucuma.core.enums.StepGuideState
import lucuma.core.enums.StepType
import lucuma.core.math.Offset
import lucuma.core.model.sequence.StepConfig
import lucuma.core.model.sequence.TelescopeConfig

trait StepConfigCodec {
trait StepConfigCodec:

import offset.decoder.given

given Decoder[TelescopeConfig] =
Decoder.instance: c =>
for
o <- c.downField("offset").as[Offset]
g <- c.downField("guiding").as[StepGuideState]
yield TelescopeConfig(o, g)

given (using Encoder[Offset]): Encoder[TelescopeConfig] =
Encoder.instance: a =>
Json.obj(
"offset" -> a.offset.asJson,
"guiding" -> a.guiding.asJson
)

given given_Decoder_Lamp: Decoder[StepConfig.Gcal.Lamp] =
Decoder.instance { c =>
for {
Decoder.instance: c =>
for
u <- c.downField("continuum").as[Option[GcalContinuum]]
a <- c.downField("arcs").as[List[GcalArc]]
r <- StepConfig.Gcal.Lamp.fromContinuumOrArcs(u, a).leftMap(msg => DecodingFailure(msg, c.history))
} yield r
}
yield r

given given_Encoder_Lamp: Encoder[StepConfig.Gcal.Lamp] =
Encoder.instance { (a: StepConfig.Gcal.Lamp) =>
Encoder.instance: a =>
Json.obj(
"continuum" -> a.continuum.asJson,
"arcs" -> a.toArcsSortedSet.asJson
)
}

given Decoder[StepConfig.Gcal] =
Decoder.instance { c =>
for {
Decoder.instance: c =>
for
l <- given_Decoder_Lamp(c)
f <- c.downField("filter").as[GcalFilter]
d <- c.downField("diffuser").as[GcalDiffuser]
s <- c.downField("shutter").as[GcalShutter]
} yield StepConfig.Gcal(l, f, d, s)
}
yield StepConfig.Gcal(l, f, d, s)

given Encoder[StepConfig.Gcal] =
Encoder.instance { (a: StepConfig.Gcal) =>
given (using Encoder[Offset]): Encoder[StepConfig.Gcal] =
Encoder.instance: a =>
given_Encoder_Lamp(a.lamp).mapObject { jo =>
jo.add("filter", a.filter.asJson)
.add("diffuser", a.diffuser.asJson)
.add("shutter", a.shutter.asJson)
jo.add("filter", a.filter.asJson)
.add("diffuser", a.diffuser.asJson)
.add("shutter", a.shutter.asJson)
}
}

given Decoder[StepConfig.Science] =
Decoder.instance { c =>
for {
o <- c.downField("offset").as[Offset]
g <- c.downField("guiding").as[StepGuideState]
} yield StepConfig.Science(o, g)
}

given (using Encoder[Offset]): Encoder[StepConfig.Science] =
Encoder.instance { (a: StepConfig.Science) =>
Json.obj(
"offset" -> a.offset.asJson,
"guiding" -> a.guiding.asJson
)
}

given Decoder[StepConfig.SmartGcal] =
Decoder.instance { c =>
c.downField("smartGcalType").as[SmartGcalType].map { sgt =>
StepConfig.SmartGcal(sgt)
}
}
Decoder.instance: c =>
c.downField("smartGcalType").as[SmartGcalType].map(StepConfig.SmartGcal.apply)

given Encoder[StepConfig.SmartGcal] =
Encoder.instance { (a: StepConfig.SmartGcal) =>
given (using Encoder[Offset]): Encoder[StepConfig.SmartGcal] =
Encoder.instance: a =>
Json.obj(
"smartGcalType" -> a.smartGcalType.asJson
)
}

given Decoder[StepConfig] =
Decoder.instance { c =>
Decoder.instance: c =>
c.downField("stepType").as[StepType].flatMap {
case StepType.Bias => StepConfig.Bias.asRight[DecodingFailure]
case StepType.Dark => StepConfig.Dark.asRight[DecodingFailure]
case StepType.Gcal => c.as[StepConfig.Gcal]
case StepType.Science => c.as[StepConfig.Science]
case StepType.Science => StepConfig.Science.asRight[DecodingFailure]
case StepType.SmartGcal => c.as[StepConfig.SmartGcal]
}
}

given (using Encoder[Offset]): Encoder[StepConfig] =
Encoder.instance { (a: StepConfig) =>
Encoder.instance: a =>
(a match {
case _: StepConfig.Bias.type => Json.obj()
case _: StepConfig.Dark.type => Json.obj()
case s: StepConfig.Science => s.asJson
case g: StepConfig.Gcal => g.asJson
case m: StepConfig.SmartGcal => m.asJson
case _: StepConfig.Bias.type => Json.obj()
case _: StepConfig.Dark.type => Json.obj()
case _: StepConfig.Science.type => Json.obj()
case g: StepConfig.Gcal => g.asJson
case m: StepConfig.SmartGcal => m.asJson
}).mapObject(("stepType" -> a.stepType.asJson) +: _)
}

}

object stepconfig extends StepConfigCodec

object stepconfig extends StepConfigCodec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import lucuma.core.math.Angle
import lucuma.core.math.Offset
import lucuma.core.model.sequence.StepConfig
import lucuma.core.model.sequence.StepConfig.SmartGcal
import lucuma.core.model.sequence.TelescopeConfig
import lucuma.odb.sequence.data.ProtoStep

/**
Expand Down Expand Up @@ -45,8 +46,8 @@ trait SequenceState[D] {
* Produces a "science" step based upon the current instrument configuration
* state and the given telescope configuration.
*/
def scienceStep(o: Offset, c: ObserveClass): State[D, ProtoStep[D]] =
step(ProtoStep(_, StepConfig.Science(o, Enabled), c))
def scienceStep(t: TelescopeConfig, c: ObserveClass): State[D, ProtoStep[D]] =
step(ProtoStep(_, StepConfig.Science, t, c))

/**
* Produces a "science" step based upon the current instrument configuration
Expand All @@ -56,18 +57,18 @@ trait SequenceState[D] {
* @param q offset in q
*/
def scienceStep(p: Angle, q: Angle, c: ObserveClass): State[D, ProtoStep[D]] =
scienceStep(Offset(Offset.P(p), Offset.Q(q)), c)
scienceStep(TelescopeConfig(Offset(Offset.P(p), Offset.Q(q)), Enabled), c)

/**
* Generates a GCAL flat based on the current instrument configuration.
*/
def flatStep(c: ObserveClass): State[D, ProtoStep[D]] =
step(ProtoStep(_, SmartGcal(Flat), c))
def flatStep(t: TelescopeConfig, c: ObserveClass): State[D, ProtoStep[D]] =
step(ProtoStep(_, SmartGcal(Flat), t, c))

/**
* Generates a GCAL arc based on the current instrument configuration.
*/
def arcStep(c: ObserveClass): State[D, ProtoStep[D]] =
step(ProtoStep(_, SmartGcal(Arc), c))
def arcStep(t: TelescopeConfig, c: ObserveClass): State[D, ProtoStep[D]] =
step(ProtoStep(_, SmartGcal(Arc), t, c))

}
Loading

0 comments on commit 536090a

Please sign in to comment.