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

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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++) {
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});

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