Skip to content

Commit

Permalink
Merge branch 'master' of github.com:thomaswmorris/maria
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Morris committed Jun 3, 2024
2 parents ab787d4 + 72c0b1b commit 198ce37
Show file tree
Hide file tree
Showing 7 changed files with 549 additions and 1,388 deletions.
4 changes: 2 additions & 2 deletions docs/source/simulations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Simulations
###########

Simulations in ``maria`` are done with a ``Simulation``, to which we pass an instrument, a site, and an observing plan:
Simulations in ``maria`` are done with a ``Simulation``, to which we pass an instrument, a site, and an observing plan::

import maria

sim = maria.Simulation(instrument="ACT", site="llano_de_chajnantor", plan="stare")


Running a simulation will spit out a ``TOD`` (short for time-ordered data)
Running a simulation will spit out a ``TOD`` (short for time-ordered data)::

tod = sim.run()

Expand Down
5 changes: 2 additions & 3 deletions docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ Tutorials
:maxdepth: 2

tutorials/custom-map-simulations
.. tutorials/MUSTANG-2_cluster.ipynb
.. tutorials/AtLAST_cluster.ipynb
.. tutorials/AtLAST_galaxy.ipynb
tutorials/MUSTANG-2_cluster.ipynb
tutorials/AtLAST_cluster.ipynb
567 changes: 261 additions & 306 deletions docs/source/tutorials/AtLAST_cluster.ipynb

Large diffs are not rendered by default.

633 changes: 0 additions & 633 deletions docs/source/tutorials/AtLAST_galaxy.ipynb

This file was deleted.

561 changes: 218 additions & 343 deletions docs/source/tutorials/MUSTANG-2_cluster.ipynb

Large diffs are not rendered by default.

123 changes: 43 additions & 80 deletions docs/source/tutorials/custom-map-simulations.ipynb

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions maria/map/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from astropy.io import fits
from astropy.wcs import WCS
from matplotlib.colors import ListedColormap
from maria import units

here, this_filename = os.path.split(__file__)

Expand Down Expand Up @@ -35,12 +36,14 @@ def __init__(
center: Tuple[float, float] = (0.0, 0.0),
frame: str = "ra_dec",
degrees: bool = True,
units: str ='K_RJ'
):
self.data = data if data.ndim > 2 else data[None]
self.weight = np.ones(self.data.shape) if weight is None else weight
self.center = tuple(np.radians(center)) if degrees else center
self.frequency = np.atleast_1d(frequency)
self.frame = frame
self.units = units

if not (width is None) ^ (resolution is None):
raise ValueError("You must pass exactly one of 'width' or 'resolution'.")
Expand All @@ -56,6 +59,9 @@ def __init__(
f"frequency dimension of the supplied map ({self.n_f})."
)

if self.units == 'Jy/pixel':
self.to('K_RJ')

self.header = ap.io.fits.header.Header()

self.header["CDELT1"] = np.degrees(self.resolution) # degree
Expand Down Expand Up @@ -109,6 +115,17 @@ def x_side(self):
def y_side(self):
y = self.resolution * np.arange(self.n_y)
return y - y.mean()


def to(self, unit):

if unit is 'K_RJ':
self.data /= units.KbrightToJyPix(self.frequency*1e9, np.degrees(self.resolution), np.degrees(self.resolution))
elif unit is 'Jy/pixel':
self.data *= units.KbrightToJyPix(self.frequency*1e9, np.degrees(self.resolution), np.degrees(self.resolution))
else:
raise ValueError(f"Unit {self.unit} not implemented.")


def plot(
self, cmap="cmb", rel_vmin=0.001, rel_vmax=0.999, units="degrees", **kwargs
Expand Down Expand Up @@ -205,31 +222,16 @@ def to_fits(self, filepath):
self.header["comment"] = "Overwrote pointing location of the output map"
self.header["comment"] = "Overwrote spectral position of the output map"

self.header["BTYPE"] = "Kelvin RJ"

# if self.map.units == "Jy/pixel":
# self.header["BUNIT"] = "Jy/pixel "
# elif self.map.units == "K_RJ":
# self.header["BUNIT"] = "Kelvin RJ" # tods are always in Kelvin
# else:
# raise ValueError(f"Units {self.map.units} not implemented.")

# save_maps = np.zeros((len(self.map.frequency), self.n_x, self.n_y))

# for i, key in enumerate(self.band_data.keys()):
# self.header["CRVAL3"] = self.band_data[key]["band_center"] * 1e9
# self.header["CDELT3"] = self.band_data[key]["band_width"] * 1e9

# save_maps[i] = self.map.data[i]
if self.units == "Jy/pixel":
self.to("Jy/pixel")
self.header["BTYPE"] = "Jy/pixel"

# # if self.map.units == "Jy/pixel":
# # save_maps[i] *= maria.units.KbrightToJyPix(
# # self.header["CRVAL3"], self.header["CDELT1"], self.header["CDELT2"]
# # )
elif self.units == "K_RJ":
self.header["BTYPE"] = "Kelvin RJ"

fits.writeto(
filename=filepath,
data=self.data,
header=self.header,
overwrite=True,
)
)

0 comments on commit 198ce37

Please sign in to comment.