starbash 0.1.11__py3-none-any.whl → 0.1.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. repo/__init__.py +1 -1
  2. repo/manager.py +14 -23
  3. repo/repo.py +52 -10
  4. starbash/__init__.py +10 -3
  5. starbash/aliases.py +49 -4
  6. starbash/analytics.py +3 -2
  7. starbash/app.py +287 -565
  8. starbash/check_version.py +18 -0
  9. starbash/commands/__init__.py +2 -1
  10. starbash/commands/info.py +26 -21
  11. starbash/commands/process.py +76 -24
  12. starbash/commands/repo.py +25 -68
  13. starbash/commands/select.py +140 -148
  14. starbash/commands/user.py +88 -23
  15. starbash/database.py +41 -27
  16. starbash/defaults/starbash.toml +1 -0
  17. starbash/exception.py +21 -0
  18. starbash/main.py +29 -7
  19. starbash/paths.py +23 -9
  20. starbash/processing.py +724 -0
  21. starbash/recipes/README.md +3 -0
  22. starbash/recipes/master_bias/starbash.toml +4 -1
  23. starbash/recipes/master_dark/starbash.toml +0 -1
  24. starbash/recipes/osc.py +190 -0
  25. starbash/recipes/osc_dual_duo/starbash.toml +31 -34
  26. starbash/recipes/osc_simple/starbash.toml +82 -0
  27. starbash/recipes/osc_single_duo/starbash.toml +51 -32
  28. starbash/recipes/seestar/starbash.toml +82 -0
  29. starbash/recipes/starbash.toml +8 -9
  30. starbash/selection.py +29 -38
  31. starbash/templates/repo/master.toml +7 -3
  32. starbash/templates/repo/processed.toml +7 -2
  33. starbash/templates/userconfig.toml +9 -0
  34. starbash/toml.py +13 -13
  35. starbash/tool.py +186 -149
  36. starbash-0.1.15.dist-info/METADATA +216 -0
  37. starbash-0.1.15.dist-info/RECORD +45 -0
  38. starbash/recipes/osc_dual_duo/starbash.py +0 -147
  39. starbash-0.1.11.dist-info/METADATA +0 -147
  40. starbash-0.1.11.dist-info/RECORD +0 -40
  41. {starbash-0.1.11.dist-info → starbash-0.1.15.dist-info}/WHEEL +0 -0
  42. {starbash-0.1.11.dist-info → starbash-0.1.15.dist-info}/entry_points.txt +0 -0
  43. {starbash-0.1.11.dist-info → starbash-0.1.15.dist-info}/licenses/LICENSE +0 -0
starbash/selection.py CHANGED
@@ -3,13 +3,19 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import logging
6
- from typing import Any, Optional, TYPE_CHECKING
6
+ from typing import TYPE_CHECKING, Any
7
+
8
+ if TYPE_CHECKING:
9
+ from starbash.database import SearchCondition
10
+
7
11
  from repo import Repo
8
12
  from starbash.aliases import normalize_target_name
9
13
 
10
14
 
11
- def where_tuple(conditions: dict[str, Any] | None) -> tuple[str, list[Any]]:
12
- """Search for sessions matching the given conditions.
15
+ def build_search_conditions(
16
+ conditions: dict[str, Any] | None,
17
+ ) -> list[SearchCondition]:
18
+ """Build a list of SearchCondition objects from a conditions dictionary.
13
19
 
14
20
  Args:
15
21
  conditions: Dictionary of session key-value pairs to match, or None for all.
@@ -18,42 +24,33 @@ def where_tuple(conditions: dict[str, Any] | None) -> tuple[str, list[Any]]:
18
24
  - 'date_end': Filter sessions starting on or before this date
19
25
 
20
26
  Returns:
