From 96e4f16c1cd7420af1127267aec9a5ea62f6a2d3 Mon Sep 17 00:00:00 2001 From: Xen0Xys Date: Wed, 15 May 2024 14:56:22 +0200 Subject: [PATCH] :memo: Update example 9 with new supported pixel regions --- examples/9_Shapes.ipynb | 129 +++++++++++++++++++++++++++++++++++----- 1 file changed, 113 insertions(+), 16 deletions(-) diff --git a/examples/9_Shapes.ipynb b/examples/9_Shapes.ipynb index 2da757e8..ef34b352 100644 --- a/examples/9_Shapes.ipynb +++ b/examples/9_Shapes.ipynb @@ -53,7 +53,10 @@ { "cell_type": "markdown", "metadata": {}, - "source": "# Add shapes from regions objects" + "source": [ + "# Add shapes from regions objects\n", + "## From sky coordinates" + ] }, { "cell_type": "code", @@ -61,11 +64,11 @@ "metadata": {}, "outputs": [], "source": [ - "aladin = Aladin(\n", + "b = Aladin(\n", " target=\"m31\",\n", " fov=10,\n", ")\n", - "aladin" + "b" ] }, { @@ -90,9 +93,9 @@ "metadata": {}, "outputs": [], "source": [ - "circle = CircleSkyRegion(center=aladin.target, radius=Angle(0.5, \"deg\"))\n", + "circle = CircleSkyRegion(center=b.target, radius=Angle(0.5, \"deg\"))\n", "\n", - "aladin.add_overlay(circle, color=\"red\")" + "b.add_overlay(circle, color=\"red\")" ] }, { @@ -102,12 +105,12 @@ "outputs": [], "source": [ "ellipse = EllipseSkyRegion(\n", - " center=aladin.target,\n", + " center=b.target,\n", " height=Angle(0.5, \"deg\"),\n", " width=Angle(1, \"deg\"),\n", " angle=Angle(45, \"deg\"),\n", ")\n", - "aladin.add_overlay(ellipse, color=\"blue\", alpha=0.5)" + "b.add_overlay(ellipse, color=\"blue\")" ] }, { @@ -117,10 +120,10 @@ "outputs": [], "source": [ "line = LineSkyRegion(\n", - " start=aladin.target,\n", - " end=aladin.target.directional_offset_by(Angle(0, \"deg\"), Angle(0.5, \"deg\")),\n", + " start=b.target,\n", + " end=b.target.directional_offset_by(Angle(0, \"deg\"), Angle(0.5, \"deg\")),\n", ")\n", - "aladin.add_overlay(line, color=\"green\", alpha=0.5)" + "b.add_overlay(line, color=\"green\")" ] }, { @@ -132,15 +135,15 @@ "polygon = PolygonSkyRegion(\n", " vertices=SkyCoord(\n", " [\n", - " aladin.target.directional_offset_by(Angle(0, \"deg\"), Angle(0.5, \"deg\")),\n", - " aladin.target.directional_offset_by(Angle(90, \"deg\"), Angle(0.5, \"deg\")),\n", - " aladin.target.directional_offset_by(Angle(-90, \"deg\"), Angle(0.5, \"deg\")),\n", + " b.target.directional_offset_by(Angle(0, \"deg\"), Angle(0.5, \"deg\")),\n", + " b.target.directional_offset_by(Angle(90, \"deg\"), Angle(0.5, \"deg\")),\n", + " b.target.directional_offset_by(Angle(-90, \"deg\"), Angle(0.5, \"deg\")),\n", " ],\n", " frame=\"icrs\",\n", " unit=\"deg\",\n", " )\n", ")\n", - "aladin.add_overlay(polygon, color=\"yellow\", alpha=0.5)" + "b.add_overlay(polygon, color=\"yellow\")" ] }, { @@ -150,12 +153,106 @@ "outputs": [], "source": [ "rectangle = RectangleSkyRegion(\n", - " center=aladin.target,\n", + " center=b.target,\n", " width=Angle(0.5, \"deg\"),\n", " height=Angle(0.5, \"deg\"),\n", " angle=Angle(45, \"deg\"),\n", ")\n", - "aladin.add_overlay(rectangle, color=\"purple\", alpha=0.5)" + "b.add_overlay(rectangle, color=\"purple\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": "## From pixel coordinates" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "c = Aladin(\n", + " target=\"m31\",\n", + " fov=10,\n", + ")\n", + "c" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from regions import (\n", + " CirclePixelRegion,\n", + " EllipsePixelRegion,\n", + " LinePixelRegion,\n", + " PolygonPixelRegion,\n", + " RectanglePixelRegion,\n", + " PixCoord,\n", + ")\n", + "from astropy.coordinates import Angle" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "circle = CirclePixelRegion(\n", + " center=PixCoord(x=200, y=200),\n", + " radius=50,\n", + " visual={\n", + " \"edgecolor\": \"red\",\n", + " },\n", + ")\n", + "c.add_overlay(circle)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ellipse = EllipsePixelRegion(\n", + " center=PixCoord(x=200, y=200), height=50, width=100, angle=Angle(90, \"deg\")\n", + ")\n", + "c.add_overlay(ellipse, color=\"blue\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "line = LinePixelRegion(start=PixCoord(x=200, y=200), end=PixCoord(x=200, y=150))\n", + "c.add_overlay(line, color=\"green\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "polygon = PolygonPixelRegion(vertices=PixCoord(x=[200, 250, 150], y=[150, 200, 200]))\n", + "c.add_overlay(polygon, color=\"yellow\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "rectangle = RectanglePixelRegion(\n", + " center=PixCoord(x=200, y=200), width=100, height=100, angle=Angle(45, \"deg\")\n", + ")" ] } ],