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

Refact component type #726

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

Conversation

luojing1211
Copy link
Member

@luojing1211 luojing1211 commented Jun 11, 2020

This Pull Request re-facts the way TimingModel stores its components and the APIs to gather the information from the same type of components. The user interface has changed as little as possible.
Motivation:
When developing Wideband TOAs, we are adding several components: DMJumps, DM noises. The current TimingModel is too big and not modulized enough.

Things are changed:

  • 'XXComponent_list' becomes a class called "ModelSector", where the components of a type are stored in ModeSector.component_list.
  • The current ModelSector has 3 subclasses 'DelaySector', 'PhaseSector', 'NoiseSector', The functions like 'delay()' and 'phase()' are moved to the corresponding ModelSector class.
  • In the TimingModel, the mode sectors are stored in the .model_sectors as a dictionary. The key is the component type name, 'XXComponent', and the value is the ModelSector class.
  • One can access the other model sector functions from TimingModel, Component, and one of the Modelsector class. All other APIs have kept the same.
  • ModelSectors are defined in a separate file.

Benefits:

  • More modulized design and keeps TimingModel class clean.
  • Easy to expend new type of component. The overall function for a new type of component can be defined in the ModelSector, instead of adding methods to the TimingModel class.
  • Remove the name 'XXComponent_list'

@luojing1211
Copy link
Member Author

Hi all, could you please take a look at this PR. I would like to move it forward for the wideband TOA development.

sector = DelaySector(self.all_components["AstrometryEquatorial"]())
copy_sector = deepcopy(sector)

assert id(sector) != id(copy_sector)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this testing? Whether copy.deepcopy works?

assert sector.__class__.__name__ == "DelaySector"
assert len(sector.component_list) == 1
assert hasattr(sector, "delay")
assert hasattr(sector, "delay_funcs")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really clear what the sector functions do but this seems like it's not testing very much - I'm not clear what aspects it is actually testing?

assert len(tm.DelayComponent_list) == 4
assert len(tm.PhaseComponent_list) == 2
assert len(tm.delay_components) == 4
assert len(tm.phase_components) == 2
Copy link
Contributor

Choose a reason for hiding this comment

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

This renaming seems like a definite improvement. But where are the tests of the new functionality coming from this change?

----------
param: str
Parameter name
target_component: str
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this accept a Component object as well as the name of a Component?

@@ -181,3 +181,7 @@ for comp, tp in Component.component_types.items():

special
```

```python
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this for?

""" Class for holding all delay components and their APIs
"""

_methods = (
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like some of these are methods and others are properties?

@@ -1391,3 +1392,38 @@ def FTest(chi2_1, dof_1, chi2_2, dof_2):
log.warning("Models have equal degrees of freedom, cannot preform F-test.")
ft = False
return ft


def get_component_type(component):
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this return the actual type object? Is it "type" in the python sense you mean here?

Object --> component --> TypeComponent. (i.e. DelayComponent)
This class type is in the third to the last of the getmro returned
result.

Copy link
Contributor

Choose a reason for hiding this comment

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

No need for blank lines at the end of a docstring.

@@ -50,7 +51,7 @@ def test_component_categories(model):

"""
for k, v in model.components.items():
assert model.get_component_type(v) != v.category
assert get_component_type(v) != v.category
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes it look like here "type" means the same thing as "category"?

)


class TestSector:
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems worth checking that the code correctly rejects sectors that share "methods", that all listed methods in existing sectors actually exist, and that the "external_sector_map" actually does what it's supposed to.

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