21
- Tuple of (WHERE clause string, list of parameters)
27
+ List of SearchCondition tuples for database queries
22
28
  """
29
+ # Import here to avoid circular dependency
30
+ from starbash.database import SearchCondition
31
+
23
32
  if conditions is None:
24
33
  conditions = {}
25
34
 
26
- # Build WHERE clause dynamically based on conditions
27
- where_clauses = []
28
- params = []
35
+ search_conditions = []
29
36
 
30
37
  # Extract date range conditions
31
38
  date_start = conditions.get("date_start")
32
39
  date_end = conditions.get("date_end")
33
40
 
34
- # Add date range filters to WHERE clause
41
+ # Add date range filters as SearchConditions
35
42
  if date_start:
36
- where_clauses.append("start >= ?")
37
- params.append(date_start)
43
+ search_conditions.append(SearchCondition("start", ">=", date_start))
38
44
 
39
45
  if date_end:
40
- where_clauses.append("start <= ?")
41
- params.append(date_end)
46
+ search_conditions.append(SearchCondition("start", "<=", date_end))
42
47
 
43
- # Add standard conditions to WHERE clause
48
+ # Add standard conditions as SearchConditions
44
49
  for key, value in conditions.items():
45
50
  if key not in ("date_start", "date_end") and value is not None:
46
- column_name = key
47
- where_clauses.append(f"{column_name} = ?")
48
- params.append(value)
51
+ search_conditions.append(SearchCondition(key, "=", value))
49
52
 
50
- # Build the query
51
- query = ""
52
-
53
- if where_clauses:
54
- query += " WHERE " + " AND ".join(where_clauses)
55
-
56
- return (query, params)
53
+ return search_conditions
57
54
 
58
55
 
59
56
  class Selection:
@@ -70,7 +67,7 @@ class Selection:
70
67
  used to build database queries.
71
68
  """
72
69
 
73
- def __init__(self, user_repo: "Repo"):
70
+ def __init__(self, user_repo: Repo):
74
71
  """Initialize the Selection with the user config repository.
75
72
 
76
73
  Args:
@@ -78,8 +75,8 @@ class Selection:
78
75
  """
79
76
  self.user_repo = user_repo
80
77
  self.targets: list[str] = []
81
- self.date_start: Optional[str] = None
82
- self.date_end: Optional[str] = None
78
+ self.date_start: str | None = None
79
+ self.date_end: str | None = None
83
80
  self.filters: list[str] = []
84
81
  self.image_types: list[str] = []
85
82
  self.telescopes: list[str] = []
@@ -194,9 +191,7 @@ class Selection:
194
191
  self.telescopes.remove(telescope)
195
192
  self._save()
196
193
 
197
- def set_date_range(
198
- self, start: Optional[str] = None, end: Optional[str] = None
199
- ) -> None:
194
+ def set_date_range(self, start: str | None = None, end: str | None = None) -> None:
200
195
  """Set the date range for the selection.
201
196
 
202
197
  Args:
@@ -242,11 +237,11 @@ class Selection:
242
237
  and not self.telescopes
243
238
  )
244
239
 
245
- def get_query_conditions(self) -> tuple[str, list[Any]]:
240
+ def get_query_conditions(self) -> list[SearchCondition]:
246
241
  """Build query conditions based on the current selection.
247
242
 
248
243
  Returns:
249
- A tuple of SQL (WHERE clause string, list of parameters)
244
+ A list of SearchCondition objects for database queries
250
245
  """
251
246
  conditions = {}
252
247
 
@@ -258,9 +253,7 @@ class Selection:
258
253
  # For now, just use the first target
259
254
  # TODO: Support multiple targets in queries
260
255
  conditions["OBJECT"] = (
261
- normalize_target_name(self.targets[0])
262
- if len(self.targets) == 1
263
- else None
256
+ normalize_target_name(self.targets[0]) if len(self.targets) == 1 else None
264
257
  )
265
258
 
266
259
  if self.filters:
@@ -271,9 +264,7 @@ class Selection:
271
264
  if self.telescopes:
272
265
  # For now, just use the first telescope
273
266
  # TODO: Support multiple telescopes in queries
274
- conditions["TELESCOP"] = (
275
- self.telescopes[0] if len(self.telescopes) == 1 else None
276
- )
267
+ conditions["TELESCOP"] = self.telescopes[0] if len(self.telescopes) == 1 else None
277
268
 
278
269
  # Add date range conditions
279
270
  if self.date_start:
@@ -281,7 +272,7 @@ class Selection:
281
272
  if self.date_end:
282
273
  conditions["date_end"] = self.date_end
283
274
 
284
- return where_tuple(conditions)
275
+ return build_search_conditions(conditions)
285
276
 
286
277
  def summary(self) -> dict[str, Any]:
287
278
  """Get a summary of the current selection state.
