{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Gaia ESA Archive\n", "\n", "![](https://gea.esac.esa.int/archive-help/css/images/header-cosmos-gaia.png)\n", "\n", "Reference: https://gea.esac.esa.int/archive/" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "''' Install astropy '''\n", "!pip install astropy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from bioexplorer import BioExplorer, Vector3\n", "import requests\n", "import gzip\n", "import astropy.coordinates as coord\n", "import astropy.units as u\n", "from tqdm import tqdm\n", "import os\n", "\n", "'''Connect to the BioExplorer and reset scene'''\n", "url = 'localhost:5000'\n", "be = BioExplorer(url)\n", "status = be.reset_scene()\n", "\n", "'''Default settings'''\n", "DEFAULT_RADIUS = 0.00005\n", "\n", "'''Gaia data source'''\n", "url = \"http://cdn.gea.esac.esa.int/Gaia/gdr1/gaia_source/csv/\"\n", "cache_folder = '/tmp'\n", "\n", "a = 0\n", "for b in range(21):\n", " for c in range(256):\n", " positions = list()\n", " radii = list()\n", "\n", " '''Download file if not already in the cache'''\n", " base_name = 'GaiaSource_%03d-%03d-%03d' % (a, b, c)\n", " path = os.path.join(cache_folder, base_name + '.csv.gz')\n", " lines = list()\n", " if not os.path.exists(path):\n", " response = requests.get(url + base_name + '.csv.gz')\n", " content = response.content\n", "\n", " # Save the file\n", " with open(path, 'wb') as file:\n", " file.write(content)\n", " lines = gzip.decompress(content).decode('utf-8').split('\\n')\n", " else:\n", " lines = gzip.open(path).readlines()\n", "\n", " header = True\n", " for line in tqdm(lines):\n", " if header:\n", " header = False\n", " continue\n", " values = str(line).split(',')\n", "\n", " '''Convert the RA and DEC coordinates to 3D coordinates'''\n", " ra = float(values[4])\n", " dec = float(values[6])\n", " icrs = coord.SkyCoord(ra=ra * u.degree, dec=dec * u.degree, frame='icrs')\n", " galactic = icrs.transform_to(coord.Galactic)\n", "\n", " '''Extract the x, y, z coordinates'''\n", " x = float(galactic.cartesian.x)\n", " y = float(galactic.cartesian.y)\n", " z = float(galactic.cartesian.z)\n", " \n", " '''Add coordinates and default radius to the list of positions'''\n", " positions.append(Vector3(x, y, z))\n", " radii.append(DEFAULT_RADIUS)\n", "\n", " '''Add spheres to the BioExplorer'''\n", " status = be.add_spheres(\n", " name=base_name,\n", " positions=positions, radii=radii)" ] } ], "metadata": { "kernelspec": { "display_name": "env", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }