Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added milky way height and radius distributions #4920

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

vikasjadhav-why
Copy link

Added two distributions

  1. milky_way_height.py
  2. milky_way_radial.py

that samples the radius and height in galactocentric co-ordinates for the milky way 3 disc exponential model

Copy link
Member

@ahnitz ahnitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to follow PEP8 style. You can run your code through the 'black' program (available through pypi) to help autoformat.

@@ -39,6 +39,10 @@
from pycbc.distributions.fixedsamples import FixedSamples
from pycbc.distributions.mass import MchirpfromUniformMass1Mass2, \
QfromUniformMass1Mass2
from pycbc.distributions.milky_way_radial import MilkyWayRadial
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be more generic than milkyway, name this after the distribution itself

the config file should be
[prior-z]
name = milky_way_height
min-z =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples should work so give number

## _scale keys removed from the params.
## Now pass to bounded.dist
super(MilkyWayHeight, self).__init__(**params)
## raising error if scale provided for param not in kwargs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove old code, but do have comments that explain what you are doing

z_weight3 =

'''
def __init__(self, **params):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's super unclear what the argument / keywords you are using

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be explicit wherever possible, and use names that are straightforward

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not even clear what the purpose of scale 1 / scale 2 / scale 3 is?

self._bounds = {}
self._scale1 = {}
self._scale2 = {}
self._scale3 = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you limitted to exactly three disks? You have a lot of extra redundant code to handle essentially the same exact operations.

self._norm[p] = 1.
self._lognorm[p] = -numpy.inf

@property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't include anything that's not required


def _logpdf(self, **kwargs):
if kwargs in self:
return sum([numpy.log((self._weight1[p]/(2*self._scale1[p]*(1 - numpy.e**(self._bounds[p][0]/self._scale1[p]))))*numpy.e**(-numpy.abs(kwargs[p])/self._scale1[p])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also code duplication here

_cdf = numpy.zeros(len(param_array))
_cdf[mask] = (beta1)*(numpy.e**(param_array[mask]/z_d1) - numpy.e**(z_min/z_d1)) + (beta2)*(numpy.e**(param_array[mask]/z_d2) - numpy.e**(z_min/z_d2)) + (beta3)*(numpy.e**(param_array[mask]/z_d3) - numpy.e**(z_min/z_d3))
_cdf[~mask] = (beta1)*(2 - (numpy.e**(z_min/z_d1) + numpy.e**(-param_array[~mask]/z_d1))) + (beta2)*(2 - (numpy.e**(z_min/z_d2) + numpy.e**(-param_array[~mask]/z_d2))) + (beta3)*(2 - (numpy.e**(z_min/z_d3) + numpy.e**(-param_array[~mask]/z_d3)))
_cdfinv = scipy.interpolate.interp1d(_cdf, param_array)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not directly solve for the inverse in this case? Why are interpolating?

r_min, r_max = bounds
#if r_min < 0:
#raise ValueError(f'Minimum value of {p} must be greater than or equal to zero ')
r = numpy.linspace(r_min, r_max, 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hardcoded, How do you we know you have enough samples here?

Copy link
Member

@ahnitz ahnitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vikasjadhav-why Make sure to follow PEP 8 style guides

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants