Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary_c-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Izzard, Robert Dr (Maths & Physics)
binary_c-python
Commits
83ca68e4
Commit
83ca68e4
authored
3 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
Got the M&S grid inplace. Will not debug and make sure the numbers are correct
parent
ed070c0e
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
binarycpython/utils/distribution_functions.py
+9
-8
9 additions, 8 deletions
binarycpython/utils/distribution_functions.py
binarycpython/utils/functions.py
+90
-0
90 additions, 0 deletions
binarycpython/utils/functions.py
binarycpython/utils/grid.py
+155
-89
155 additions, 89 deletions
binarycpython/utils/grid.py
with
254 additions
and
97 deletions
binarycpython/utils/distribution_functions.py
+
9
−
8
View file @
83ca68e4
...
@@ -22,7 +22,7 @@ Tasks:
...
@@ -22,7 +22,7 @@ Tasks:
import
math
import
math
import
numpy
as
np
import
numpy
as
np
from
typing
import
Optional
,
Union
from
typing
import
Optional
,
Union
from
binarycpython.utils.useful_funcs
import
calc_period_from_sep
from
binarycpython.utils.useful_funcs
import
calc_period_from_sep
,
calc_sep_from_period
###
###
# File containing probability distributions
# File containing probability distributions
...
@@ -1425,12 +1425,6 @@ def Moe_de_Stefano_2017_pdf(options):
...
@@ -1425,12 +1425,6 @@ def Moe_de_Stefano_2017_pdf(options):
prob
=
[]
# Value that we will return
prob
=
[]
# Value that we will return
# Separation of the inner binary
options
[
'
sep
'
]
=
calc_sep_from_period
(
options
[
'
M1
'
],
options
[
'
M2
'
],
options
[
'
P
'
])
# Total mass inner binary:
options
[
'
M1+M2
'
]
=
options
[
'
M1
'
]
+
options
[
'
M2
'
]
multiplicity
=
options
[
'
multiplicity
'
]
multiplicity
=
options
[
'
multiplicity
'
]
if
not
options
.
get
(
'
multiplicity
'
,
None
):
if
not
options
.
get
(
'
multiplicity
'
,
None
):
multiplicity
=
1
multiplicity
=
1
...
@@ -1446,7 +1440,7 @@ def Moe_de_Stefano_2017_pdf(options):
...
@@ -1446,7 +1440,7 @@ def Moe_de_Stefano_2017_pdf(options):
############################################################
############################################################
# multiplicity fraction
# multiplicity fraction
prob
.
append
(
Moe_de_Stefano_2017_multiplicity_fractions
(
opts
)[
multiplicity
-
1
])
prob
.
append
(
Moe_de_Stefano_2017_multiplicity_fractions
(
opt
ion
s
)[
multiplicity
-
1
])
############################################################
############################################################
# always require an IMF for the primary star
# always require an IMF for the primary star
...
@@ -1458,6 +1452,13 @@ def Moe_de_Stefano_2017_pdf(options):
...
@@ -1458,6 +1452,13 @@ def Moe_de_Stefano_2017_pdf(options):
prob
.
append
(
Kroupa2001
(
options
[
'
M1
'
])
*
options
[
'
M1
'
])
prob
.
append
(
Kroupa2001
(
options
[
'
M1
'
])
*
options
[
'
M1
'
])
if
(
multiplicity
>=
2
):
if
(
multiplicity
>=
2
):
# Separation of the inner binary
options
[
'
sep
'
]
=
calc_sep_from_period
(
options
[
'
M1
'
],
options
[
'
M2
'
],
options
[
'
P
'
])
# Total mass inner binary:
options
[
'
M1+M2
'
]
=
options
[
'
M1
'
]
+
options
[
'
M2
'
]
# binary, triple or quadruple system
# binary, triple or quadruple system
if
not
Moecache
.
get
(
"
rinterpolator_log10P
"
,
None
):
if
not
Moecache
.
get
(
"
rinterpolator_log10P
"
,
None
):
Moecache
[
'
rinterpolator_log10P
'
]
=
py_rinterpolate
.
Rinterpolate
(
Moecache
[
'
rinterpolator_log10P
'
]
=
py_rinterpolate
.
Rinterpolate
(
...
...
This diff is collapsed.
Click to expand it.
binarycpython/utils/functions.py
+
90
−
0
View file @
83ca68e4
...
@@ -1257,6 +1257,96 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict:
...
@@ -1257,6 +1257,96 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict:
#
#
return
new_dict
return
new_dict
def
update_dicts
(
dict_1
:
dict
,
dict_2
:
dict
)
->
dict
:
"""
Function to update dict_1 with values of dict_2 in a recursive way.
Behaviour:
When dict keys are only present in one of either:
- we just add the content to the new dict
When dict keys are present in both, we decide based on the value types how to combine them:
- value of dict2 will be taken
Args:
dict_1: first dictionary
dict_2: second dictionary
Returns:
New dictionary with Updated values
"""
# Set up new dict
new_dict
=
{}
#
keys_1
=
dict_1
.
keys
()
keys_2
=
dict_2
.
keys
()
# Find overlapping keys of both dicts
overlapping_keys
=
set
(
keys_1
).
intersection
(
set
(
keys_2
))
# Find the keys that are unique
unique_to_dict_1
=
set
(
keys_1
).
difference
(
set
(
keys_2
))
unique_to_dict_2
=
set
(
keys_2
).
difference
(
set
(
keys_1
))
# Add the unique keys to the new dict
for
key
in
unique_to_dict_1
:
# If these items are ints or floats, then just put them in
if
isinstance
(
dict_1
[
key
],
(
float
,
int
)):
new_dict
[
key
]
=
dict_1
[
key
]
# Else, to be safe we should deepcopy them
else
:
copy_dict
=
copy
.
deepcopy
(
dict_1
[
key
])
new_dict
[
key
]
=
copy_dict
for
key
in
unique_to_dict_2
:
# If these items are ints or floats, then just put them in
if
isinstance
(
dict_2
[
key
],
(
float
,
int
)):
new_dict
[
key
]
=
dict_2
[
key
]
# Else, to be safe we should deepcopy them
else
:
copy_dict
=
copy
.
deepcopy
(
dict_2
[
key
])
new_dict
[
key
]
=
copy_dict
# Go over the common keys:
for
key
in
overlapping_keys
:
# See whether the types are actually the same
if
not
type
(
dict_1
[
key
])
is
type
(
dict_2
[
key
]):
# Exceptions:
if
(
type
(
dict_1
[
key
])
in
[
int
,
float
])
and
(
type
(
dict_2
[
key
])
in
[
int
,
float
]
):
new_dict
[
key
]
=
dict_2
[
key
]
else
:
print
(
"
Error key: {} value: {} type: {} and key: {} value: {} type: {} are not of the same type and cannot be merged
"
.
format
(
key
,
dict_1
[
key
],
type
(
dict_1
[
key
]),
key
,
dict_2
[
key
],
type
(
dict_2
[
key
]),
)
)
raise
ValueError
# Here we check for the cases that we want to explicitly catch. Ints will be added,
# floats will be added, lists will be appended (though that might change) and dicts will be
# dealt with by calling this function again.
else
:
# dicts
if
isinstance
(
dict_1
[
key
],
dict
)
and
isinstance
(
dict_2
[
key
],
dict
):
new_dict
[
key
]
=
update_dicts
(
dict_1
[
key
],
dict_2
[
key
])
else
:
new_dict
[
key
]
=
dict_2
[
key
]
#
return
new_dict
def
extract_ensemble_json_from_string
(
binary_c_output
:
str
)
->
dict
:
def
extract_ensemble_json_from_string
(
binary_c_output
:
str
)
->
dict
:
"""
"""
...
...
This diff is collapsed.
Click to expand it.
binarycpython/utils/grid.py
+
155
−
89
View file @
83ca68e4
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment