Skip to content

Commit 7ff0f88

Browse files
authored
Merge branch 'main' into downgrade-python
2 parents e6dc8c8 + 0229d52 commit 7ff0f88

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ called 'extra' that will be rendered in the UI. For example:
488488
}
489489
]
490490
```
491+
Such a list of sources can be loaded using `tilemaker open` by passing the JSON filename, e.g.
492+
```
493+
tilemaker open my_catalog.json my_map.fits
494+
```
491495

492496
### Highlight Boxes
493497

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ tilemaker = ["server/static/*", "server/static/assets/*"]
1010

1111
[project]
1212
name = "tilemaker"
13-
version = "2.3.3"
13+
version = "2.5.0"
1414
requires-python = ">=3.10"
1515
dependencies = [
1616
"pixell",

tilemaker/metadata/database.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Iterable
1010

1111
import structlog
12-
from sqlalchemy import create_engine
12+
from sqlalchemy import create_engine, event
1313
from sqlalchemy.orm import Session, sessionmaker
1414

1515
from .boxes import Box
@@ -49,6 +49,11 @@ def __init__(self, database_url: str):
4949
SQLAlchemy database URL (e.g., 'sqlite:///config.db', 'postgresql://user:password@localhost/dbname')
5050
"""
5151
self.engine = create_engine(database_url)
52+
53+
def _fk_pragma_on_connect(dbapi_con, con_record):
54+
dbapi_con.execute("pragma foreign_keys=ON")
55+
56+
event.listen(self.engine, "connect", _fk_pragma_on_connect)
5257
self.session_maker = sessionmaker(bind=self.engine)
5358
self.log = structlog.get_logger()
5459

tilemaker/metadata/generation.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
import structlog
1111
from astropy import units
1212
from astropy.io import fits
13-
from pydantic import BaseModel
13+
from pydantic import BaseModel, TypeAdapter
1414

1515
from tilemaker.metadata.core import DataConfiguration
1616
from tilemaker.metadata.definitions import Band, FITSLayerProvider, Layer, Map, MapGroup
17+
from tilemaker.metadata.sources import Source, SourceGroup
1718

1819
# Define the hits unit
1920
hits = units.def_unit("hits", units.dimensionless_unscaled)
@@ -25,14 +26,30 @@ def generate(
2526
) -> DataConfiguration:
2627
map_files = [x for x in filenames if "fits" in x.name]
2728
map_group = map_group_from_fits(map_files, force_auto_contrast=force_auto_contrast)
29+
source_files = [x for x in filenames if "json" in x.name]
30+
source_groups = [source_group_from_json(x) for x in source_files]
2831

29-
return DataConfiguration(map_groups=[map_group], boxes=[], source_groups=[])
32+
return DataConfiguration(
33+
map_groups=[map_group], boxes=[], source_groups=source_groups
34+
)
3035

3136

3237
def filename_to_id(filename: str | Path) -> str:
3338
return md5(str(filename).encode("utf-8")).hexdigest()[:6]
3439

3540

41+
def source_group_from_json(source_file: Path) -> SourceGroup:
42+
with open(source_file, "r") as handle:
43+
SourceListTypeAdapter = TypeAdapter(list[Source])
44+
return SourceGroup(
45+
source_group_id=filename_to_id(source_file),
46+
name=source_file.name,
47+
description="Source group read from file",
48+
sources=SourceListTypeAdapter.validate_json(handle.read()),
49+
grant=None,
50+
)
51+
52+
3653
def map_group_from_fits(
3754
filenames: list[Path],
3855
force_auto_contrast: bool = False,

0 commit comments

Comments
 (0)