-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
8,573 additions
and
8,647 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package nebulosa.api.atlas | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class MoonPhaseDateTime( | ||
@JvmField val dateTime: LocalDateTime = LocalDateTime.MIN, | ||
@JvmField val name: MoonPhaseName = MoonPhaseName.NEW_MOON, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package nebulosa.api.atlas | ||
|
||
import nebulosa.constants.PIOVERTWO | ||
import nebulosa.horizons.HorizonsElement | ||
import nebulosa.horizons.HorizonsQuantity | ||
import nebulosa.horizons.HorizonsService | ||
import nebulosa.horizons.ObservingSite | ||
import nebulosa.math.Angle | ||
import nebulosa.math.Distance | ||
import nebulosa.math.deg | ||
import nebulosa.nova.almanac.computeDiffAndReduceToIndices | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
import java.time.temporal.TemporalAdjusters | ||
import kotlin.math.floor | ||
|
||
@Component | ||
class MoonPhaseFinder(private val horizonsService: HorizonsService) { | ||
|
||
fun find( | ||
date: LocalDate, | ||
longitude: Angle, latitude: Angle, elevation: Distance = 0.0, | ||
offsetInMinutes: Long = 0L, | ||
): List<MoonPhaseDateTime> { | ||
return find(date, ObservingSite.Geographic(longitude, latitude, elevation), offsetInMinutes) | ||
} | ||
|
||
fun find(date: LocalDate, offsetInMinutes: Long = 0L): List<MoonPhaseDateTime> { | ||
return find(date, ObservingSite.Geocentric.EARTH, offsetInMinutes) | ||
} | ||
|
||
private fun find(date: LocalDate, site: ObservingSite, offsetInMinutes: Long = 0L): List<MoonPhaseDateTime> { | ||
val startTime = LocalDateTime.of(date.withDayOfMonth(1), LocalTime.MIN).minusMinutes(offsetInMinutes) | ||
val endTime = LocalDateTime.of(date.with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX).minusMinutes(offsetInMinutes) | ||
return compute(60, startTime, endTime, site, offsetInMinutes) | ||
} | ||
|
||
private fun compute( | ||
stepSizeInMinutes: Int, | ||
startTime: LocalDateTime, endTime: LocalDateTime, | ||
site: ObservingSite, offsetInMinutes: Long, | ||
): List<MoonPhaseDateTime> { | ||
val sun = horizonsService.observer( | ||
"10", site, | ||
startTime, endTime, | ||
stepSizeInMinutes, | ||
extraPrecision = false, | ||
quantities = QUANTITIES, | ||
).execute().body()!! | ||
|
||
val moon = horizonsService.observer( | ||
"301", site, | ||
startTime, endTime, | ||
stepSizeInMinutes, | ||
extraPrecision = false, | ||
quantities = QUANTITIES, | ||
).execute().body()!! | ||
|
||
val phases = IntArray(sun.size) { floor((moon[it].eclipticLongitude() - sun[it].eclipticLongitude()) / PIOVERTWO).mod(4.0).toInt() } | ||
val indices = phases.computeDiffAndReduceToIndices() | ||
|
||
if (stepSizeInMinutes == 1) { | ||
return indices.map { MoonPhaseDateTime(moon[it].dateTime.plusMinutes(offsetInMinutes), MoonPhaseName.entries[phases[it + 1]]) } | ||
} else { | ||
val res = ArrayList<MoonPhaseDateTime>(5) | ||
|
||
for (i in indices) { | ||
val dateTime = moon[i].dateTime | ||
val a = dateTime.minusMinutes(stepSizeInMinutes.toLong()) | ||
val b = dateTime.plusMinutes(stepSizeInMinutes.toLong()) | ||
res.addAll(compute(1, a, b, site, offsetInMinutes)) | ||
} | ||
|
||
return res | ||
} | ||
} | ||
|
||
companion object { | ||
|
||
@JvmStatic private val QUANTITIES = arrayOf(HorizonsQuantity.OBSERVER_ECLIPTIC_LONGITUDE) | ||
|
||
private fun HorizonsElement.eclipticLongitude(): Double { | ||
return this[HorizonsQuantity.OBSERVER_ECLIPTIC_LONGITUDE]!!.toDouble().deg | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package nebulosa.api.atlas | ||
|
||
enum class MoonPhaseName { | ||
NEW_MOON, | ||
FIRST_QUARTER, | ||
FULL_MOON, | ||
LAST_QUARTER, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.