Skip to content

Commit

Permalink
Merge pull request #4270 from gemini-hlsw/sc-3813-different-itc-outpu…
Browse files Browse the repository at this point in the history
…t-before-and-after-accepting

Simplify and unify ITC model
  • Loading branch information
rpiaggio authored Oct 30, 2024
2 parents c5391ab + 254a14b commit 447bd80
Show file tree
Hide file tree
Showing 28 changed files with 683 additions and 508 deletions.
6 changes: 3 additions & 3 deletions common/src/main/scala/explore/model/reusability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import explore.model.enums.AgsState
import explore.model.enums.SelectedPanel
import explore.model.itc.ItcExposureTime
import explore.model.itc.ItcTarget
import explore.modes.InstrumentConfig
import explore.modes.InstrumentOverrides
import explore.modes.InstrumentRow
import explore.undo.UndoStacks
import explore.utils.OdbRestClient
import japgolly.scalajs.react.ReactCats.*
Expand Down Expand Up @@ -101,7 +101,7 @@ object reusability:
given Reusability[AngularSize] = Reusability.byEq
given Reusability[CatalogTargetResult] = Reusability.byEq
given Reusability[BasicConfiguration] = Reusability.byEq
given Reusability[BasicConfigAndItc] = Reusability.byEq
given Reusability[InstrumentConfigAndItcResult] = Reusability.byEq
given Reusability[GuideStarCandidate] = Reusability.by(_.name.value)
given Reusability[AgsPosition] = Reusability.byEq
given Reusability[AgsParams] = Reusability.byEq
Expand All @@ -110,7 +110,7 @@ object reusability:
given Reusability[ObsConfiguration] = Reusability.byEq
given Reusability[Existence] = Reusability.byEq
given Reusability[ItcExposureTime] = Reusability.byEq
given Reusability[InstrumentRow] = Reusability.byEq
given Reusability[InstrumentConfig] = Reusability.byEq
given Reusability[CentralWavelength] = Reusability.byEq
given Reusability[ObjectTracking] = Reusability.byEq
given Reusability[Asterism] = Reusability.byEq[Asterism]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
package explore.cache

import cats.Endo
import cats.Monoid
import cats.MonoidK
import cats.Order.given
import cats.syntax.all.*
import crystal.Pot
import eu.timepit.refined.auto.autoUnwrap
import explore.givens.given
import explore.model.GroupTree
import explore.model.GroupUpdate
import explore.model.Observation
Expand All @@ -30,9 +29,6 @@ import queries.common.TargetQueriesGQL.ProgramTargetsDelta.Data.TargetEdit
* Functions to modify cache through subscription updates
*/
trait CacheModifierUpdaters {
// TODO Move somewhere else
private given [A]: Monoid[Endo[A]] = MonoidK[Endo].algebra[A]

protected def modifyTargets(targetEdit: TargetEdit): ProgramSummaries => ProgramSummaries =
ProgramSummaries.targets
.modify: targets =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import explore.components.HelpIcon
import explore.components.ui.ExploreStyles
import explore.config.ConfigurationFormats.*
import explore.model.AppContext
import explore.model.BasicConfigAndItc
import explore.model.ExploreModelValidators
import explore.model.Observation
import explore.model.ScienceRequirements
import explore.model.display.*
import explore.model.display.given
import explore.model.enums.WavelengthUnits
import explore.modes.GmosNorthSpectroscopyRow
import explore.modes.GmosSouthSpectroscopyRow
import explore.modes.InstrumentConfig
import explore.modes.ModeCommonWavelengths
import explore.modes.ModeSlitSize
import explore.modes.ModeWavelength
Expand Down Expand Up @@ -82,9 +80,8 @@ sealed trait AdvancedConfigurationPanel[T <: ObservingMode, Input]:
def calibrationRole: Option[CalibrationRole]
def observingMode: Aligner[T, Input]
def spectroscopyRequirements: View[ScienceRequirements.Spectroscopy]
def deleteConfig: Callback
def revertConfig: Callback
def confMatrix: SpectroscopyModesMatrix
def selectedConfig: View[Option[BasicConfigAndItc]]
def sequenceChanged: Callback
def readonly: Boolean
def units: WavelengthUnits
Expand Down Expand Up @@ -232,11 +229,11 @@ sealed abstract class AdvancedConfigurationPanelBuilder[
reqsWavelength.flatMap(cw =>
(mode, row.instrument) match
case (m: ObservingMode.GmosNorthLongSlit,
GmosNorthSpectroscopyRow(rGrating, rFpu, rFilter, _)
InstrumentConfig.GmosNorthSpectroscopy(rGrating, rFpu, rFilter, _)
) if m.grating === rGrating && m.filter === rFilter && m.fpu === rFpu =>
ModeData.build(row, reqsWavelength)
case (m: ObservingMode.GmosSouthLongSlit,
GmosSouthSpectroscopyRow(rGrating, rFpu, rFilter, _)
InstrumentConfig.GmosSouthSpectroscopy(rGrating, rFpu, rFilter, _)
) if m.grating === rGrating && m.filter === rFilter && m.fpu === rFpu =>
ModeData.build(row, reqsWavelength)
case _ => none
Expand Down Expand Up @@ -726,13 +723,7 @@ sealed abstract class AdvancedConfigurationPanelBuilder[
label = "Revert Configuration",
icon = Icons.ListIcon,
severity = Button.Severity.Secondary,
onClick = props.selectedConfig.mod(c =>
BasicConfigAndItc(
props.observingMode.get.toBasicConfiguration,
c.flatMap(_.itcResult.flatMap(_.toOption.map(_.asRight)))
).some
)
>> props.deleteConfig
onClick = props.revertConfig
).compact.small
.unless(isCustomized(props.observingMode)),
Button(
Expand Down Expand Up @@ -795,9 +786,8 @@ object AdvancedConfigurationPanel {
calibrationRole: Option[CalibrationRole],
observingMode: Aligner[ObservingMode.GmosNorthLongSlit, GmosNorthLongSlitInput],
spectroscopyRequirements: View[ScienceRequirements.Spectroscopy],
deleteConfig: Callback,
revertConfig: Callback,
confMatrix: SpectroscopyModesMatrix,
selectedConfig: View[Option[BasicConfigAndItc]],
sequenceChanged: Callback,
readonly: Boolean,
units: WavelengthUnits
Expand Down Expand Up @@ -998,9 +988,8 @@ object AdvancedConfigurationPanel {
calibrationRole: Option[CalibrationRole],
observingMode: Aligner[ObservingMode.GmosSouthLongSlit, GmosSouthLongSlitInput],
spectroscopyRequirements: View[ScienceRequirements.Spectroscopy],
deleteConfig: Callback,
revertConfig: Callback,
confMatrix: SpectroscopyModesMatrix,
selectedConfig: View[Option[BasicConfigAndItc]],
sequenceChanged: Callback,
readonly: Boolean,
units: WavelengthUnits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import crystal.react.hooks.*
import explore.Icons
import explore.components.ui.ExploreStyles
import explore.model.AppContext
import explore.model.BasicConfigAndItc
import explore.model.ImagingConfigurationOptions
import explore.model.InstrumentConfigAndItcResult
import explore.model.Observation
import explore.model.ScienceRequirements
import explore.model.ScienceRequirements.Spectroscopy
Expand All @@ -38,7 +38,7 @@ case class BasicConfigurationPanel(
userId: Option[User.Id],
obsId: Observation.Id,
spectroscopyView: ViewOpt[Spectroscopy],
selectedConfig: View[Option[BasicConfigAndItc]],
selectedConfig: View[Option[InstrumentConfigAndItcResult]],
constraints: ConstraintSet,
itcTargets: List[ItcTarget],
baseCoordinates: Option[CoordinatesAtVizTime],
Expand Down Expand Up @@ -73,7 +73,7 @@ private object BasicConfigurationPanel:
.map(_.wavelength)
.fold("Wavelength is required for creating a configuration.".some)(_ =>
props.selectedConfig.get match {
case Some(BasicConfigAndItc(_, itc)) =>
case Some(InstrumentConfigAndItcResult(_, itc)) =>
itc match {
case Some(Right(r)) if r.isPending => "Waiting for ITC result...".some
case Some(Right(r)) if r.isSuccess => none
Expand Down
51 changes: 30 additions & 21 deletions explore/src/main/scala/explore/config/ConfigurationPanel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import explore.common.ScienceQueries.ScienceRequirementsUndoView
import explore.common.ScienceQueries.UpdateScienceRequirements
import explore.components.ui.ExploreStyles
import explore.model.AppContext
import explore.model.BasicConfigAndItc
import explore.model.InstrumentConfigAndItcResult
import explore.model.ObsConfiguration
import explore.model.Observation
import explore.model.ScienceRequirements
import explore.model.ScienceRequirements.Spectroscopy
import explore.model.enums.WavelengthUnits
import explore.model.itc.ItcTarget
import explore.modes.InstrumentConfig
import explore.modes.SpectroscopyModesMatrix
import explore.undo.*
import japgolly.scalajs.react.*
Expand All @@ -44,20 +45,21 @@ import monocle.Iso
import queries.common.ObsQueriesGQL

case class ConfigurationPanel(
userId: Option[User.Id],
programId: Program.Id,
obsId: Observation.Id,
requirements: UndoSetter[ScienceRequirements],
mode: UndoSetter[Option[ObservingMode]],
posAngle: View[PosAngleConstraint],
obsConf: ObsConfiguration,
itcTargets: List[ItcTarget],
baseCoordinates: Option[CoordinatesAtVizTime],
selectedConfig: View[Option[BasicConfigAndItc]],
modes: SpectroscopyModesMatrix,
sequenceChanged: Callback,
readonly: Boolean,
units: WavelengthUnits
userId: Option[User.Id],
programId: Program.Id,
obsId: Observation.Id,
requirements: UndoSetter[ScienceRequirements],
mode: UndoSetter[Option[ObservingMode]],
posAngle: View[PosAngleConstraint],
obsConf: ObsConfiguration,
itcTargets: List[ItcTarget],
baseCoordinates: Option[CoordinatesAtVizTime],
selectedConfig: View[Option[InstrumentConfigAndItcResult]],
revertedInstrumentConfig: Option[InstrumentConfig],
modes: SpectroscopyModesMatrix,
sequenceChanged: Callback,
readonly: Boolean,
units: WavelengthUnits
) extends ReactFnProps[ConfigurationPanel](ConfigurationPanel.component)

object ConfigurationPanel:
Expand Down Expand Up @@ -151,7 +153,16 @@ object ConfigurationPanel:
val optModeView: View[Option[ObservingMode]] =
modeAligner.view(_.map(_.toInput).orUnassign)

val deleteConfiguration = optModeView.set(none)
val revertConfiguration: Callback =
optModeView.set(none) >>
props.revertedInstrumentConfig
.map: row => // Select the reverted config
props.selectedConfig.mod: c =>
InstrumentConfigAndItcResult(
row,
c.flatMap(_.itcResult.flatMap(_.toOption.map(_.asRight)))
).some
.orEmpty

val optModeAligner = modeAligner.toOption

Expand Down Expand Up @@ -213,7 +224,7 @@ object ConfigurationPanel:
props.obsConf.calibrationRole,
createConfiguration(
props.obsId,
props.selectedConfig.get.map(_.configuration),
props.selectedConfig.get.flatMap(_.toBasicConfiguration),
optModeView
),
props.modes,
Expand All @@ -232,9 +243,8 @@ object ConfigurationPanel:
props.obsConf.calibrationRole,
northAligner,
specView,
deleteConfiguration,
revertConfiguration,
props.modes,
props.selectedConfig,
props.sequenceChanged,
props.readonly,
props.units
Expand All @@ -249,9 +259,8 @@ object ConfigurationPanel:
props.obsConf.calibrationRole,
southAligner,
specView,
deleteConfiguration,
revertConfiguration,
props.modes,
props.selectedConfig,
props.sequenceChanged,
props.readonly,
props.units
Expand Down
Loading

0 comments on commit 447bd80

Please sign in to comment.