Skip to content

Commit

Permalink
First commit for fetching Ebv from dustmap
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunhopang committed Jul 9, 2024
1 parent 5279f4d commit 5067fed
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions nmma/em/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ def get_parser(**kwargs):
type=float,
help="Distance of the location; to be used together with fits file"
)
parser.add_argument(
"--fetch-Ebv-from-dustmap",
help="Fetching Ebv from dustmap, to be used as fixed-value prior",
action="store_true",
default=False,
)

parser.add_argument(
"--skip-sampling",
Expand Down
29 changes: 29 additions & 0 deletions nmma/em/prior.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,33 @@ def convert_mtot_mni(parameters):
if args.fits_file:
priors = inclination_prior_from_fits(priors, args)

if args.fetch_Ebv_from_dustmap:
assert args.ra and args.dec, \
"sky location is needed for fetching Ebv from dustmap"
print("Fetching value of Ebv from dustmap, overwriting the original prior on Ebv")
try:
import dustmaps.sfd
from dustmaps.config import config
from astropy import coordinates
except ImportError:
print("Package dustmap is needed")
import sys
sys.exit(1)

# check if the dust fits are downloaded
import os
default_dir = os.path.join(os.path.dirname(__file__))
# config dustmaps to fetch and place fits from default_dir
config['data_dir'] = default_dir
required_files = ['sfd/SFD_dust_4096_ngp.fits', 'sfd/SFD_dust_4096_sgp.fits']
if any([
not os.path.isfile(os.path.join(default_dir, f)) for f in required_files]
):
dustmaps.sfd.fetch()
# fetching the Ebv value
coord = coordinates.SkyCoord(args.ra, args.dec, unit='rad')
priors['Ebv'] = float(dustmaps.sfd.SFDQuery()(coord))

print(f"The prior on Ebv is set to fixed value of {priors['Ebv']}")

return priors
1 change: 1 addition & 0 deletions nmma/tests/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def args():
cosiota_node_num=10,
ra=None,
dec=None,
fetch_Ebv_from_dustmap=False
)

return args
Expand Down
3 changes: 2 additions & 1 deletion nmma/tests/analysis_lbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def args():
fits_file=None,
cosiota_node_num=10,
ra=None,
dec=None
dec=None,
fetch_Ebv_from_dustmap=False
)

return args
Expand Down

0 comments on commit 5067fed

Please sign in to comment.