Code Monkey home page Code Monkey logo

cosmoglobe's Introduction

Documentation Status astropy


cosmoglobe is a python package that interfaces the Cosmoglobe Sky Model with Commander outputs for the purpose of producing astrophysical sky maps.

Features

See the documentation for a more comprehensive guide.

Initialize the Cosmoglobe Sky Model (this downloads and caches a ~800 MB file with the sky model data)

import cosmoglobe

model = cosmoglobe.sky_model(nside=256)

Simulate the sky at 150 GHz in units of MJy/sr, smoothed to 40 arcmin with a gaussian beam:

import astropy.units as u

emission = model(150*u.GHz, fwhm=40*u.arcmin, output_unit="MJy/sr")

Integrate over a bandpass:

import numpy as np
import healpy as hp
import matplotlib.pyplot as plt

# Reading in WMAP K-band bandpass profile.
bandpass_frequencies, bandpass_weights = np.loadtxt(wmap_bandpass.txt, unpack=True)

# The units of the detector must be specified even if the bandpass is pre-normalized.
bandpass_weights *= u.Unit("K_RJ") # Specify K_RJ or K_CMB
bandpass_frequencies *= u.GHz

model.remove_dipole() # Remove the dipole from the CMB component
emission = model(
    freqs=bandpass_frequencies, 
    weights=bandpass_weights, 
    fwhm=0.8*u.deg, 
    output_unit="mK_RJ",
)

hp.mollview(emission[0], hist="norm") # Plotting the intensity
plt.show()

Installation

cosmoglobe can be installed via pip

pip install cosmoglobe

Funding

This work has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreements No 776282 (COMPET-4; BeyondPlanck), 772253 (ERC; bits2cosmology) and 819478 (ERC; Cosmoglobe).

License

GNU GPLv3

cosmoglobe's People

Contributors

dncnwtts avatar maksymbrl avatar metinsa avatar trygvels avatar unfunfunt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cosmoglobe's Issues

Producing sky models as spherical harmonic coefficients?

Many current simulation efforts are working with non-axisymmetric beams and partially with rotating half-wave plates, and to implement these effects efficiently, an input sky given in the form of a_lm is much preferrable to, say, Healpix sky maps.
Of course this can be obtained by running a map analysis on the outputs of the sky model, but I wonder if it wouldn't be advantageous to actually run as many of the sky model calculations as possible in harmonic space as well. Advantages would include

  • no accuracy loss during rotations
  • no accuracy loss (and much higher performance) when smoothing
  • input "maps" to the sky model components could be stored as a_lm as well. If that is done, only one set of a_lm is sufficient for all possible output resolutions, since a_lm can be read in to any desired band limit, as opposed to maps, where either maps at different resolutions have to be stored, or downscaling must be performed.

There are of course some components where at least some of the calculations have to be performed in position space, but these would simply be treated as before, and the maps internally converted to a_lm at a convenient stage.

