Skip to content

Commit

Permalink
add milkyway background image in other wavelengths
Browse files Browse the repository at this point in the history
  • Loading branch information
henrysky committed Jun 19, 2024
1 parent 6977f7d commit 6f9ed86
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## [0.13.0] - xx xxxx 20xx
- Remove `setuptools` as a requirement
- Add milkyway background in far-infrared, infrared and gamma

## [0.12.0] - 10 June 2024
- Add radius (r) as supported parameter for bokeh figures (Mitlasóczki Bence)
- Fix a bug where ticks show up in between the all-sky plot and the colour bar when doing all-sky plot + scatter plot + colorbar (Camila Navarrete)
Expand Down
6 changes: 3 additions & 3 deletions docs/source/matplotlib_gallery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Orbit of Sun
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot

from galpy.potential import MWPotential2014
Expand Down Expand Up @@ -65,7 +65,7 @@ Orbit of Sun 2
.. code-block:: python
:linenos:
import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot
from astropy import units as u
from galpy.potential import MWPotential2014
Expand Down Expand Up @@ -100,7 +100,7 @@ Orbit of Sun 2
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot
from astropy import units as u
from galpy.potential import MWPotential2014
Expand Down
79 changes: 68 additions & 11 deletions docs/source/matplotlib_multi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Tranform a single subplot
.. code-block:: python
:linenos:
import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot
from astropy import units as u
Expand All @@ -32,7 +32,7 @@ Tranform a single subplot
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot
from astropy import units as u

Expand All @@ -59,7 +59,7 @@ Tranform multiple subplots
.. code-block:: python
:linenos:
import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot
from astropy import units as u
Expand All @@ -82,7 +82,7 @@ Tranform multiple subplots
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot
from astropy import units as u

Expand Down Expand Up @@ -112,7 +112,7 @@ Not only you can transform with one style, you can do multiple style too
.. code-block:: python
:linenos:
import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot, MWSkyMap
from astropy import units as u
Expand All @@ -136,7 +136,7 @@ Not only you can transform with one style, you can do multiple style too
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot, MWSkyMap
from astropy import units as u

Expand Down Expand Up @@ -166,9 +166,8 @@ You can quickly transform all subplots in a figure
.. code-block:: python
:linenos:
import pylab as plt
from mw_plot import MWPlot
from astropy import units as u
import matplotlib.pyplot as plt
from mw_plot import MWSkyMap
# setup a mw-plot instance of bird's eyes view of the disc
mw1 = MWPlot(radius=20 * u.kpc, center=(0, 0)*u.kpc, unit=u.kpc, coord='galactocentric', grayscale=False, annotation=False)
Expand All @@ -182,7 +181,7 @@ You can quickly transform all subplots in a figure
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
from mw_plot import MWPlot
from astropy import units as u

Expand All @@ -196,4 +195,62 @@ You can quickly transform all subplots in a figure
# mw1.transform([ax1, ax2]) will have the same effect
mw1.transform(fig)

plt.tight_layout()
plt.tight_layout()

Tranform subplots with projection
---------------------------------------

If you are plotting sky maps with projection, your subplot should be in that particular projection.

.. code-block:: python
:linenos:
import matplotlib.pyplot as plt
from mw_plot import MWSkyMap
fig = plt.figure(figsize=(15, 10))
ax1 = fig.add_subplot(221, projection="mollweide")
ax2 = fig.add_subplot(222, projection="mollweide")
ax3 = fig.add_subplot(223, projection="mollweide")
ax4 = fig.add_subplot(224, projection="mollweide")
mw1 = MWSkyMap(projection="mollweide", wavelength="far-infrared")
mw1.transform(ax1)
mw2 = MWSkyMap(projection="mollweide", wavelength="infrared")
mw2.transform(ax2)
mw3 = MWSkyMap(projection="mollweide", wavelength="optical")
mw3.transform(ax3)
mw4 = MWSkyMap(projection="mollweide", wavelength="gamma")
mw4.transform(ax4)
ax1.set_title("Milk Way Far-Infrared Sky Map")
ax2.set_title("Milk Way Infrared Sky Map")
ax3.set_title("Milk Way Optical Sky Map")
ax4.set_title("Milk Way Gamma-Ray Sky Map")
.. plot::

import matplotlib.pyplot as plt
from mw_plot import MWSkyMap

fig = plt.figure(figsize=(15, 10))
ax1 = fig.add_subplot(221, projection="mollweide")
ax2 = fig.add_subplot(222, projection="mollweide")
ax3 = fig.add_subplot(223, projection="mollweide")
ax4 = fig.add_subplot(224, projection="mollweide")

mw1 = MWSkyMap(projection="mollweide", wavelength="far-infrared")
mw1.transform(ax1)
mw2 = MWSkyMap(projection="mollweide", wavelength="infrared")
mw2.transform(ax2)
mw3 = MWSkyMap(projection="mollweide", wavelength="optical")
mw3.transform(ax3)
mw4 = MWSkyMap(projection="mollweide", wavelength="gamma")
mw4.transform(ax4)

ax1.set_title("Milk Way Far-Infrared Sky Map")
ax2.set_title("Milk Way Infrared Sky Map")
ax3.set_title("Milk Way Optical Sky Map")
ax4.set_title("Milk Way Gamma-Ray Sky Map")