@@ -1,13 +1,17 @@
1
- # This is a master repository for (Starbash)[{PROJECT_URL}].
1
+ # This is a master repository for (Starbash)[$PROJECT_URL].
2
2
  #
3
3
  # This file marks the root directory of a set of auto matinained astrophotography
4
4
  # 'master' files, such as master darks, flats or biases.
5
5
  #
6
6
  # You generally don't need to edit this file directly - it was auto generated when you ran
7
- # "sb repo add --master {REPO_PATH}".
7
+ # "sb repo add --$REPO_TYPE $REPO_PATH".
8
8
  #
9
9
 
10
10
  [repo]
11
11
  kind = "master"
12
12
 
13
- relative = "{DEFAULT_RELATIVE}"
13
+ # Given a particular 'kind' of master, we can use different relative paths
14
+ relative.flat = "{instrument}/{date}/{imagetyp}/master_{session_config}.fit"
15
+
16
+ # For any other kind we use the default path (i.e. bias, dark, etc)
17
+ relative.default = "{camera_id}/{date}/{imagetyp}/master_{session_config}.fit"
@@ -1,10 +1,15 @@
1
- # This is a processed repository for (Starbash)[{PROJECT_URL}].
1
+ # This is a processed repository for (Starbash)[$PROJECT_URL].
2
2
  #
3
3
  # This file marks the root directory of a set of generated/processed starbash output files.
4
4
  #
5
5
  # You generally don't need to edit this file directly - it was auto generated when you ran
6
- # "sb repo add --processed {REPO_PATH}".
6
+ # "sb repo add --$REPO_TYPE $REPO_PATH".
7
7
  #
8
8
 
9
9
  [repo]
10
10
  kind = "processed"
11
+
12
+ # This path should at least point to a FITS file - so that 'is output file generated' test can work.
13
+ # if this expression includes a * at the end we assume multiple files might be generated and they are all
14
+ # placed in the indicated directory.
15
+ relative.default = "{target}/*"
@@ -6,6 +6,15 @@
6
6
  [repo]
7
7
  kind = "preferences"
8
8
 
9
+ #[aliases]
10
+ # aliases can be used to map non standard (or non english) frame names to standard terms
11
+ # This is also used to map filters based on common misspellings or variations.
12
+ # We assume the first listed option in the list is the 'canonical' name used for printing etc...
13
+
14
+ # frame types
15
+ # dark = ["dark", "darks"]
16
+ # etc...
17
+
9
18
  [analytics]
10
19
  # enabled = true # default is true - change to false if you don't want any analytics/crash-reports
11
20
  # include_user = false # default is false - change to true if you'd like your email added to crash reports/analytics
starbash/toml.py CHANGED
@@ -1,28 +1,28 @@
1
- import tomlkit
2
- from tomlkit.toml_file import TOMLFile
3
- from pathlib import Path
4
1
  from importlib import resources
2
+ from pathlib import Path
3
+ from string import Template
5
4
  from typing import Any
6
5
 
6
+ import tomlkit
7
+ from tomlkit.toml_file import TOMLFile
8
+
7
9
  from starbash import url
8
10
 
9
- def toml_from_template(template_name: str, dest_path: Path, overrides: dict[str, Any] = {}) -> tomlkit.TOMLDocument:
11
+
12
+ def toml_from_template(
13
+ template_name: str, dest_path: Path, overrides: dict[str, Any] = {}
14
+ ) -> tomlkit.TOMLDocument:
10
15
  """Load a TOML document from a template file.
11
16
  expand {vars} in the template using the `overrides` dictionary.
12
17
  """
13
18
 
14
- tomlstr = (
15
- resources.files("starbash")
16
- .joinpath(f"templates/{template_name}.toml")
17
- .read_text()
18
- )
19
+ tomlstr = resources.files("starbash").joinpath(f"templates/{template_name}.toml").read_text()
19
20
 
20
21
  # add default vars always available
21
- vars = {
22
- "PROJECT_URL": url.project
23
- }
22
+ vars = {"PROJECT_URL": url.project}
24
23
  vars.update(overrides)
25
- tomlstr = tomlstr.format(**vars)
24
+ t = Template(tomlstr)
25
+ tomlstr = t.substitute(vars)
26
26
 
27
27
  toml = tomlkit.parse(tomlstr)
28
28
  TOMLFile(dest_path).write(toml)