Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
lucuma.schemas.model.ObservingMode.scala Maven / Gradle / Ivy
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause
package lucuma.schemas.model
import cats.Eq
import cats.data.NonEmptyList
import cats.derived.*
import cats.syntax.all.*
import io.circe.Decoder
import io.circe.generic.semiauto.*
import lucuma.core.enums.*
import lucuma.core.math.Offset
import lucuma.core.math.Wavelength
import lucuma.core.math.WavelengthDither
import lucuma.odb.json.offset.decoder.given
import lucuma.odb.json.wavelength.decoder.given
import monocle.Focus
import monocle.Lens
import monocle.Prism
import monocle.macros.GenPrism
sealed abstract class ObservingMode(val instrument: Instrument) extends Product with Serializable
derives Eq {
def isCustomized: Boolean
def fpuAlternative: Option[Either[GmosNorthFpu, GmosSouthFpu]] = this match
case ObservingMode.GmosNorthLongSlit(
_,
_,
_,
_,
_,
fpu,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
fpu.asLeft.some
case ObservingMode.GmosSouthLongSlit(
_,
_,
_,
_,
_,
fpu,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
fpu.asRight.some
def siteFor: Site = this match
case ObservingMode.GmosNorthLongSlit(
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
Site.GN
case ObservingMode.GmosSouthLongSlit(
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
Site.GS
def toBasicConfiguration: BasicConfiguration = this match
case ObservingMode.GmosNorthLongSlit(
_,
grating,
_,
filter,
_,
fpu,
_,
centralWavelength,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
BasicConfiguration.GmosNorthLongSlit(grating, filter, fpu, centralWavelength)
case ObservingMode.GmosSouthLongSlit(
_,
grating,
_,
filter,
_,
fpu,
_,
centralWavelength,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_,
_
) =>
BasicConfiguration.GmosSouthLongSlit(grating, filter, fpu, centralWavelength)
}
object ObservingMode:
given Decoder[WavelengthDither] =
Decoder.instance:
_.downField("picometers").as[Int].map(WavelengthDither.intPicometers.get)
given Decoder[ObservingMode] =
Decoder
.instance: c =>
c.downField("gmosNorthLongSlit")
.as[GmosNorthLongSlit]
.orElse:
c.downField("gmosSouthLongSlit").as[GmosSouthLongSlit]
case class GmosNorthLongSlit(
initialGrating: GmosNorthGrating,
grating: GmosNorthGrating,
initialFilter: Option[GmosNorthFilter],
filter: Option[GmosNorthFilter],
initialFpu: GmosNorthFpu,
fpu: GmosNorthFpu,
initialCentralWavelength: CentralWavelength,
centralWavelength: CentralWavelength,
defaultXBin: GmosXBinning,
explicitXBin: Option[GmosXBinning],
defaultYBin: GmosYBinning,
explicitYBin: Option[GmosYBinning],
defaultAmpReadMode: GmosAmpReadMode,
explicitAmpReadMode: Option[GmosAmpReadMode],
defaultAmpGain: GmosAmpGain,
explicitAmpGain: Option[GmosAmpGain],
defaultRoi: GmosRoi,
explicitRoi: Option[GmosRoi],
defaultWavelengthDithers: NonEmptyList[WavelengthDither],
explicitWavelengthDithers: Option[NonEmptyList[WavelengthDither]],
defaultSpatialOffsets: NonEmptyList[Offset.Q],
explicitSpatialOffsets: Option[NonEmptyList[Offset.Q]]
) extends ObservingMode(Instrument.GmosNorth)
derives Eq:
def isCustomized: Boolean =
initialGrating =!= grating ||
initialFilter =!= filter ||
initialFpu =!= fpu ||
initialCentralWavelength =!= centralWavelength ||
explicitXBin.exists(_ =!= defaultXBin) ||
explicitYBin.exists(_ =!= defaultYBin) ||
explicitAmpReadMode.exists(_ =!= defaultAmpReadMode) ||
explicitAmpGain.exists(_ =!= defaultAmpGain) ||
explicitRoi.exists(_ =!= defaultRoi) ||
explicitWavelengthDithers.exists(_ =!= defaultWavelengthDithers) ||
explicitSpatialOffsets.exists(_ =!= defaultSpatialOffsets)
def revertCustomizations: GmosNorthLongSlit =
this.copy(
grating = this.initialGrating,
filter = this.initialFilter,
fpu = this.initialFpu,
centralWavelength = this.initialCentralWavelength,
explicitXBin = None,
explicitYBin = None,
explicitAmpReadMode = None,
explicitAmpGain = None,
explicitRoi = None,
explicitWavelengthDithers = None,
explicitSpatialOffsets = None
)
object GmosNorthLongSlit:
given Decoder[GmosNorthLongSlit] = deriveDecoder
val initialGrating: Lens[GmosNorthLongSlit, GmosNorthGrating] =
Focus[GmosNorthLongSlit](_.initialGrating)
val grating: Lens[GmosNorthLongSlit, GmosNorthGrating] =
Focus[GmosNorthLongSlit](_.grating)
val initialFilter: Lens[GmosNorthLongSlit, Option[GmosNorthFilter]] =
Focus[GmosNorthLongSlit](_.initialFilter)
val filter: Lens[GmosNorthLongSlit, Option[GmosNorthFilter]] =
Focus[GmosNorthLongSlit](_.filter)
val initialFpu: Lens[GmosNorthLongSlit, GmosNorthFpu] =
Focus[GmosNorthLongSlit](_.initialFpu)
val fpu: Lens[GmosNorthLongSlit, GmosNorthFpu] =
Focus[GmosNorthLongSlit](_.fpu)
val initialCentralWavelength: Lens[GmosNorthLongSlit, CentralWavelength] =
Focus[GmosNorthLongSlit](_.initialCentralWavelength)
val centralWavelength: Lens[GmosNorthLongSlit, CentralWavelength] =
Focus[GmosNorthLongSlit](_.centralWavelength)
val defaultXBin: Lens[GmosNorthLongSlit, GmosXBinning] =
Focus[GmosNorthLongSlit](_.defaultXBin)
val explicitXBin: Lens[GmosNorthLongSlit, Option[GmosXBinning]] =
Focus[GmosNorthLongSlit](_.explicitXBin)
val defaultYBin: Lens[GmosNorthLongSlit, GmosYBinning] =
Focus[GmosNorthLongSlit](_.defaultYBin)
val explicitYBin: Lens[GmosNorthLongSlit, Option[GmosYBinning]] =
Focus[GmosNorthLongSlit](_.explicitYBin)
val defaultAmpReadMode: Lens[GmosNorthLongSlit, GmosAmpReadMode] =
Focus[GmosNorthLongSlit](_.defaultAmpReadMode)
val explicitAmpReadMode: Lens[GmosNorthLongSlit, Option[GmosAmpReadMode]] =
Focus[GmosNorthLongSlit](_.explicitAmpReadMode)
val defaultAmpGain: Lens[GmosNorthLongSlit, GmosAmpGain] =
Focus[GmosNorthLongSlit](_.defaultAmpGain)
val explicitAmpGain: Lens[GmosNorthLongSlit, Option[GmosAmpGain]] =
Focus[GmosNorthLongSlit](_.explicitAmpGain)
val defaultRoi: Lens[GmosNorthLongSlit, GmosRoi] =
Focus[GmosNorthLongSlit](_.defaultRoi)
val explicitRoi: Lens[GmosNorthLongSlit, Option[GmosRoi]] =
Focus[GmosNorthLongSlit](_.explicitRoi)
val defaultWavelengthDithers: Lens[GmosNorthLongSlit, NonEmptyList[WavelengthDither]] =
Focus[GmosNorthLongSlit](_.defaultWavelengthDithers)
val explicitWavelengthDithers: Lens[GmosNorthLongSlit, Option[NonEmptyList[WavelengthDither]]] =
Focus[GmosNorthLongSlit](_.explicitWavelengthDithers)
val defaultSpatialOffsets: Lens[GmosNorthLongSlit, NonEmptyList[Offset.Q]] =
Focus[GmosNorthLongSlit](_.defaultSpatialOffsets)
val explicitSpatialOffsets: Lens[GmosNorthLongSlit, Option[NonEmptyList[Offset.Q]]] =
Focus[GmosNorthLongSlit](_.explicitSpatialOffsets)
case class GmosSouthLongSlit(
initialGrating: GmosSouthGrating,
grating: GmosSouthGrating,
initialFilter: Option[GmosSouthFilter],
filter: Option[GmosSouthFilter],
initialFpu: GmosSouthFpu,
fpu: GmosSouthFpu,
initialCentralWavelength: CentralWavelength,
centralWavelength: CentralWavelength,
defaultXBin: GmosXBinning,
explicitXBin: Option[GmosXBinning],
defaultYBin: GmosYBinning,
explicitYBin: Option[GmosYBinning],
defaultAmpReadMode: GmosAmpReadMode,
explicitAmpReadMode: Option[GmosAmpReadMode],
defaultAmpGain: GmosAmpGain,
explicitAmpGain: Option[GmosAmpGain],
defaultRoi: GmosRoi,
explicitRoi: Option[GmosRoi],
defaultWavelengthDithers: NonEmptyList[WavelengthDither],
explicitWavelengthDithers: Option[NonEmptyList[WavelengthDither]],
defaultSpatialOffsets: NonEmptyList[Offset.Q],
explicitSpatialOffsets: Option[NonEmptyList[Offset.Q]]
) extends ObservingMode(Instrument.GmosSouth)
derives Eq:
def isCustomized: Boolean =
initialGrating =!= grating ||
initialFilter =!= filter ||
initialFpu =!= fpu ||
initialCentralWavelength =!= centralWavelength ||
explicitXBin.exists(_ =!= defaultXBin) ||
explicitYBin.exists(_ =!= defaultYBin) ||
explicitAmpReadMode.exists(_ =!= defaultAmpReadMode) ||
explicitAmpGain.exists(_ =!= defaultAmpGain) ||
explicitRoi.exists(_ =!= defaultRoi) ||
explicitWavelengthDithers.exists(_ =!= defaultWavelengthDithers) ||
explicitSpatialOffsets.exists(_ =!= defaultSpatialOffsets)
def revertCustomizations: GmosSouthLongSlit =
this.copy(
grating = this.initialGrating,
filter = this.initialFilter,
fpu = this.initialFpu,
centralWavelength = this.initialCentralWavelength,
explicitXBin = None,
explicitYBin = None,
explicitAmpReadMode = None,
explicitAmpGain = None,
explicitRoi = None,
explicitWavelengthDithers = None,
explicitSpatialOffsets = None
)
object GmosSouthLongSlit:
given Decoder[GmosSouthLongSlit] = deriveDecoder
val initialGrating: Lens[GmosSouthLongSlit, GmosSouthGrating] =
Focus[GmosSouthLongSlit](_.initialGrating)
val grating: Lens[GmosSouthLongSlit, GmosSouthGrating] =
Focus[GmosSouthLongSlit](_.grating)
val initialFilter: Lens[GmosSouthLongSlit, Option[GmosSouthFilter]] =
Focus[GmosSouthLongSlit](_.initialFilter)
val filter: Lens[GmosSouthLongSlit, Option[GmosSouthFilter]] =
Focus[GmosSouthLongSlit](_.filter)
val initialFpu: Lens[GmosSouthLongSlit, GmosSouthFpu] =
Focus[GmosSouthLongSlit](_.initialFpu)
val fpu: Lens[GmosSouthLongSlit, GmosSouthFpu] =
Focus[GmosSouthLongSlit](_.fpu)
val initialCentralWavelength: Lens[GmosSouthLongSlit, CentralWavelength] =
Focus[GmosSouthLongSlit](_.initialCentralWavelength)
val centralWavelength: Lens[GmosSouthLongSlit, CentralWavelength] =
Focus[GmosSouthLongSlit](_.centralWavelength)
val defaultXBin: Lens[GmosSouthLongSlit, GmosXBinning] =
Focus[GmosSouthLongSlit](_.defaultXBin)
val explicitXBin: Lens[GmosSouthLongSlit, Option[GmosXBinning]] =
Focus[GmosSouthLongSlit](_.explicitXBin)
val defaultYBin: Lens[GmosSouthLongSlit, GmosYBinning] =
Focus[GmosSouthLongSlit](_.defaultYBin)
val explicitYBin: Lens[GmosSouthLongSlit, Option[GmosYBinning]] =
Focus[GmosSouthLongSlit](_.explicitYBin)
val defaultAmpReadMode: Lens[GmosSouthLongSlit, GmosAmpReadMode] =
Focus[GmosSouthLongSlit](_.defaultAmpReadMode)
val explicitAmpReadMode: Lens[GmosSouthLongSlit, Option[GmosAmpReadMode]] =
Focus[GmosSouthLongSlit](_.explicitAmpReadMode)
val defaultAmpGain: Lens[GmosSouthLongSlit, GmosAmpGain] =
Focus[GmosSouthLongSlit](_.defaultAmpGain)
val explicitAmpGain: Lens[GmosSouthLongSlit, Option[GmosAmpGain]] =
Focus[GmosSouthLongSlit](_.explicitAmpGain)
val defaultRoi: Lens[GmosSouthLongSlit, GmosRoi] =
Focus[GmosSouthLongSlit](_.defaultRoi)
val explicitRoi: Lens[GmosSouthLongSlit, Option[GmosRoi]] =
Focus[GmosSouthLongSlit](_.explicitRoi)
val defaultWavelengthDithers: Lens[GmosSouthLongSlit, NonEmptyList[WavelengthDither]] =
Focus[GmosSouthLongSlit](_.defaultWavelengthDithers)
val explicitWavelengthDithers: Lens[GmosSouthLongSlit, Option[NonEmptyList[WavelengthDither]]] =
Focus[GmosSouthLongSlit](_.explicitWavelengthDithers)
val defaultSpatialOffsets: Lens[GmosSouthLongSlit, NonEmptyList[Offset.Q]] =
Focus[GmosSouthLongSlit](_.defaultSpatialOffsets)
val explicitSpatialOffsets: Lens[GmosSouthLongSlit, Option[NonEmptyList[Offset.Q]]] =
Focus[GmosSouthLongSlit](_.explicitSpatialOffsets)
val gmosNorthLongSlit: Prism[ObservingMode, GmosNorthLongSlit] =
GenPrism[ObservingMode, GmosNorthLongSlit]
val gmosSouthLongSlit: Prism[ObservingMode, GmosSouthLongSlit] =
GenPrism[ObservingMode, GmosSouthLongSlit]