plt.tight_layout()
56 changes: 50 additions & 6 deletions docs/source/matplotlib_single.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ MilkyWay Bird's Eye
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from mw_plot import MWPlot
Expand Down Expand Up @@ -78,7 +78,7 @@ Annotation
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from mw_plot import MWPlot
Expand Down Expand Up @@ -116,7 +116,7 @@ MilkyWay Sky Map
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from mw_plot import MWSkyMap
Expand All @@ -135,6 +135,50 @@ MilkyWay Sky Map
mw1.scatter(lsmc_ra, lsmc_dec, c="r", s=200)
plt.tight_layout()

You can also plot in different wavelength
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
:linenos:
import numpy as np
from astropy import units as u
from mw_plot import MWSkyMap
# setup a MWSkyMap instance with projection, other projection can be 'hammer', 'mollweide' etc
# grid: whether to show the Galactic grid
mw1 = MWSkyMap(projection="aitoff", wavelength="gamam")
# set up plot title
mw1.title = "LMC and SMC in Green dots"
# LMC and SMC coordinates
lsmc_ra = [78.77, 16.26] * u.degree
lsmc_dec = [-69.01, -72.42] * u.degree
mw1.scatter(lsmc_ra, lsmc_dec, c="g", s=200)
.. plot::

import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from mw_plot import MWSkyMap

# setup a MWSkyMap instance with projection, other projection can be 'hammer', 'mollweide' etc
# grid: whether to show the Galactic grid
mw1 = MWSkyMap(projection="aitoff", wavelength="gamam")

# set up plot title
mw1.title = "LMC and SMC in red dots with Galactic Grid"

# LMC and SMC coordinates
lsmc_ra = [78.77, 16.26] * u.degree
lsmc_dec = [-69.01, -72.42] * u.degree

mw1.scatter(lsmc_ra, lsmc_dec, c="g", s=200)
plt.tight_layout()

You can also plot with grid
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -160,7 +204,7 @@ You can also plot with grid
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from mw_plot import MWSkyMap
Expand Down Expand Up @@ -201,7 +245,7 @@ You can also plot with grid
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from mw_plot import MWSkyMap
Expand Down Expand Up @@ -243,7 +287,7 @@ You can also plot with grid
.. plot::

import pylab as plt
import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from mw_plot import MWSkyMap
Expand Down
Binary file added mw_plot/MW_2mass.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mw_plot/MW_farinfrared.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mw_plot/MW_fermi_gamma.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mw_plot/mw_plot_bokeh.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def __init__(
super().__init__(
grayscale=grayscale,
projection="equirectangular",
wavelength="optical",
center=center,
radius=radius,
figsize=None,
Expand Down
28 changes: 21 additions & 7 deletions mw_plot/mw_plot_masters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import numpy as np
import pylab as plt
import matplotlib.pyplot as plt
from abc import ABC, abstractmethod
import astropy.units as u
import astropy.coordinates as coord
Expand Down Expand Up @@ -263,7 +263,7 @@ class MWSkyMapMaster(MWPlotMaster):
MWSkyMap master class
"""

def __init__(self, grayscale, projection, center, radius, figsize, dpi, grid=False):
def __init__(self, grayscale, projection, wavelength, center, radius, figsize, dpi, grid=False):
if projection in [
"equirectangular",
"aitoff",
Expand All @@ -274,6 +274,11 @@ def __init__(self, grayscale, projection, center, radius, figsize, dpi, grid=Fal
self._projection = projection
else:
raise ValueError("Unknown projection")

if wavelength in (allowed_wavelength := ["gamma", "optical", "infrared", "far-infrared"]):
self.wavlength = wavelength
else:
raise ValueError(f"Unknown wavelength, allowed values are: {allowed_wavelength}")

self._center = center
self._radius = radius
Expand Down Expand Up @@ -304,16 +309,25 @@ def __init__(self, grayscale, projection, center, radius, figsize, dpi, grid=Fal
self._in_jupyter = True

def images_read(self):
image_filename = "MW_edgeon_edr3_unannotate.jpg"
if self.wavlength == "optical":
image_filename = "MW_edgeon_edr3_unannotate.jpg"
elif self.wavlength == "gamma":
image_filename = "MW_fermi_gamma.jpg"
elif self.wavlength == "infrared":
image_filename = "MW_2mass.jpg"
elif self.wavlength == "far-infrared":
image_filename = "MW_farinfrared.jpg"
else:
raise ValueError("Unknown wavelength")
path = os.path.join(os.path.dirname(__file__), image_filename)
img = plt.imread(path)
self._img = img

# find center pixel and radius pixel
y_img_center = 1625 - int((3250 / 180) * self._center[1].value)
y_radious_px = int((3250 / 180) * self._radius[1].value)
x_img_center = int((6500 / 360) * self._center[0].value) + 3250
x_radious_px = int((6500 / 360) * self._radius[0].value)
y_img_center = self._img.shape[0] // 2 - int((self._img.shape[0] / 180) * self._center[1].value)
y_radious_px = int((self._img.shape[0] / 180) * self._radius[1].value)
x_img_center = int((self._img.shape[1] / 360) * self._center[0].value) + self._img.shape[0]
x_radious_px = int((self._img.shape[1] / 360) * self._radius[0].value)

self._ext = [
(self._center[0] - self._radius[0]).value,
Expand Down
Loading

0 comments on commit 6f9ed86

Please sign in to comment.