I have suggested this to the pysm developers as well, but have not had a response yet (galsci/pysm#90 (comment)). @hke, do you think such an approach could be generally useful?

Smoothing is really slow on polarized maps

High nside maps with the fwhm parameter set take forever, and I think part of the issue is that the smoothing takes place before the sig is selected. So if I pass an I,Q,U map in with -sig 1 and -fwhm 60, first it smoothes all three channels to 1 degree and then selects Q. If this was in the other order then it would speed things up by a factor of 3, which is better than nothing

cosmoglobe plot width issue

Issue when calling width strings in command line:

Traceback (most recent call last): File "/home/daniel/miniforge3/bin/cosmoglobe", line 8, in <module> sys.exit(cli()) File "/home/daniel/miniforge3/lib/python3.9/site-packages/click/core.py", line 1137, in __call__ return self.main(*args, **kwargs) File "/home/daniel/miniforge3/lib/python3.9/site-packages/click/core.py", line 1062, in main rv = self.invoke(ctx) File "/home/daniel/miniforge3/lib/python3.9/site-packages/click/core.py", line 1668, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/daniel/miniforge3/lib/python3.9/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/daniel/miniforge3/lib/python3.9/site-packages/click/core.py", line 763, in invoke return __callback(*args, **kwargs) File "/home/daniel/miniforge3/lib/python3.9/site-packages/cosmoglobe/plot/click_plotting.py", line 503, in plot fn = fn + f"_{sig}_w{str(int(width))}" + nside_tag ValueError: invalid literal for int() with base 10: 'm'

Downloads URLError

Hi,

This is not an issue with respect to the code, which I believe should be working, but the links to download the data seem broken?
I tried to directly get them in this link, but I still cannot access them.

import cosmoglobe
chain = cosmoglobe.get_test_chain()

Then the error:

Traceback (most recent call last):
  File "/Users/tcassanelli/anaconda3/lib/python3.9/urllib/request.py", line 1346, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Users/tcassanelli/anaconda3/lib/python3.9/http/client.py", line 1285, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Users/tcassanelli/anaconda3/lib/python3.9/http/client.py", line 1331, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Users/tcassanelli/anaconda3/lib/python3.9/http/client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Users/tcassanelli/anaconda3/lib/python3.9/http/client.py", line 1040, in _send_output
    self.send(msg)
  File "/Users/tcassanelli/anaconda3/lib/python3.9/http/client.py", line 980, in send
    self.connect()
  File "/Users/tcassanelli/anaconda3/lib/python3.9/http/client.py", line 946, in connect
    self.sock = self._create_connection(
  File "/Users/tcassanelli/anaconda3/lib/python3.9/socket.py", line 844, in create_connection
    raise err
  File "/Users/tcassanelli/anaconda3/lib/python3.9/socket.py", line 832, in create_connection
    sock.connect(sa)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/tcassanelli/anaconda3/lib/python3.9/site-packages/cosmoglobe/__init__.py", line 37, in get_test_chain
    file = download_file(filename, cache=cache)
  File "/Users/tcassanelli/anaconda3/lib/python3.9/site-packages/astropy/utils/data.py", line 1532, in download_file
    raise errors[sources[0]]
  File "/Users/tcassanelli/anaconda3/lib/python3.9/site-packages/astropy/utils/data.py", line 1500, in download_file
    f_name = _download_file_from_source(
  File "/Users/tcassanelli/anaconda3/lib/python3.9/site-packages/astropy/utils/data.py", line 1284, in _download_file_from_source
    with _try_url_open(
  File "/Users/tcassanelli/anaconda3/lib/python3.9/site-packages/astropy/utils/data.py", line 1202, in _try_url_open
    return urlopener.open(req, timeout=timeout)
  File "/Users/tcassanelli/anaconda3/lib/python3.9/urllib/request.py", line 517, in open
    response = self._open(req, data)
  File "/Users/tcassanelli/anaconda3/lib/python3.9/urllib/request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Users/tcassanelli/anaconda3/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/Users/tcassanelli/anaconda3/lib/python3.9/urllib/request.py", line 1375, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/Users/tcassanelli/anaconda3/lib/python3.9/urllib/request.py", line 1349, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error timed out>

I am not really familiar with any of these cosmology data products, but it would be awesome I we could get a simple Jupyter showing how to compile the chain files yourself and to not fall into this problems, or equivalently make the links available again.
Thanks!

Maps with masked pixels are not plotted with a mask

The HEALPix missing value is included in the automatic error bars, causing masked maps to look terrible when plotting. It would be very helpful to have maps with missval pixels to have them automatically masked when plotted.

Support for map differences in plotting

One of the things I commonly do is subtract two maps from different runs/iterations and then plot the difference. It would be great if the plot functionality could support something like:

--diff map_1.fits map_2.fits --type freqmap

or something of that nature

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.