Skip to content

Commit

Permalink
rebase onto main and update with changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ntessore committed Dec 13, 2023
1 parent 339e669 commit 7f6d09f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
32 changes: 16 additions & 16 deletions heracles/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

# valid option keys
FIELD_TYPES = {
"positions": "heracles.maps:PositionMap",
"shears": "heracles.maps:ShearMap",
"visibility": "heracles.maps:VisibilityMap",
"weights": "heracles.maps:WeightMap",
"positions": "heracles.fields:Positions",
"shears": "heracles.fields:Shears",
"visibility": "heracles.fields:Visibility",
"weights": "heracles.fields:Weights",
}


Expand Down Expand Up @@ -152,8 +152,8 @@ def subsections(self, group: str) -> dict[str, str]:
return {s.rpartition(":")[-1].strip(): s for s in sections}


def map_from_config(config, section):
"""Construct a map instance from config."""
def field_from_config(config, section):
"""Construct a field instance from config."""

from pkgutil import resolve_name

Expand All @@ -176,11 +176,11 @@ def map_from_config(config, section):
return cls(nside, *columns)


def maps_from_config(config, group="fields"):
"""Construct all map instances from config."""
def fields_from_config(config, group="fields"):
"""Construct all field instances from config."""
sections = config.subsections(group)
return {
name: map_from_config(config, section) for name, section in sections.items()
name: field_from_config(config, section) for name, section in sections.items()
}


Expand Down Expand Up @@ -364,7 +364,7 @@ def map_all_selections(
) -> Iterator:
"""Iteratively map the catalogues defined in config."""

from .maps import map_catalogs
from .fields import map_catalogs

# turn groups into a deduplicated sequence
if groups is None:
Expand All @@ -374,13 +374,13 @@ def map_all_selections(
else:
groups = list(dict.fromkeys(groups))

# load catalogues and maps to process
# load catalogues and fields to process
catalogs = catalogs_from_config(config)
maps = {}
fields = {}
for group in groups:
maps |= maps_from_config(config, group)
fields |= fields_from_config(config, group)

logger.info("mapping %s", ", ".join(map(repr, maps)))
logger.info("fields %s", ", ".join(map(repr, fields)))

# process each catalogue separately into maps
for key, catalog in catalogs.items():
Expand All @@ -393,7 +393,7 @@ def map_all_selections(

# maps for single catalogue
yield map_catalogs(
maps,
fields,
{key: catalog},
parallel=True, # no effect but prettier log output
progress=True,
Expand Down Expand Up @@ -464,8 +464,8 @@ def alms(
"""

from .fields import transform_maps
from .io import AlmFits
from .maps import transform_maps

# load the config file, this contains alms setting and maps definition
logger.info("reading configuration from %s", files)
Expand Down
11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ optional-dependencies = {all = [
]}
readme = "README.md"
requires-python = ">=3.9"
urls.Documentation = "https://heracles.readthedocs.io/"
urls.Homepage = "https://github.com/heracles-ec/heracles"
urls.Issues = "https://github.com/heracles-ec/heracles/issues"

[project.scripts]
heracles = "heracles.cli:main"

[project.urls]
Documentation = "https://heracles.readthedocs.io/"
Homepage = "https://github.com/heracles-ec/heracles"
Issues = "https://github.com/heracles-ec/heracles/issues"

[tool.black]
force-exclude = """
Expand Down
18 changes: 9 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ def test_subsections():
assert config.subsections("getme") == {"a": "getme:a", "b": "getme: b "}


def test_map_from_config():
def test_field_from_config():
from unittest.mock import Mock

from heracles.cli import ConfigParser, map_from_config
from heracles.cli import ConfigParser, field_from_config

mock = Mock()

Expand Down Expand Up @@ -132,19 +132,19 @@ def test_map_from_config():
)

with patch.dict("heracles.cli.FIELD_TYPES", mock_field_types):
a = map_from_config(config, "a")
b = map_from_config(config, "b")
a = field_from_config(config, "a")
b = field_from_config(config, "b")
with pytest.raises(RuntimeError, match="Internal error"):
map_from_config(config, "c")
field_from_config(config, "c")

mock.assert_called_once_with(1, "COL1", "-COL2")
assert mock.return_value is a
assert isinstance(b, int) and b == 1


@patch("heracles.cli.map_from_config")
def test_maps_from_config(mock):
from heracles.cli import ConfigParser, maps_from_config
@patch("heracles.cli.field_from_config")
def test_fields_from_config(mock):
from heracles.cli import ConfigParser, fields_from_config

config = ConfigParser()
config.read_dict(
Expand All @@ -155,7 +155,7 @@ def test_maps_from_config(mock):
},
)

m = maps_from_config(config)
m = fields_from_config(config)

assert m == {
"a": mock.return_value,
Expand Down

0 comments on commit 7f6d09f

Please sign in to comment.