Skip to content

Commit

Permalink
Merge pull request #22 from telegraphic/dcp_init_gsm
Browse files Browse the repository at this point in the history
Adding init_gsm, init_observer and tests
  • Loading branch information
telegraphic committed Apr 15, 2024
2 parents 2e24837 + e2c871f commit 285cfbe
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* 1.5.3 (2024.04.15) - Added `init_gsm()` and `init_observer()` helper functions
* 1.5.2 (2024.03.29) - Fix PyPi distribution files (thanks to D. McKenna)
* 1.5.0 (2024.03.29) - Fix to `GlobalSkyModel16`, correct T_CMB monopole addition (thanks to R. Francis)
* 1.4.1 (2023.04.28) - Added `include_cmb` option to sky models.
* 1.4.0 (2023.04.27) - Added new interpolation method (courtesy R. Braun)
Expand Down
71 changes: 69 additions & 2 deletions pygdsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from .gsm08 import GlobalSkyModel
from .gsm08 import GSMObserver

GlobalSkyModel08 = GlobalSkyModel

from .gsm16 import GlobalSkyModel16
from .gsm16 import GSMObserver16

Expand All @@ -12,3 +10,72 @@

from .haslam import HaslamSkyModel
from .haslam import HaslamObserver

# Add aliases
GlobalSkyModel08 = GlobalSkyModel
GSMObserver08 = GSMObserver

def init_gsm(gsm_name: str='gsm08'):
""" Initialize a GDSM object by ID/name
Returns a diffuse sky model (subclass of BaseSkyModel), based on one of:
* **GSM08:** A model of diffuse Galactic radio emission from 10 MHz to 100 GHz,
[Oliveira-Costa et. al., (2008)](https://ui.adsabs.harvard.edu/abs/2008MNRAS.388..247D/abstract).
* **GSM16:** An improved model of diffuse galactic radio emission from 10 MHz to 5 THz,
[Zheng et. al., (2016)](https://ui.adsabs.harvard.edu/abs/2017MNRAS.464.3486Z/abstract).
* **LFSM:** The LWA1 Low Frequency Sky Survey (10-408 MHz)
[Dowell et. al. (2017)](https://ui.adsabs.harvard.edu/abs/2017MNRAS.469.4537D/abstract).
* **Haslam:** A frequency-scaled model using a spectral index, based on the Haslam 408 MHz map
[Haslam 408 MHz](https://lambda.gsfc.nasa.gov/product/foreground/fg_2014_haslam_408_info.cfm).
Args:
gsm_name (str): One of 'gsm08', 'gsm16', 'lfsm' or 'haslam'
Returns:
sky_model (various): Corresponding sky model
"""
gsm_name = gsm_name.lower().strip()
match gsm_name:
case 'gsm': # Shorthand for GSM08
return GlobalSkyModel()
case 'gsm08':
return GlobalSkyModel()
case 'gsm16':
return GlobalSkyModel16()
case 'lfsm':
return LowFrequencySkyModel()
case 'haslam':
return HaslamSkyModel()


def init_observer(gsm_name: str='gsm08'):
""" Initialize a GDSM Observer object by ID/name
Returns an observer (subclass of BaseObserver), where the diffuse sky is created from one of:
* **GSM08:** A model of diffuse Galactic radio emission from 10 MHz to 100 GHz,
[Oliveira-Costa et. al., (2008)](https://ui.adsabs.harvard.edu/abs/2008MNRAS.388..247D/abstract).
* **GSM16:** An improved model of diffuse galactic radio emission from 10 MHz to 5 THz,
[Zheng et. al., (2016)](https://ui.adsabs.harvard.edu/abs/2017MNRAS.464.3486Z/abstract).
* **LFSM:** The LWA1 Low Frequency Sky Survey (10-408 MHz)
[Dowell et. al. (2017)](https://ui.adsabs.harvard.edu/abs/2017MNRAS.469.4537D/abstract).
* **Haslam:** A frequency-scaled model using a spectral index, based on the Haslam 408 MHz map
[Haslam 408 MHz](https://lambda.gsfc.nasa.gov/product/foreground/fg_2014_haslam_408_info.cfm).
Args:
gsm_name (str): One of 'gsm08', 'gsm16', 'lfsm' or 'haslam'
Returns:
observer (various): Corresponding sky model observer
"""
gsm_name = gsm_name.lower().strip()
match gsm_name:
case 'gsm': # Shorthand for GSM08
return GSMObserver()
case 'gsm08':
return GSMObserver()
case 'gsm16':
return GSMObserver16()
case 'lfsm':
return LFSMObserver()
case 'haslam':
return HaslamObserver()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.5.2',
version='1.5.3',

description='Python Global Sky Model of diffuse Galactic radio emission',
long_description=long_description,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_gsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
from pygdsm import GlobalSkyModel
from pygdsm import init_gsm, init_observer

import time
import numpy as np
Expand Down Expand Up @@ -108,7 +109,7 @@ def test_cmb_removal():
g = GlobalSkyModel(freq_unit='MHz', include_cmb=False)
sky_no_cmb = g.generate(400)
g = GlobalSkyModel(freq_unit='MHz', include_cmb=True)
sky_with_cmb = g.generate(400)
sky_with_cmb = g.generate(400)

T_cmb = (sky_with_cmb - sky_no_cmb).mean()
print(T_cmb)
Expand Down

0 comments on commit 285cfbe

Please sign in to comment.