Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1019 add moon to aladin sky chart on target list page #1118

Merged
merged 21 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f5c9b9a
add library used for aladin sun,moon positioning
phycodurus Nov 13, 2024
bcd653e
load suncalc.js for use in finding sun,moon positions for aladin
phycodurus Nov 13, 2024
c746ff5
make aladin coordinate grid more subtle
phycodurus Nov 13, 2024
1299b93
refactor to facilitate tweaks to dot definition
phycodurus Nov 13, 2024
7b60046
wip: define and display Moon catalog in aladin
phycodurus Nov 13, 2024
1876e1f
remove suncalc.js to use astropy instead
phycodurus Nov 14, 2024
e4230f3
send moon/sun data to aladin_skymap for position display
phycodurus Nov 14, 2024
cd7db72
make Moon icon light/dark according to illumination
phycodurus Nov 14, 2024
cdcee69
get Moon pos from context; simplify popup description
phycodurus Nov 14, 2024
6ddeccb
display sun in position given by astropy via context
phycodurus Nov 14, 2024
af1c69b
name catalogOptions what they are - not dot_defintion which it isn't
phycodurus Nov 14, 2024
94bfa48
nfc: comments, formatting, code organization
phycodurus Nov 15, 2024
e721c31
put targets in one catalog (vs. each in its own)
phycodurus Nov 15, 2024
10bf258
add symbolic representation of moon phase
jchate6 Nov 19, 2024
80228b6
make Target symbols a standard color
phycodurus Nov 20, 2024
200c950
clarify popupTitle wording
phycodurus Nov 20, 2024
b7cc2df
match the size of the icons for the Sun and Moon
phycodurus Nov 20, 2024
7cf7407
Merge branch 'dev' into 1019-add-moon-to-aladin-sky-chart-on-target-l…
jchate6 Nov 20, 2024
64523ef
Merge branch 'dev' into 1019-add-moon-to-aladin-sky-chart-on-target-l…
jchate6 Dec 5, 2024
17c2f1f
final touches
jchate6 Dec 5, 2024
66e294c
Merge branch '1019-add-moon-to-aladin-sky-chart-on-target-list-page' …
jchate6 Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 76 additions & 6 deletions tom_targets/templates/tom_targets/partials/aladin_skymap.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,87 @@
showCooGridControl: true,
});

aladin.setCooGrid({ color: 'green', labelSize: 10 });

aladin.setCooGrid({ color: 'grey', labelSize: 10 });

// extract the targets from the context
var targets = {{ targets|safe }}; //targets cannot be a queryset; here it is a list of dictionaries

// define catalog for the targets
var catalogOptions = {
name: 'Targets',
color: 'blue',
sourceSize: 16};
var targetCatalog = A.catalog(catalogOptions);

// add targets to the catalog
for (var i = 0; i < targets.length; i++) {
jchate6 marked this conversation as resolved.
Show resolved Hide resolved
var target = targets[i];
var cat = A.catalog({name: target.name , color: 'blue', sourceSize: 16});
aladin.addCatalog(cat);
popup_info = ['RA: '.concat(target.ra, '<br>', 'Dec: ', target.dec)];
cat.addSources([A.marker(target.ra, target.dec, {popupTitle: target.name, popupDesc: popup_info})]);
popupInfo = ['RA: '.concat(target.ra, '<br>', 'Dec: ', target.dec)];
targetCatalog.addSources([A.marker(target.ra, target.dec, {popupTitle: target.name, popupDesc: popupInfo})]);
}
aladin.addCatalog(targetCatalog);

// extract Moon information from the context
const moonRaDeg = {{ moon_ra|safe }};
const moonDecDeg = {{ moon_dec|safe }};
const moonIllumination = {{ moon_illumination|safe }}.toFixed(3);
const moonGreyscale = 255 * moonIllumination;

// get a unicode representation of the Moon based on illumination fraction
phycodurus marked this conversation as resolved.
Show resolved Hide resolved
var unicodeMoon;
if (moonIllumination <= 0.125 ) {
unicodeMoon = "\uD83C\uDF11";
} else if (moonIllumination <= 0.375) {
unicodeMoon = "\uD83C\uDF12";
} else if (moonIllumination <= 0.625) {
unicodeMoon = "\uD83C\uDF13";
} else if (moonIllumination <= 0.875) {
unicodeMoon = "\uD83C\uDF14";
} else if (moonIllumination <= 1.0) {
unicodeMoon = "\uD83C\uDF15";
}

// Create a text based symbol for the moon centered on the source coordinates
var drawMoon = function(source, canvasCtx) {
canvasCtx.globalAlpha = 1;
canvasCtx.font = '25px Arial';
canvasCtx.fillStyle = '#eee';
canvasCtx.textBaseline = 'middle';
canvasCtx.textAlign = 'center';
canvasCtx.fillText(unicodeMoon, source.x, source.y);
};

// create a catalog for the moon
const moonImage = A.catalog({shape: drawMoon});
jchate6 marked this conversation as resolved.
Show resolved Hide resolved

const popupMoonDescription = `Illumination: ${moonIllumination} <br> RA: ${moonRaDeg.toFixed(4)} <br> Dec: ${moonDecDeg.toFixed(4)}`;

moonImage.addSources([A.marker(moonRaDeg, moonDecDeg,
{popupTitle: 'Moon (Geocentric)',
popupDesc: popupMoonDescription,
})]);

aladin.addCatalog(moonImage);

// now add the sun in its own catalog
const sunCatalog = A.catalog({
name: 'Sun',
shape: 'circle',
color: 'yellow',
sourceSize: 30}); // fontSize from Moon canvas plus 5 to match sizes

const sunRaDeg = {{ sun_ra|safe }};
const sunDecDeg = {{ sun_dec|safe }};

const popupSunDescription = `RA: ${sunRaDeg.toFixed(4)} <br> Dec: ${sunDecDeg.toFixed(4)}`;

sunCatalog.addSources([A.marker(sunRaDeg, sunDecDeg,
{popupTitle: 'Sun (Geocentric)',
popupDesc: popupSunDescription,
})]);

aladin.addCatalog(sunCatalog);

});
</script>

19 changes: 17 additions & 2 deletions tom_targets/templatetags/targets_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,32 @@ def aladin_skymap(targets):
Displays aladin skyview on Target Distribution skymap. Markers on the skymap show where your targets are. Max of
25 targets show at a time (one page of targets). This templatetag converts the targets queryset into a list of
dictionaries suitable for javascript and aladin, and only works for sidereal targets.

Also, puts the current Moon and Sun positions (from astropy) into the context.
"""
target_list = []

for target in targets:
if target.type == Target.SIDEREAL:
name = target.name
ra = target.ra
dec = target.dec
target_list.append({'name': name, 'ra': ra, 'dec': dec})

context = {'targets': target_list}
# To display the Moon and Sun on the skymap, calculate postions for
# them here and pass them to the template in the context
now = Time.now()
moon_pos = get_body('moon', now)
moon_illum = moon_illumination(now)
sun_pos = get_body('sun', now)

context = {
'targets': target_list,
'moon_ra': moon_pos.ra.deg,
'moon_dec': moon_pos.dec.deg,
'moon_illumination': moon_illum,
'sun_ra': sun_pos.ra.deg,
'sun_dec': sun_pos.dec.deg,
}
return context


Expand Down
Loading