Skip to content

Commit

Permalink
invoke itc chart only once when IQ changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiaggio committed Sep 23, 2024
1 parent 3a4f16a commit 53d7436
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 183 deletions.
137 changes: 136 additions & 1 deletion common/src/main/scala/explore/model/reusability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package explore.model

import cats.Eq
import cats.data.NonEmptyChain
import cats.syntax.all.*
import clue.PersistentClientStatus
import explore.data.KeyedIndexedList
import explore.model.IsActive
Expand All @@ -24,7 +25,15 @@ import lucuma.ags.AgsPosition
import lucuma.ags.GuideStarCandidate
import lucuma.catalog.AngularSize
import lucuma.catalog.CatalogTargetResult
import lucuma.core.enums.GmosNorthFilter
import lucuma.core.enums.GmosNorthFpu
import lucuma.core.enums.GmosNorthGrating
import lucuma.core.enums.GmosSouthFilter
import lucuma.core.enums.GmosSouthFpu
import lucuma.core.enums.GmosSouthGrating
import lucuma.core.math.Offset
import lucuma.core.math.SignalToNoise
import lucuma.core.math.WavelengthDither
import lucuma.core.model.ObjectTracking
import lucuma.core.model.PosAngleConstraint
import lucuma.core.model.TimingWindow
Expand Down Expand Up @@ -91,7 +100,6 @@ object reusability:
given Reusability[Progress] = Reusability.byEq
given Reusability[AngularSize] = Reusability.byEq
given Reusability[CatalogTargetResult] = Reusability.byEq
given Reusability[ObservingMode] = Reusability.byEq
given Reusability[BasicConfiguration] = Reusability.byEq
given Reusability[BasicConfigAndItc] = Reusability.byEq
given Reusability[GuideStarCandidate] = Reusability.by(_.name.value)
Expand Down Expand Up @@ -132,6 +140,133 @@ object reusability:
given Reusability[CategoryAllocationList] = Reusability.byEq
given Reusability[InstrumentOverrides] = Reusability.byEq
given [A: Reusability]: Reusability[NonEmptyChain[A]] = Reusability.by(_.toNonEmptyList)
given Reusability[WavelengthDither] = Reusability.byEq
given [A]: Reusability[Offset.Component[A]] = Reusability.byEq
// We explicitly leave default binning out of ObservingMode Reusability since we compute it each time, ignoring the server value.
given Reusability[ObservingMode.GmosNorthLongSlit] =
Reusability.by: x =>
(x.grating,
x.filter,
x.fpu,
x.centralWavelength,
(x.explicitXBin, x.explicitYBin).tupled,
x.explicitAmpReadMode.getOrElse(x.defaultAmpReadMode),
x.explicitAmpGain.getOrElse(x.defaultAmpGain),
x.explicitRoi.getOrElse(x.defaultRoi),
x.explicitWavelengthDithers.getOrElse(x.defaultWavelengthDithers),
x.explicitSpatialOffsets.getOrElse(x.defaultSpatialOffsets)
)
given Reusability[ObservingMode.GmosSouthLongSlit] =
Reusability.by: x =>
(x.grating,
x.filter,
x.fpu,
x.centralWavelength,
(x.explicitXBin, x.explicitYBin).tupled,
x.explicitAmpReadMode.getOrElse(x.defaultAmpReadMode),
x.explicitAmpGain.getOrElse(x.defaultAmpGain),
x.explicitRoi.getOrElse(x.defaultRoi),
x.explicitWavelengthDithers.getOrElse(x.defaultWavelengthDithers),
x.explicitSpatialOffsets.getOrElse(x.defaultSpatialOffsets)
)
given Reusability[ObservingMode] = Reusability:
case (x @ ObservingMode.GmosNorthLongSlit(_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
),
y @ ObservingMode.GmosNorthLongSlit(_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
)
) =>
summon[Reusability[ObservingMode.GmosNorthLongSlit]].test(x, y)
case (x @ ObservingMode.GmosSouthLongSlit(_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
),
y @ ObservingMode.GmosSouthLongSlit(_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
)
) =>
summon[Reusability[ObservingMode.GmosSouthLongSlit]].test(x, y)
case _ => false

// We want to re render only when the vizTime changes at least a month
// We keep the candidates data pm corrected for the viz time
Expand Down
21 changes: 10 additions & 11 deletions explore/src/main/scala/explore/itc/ItcProps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,13 @@ case class ItcProps(
action.getOrElse(orElse)

object ItcProps:
given Reusability[ItcProps] = Reusability.by(p =>
(p.observation.scienceTargetIds.toList,
p.observation.constraints,
p.observation.scienceRequirements,
p.observation.observingMode,
p.observation.wavelength,
p.selectedConfig,
p.at,
p.modeOverrides
)
)
given Reusability[ItcProps] =
Reusability.by: p =>
(p.observation.scienceTargetIds.toList.sorted,
p.observation.constraints,
p.observation.scienceRequirements,
p.observation.wavelength,
p.selectedConfig,
p.at,
p.modeOverrides
)
66 changes: 33 additions & 33 deletions explore/src/main/scala/explore/tabs/ObsTabTiles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ object ObsTabTiles:
private def itcQueryProps(
obs: Observation,
selectedConfig: Option[BasicConfigAndItc],
targetsList: TargetList
targetList: TargetList
): ItcProps =
ItcProps(obs, selectedConfig, targetsList, obs.toModeOverride)
ItcProps(obs, selectedConfig, targetList, obs.toModeOverride(targetList))

private case class Offsets(
science: Option[NonEmptyList[Offset]],
Expand Down Expand Up @@ -182,39 +182,39 @@ object ObsTabTiles:
.useStateWithReuse(LoadingState.Done)
.useEffectWithDepsBy((props, _, _, _, _, selectedConfig, _, _, _, _) =>
itcQueryProps(props.observation.get, selectedConfig.get, props.allTargets)
) { (props, ctx, _, _, _, _, oldItcProps, graphs, brightestTarget, loading) => itcProps =>
import ctx.given
): (props, ctx, _, _, _, _, oldItcProps, graphs, brightestTarget, loading) =>
itcProps =>
import ctx.given

oldItcProps.setState(itcProps).when_(itcProps.isExecutable) *>
itcProps
.requestGraphs(
(asterismGraphs, brightestTargetResult) => {
val graphsResult =
asterismGraphs
.map:
case (k, Left(e)) =>
k -> (Pot.error(new RuntimeException(e.shortName)): Pot[ItcGraphResult])
case (k, Right(e)) =>
k -> (Pot.Ready(e): Pot[ItcGraphResult])
oldItcProps.setState(itcProps).when_(itcProps.isExecutable) *>
itcProps
.requestGraphs(
(asterismGraphs, brightestTargetResult) => {
val graphsResult =
asterismGraphs
.map:
case (k, Left(e)) =>
k -> (Pot.error(new RuntimeException(e.shortName)): Pot[ItcGraphResult])
case (k, Right(e)) =>
k -> (Pot.Ready(e): Pot[ItcGraphResult])
.toMap
graphs.setStateAsync(graphsResult) *>
brightestTarget.setStateAsync(brightestTargetResult) *>
loading.setState(LoadingState.Done).value.toAsync
},
(graphs.setState(
itcProps.targets
.map: t =>
t -> Pot.error:
new RuntimeException("Not enough information to calculate the ITC graph")
.toMap
graphs.setStateAsync(graphsResult) *>
brightestTarget.setStateAsync(brightestTargetResult) *>
loading.setState(LoadingState.Done).value.toAsync
},
(graphs.setState(
itcProps.targets
.map: t =>
t -> Pot.error:
new RuntimeException("Not enough information to calculate the ITC graph")
.toMap
) *>
brightestTarget.setState(none) *>
loading.setState(LoadingState.Done)).toAsync,
loading.setState(LoadingState.Loading).value.toAsync
)
.whenA(itcProps.isExecutable)
.runAsyncAndForget
}
) *>
brightestTarget.setState(none) *>
loading.setState(LoadingState.Done)).toAsync,
loading.setState(LoadingState.Loading).value.toAsync
)
.whenA(itcProps.isExecutable)
.runAsyncAndForget
// Signal that the sequence has changed
.useStateView(().ready)
.useEffectKeepResultWithDepsBy((p, _, _, _, _, _, _, _, _, _, _) =>
Expand Down
Loading

0 comments on commit 53d7436

Please sign in to comment.