Skip to content

Commit

Permalink
Merge pull request #240 from gmzsebastian/master
Browse files Browse the repository at this point in the history
MOSFiT v1.2 Pull Request
  • Loading branch information
mnicholl authored Aug 13, 2024
2 parents a90d474 + d2c5ff4 commit fd886ca
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 86 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class compat(types.ModuleType):
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
2 changes: 1 addition & 1 deletion mosfit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
else:
contributors.append(cont.split('(')[0].strip())

__version__ = '1.1.9'
__version__ = '1.2'
__author__ = ' & '.join([', '.join(authors[:-1]), authors[-1]])
__contributors__ = ' & '.join([', '.join(contributors[:-1]), contributors[-1]])
__license__ = 'MIT'
Expand Down
118 changes: 74 additions & 44 deletions mosfit/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def fit_events(self,
speak=False,
return_fits=True,
extra_outputs=None,
quick_save=False,
walker_paths=[],
catalogs=[],
exit_on_prompt=False,
Expand Down Expand Up @@ -493,7 +494,8 @@ def fit_events(self,
convergence_type=convergence_type,
convergence_criteria=convergence_criteria,
save_full_chain=save_full_chain,
extra_outputs=extra_outputs)
extra_outputs=extra_outputs,
quick_save=quick_save)
if return_fits:
entries[ei][mi] = deepcopy(entry)
ps[ei][mi] = deepcopy(p)
Expand Down Expand Up @@ -536,7 +538,8 @@ def fit_data(self,
convergence_type=None,
convergence_criteria=None,
save_full_chain=False,
extra_outputs=None):
extra_outputs=None,
quick_save=False):
"""Fit the data for a given event.
Fitting performed using a combination of emcee and fracking.
Expand Down Expand Up @@ -864,15 +867,22 @@ def fit_data(self,

if write:
prt.message('writing_complete')
with open_atomic(
os.path.join(model.get_products_path(), 'walkers.json'),
'w') as flast, open_atomic(
os.path.join(
model.get_products_path(), self._event_name + (
('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
entabbed_json_dump(oentry, flast, separators=(',', ':'))
entabbed_json_dump(oentry, feven, separators=(',', ':'))
if not quick_save:
with open_atomic(
os.path.join(model.get_products_path(), 'walkers.json'),
'w') as flast, open_atomic(
os.path.join(
model.get_products_path(), self._event_name + (
('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
entabbed_json_dump(oentry, flast, separators=(',', ':'))
entabbed_json_dump(oentry, feven, separators=(',', ':'))
else:
with open_atomic(
os.path.join(model.get_products_path(), self._event_name + '_walkers' +
(('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
entabbed_json_dump(oentry, feven, separators=(',', ':'))

if save_full_chain:
prt.message('writing_full_chain')
Expand All @@ -891,46 +901,66 @@ def fit_data(self,
pi = pi + 1
my_chain = my_chain.tolist()
my_chain.append(param_names)
with open_atomic(
os.path.join(model.get_products_path(), 'chain.json'),
'w') as flast, open_atomic(
os.path.join(
model.get_products_path(),
self._event_name + '_chain' +
(('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
entabbed_json_dump(
my_chain,
flast,
separators=(',', ':'))
entabbed_json_dump(
my_chain,
feven,
separators=(',', ':'))
if not quick_save:
with open_atomic(
os.path.join(model.get_products_path(), 'chain.json'),
'w') as flast, open_atomic(
os.path.join(
model.get_products_path(),
self._event_name + '_chain' +
(('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
entabbed_json_dump(
my_chain,
flast,
separators=(',', ':'))
entabbed_json_dump(
my_chain,
feven,
separators=(',', ':'))
else:
with open_atomic(os.path.join(model.get_products_path(),
self._event_name + '_chain' +
(('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
entabbed_json_dump(
my_chain,
feven,
separators=(',', ':'))

if extra_outputs is not None:
prt.message('writing_extras')
if not quick_save:
with open_atomic(
os.path.join(model.get_products_path(), 'extras.json'),
'w') as flast, open_atomic(
os.path.join(
model.get_products_path(),
self._event_name + '_extras' +
(('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
if not quick_save:
entabbed_json_dump(extras, flast, separators=(',', ':'))
entabbed_json_dump(extras, feven, separators=(',', ':'))
else:
with open_atomic(os.path.join(model.get_products_path(),
self._event_name + '_extras' +
(('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
entabbed_json_dump(extras, feven, separators=(',', ':'))

if not quick_save:
prt.message('writing_model')
with open_atomic(
os.path.join(model.get_products_path(), 'extras.json'),
os.path.join(model.get_products_path(), 'upload.json'),
'w') as flast, open_atomic(
os.path.join(
model.get_products_path(),
self._event_name + '_extras' +
(('_' + suffix) if suffix else '') + '.json'),
model.get_products_path(), uname + (
('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
entabbed_json_dump(extras, flast, separators=(',', ':'))
entabbed_json_dump(extras, feven, separators=(',', ':'))

prt.message('writing_model')
with open_atomic(
os.path.join(model.get_products_path(), 'upload.json'),
'w') as flast, open_atomic(
os.path.join(
model.get_products_path(), uname + (
('_' + suffix) if suffix else '') + '.json'),
'w') as feven:
entabbed_json_dump(ouentry, flast, separators=(',', ':'))
entabbed_json_dump(ouentry, feven, separators=(',', ':'))
if not quick_save:
entabbed_json_dump(ouentry, flast, separators=(',', ':'))
entabbed_json_dump(ouentry, feven, separators=(',', ':'))

if upload_model:
prt.message('ul_fit', [entryhash, modelhash])
Expand Down
8 changes: 8 additions & 0 deletions mosfit/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,14 @@ def get_parser(only=None, printer=None):
const=True,
help=prt.text('parser_save_full_chain'))

parser.add_argument(
'--quick-save',
'-qs',
dest='quick_save',
action='store_const',
const=True,
help=prt.text('parser_quick_save'))

parser.add_argument(
'--print-trees',
dest='print_trees',
Expand Down
9 changes: 5 additions & 4 deletions mosfit/models/slsnni/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
"log":true
},
"Pspin":{
"min_value":1.0,
"max_value":10.0
"min_value":0.7,
"max_value":20.0
},
"Bfield":{
"min_value":0.1,
"max_value":10.0
"min_value":0.01,
"max_value":10.0,
"log":true
},
"Mns":{
"min_value":1.0,
Expand Down
6 changes: 3 additions & 3 deletions mosfit/models/slsnni/slsnni.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
},
"alpha":{
"kind":"parameter",
"value":0.0,
"value":1.0,
"class":"parameter",
"latex":"\\alpha"
},
Expand Down Expand Up @@ -206,7 +206,7 @@
"lumdist"
]
},
"slsnni_constraints":{
"slsn_constraints":{
"kind":"constraint",
"inputs":[
"mejecta",
Expand All @@ -226,7 +226,7 @@
"kind":"objective",
"inputs":[
"diagonal",
"slsnni_constraints"
"slsn_constraints"
]
}
}
2 changes: 1 addition & 1 deletion mosfit/modules/arrays/alltimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def process(self, **kwargs):
self._zps = np.array(
[x[9] for x in zip(*self._all_observations)])
self._measures = np.array(
[x[10] for x in zip(*self._all_observations)])
[x[10] for x in zip(*self._all_observations)], dtype = object)
self._observation_types = np.array([
'magcount' if
('countrate' in msr and 'magnitude' in msr and zp is not None
Expand Down
4 changes: 2 additions & 2 deletions mosfit/modules/engines/bns_magnetar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from math import isnan

import numpy as np
from scipy.integrate import cumtrapz
from scipy.integrate import cumulative_trapezoid
from astrocats.catalog.source import SOURCE

from mosfit.constants import DAY_CGS, M_SUN_CGS, KM_CGS, G_CGS, C_CGS
Expand Down Expand Up @@ -105,7 +105,7 @@ def process(self, **kwargs):

# Magnetar input stops when extractable energy used up:

E_rad = cumtrapz(luminosities, x = np.array(ts) * DAY_CGS, initial=0)
E_rad = cumulative_trapezoid(luminosities, x = np.array(ts) * DAY_CGS, initial=0)

luminosities = [0.0 if E_rad[i]>E_available else luminosities[i] for
i in range(len(luminosities))]
Expand Down
Loading

0 comments on commit fd886ca

Please sign in to comment.