Skip to content

Performance in euclidean search script #50

@Gabriel-p

Description

@Gabriel-p

Make the custers.json file smaller by storing the data as:

["ADS 12696","ads12696",294.29,29.33,64,3.99]
["ADS 16795","ads16795,arcas",352.55,58.55,112.49,-2.66]
["AH03 J0822-36.4","ah03j0822364",125.54,-36.4,254.98,0.32]
["AH03 J2011+26.7","ah03j2011p267,mwsc3281",302.99,26.74,65.74,-3.92]
...

where we also removed the last two columns that are used by the map_search.js only and create a new JSON file with that data. We can read this file with:

// Fetch and decompress data
fetch("assets/clusters.json.gz")
    .then(response => response.arrayBuffer())
    .then(buffer => {
        const decompressed = pako.ungzip(new Uint8Array(buffer), { to: "string" });
        // Split into lines and filter empty ones
        const lines = decompressed.split('\n').filter(line => line.trim() !== '');
        // Parse each line and convert to an array of objects
        users = lines.map(line => {
            const [N,F,R,D,L,B,P,M] = JSON.parse(line);
            return { N,F,R,D,L,B,P,M };
        });

    })
    .catch(error => console.error("Error fetching or decompressing data:", error));

We can also remove the (lon, lat) columns

["ADS 12696","ads12696",294.29,29.33]
["ADS 16795","ads16795,arcas",352.55,58.55]
["AH03 J0822-36.4","ah03j0822364",125.54,-36.4]
["AH03 J2011+26.7","ah03j2011p267,mwsc3281",302.99,26.74]
...

and use a JS function to generate those values from (ra, dec)

function equatorialToGalactic(ra, dec) {
    // Constants for J2000.0 epoch
    // Galactic North Pole in equatorial coordinates
    const RA_NGP = 192.859508; // degrees (12h 51m 26.3s)
    const DEC_NGP = 27.128336;  // degrees (+27° 07' 42")
    
    // Galactic center longitude (ascending node)
    const L_NCP = 122.932;      // degrees (galactic longitude of north celestial pole)
    
    // Convert degrees to radians
    const toRad = Math.PI / 180;
    const toDeg = 180 / Math.PI;
    
    const ra_rad = ra * toRad;
    const dec_rad = dec * toRad;
    const ra_ngp_rad = RA_NGP * toRad;
    const dec_ngp_rad = DEC_NGP * toRad;
    
    // Calculate galactic latitude (b)
    const sin_b = Math.sin(dec_rad) * Math.sin(dec_ngp_rad) + 
                  Math.cos(dec_rad) * Math.cos(dec_ngp_rad) * Math.cos(ra_rad - ra_ngp_rad);
    const b = Math.asin(sin_b) * toDeg;
    
    // Calculate galactic longitude (l)
    const y = Math.sin(ra_rad - ra_ngp_rad);
    const x = Math.cos(ra_rad - ra_ngp_rad) * Math.sin(dec_ngp_rad) - 
              Math.tan(dec_rad) * Math.cos(dec_ngp_rad);
    
    let l = Math.atan2(y, x) * toDeg + L_NCP - 180;
    
    // Normalize longitude to 0-360 degrees
    l = ((l % 360) + 360) % 360;
    
    return {
        l: l,  // galactic longitude
        b: b   // galactic latitude
    };
}

const original = { ra: 261.73, dec: -26.19 };
const galactic = equatorialToGalactic(original.ra, original.dec);
console.log(`   Galactic: l=${galactic.l.toFixed(2)}°, b=${galactic.b.toFixed(2)}°`);

Remove also the [, ] characters?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions