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

Unique components #410

Merged
merged 8 commits into from
Sep 21, 2017
Merged

Unique components #410

merged 8 commits into from
Sep 21, 2017

Conversation

profxj
Copy link
Contributor

@profxj profxj commented Sep 18, 2017

There are two threads to this PR:

  • Refactor from LineLimits to zLimits
  • Add a unique_components() method

The first allows for limits without reference to wrest.
That becomes optional, so previous functionality is maintained.

The second is a method useful for querying lists of components.

I also removed GaussianAbsorption1D as that is deprecated in astropy.

Includes a new test, but no new docs.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 71.756% when pulling d1efe3d on unique_components into 21556df on master.

Copy link
Collaborator

@jnburchett jnburchett left a comment

Choose a reason for hiding this comment

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

Few minor suggestions.

@@ -23,7 +24,8 @@ class LineLimits(object):
zlim : tuple of floats
Redshift limits for a line
Defined as wave/wrest - 1.
wvlim : Quantity array
or
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not really need 'or' line, do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I even removed the line above as wrest is not required

@@ -41,7 +43,7 @@ def from_specline(cls, aline, z, zlim):
if not isinstance(aline, (AbsLine, EmLine)):
raise IOError("Input aline must be AbsLine or EmLine")
#
slf = cls(aline.wrest, z, zlim)
slf = cls(z, zlim, wrest=aline.wrest)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to add z and zlim to parameters list in the docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

z : float
Redshift of the line.
zlim : tuple or list
Redshift limits for a line
Defined as wave/wrest - 1.
Ok to have zlim[1]==zlim[0], but then self.is_set() == False
wrest : Quantity, optional
Rest wavelength. Used for SpectralLine objects
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't have to be used by SpectralLine objects, right? I'm able to instantiate just by declaring wrest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

edited

@@ -142,7 +149,7 @@ def is_set(self):
return False

def set(self, inp, chk_z=False):#, itype='zlim'):
""" Over-ride = to re-init values
""" Set (or reset) limits relative to self._z
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add a note that this does not change the reference redshift. Perhaps change to: "Set (or reset) limits relative to self._z but does not change self._z"

I was unclear as to what this did before I tried it.

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed with the suggestion above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

edited

self.vlim = vlim
# Limits
zlim = ltu.z_from_dv(vlim, zcomp)
self.limits = zLimits(zcomp, zlim.tolist())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there needs to be a way to set the reference redshift, e.g., mycomp.limits.setz(0.4)

One could imagine plenty of scenarios where one may wish to instantiate an AbsLine or AbsComponent with some lines then change the redshift on later. I realize this can be done by setting limits._z, but that's a bit under the hood and may not occur to a user who did not review the PR ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea, should probably be a method of zLimit class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand the desire, but how does one modify the limits
in that case? Leave them as is?

I think I'd argue that the user should in that case instantiate
a new zLimits object.

# Set vlim by min/max [Using non-relativistic + buffer]
vmin = u.Quantity([(comp.zcomp-zcomp)/(1+zcomp)*const.c.to('km/s')+comp.vlim[0] for comp in components])
vmax = u.Quantity([(comp.zcomp-zcomp)/(1+zcomp)*const.c.to('km/s')+comp.vlim[1] for comp in components])
synth_comp.vlim = u.Quantity([np.min(vmin)-vbuff, np.max(vmax)+vbuff])
vlim = u.Quantity([np.min(vmin)-vbuff, np.max(vmax)+vbuff])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like the default value of vbuff is 0 km/s but the docstring indicates 10 km/s?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Must have used to have been 10 km/s. I guess
I figured that was a problem..

Have edited the doc string accordingly and kept it at 0 km/s.

def unique_components(comps1, comps2, tol=5*u.arcsec):
""" Identify which members of comps1 are *not* within
comps2, to given tolerances. Note, that repeats in
comps1 are not looked for.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps clarify 2nd sentence? "Note: nonunique members of comps1 are not identified."

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not understand this either. How can a component be within another component? This is based on velocity limits or was supposed to identify two components that may be considered the same physical entity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have tried to clarify.

Copy link
Contributor

Choose a reason for hiding this comment

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

This remains unclear to me. I beleive you try to identify component duplications (?), but in this case why to allow for a tolerance? If you allow a tolerance (specially in velocity limits), then what would happen for multiple contiguous and overlapping components? Will there be considered the same? If so, why is this useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I forgot to push utils.py

Look at the new docstring please

Copy link
Contributor

@ntejos ntejos left a comment

Choose a reason for hiding this comment

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

Left some comments. I think is a good idea to add a method in zLimits to reset z. Probably with some restrictions like:

  1. New z must be within zlims of the previous one
  2. wvlims must be preserved (?)

Another option is to add a resetz method to AbsComponent, redefining the zLimits from scracth.

@@ -23,7 +24,8 @@ class LineLimits(object):
zlim : tuple of floats
Redshift limits for a line
Defined as wave/wrest - 1.
wvlim : Quantity array
or
wvlim : Quantity array, only if _wrest is set
wavelength limits for the line in observer frame
Copy link
Contributor

Choose a reason for hiding this comment

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

this docstring only if _wrest is set is confusing. Maybe say that this is an optional parameter that applies for zLimits to individual AbsLines (for which a single wrest makes sense)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

improved

@@ -23,7 +24,8 @@ class LineLimits(object):
zlim : tuple of floats
Copy link
Contributor

Choose a reason for hiding this comment

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

add z to docstring

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"""
Parameters
----------
wrest : Quantity
Rest wavelength of the line.
z : float
Redshift of the line.
Copy link
Contributor

Choose a reason for hiding this comment

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

redshift of the line -> redshift to apply the zlimits to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

edited. ps. your version looks a bit out of date

z : float
Redshift of the line.
zlim : tuple or list
Redshift limits for a line
Defined as wave/wrest - 1.
Ok to have zlim[1]==zlim[0], but then self.is_set() == False
wrest : Quantity, optional
Rest wavelength. Used for SpectralLine objects
Copy link
Contributor

Choose a reason for hiding this comment

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

Used for SpectralLine objects -> Used for applying zLimits to individual SpectralLine objects

Copy link
Contributor Author

Choose a reason for hiding this comment

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

edited

@@ -142,7 +149,7 @@ def is_set(self):
return False

def set(self, inp, chk_z=False):#, itype='zlim'):
""" Over-ride = to re-init values
""" Set (or reset) limits relative to self._z
Copy link
Contributor

Choose a reason for hiding this comment

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

agreed with the suggestion above.

self.vlim = vlim
# Limits
zlim = ltu.z_from_dv(vlim, zcomp)
self.limits = zLimits(zcomp, zlim.tolist())
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea, should probably be a method of zLimit class.

def unique_components(comps1, comps2, tol=5*u.arcsec):
""" Identify which members of comps1 are *not* within
comps2, to given tolerances. Note, that repeats in
comps1 are not looked for.
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not understand this either. How can a component be within another component? This is based on velocity limits or was supposed to identify two components that may be considered the same physical entity?

@profxj
Copy link
Contributor Author

profxj commented Sep 21, 2017

Ok, the outstanding issue is how to modify the redshift if at all.

I am preferring that the user re-instantiate, i.e. self._z is fixed.
But you can convince me otherwise.

Another option would be a method that takes in a new redshift and
shifts the limits accordingly. It would also reinstantiate, e.g.

self.limits = self.limits.shift_z(z)

Thoughts?

@ntejos
Copy link
Contributor

ntejos commented Sep 21, 2017

Now that I re-think about it, zLimits is a utility class to be used within the framework of SpectralLines, AbsComponents, etc. It is not meant for stand-alone use (let me know if you envision where this would be useful). In that context, it may be preferable (cleaner) that for changing the redshift, one has to create a new object from scratch. The advantage for the alternative is speed, but it is not obvious what to do with the limits when self._z changes. Thus, cleaner may be better than faster in this context.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 71.756% when pulling baade8c on unique_components into 21556df on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 71.756% when pulling 03a1cba on unique_components into 21556df on master.

@jnburchett
Copy link
Collaborator

jnburchett commented Sep 21, 2017 via email

comps1 are not looked for.
""" Identify which AbsComponent members of the comps1 list
are *not* within the comps2 list, to given tolerances.
Note, AbsComponent objects in the comps1 list are examined
Copy link
Collaborator

Choose a reason for hiding this comment

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

AbsComponent objects in the comps1 list are not examined against each other right? I though that's what the previous docstring was saying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops.. edited

@profxj
Copy link
Contributor Author

profxj commented Sep 21, 2017

Ok, give this a thumbs up (if you agree).

@ntejos
Copy link
Contributor

ntejos commented Sep 21, 2017

I still do not understand the idea behind unique_components(), but I guess is fine.

@profxj
Copy link
Contributor Author

profxj commented Sep 21, 2017

Merging.

@ntejos -- You'll see this new method in use shortly. (z1IGM)

Note, I suspect igmguesses will break again. But I'll help fix it.

@profxj profxj merged commit 681e086 into master Sep 21, 2017
@profxj profxj deleted the unique_components branch September 21, 2017 19:39
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 71.756% when pulling fd2005b on unique_components into 21556df on master.

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.

None yet

4 participants