Skip to content

Commit

Permalink
itc fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiaggio committed Oct 30, 2024
1 parent a06b988 commit ad0faf4
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ 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
Expand Down Expand Up @@ -84,7 +83,6 @@ sealed trait AdvancedConfigurationPanel[T <: ObservingMode, Input]:
def spectroscopyRequirements: View[ScienceRequirements.Spectroscopy]
def deleteConfig: Callback
def confMatrix: SpectroscopyModesMatrix
def selectedConfig: View[Option[BasicConfigAndItc]]
def sequenceChanged: Callback
def readonly: Boolean
def units: WavelengthUnits
Expand Down Expand Up @@ -726,13 +724,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.deleteConfig
).compact.small
.unless(isCustomized(props.observingMode)),
Button(
Expand Down Expand Up @@ -797,7 +789,6 @@ object AdvancedConfigurationPanel {
spectroscopyRequirements: View[ScienceRequirements.Spectroscopy],
deleteConfig: Callback,
confMatrix: SpectroscopyModesMatrix,
selectedConfig: View[Option[BasicConfigAndItc]],
sequenceChanged: Callback,
readonly: Boolean,
units: WavelengthUnits
Expand Down Expand Up @@ -1000,7 +991,6 @@ object AdvancedConfigurationPanel {
spectroscopyRequirements: View[ScienceRequirements.Spectroscopy],
deleteConfig: Callback,
confMatrix: SpectroscopyModesMatrix,
selectedConfig: View[Option[BasicConfigAndItc]],
sequenceChanged: Callback,
readonly: Boolean,
units: WavelengthUnits
Expand Down
18 changes: 14 additions & 4 deletions explore/src/main/scala/explore/config/ConfigurationPanel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import explore.model.ScienceRequirements
import explore.model.ScienceRequirements.Spectroscopy
import explore.model.enums.WavelengthUnits
import explore.model.itc.ItcTarget
import explore.modes.InstrumentRow
import explore.modes.SpectroscopyModesMatrix
import explore.undo.*
import japgolly.scalajs.react.*
Expand Down Expand Up @@ -54,6 +55,7 @@ case class ConfigurationPanel(
itcTargets: List[ItcTarget],
baseCoordinates: Option[CoordinatesAtVizTime],
selectedConfig: View[Option[BasicConfigAndItc]],
instrumentRow: Option[InstrumentRow], // configuration selected if reverted
modes: SpectroscopyModesMatrix,
sequenceChanged: Callback,
readonly: Boolean,
Expand Down Expand Up @@ -151,7 +153,17 @@ object ConfigurationPanel:
val optModeView: View[Option[ObservingMode]] =
modeAligner.view(_.map(_.toInput).orUnassign)

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

val optModeAligner = modeAligner.toOption

Expand Down Expand Up @@ -213,7 +225,7 @@ object ConfigurationPanel:
props.obsConf.calibrationRole,
createConfiguration(
props.obsId,
props.selectedConfig.get.map(_.configuration),
props.selectedConfig.get.flatMap(_.toBasicConfiguration),
optModeView
),
props.modes,
Expand All @@ -234,7 +246,6 @@ object ConfigurationPanel:
specView,
deleteConfiguration,
props.modes,
props.selectedConfig,
props.sequenceChanged,
props.readonly,
props.units
Expand All @@ -251,7 +262,6 @@ object ConfigurationPanel:
specView,
deleteConfiguration,
props.modes,
props.selectedConfig,
props.sequenceChanged,
props.readonly,
props.units
Expand Down
29 changes: 12 additions & 17 deletions explore/src/main/scala/explore/config/SpectroscopyModesTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import lucuma.react.primereact.Button
import lucuma.react.syntax.*
import lucuma.react.table.*
import lucuma.refined.*
import lucuma.schemas.model.BasicConfiguration
import lucuma.typed.tanstackVirtualCore as rawVirtual
import lucuma.ui.components.ThemeIcons
import lucuma.ui.primereact.*
Expand Down Expand Up @@ -100,7 +99,7 @@ private object SpectroscopyModesTable:
entry: SpectroscopyModeRow,
result: EitherNec[ItcTargetProblem, ItcResult],
wavelengthInterval: Option[BoundedInterval[Wavelength]],
configurationSummary: String
configurationSummary: Option[String]
):
lazy val rowId: RowId = RowId(entry.id.orEmpty.toString)

Expand Down Expand Up @@ -458,8 +457,8 @@ private object SpectroscopyModesTable:
.useStateBy: (props, _, _, rows, _, _, _, _, _) => // selectedRow
props.selectedConfig.get
.flatMap: c =>
rows.value.find:
_.equalsConf(c.configuration, props.spectroscopyRequirements.wavelength)
rows.value.find: row =>
c.configuration === row.entry.instrument
.map(_.entry)
// selectedIndex
// The selected index needs to be the index into the sorted data, because that is what
Expand All @@ -477,7 +476,8 @@ private object SpectroscopyModesTable:
val optRow: Option[SpectroscopyModeRowWithResult] =
selectedIndex.value.flatMap(idx => sortedRows.lift(idx))
val conf: Option[BasicConfigAndItc] =
optRow.flatMap(_.rowToConfAndItc(props.spectroscopyRequirements.wavelength))
optRow.map: row =>
BasicConfigAndItc(row.entry.instrument, row.result.some)
if (props.selectedConfig.get =!= conf)
props.selectedConfig.set(conf)
else Callback.empty
Expand Down Expand Up @@ -612,10 +612,9 @@ private object SpectroscopyModesTable:

def toggleRow(
row: SpectroscopyModeRowWithResult
): Option[explore.model.BasicConfigAndItc] =
row
.rowToConfAndItc(props.spectroscopyRequirements.wavelength)
.filterNot(conf => props.selectedConfig.get.contains_(conf))
): Option[BasicConfigAndItc] =
Option.when(props.selectedConfig.get.forall(_.configuration =!= row.entry.instrument)):
BasicConfigAndItc(row.entry.instrument, row.result.some)

def scrollButton(content: VdomNode, style: Css, indexCondition: Int => Boolean): TagMod =
selectedIndex.value.whenDefined(idx =>
Expand Down Expand Up @@ -687,14 +686,10 @@ private object SpectroscopyModesTable:
TagMod(
^.disabled := !row.original.entry.enabledRow,
ExploreStyles.TableRowSelected
.when(
props.selectedConfig.get.exists(c =>
row.original.equalsConf(
c.configuration,
props.spectroscopyRequirements.wavelength
)
)
),
.when:
props.selectedConfig.get
.exists(_.configuration === row.original.entry.instrument)
,
(
^.onClick --> (
props.selectedConfig.set(toggleRow(row.original)) >>
Expand Down
1 change: 0 additions & 1 deletion explore/src/main/scala/explore/itc/ItcPanelBody.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ object ItcPanelBody:
_.left.toOption.map(_.message)
.orElse(targetErrors)

pprint.pprintln(selectedResult.map(_.itcExposureTime))
<.div(
ExploreStyles.ItcPlotSection,
ExploreStyles.ItcPlotDetailsHidden.unless(detailsView.get.value)
Expand Down
4 changes: 2 additions & 2 deletions explore/src/main/scala/explore/itc/ItcPanelTitle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ object ItcPanelTitle:
props => itcBrightestTarget => props.selectedTarget.set(itcBrightestTarget)
.render: props =>
def newSelected(p: Int): Option[ItcTarget] =
props.itcPanelProps.itcTargets.flatMap(_.toList.lift(p))
props.itcPanelProps.targets.lift(p)

val selectedResult: Pot[ItcGraphResult] =
props.selectedTarget.get.toPot
.flatMap: t =>
props.itcGraphResults.flatMap(_.asterismGraphs.get(t).flatMap(_.toOption).toPot)

val selectedTarget = props.selectedTarget
val existTargets = props.itcPanelProps.itcTargets.isDefined && selectedTarget.get.isDefined
val existTargets = props.itcPanelProps.targets.nonEmpty && selectedTarget.get.isDefined

val itcTargets = props.itcPanelProps.itcTargets.foldMap(_.toList)
val idx = itcTargets.indexWhere(props.selectedTarget.get.contains)
Expand Down
60 changes: 25 additions & 35 deletions explore/src/main/scala/explore/itc/ItcProps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import explore.events.ItcMessage
import explore.model.BasicConfigAndItc
import explore.model.Observation
import explore.model.ScienceRequirements
import explore.model.TargetList
import explore.model.WorkerClients.ItcClient
import explore.model.boopickle.ItcPicklers.given
import explore.model.itc.*
import explore.model.reusability.given
import explore.modes.GmosNorthSpectroscopyRow
import explore.modes.GmosSouthSpectroscopyRow
import explore.modes.GmosSpectroscopyOverrides
import explore.modes.InstrumentOverrides
import explore.modes.InstrumentRow
import japgolly.scalajs.react.Reusability
import lucuma.core.enums.Band
Expand All @@ -30,33 +30,36 @@ import lucuma.core.math.Wavelength
import lucuma.core.math.dimensional.Units
import lucuma.core.model.SourceProfile
import lucuma.core.model.Target
import lucuma.schemas.model.BasicConfiguration
import lucuma.schemas.model.CentralWavelength
import lucuma.ui.reusability.given
import queries.schemas.itc.syntax.*
import workers.WorkerClient

import scala.collection.immutable.SortedMap

case class ItcProps(
observation: Observation,
selectedConfig: Option[BasicConfigAndItc], // selected row in spectroscopy modes table
// modeOverrides: Option[InstrumentOverrides],
itcTargets: Option[NonEmptyList[ItcTarget]]
at: TargetList
) derives Eq:
private val spectroscopyRequirements: Option[ScienceRequirements.Spectroscopy] =
ScienceRequirements.spectroscopy.getOption(observation.scienceRequirements)

private val allTargets: TargetList =
SortedMap.from:
at.view.mapValues(Target.sourceProfile.modify(_.gaiaFree))

private val constraints = observation.constraints
private val asterismIds = observation.scienceTargetIds

// The remote configuration is read in a different query than the itc results
// This will work even in the case the user has overriden some parameters
// When we use the remote configuration we don't need the exposure time.
private val remoteConfig: Option[InstrumentRow] = observation.toModeOverride(itcTargets)
// .observingMode.map { o =>
// BasicConfigAndItc(
// o.toBasicConfiguration,
// none
// )
// }
private val remoteConfig: Option[BasicConfigAndItc] =
observation
.toInstrumentRow(at)
.map: row =>
BasicConfigAndItc(row, none)

// The user may select a configuration on the modes tables, we'd prefer than but if not
// we can try with the remote confiiguration provided by the database
Expand All @@ -72,30 +75,18 @@ case class ItcProps(
private val wavelength: Option[CentralWavelength] =
finalConfig
.map(_.configuration)
.map:
case BasicConfiguration.GmosNorthLongSlit(_, _, _, cw) =>
modeOverrides match
case Some(GmosSpectroscopyOverrides(overrideCw, _, _)) => overrideCw
case _ => cw
case BasicConfiguration.GmosSouthLongSlit(_, _, _, cw) =>
modeOverrides match
case Some(GmosSpectroscopyOverrides(overrideCw, _, _)) => overrideCw
case _ => cw
.flatMap:
case GmosNorthSpectroscopyRow(_, _, _, Some(GmosSpectroscopyOverrides(cw, _, _))) => cw.some
case GmosSouthSpectroscopyRow(_, _, _, Some(GmosSpectroscopyOverrides(cw, _, _))) => cw.some
case _ => none

private val instrumentRow: Option[InstrumentRow] =
finalConfig
.map(_.configuration)
.map:
case BasicConfiguration.GmosNorthLongSlit(grating, filter, fpu, _) =>
val gmosOverride: Option[GmosSpectroscopyOverrides] = modeOverrides match
case Some(o @ GmosSpectroscopyOverrides(_, _, _)) => o.some
case _ => none
GmosNorthSpectroscopyRow(grating, fpu, filter, gmosOverride)
case BasicConfiguration.GmosSouthLongSlit(grating, filter, fpu, _) =>
val gmosOverride: Option[GmosSpectroscopyOverrides] = modeOverrides match
case Some(o @ GmosSpectroscopyOverrides(_, _, _)) => o.some
case _ => none
GmosSouthSpectroscopyRow(grating, fpu, filter, gmosOverride)
finalConfig.map(_.configuration)

val itcTargets: Option[NonEmptyList[ItcTarget]] =
asterismIds.itcTargets(allTargets).filter(_.canQueryITC).toNel

val targets: List[ItcTarget] = itcTargets.foldMap(_.toList)

private val queryProps: List[Option[?]] =
List(itcTargets, finalConfig, wavelength, instrumentRow, signalToNoise)
Expand Down Expand Up @@ -146,6 +137,5 @@ object ItcProps:
p.observation.wavelength,
p.observation.basicConfiguration,
p.selectedConfig,
p.itcTargets,
p.modeOverrides
p.at
)
3 changes: 3 additions & 0 deletions explore/src/main/scala/explore/tabs/ConfigurationTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import explore.model.Observation
import explore.model.ScienceRequirements
import explore.model.TargetList
import explore.model.enums.WavelengthUnits
import explore.modes.InstrumentRow
import explore.modes.SpectroscopyModesMatrix
import explore.undo.*
import japgolly.scalajs.react.Callback
Expand All @@ -41,6 +42,7 @@ object ConfigurationTile:
baseCoordinates: Option[CoordinatesAtVizTime],
obsConf: ObsConfiguration,
selectedConfig: View[Option[BasicConfigAndItc]],
instrumentRow: Option[InstrumentRow], // configuration selected if reverted
modes: SpectroscopyModesMatrix,
allTargets: TargetList,
sequenceChanged: Callback,
Expand All @@ -63,6 +65,7 @@ object ConfigurationTile:
scienceTargetIds.itcTargets(allTargets),
baseCoordinates,
selectedConfig,
instrumentRow,
modes,
sequenceChanged,
readonly,
Expand Down
Loading

0 comments on commit ad0faf4

Please sign in to comment.