Skip to content

Commit

Permalink
#481 ShadeTool Touchups (#482)
Browse files Browse the repository at this point in the history
* #481 ShadeTool Touchups

* #481 Fix docs
  • Loading branch information
tariqksoliman authored Dec 20, 2023
1 parent 11bc3bd commit dc16666
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 45 deletions.
10 changes: 8 additions & 2 deletions docs/pages/Tools/Shade/Shade.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ There are two SPICE python scripts that require these backend kernel setups:
"value": "MSL"
}
],
"defaultHeight": 0
"defaultHeight": 0,
"observerTimePlaceholder": null,
"utcTimeFormat": null
}
```

Expand All @@ -80,14 +82,18 @@ _**observers**_ - An array of objects with the properties "name" and "value". "n

_**defaultHeight**_ - Sets a default for the 'Height' parameter (see below). The regular default is 0 meters.

_**observerTimePlaceholder**_ - Sets the placeholder information for when the observer time's input box is cleared. Useful for denoting the expected time format to be inputed. For example "SOL DDDD HH:MM:SS". Default null.

_**utcTimeFormat**_ - Sets the placeholder information for when the observer time's input box is cleared. Useful for denoting the expected time format to be inputed. Uses [d3 time syntax](https://d3js.org/d3-time-format#locale_format). Example for day-of-year: `"%Y-%j %H:%M:%S"`. Defaults to times like so: `2023 SEP 06 19:27:05`.

## Tool Use

**Note:** Terrain beyond the screen's current extent is **not** factored into the displayed visiblity map — only observer-target direction and on-screen terrain is considered. A distant off-screen mountain will **not** cast shadows.

### Interface

- _Time_
- The desired datetime to query. Formatted as `YYYY MMM DD HH:MM:SS` and for example `2023 SEP 06 19:27:05`. Updating this time and pressing 'Enter' will set it as the current time for the ShadeTool and for all of MMGIS. It is both connected to the Observer's local time as well as MMGIS' timeline (expandable via the clock icon in the bottom left of the screen).
- The desired datetime to query. Formatted as `YYYY MMM DD HH:MM:SS` and for example `2023 SEP 06 19:27:05` (or based on `utcTimeFormat`). Updating this time and pressing 'Enter' will set it as the current time for the ShadeTool and for all of MMGIS. It is both connected to the Observer's local time as well as MMGIS' timeline (expandable via the clock icon in the bottom left of the screen).

#### Source

Expand Down
71 changes: 71 additions & 0 deletions private/api/spice/chronice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# chronice: chronos + spice (but without chronos since spice-alone offered more controll)
# chronice.py <target> <from_format> <time>
# <from_format>: 'utc' or 'lmst' and will convert into the other
# !!! Currently only designed for Mars

# examples:
# python chronice.py msl utc "2024-01-17T20:56:20.280"
# => {"result": "SOL-04070M09:30:00"}
# python chronice.py msl lmst "SOL-4070M09:30:00"
# => {"result": "2024-01-17T20:56:20.279"}

import sys
import json
import os

import spiceypy

try:
from urllib.parse import unquote
except ImportError:
from urllib import unquote

def chronice(target, fromFormat, time):
# Load kernels
package_dir = os.path.dirname(os.path.abspath(__file__)).replace('\\','/')

kernels_to_load = []
# Crawl dir for kernels
for x in os.listdir(os.path.join(package_dir + '/kernels')):
if x.endswith(('.bsp', '.tpc', '.tsc', '.tf', '.tls')) and not x.startswith('dynamic'):
# Prints only text file present in My Folder
kernels_to_load.append(x)

for k in kernels_to_load:
spiceypy.furnsh( os.path.join(package_dir + '/kernels/', k) )

targetId = 0
if target == 'msl':
targetId = -76900
# LMST
if fromFormat == 'utc':
et = spiceypy.utc2et(time)
result = spiceypy.sce2s(targetId, et)
result = sclk2lmst(result, target)
else:
time = lmst2sclk(time, target)
et = spiceypy.scs2e(targetId, time)
result = spiceypy.et2utc(et, "ISOC", 3)

return json.dumps({
"result": result
})

def sclk2lmst(sclk, target):
if target == 'msl':
s = sclk.split('/')[1].split(':')
return f'SOL-{s[0]}M{s[1]}:{s[2]}:{s[3]}'
def lmst2sclk(lmst, target, partition = 1):
if target == 'msl':
s = lmst.replace(' ', ':').replace('-', ':').replace('M', ':').split(':')
return f'{partition}/{s[1].zfill(5)}:{s[2].zfill(2)}:{s[3].zfill(2)}:{s[4].zfill(2)}:00000'

# Start
target = unquote(sys.argv[1])
fromFormat = unquote(sys.argv[2])
time = unquote(sys.argv[3])

try:
print(chronice(target, fromFormat, time))
except:
print(json.dumps({"error": True, "message": 'Error: ' + str(sys.exc_info()[0])}))
2 changes: 1 addition & 1 deletion private/api/spice/chronos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SImply wraps commands such as
# Simply wraps commands such as
# chronos.exe -setup ./chronos/chronos-msl.setup -from utc -fromtype scet -to lst -totype lst -time "2023-07-27 23:16:05.644" -NOLABEL
# chronos.exe -setup ./chronos/chronos-msl.setup -to utc -totype scet -from lst -fromtype lst -time "SOL 3901 03:46:54" -NOLABEL

Expand Down
24 changes: 24 additions & 0 deletions scripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,30 @@ setups.getBackendSetups(function (setups) {
}
);

//utils chronos (spice time converter)
app.post(
`${ROOT_PATH}/api/utils/chronice`,
ensureUser(),
ensureGroup(permissions.users),
function (req, res) {
const target = encodeURIComponent(req.body.target);
const fromFormat = encodeURIComponent(req.body.from);
const time = encodeURIComponent(req.body.time)
.replace(/%20/g, " ")
.replace(/%3A/g, ":");

execFile(
"python",
["private/api/spice/chronice.py", target, fromFormat, time],
function (error, stdout, stderr) {
if (error)
logger("error", "chronice failure:", "server", null, error);
res.send(stdout);
}
);
}
);

//utils chronos (spice time converter)
app.get(
`${ROOT_PATH}/api/utils/proj42wkt`,
Expand Down
Loading

0 comments on commit dc16666

Please sign in to comment.