Skip to content

Commit

Permalink
Fix #957
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdstein committed Aug 20, 2024
1 parent 5b6318d commit 761682d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
3 changes: 3 additions & 0 deletions mirar/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
ml_models_dir = base_output_dir.joinpath("ml_models")
ml_models_dir.mkdir(exist_ok=True)

config_dir = base_output_dir.joinpath("configs")
config_dir.mkdir(exist_ok=True)


def raw_img_dir(
sub_dir: str = "", raw_dir: Path = base_raw_dir, img_sub_dir: str = RAW_IMG_SUB_DIR
Expand Down
4 changes: 2 additions & 2 deletions mirar/processors/astromatic/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Module for configs of astrometry
"""

import os
from pathlib import Path

astromatic_config_dir = os.path.dirname(__file__)
astromatic_config_dir = Path(__file__).parent
3 changes: 3 additions & 0 deletions mirar/processors/astromatic/sextractor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Module for interfacing with SExtractor.
"""
40 changes: 28 additions & 12 deletions mirar/processors/astromatic/sextractor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,39 @@
Module with sextractor utilities
"""

import os
import shutil
from pathlib import Path

from mirar.paths import config_dir
from mirar.processors.astromatic.config import astromatic_config_dir

default_param_path = os.path.join(astromatic_config_dir, "temp.param")
default_conv_path = os.path.join(astromatic_config_dir, "sex.conv")
default_config_path = os.path.join(astromatic_config_dir, "sex.config")
default_starnnw_path = os.path.join(astromatic_config_dir, "default.nnw")
readonly_param_path = astromatic_config_dir / "temp.param"
default_param_path = config_dir / "default.param"
if not default_param_path.exists():
shutil.copy(readonly_param_path, default_param_path)

readonly_conv_path = astromatic_config_dir / "sex.conv"
default_conv_path = config_dir / "default.conv"
if not default_conv_path.exists():
shutil.copy(readonly_conv_path, default_conv_path)

readonly_config_path = astromatic_config_dir / "sex.conv"
default_config_path = config_dir / "default.config"
if not default_config_path.exists():
shutil.copy(readonly_config_path, default_config_path)

readonly_starnnw_path = astromatic_config_dir / "default.nnw"
default_starnnw_path = config_dir / "default.nnw"
if not default_starnnw_path.exists():
shutil.copy(readonly_starnnw_path, default_starnnw_path)


def parse_sextractor_config(config_file: str | Path):
"""
Parse a sextractor config file into a dictionary
param config_file: path to sextractor config file
"""
with open(config_file, "r") as f:
with open(config_file, "r", encoding="utf8") as f:
data = f.readlines()

keys, values = [], []
Expand Down Expand Up @@ -48,12 +64,12 @@ def write_sextractor_config_to_file(config_dict: dict, config_filename: str | Pa
param config_dict: dictionary of sextractor config parameters
param config_filename: path to write config file
"""
with open(config_filename, "w") as f:
with open(config_filename, "w", encoding="utf8") as f:
for key in config_dict:
f.write(f"{key.ljust(20, ' ')} {config_dict[key]} \n")


def write_param_file(param_path: str = default_param_path, params: list = None):
def write_param_file(param_path: str | Path = default_param_path, params: list = None):
"""
Write a default parameter file for sextractor
param param_path: path to write parameter file
Expand All @@ -76,7 +92,7 @@ def write_param_file(param_path: str = default_param_path, params: list = None):
param_f.write(f"{param}\n")


def write_conv_file(conv_path: str = default_conv_path):
def write_conv_file(conv_path: str | Path = default_conv_path):
"""
Write a default convolution file for sextractor
"""
Expand All @@ -91,9 +107,9 @@ def write_conv_file(conv_path: str = default_conv_path):


def write_config_file(
param_path: str = default_param_path,
conv_path: str = default_conv_path,
config_path: str = default_config_path,
param_path: str | Path = default_param_path,
conv_path: str | Path = default_conv_path,
config_path: str | Path = default_config_path,
saturation_key: str = "SATURATE",
):
"""
Expand Down

0 comments on commit 761682d

Please sign in to comment.