Skip to content

Commit

Permalink
Release Version - v0.2.4 (#76)
Browse files Browse the repository at this point in the history
* Update version - v0.2.4

* change `spice.state` to `spice.get_state` for clarity
  • Loading branch information
dahlend authored Jul 15, 2024
1 parent 5013967 commit c02b0e3
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 33 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.4] - 2024 - 7 - 15

### Added

- Add `J2` non-spherical terms for the gravitational models of Earth and Jupiter.
Expand Down Expand Up @@ -155,6 +157,7 @@ Initial Release


[Unreleased]: https://github.com/IPAC-SW/neospy/tree/main
[0.2.4]: https://github.com/IPAC-SW/neospy/releases/tag/v0.2.4
[0.2.3]: https://github.com/IPAC-SW/neospy/releases/tag/v0.2.3
[0.2.2]: https://github.com/IPAC-SW/neospy/releases/tag/v0.2.2
[0.2.1]: https://github.com/IPAC-SW/neospy/releases/tag/v0.2.1
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[package]
name = "_core"
version = "0.2.3"
version = "0.2.4"
edition = "2021"


Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/propagation_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
jd_start = neospy.Time.from_ymd(1920, 1, 1).jd
jd_end = neospy.Time.from_ymd(2020, 1, 1).jd

state = neospy.spice.state("42", jd_end)
state = neospy.spice.get_state("42", jd_end)

jds = np.logspace(np.log10(jd_end), np.log10(jd_end - 10), 1000)
jds = np.concatenate(
Expand All @@ -21,9 +21,9 @@
error_2body = []
n_body_no_asteroids = []
n_body_ast = []
state = neospy.spice.state("42", jd_end)
state = neospy.spice.get_state("42", jd_end)
for jd in jds:
jpl_pos = neospy.spice.state("42", jd).pos
jpl_pos = neospy.spice.get_state("42", jd).pos

line = state.pos + state.vel * (jd - state.jd)
error_line.append((jpl_pos - line).r * neospy.constants.AU_KM)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "neospy"
version = "0.2.3"
version = "0.2.4"
description = "NEO Surveyor Simulation Tools"
readme = "README.md"
authors = [{name = "Dar Dahlen", email = "[email protected]"},
Expand Down
2 changes: 1 addition & 1 deletion src/examples/galactic_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
while states[0].jd < jd_end:
states = neospy.propagate_two_body(states, states[0].jd + 1)

earth = neospy.spice.state("Earth", states[0].jd)
earth = neospy.spice.get_state("Earth", states[0].jd)

earth_to_obj = [(s.pos - earth.pos) for s in states]
dist_to_galactic_center.append(
Expand Down
2 changes: 1 addition & 1 deletion src/examples/plot_close_approach.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
rel_earth_state = cur_state.change_center(399)
pos.append([rel_earth_state.pos.x, rel_earth_state.pos.y])
# gets earths position and record the distances.
moon = neospy.spice.state("Moon", cur_state.jd, center=399).pos
moon = neospy.spice.get_state("Moon", cur_state.jd, center=399).pos
dist_to_moon.append((moon - rel_earth_state.pos).r * neospy.constants.AU_KM)
dist_to_earth.append(rel_earth_state.pos.r * neospy.constants.AU_KM)
moon_pos.append([moon.x, moon.y])
Expand Down
6 changes: 3 additions & 3 deletions src/examples/plot_close_encounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
for jd in jds:
last_state = neospy.propagate_two_body([last_state], jd)[0]
obj_pos.append(last_state.pos)
earth_pos.append(neospy.spice.state("Earth", jd).pos)
earth_pos.append(neospy.spice.get_state("Earth", jd).pos)
earth_r.append(neospy.Vector(obj_pos[-1] - earth_pos[-1]).r)

# Find the time where the closest encounter with the earth
Expand All @@ -55,10 +55,10 @@
ax.plot(pos[0], pos[1], pos[2], alpha=0.5, color="black")
ax.scatter(pos_center.x, pos_center.y, pos_center.z, s=5, color="black")
for i, planet in enumerate(["Mercury", "Venus", "Earth", "Mars", "Jupiter"]):
states = [neospy.spice.state(planet, jd).pos for jd in jds]
states = [neospy.spice.get_state(planet, jd).pos for jd in jds]
pos = np.array(states).T
ax.plot(pos[0], pos[1], pos[2], color=f"C{i}", alpha=0.5)
pos = neospy.spice.state(planet, jd_center).pos
pos = neospy.spice.get_state(planet, jd_center).pos
ax.scatter(pos.x, pos.y, pos.z, color=f"C{i}", s=5)
ax.scatter(0, 0, 0, color="red")
ax.set_xticks([-zoom, 0, zoom])
Expand Down
4 changes: 2 additions & 2 deletions src/examples/plot_light_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


# Using ceres as a source for a state vector
state = neospy.spice.state("ceres", 2460000.5)
state = neospy.spice.get_state("ceres", 2460000.5)

# Various input values
albedo = 0.1
Expand Down Expand Up @@ -39,7 +39,7 @@

for dt in dts:
# Find the observer and object positions some time in the future.
earth_pos = neospy.spice.state("Earth", jd + dt).pos
earth_pos = neospy.spice.get_state("Earth", jd + dt).pos
final_pos = neospy.propagate_two_body([state], jd + dt, earth_pos)[0].pos

obj2obs = final_pos - earth_pos
Expand Down
4 changes: 2 additions & 2 deletions src/examples/plot_mpc_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
# Plot the planets for 1 orbit each
for i, planet in enumerate(["Mercury", "Venus", "Earth", "Mars", "Jupiter"]):
jd = states[0].jd
plan = neospy.spice.state(planet, jd)
plan = neospy.spice.get_state(planet, jd)
ax.scatter(plan.pos.x, plan.pos.y, color=f"C{i}", s=10)
jds = np.linspace(jd - plan.elements.orbital_period, jd, 100)
pos = np.array([neospy.spice.state(planet, jd).pos for jd in jds]).T
pos = np.array([neospy.spice.get_state(planet, jd).pos for jd in jds]).T
ax.plot(pos[0], pos[1], pos[2], color="black", alpha=0.2)

for state in states:
Expand Down
2 changes: 1 addition & 1 deletion src/examples/plot_phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Move the entire population of asteroids to that time using 2-body
# mechanics, this can be directly substituted with propagate_n_body if you
# want more precision.
sun2earth = neospy.spice.state("Earth", jd).pos
sun2earth = neospy.spice.get_state("Earth", jd).pos
states = neospy.propagate_two_body(neos, jd)

# Compute the expected V-mags for these objects at this time
Expand Down
2 changes: 1 addition & 1 deletion src/examples/plot_trojans.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
states = neospy.propagate_n_body(states, states[0].jd)

# Where is jupiter?
jupiter = neospy.spice.state("Jupiter", states[0].jd)
jupiter = neospy.spice.get_state("Jupiter", states[0].jd)
# found it!

# Compute the positions, and relative longitudinal distance from jupiter
Expand Down
4 changes: 2 additions & 2 deletions src/examples/plot_uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
mags = []
for jd in jds:
states = neospy.propagate_n_body(states, jd)
earth = neospy.spice.state("earth", jd)
earth = neospy.spice.get_state("earth", jd)
m = [
neospy.flux.hg_apparent_mag(
sun2obj=x.pos, sun2obs=earth.pos, h_mag=obj.h_mag, g_param=g
Expand All @@ -65,7 +65,7 @@

# position at lowest mag
states = neospy.propagate_n_body(states, brightest_jd)
earth = neospy.spice.state("earth", brightest_jd)
earth = neospy.spice.get_state("earth", brightest_jd)
vecs = [(s.pos - earth.pos).as_equatorial for s in states]
ras = np.array([v.ra for v in vecs])
decs = np.array([v.dec for v in vecs])
Expand Down
2 changes: 1 addition & 1 deletion src/neospy/mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def _read_second_line(line, jd):
y = float(line[46:57].replace(" ", "")) / constants.AU_KM
z = float(line[58:69].replace(" ", "")) / constants.AU_KM
earth2sc = Vector([x, y, z], Frames.Equatorial).as_ecliptic
sun2earth = spice.state("Earth", jd).pos
sun2earth = spice.get_state("Earth", jd).pos
sun2sc = sun2earth + earth2sc
return list(sun2sc)

Expand Down
2 changes: 1 addition & 1 deletion src/neospy/propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ def moid(state: State, other: Optional[State] = None):
calculation.
"""
if other is None:
other = spice.state("Earth", state.jd)
other = spice.get_state("Earth", state.jd)
return _moid_single(state, other)
8 changes: 4 additions & 4 deletions src/neospy/spice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

__all__ = [
"SpkInfo",
"state",
"get_state",
"name_lookup",
"loaded_objects",
"loaded_object_info",
Expand Down Expand Up @@ -71,7 +71,7 @@ def _validate_time(time: Union[float, Time]) -> float:
_NAME_CACHE: dict = {}


def state(
def get_state(
target: Union[str, int],
jd: Union[float, Time],
center: str = "Sun",
Expand Down Expand Up @@ -372,7 +372,7 @@ def moon_illumination_frac(jd: Union[float, Time], observer: str = "399"):
"""
jd = _validate_time(jd)

moon2sun = -state("moon", jd).pos
moon2earth = -state("moon", jd, center=observer).pos
moon2sun = -get_state("moon", jd).pos
moon2earth = -get_state("moon", jd, center=observer).pos
perc = 1.0 - moon2sun.angle_between(moon2earth) / 180
return 0.5 - np.cos(np.pi * perc) / 2
2 changes: 1 addition & 1 deletion src/neospy/wise.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def fetch_WISE_fovs(phase):

fovs = []
for row in res.itertuples():
state = spice.state("WISE", row.jd)
state = spice.get_state("WISE", row.jd)

pointing = Vector.from_ra_dec(row.ra, row.dec).as_ecliptic
fov = WiseCmos(
Expand Down
2 changes: 1 addition & 1 deletion src/neospy_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "neospy_core"
version = "0.2.3"
version = "0.2.4"
edition = "2021"

[lib]
Expand Down
10 changes: 5 additions & 5 deletions src/tests/test_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ def test_propagation_single(self):
Propagate Venus using StateVector and compare the result to using spice.
This is only over 5 days the 2 body approximation is accurate over that time.
"""
state = spice.state("Venus", 2461161.5)
state = spice.get_state("Venus", 2461161.5)

for jd in range(-5, 5):
jd = state.jd + jd
vec_state = propagate_two_body([state], jd)[0]
jpl_state = spice.state("Venus", jd)
jpl_state = spice.get_state("Venus", jd)
assert vec_state.jd == jpl_state.jd
assert np.allclose(vec_state.vel, jpl_state.vel)
assert np.allclose(vec_state.pos, jpl_state.pos)
Expand All @@ -92,7 +92,7 @@ def test_propagation_light_delay(self):
Place an observer X AU away from Venus and ensure that the delay is correct.
"""
state = spice.state("Venus", 2461161.5)
state = spice.get_state("Venus", 2461161.5)

for au in range(0, 5):
sun2obs = Vector(state.pos + [au, 0.0, 0.0])
Expand All @@ -108,9 +108,9 @@ def test_propagation_light_delay(self):
def test_moid(planet):
if planet is None:
state = None
vs = spice.state("Earth", 2461161.5)
vs = spice.get_state("Earth", 2461161.5)
else:
state = spice.state(planet, 2461161.5)
state = spice.get_state(planet, 2461161.5)
vs = state

assert np.isclose(moid(vs, state), 0)
4 changes: 2 additions & 2 deletions src/tests/test_spice.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class TestSpice:
def test_ecliptic_state(self, expected):
e_pos = expected[2:5]
e_vel = expected[5:8]
state = spice.state(expected[0], expected[1])
state = spice.get_state(expected[0], expected[1])
assert isinstance(state, State)
assert np.allclose(state.pos.as_equatorial, e_pos)
assert np.allclose(state.vel.as_equatorial, e_vel)

# Ensure that the same values are calculated if using an astropy time
jd = Time(expected[1])
state = spice.state(expected[0], jd)
state = spice.get_state(expected[0], jd)
assert isinstance(state, State)
assert np.allclose(state.pos.as_equatorial, e_pos)
assert np.allclose(state.vel.as_equatorial, e_vel)
Expand Down

0 comments on commit c02b0e3

Please sign in to comment.