Loading noche/__init__.py +1 −0 Original line number Diff line number Diff line from .noche import Noche noche/noche_daemon.py→noche/daemon.py +17 −15 Original line number Diff line number Diff line Loading @@ -194,12 +194,14 @@ def start_daemon(daemon_settings): log.info("Noche daemon stopped.") if __name__ == "__main__": def run(): try: daemon_settings = load_daemon_config(sys.argv[1]) except SystemExit: sys.exit(1) start_daemon(daemon_settings) if __name__ == "__main__": run() noche/noche.py +63 −67 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ class Noche: self._update() def fill_keyword(self, k, val): def fill_keyword(self, k, val, silent=False): """ Fill new header keyword with its value. Why use this function instea of simply self.header[keyword] = value? Loading @@ -146,13 +146,14 @@ class Noche: val = self._parse(val) # log.debug(f"{val}, {typ}, {fmt}") if typ.strip() == "float": with custom_float(): val = header_round(val, int(fmt)) self.header[k] = val log.info(f"{k:<11}: filled with {val} as {typ:<5}, {fmt:<1} digits") if not silent: log.info(f"{k:<11} : filled with value : {val} as {typ:<5}, {fmt:<1} digits") def load_noctis_observatory(self, name='oarpaf', fits_file=None): Loading Loading @@ -214,8 +215,8 @@ class Noche: log.warning(f"{k:<8} : fixed value missing! Leave blank") pass else: log.info(f"{k:<11} : set to fixed value, value: {val:<28}") self.fill_keyword(k, val) log.info(f"{k:<11} : fixed to the value : {val:<28}") self.fill_keyword(k, val, silent=True) if fits_file: self.fill_from_fits_file(path, fits_file) Loading Loading @@ -262,8 +263,8 @@ class Noche: try: val = fits_file_header[fits_keyword] self.fill_keyword(k, val) log.info(f"{k:<11} : mapped to {fits_keyword:<11}, value: {val:<28}") self.fill_keyword(k, val, silent=True) log.info(f"{k:<11} : mapped to {fits_keyword:<11} : {val:<28}") except TypeError as e: log.debug(e) log.warning(f"{k:<8} : mapped to {fits_keyword:<11}, but empty! Leave empty.") Loading @@ -279,8 +280,8 @@ class Noche: x = self.header[k] # i.e. value of RA: x=12.345 new_val = eval(pre_formulas[k]) try: self.fill_keyword(k, new_val) log.warning(f"{k:<11}: pre-formula from {x:<28} to {self.header[k]:<28}") self.fill_keyword(k, new_val, silent=True) log.warning(f"{k:<8} : pre-formula from value : {x:<11} to {self.header[k]:<11}") except Exception as e: log.error(f"Failed to evaluate pre-formula for {k}: {e}") Loading @@ -294,8 +295,8 @@ class Noche: x = self.header[k] new_val = eval(formula) try: self.fill_keyword(k, new_val) log.warning(f"{k:<8}: tweak from {x:<28} to {self.header[k]:<28}") self.fill_keyword(k, new_val, silent=True) log.warning(f"{k:<8} : tweak from value : {x:11} to {self.header[k]:<11}") except Exception as e: log.error(f"Failed to evaluate tweak for {k}: {e}") else: Loading Loading @@ -413,7 +414,6 @@ class Noche: time = Time(obstime) self.set_obstime(time) with custom_float(): self.fill_keyword("RA", coord.ra.to_string(unit=u.hourangle, sep=':', pad=True, precision=1) ) Loading Loading @@ -444,7 +444,6 @@ class Noche: altaz = self._coord.altaz # Altitudine and Azimuth with custom_float(): self.fill_keyword("ALT", altaz.alt.deg) self.fill_keyword("AZ", altaz.az.deg) Loading Loading @@ -497,7 +496,6 @@ class Noche: _, xsize = map(int, x_str.split(":")) _, ysize = map(int, y_str.split(":")) with custom_float(): crpix = [xsize/self.header["XBINNING"]/2, ysize/self.header["YBINNING"]/2] cdelt1 = self.header["PIXSCALE"]*self.header["XBINNING"]*u.arcsec.to(u.deg) cdelt2 = self.header["PIXSCALE"]*self.header["YBINNING"]*u.arcsec.to(u.deg) Loading @@ -515,7 +513,6 @@ class Noche: flip = -1 # East to the left with custom_float(): self.fill_keyword("CRPIX1", crpix[0]) self.fill_keyword("CRPIX2", crpix[1]) self.fill_keyword("CRVAL1", crval_ra) Loading Loading @@ -552,9 +549,6 @@ class Noche: moon = get_body("moon", time) moon.location = loc with custom_float(): # MOONDIST: angular distance between target and Moon moondist = moon.separation(self._coord, origin_mismatch="ignore").deg self.fill_keyword("MOONDIST", moondist) Loading @@ -579,6 +573,7 @@ class Noche: if self.header[k] == None: log.warning(f"{k:<8}: still empty ({self.header[k]})") def load_fits(self, fits_file): log.debug(sys._getframe().f_code.co_name) Loading @@ -593,6 +588,7 @@ class Noche: noche_hdu.writeto(filename, overwrite=overwrite, checksum=True) @staticmethod def _load_config(path): log.debug(sys._getframe().f_code.co_name) Loading pyproject.toml +49 −0 Original line number Diff line number Diff line [build-system] requires = ["setuptools>=42", "wheel", "watchdog"] build-backend = "setuptools.build_meta" [project] name = "noche" version = "0.1.0" authors = [ { name="Davide Ricci", email="davide.ricci@inaf.it" }, ] description = "NOCTIS common header." readme = "README.md" requires-python = ">=3.12" #license = { file="LICENSE" } # If you have a LICENSE file classifiers = [ "Programming Language :: Python :: 3", # "License :: OSI Approved :: MIT License", # Choose your license "Operating System :: OS Independent", "Topic :: Scientific/Engineering :: Astronomy", "Intended Audience :: Developers", "Development Status :: 3 - Alpha", # Or appropriate status ] dependencies = [ "astropy", "numpy", ] [project.urls] "Homepage" = "https://www.ict.inaf.it/gitlab/noctis/noche" # "Bug Tracker" = "..." [project.scripts] noche-daemon = "noche.daemon:run" [tool.setuptools.packages.find] where = ["."] # list of folders that contain the packages (["."] by default) include = ["noche"] # package names should match these glob patterns (["*"] by default) exclude = [] # exclude packages matching these glob patterns (empty by default) namespaces = false # to disable scanning PEP 420 namespaces (true by default) [tool.setuptools.package-data] noche = [ "headers/*.ini", "observatories/*.ini", "daemon_config.ini" ] Loading
noche/noche_daemon.py→noche/daemon.py +17 −15 Original line number Diff line number Diff line Loading @@ -194,12 +194,14 @@ def start_daemon(daemon_settings): log.info("Noche daemon stopped.") if __name__ == "__main__": def run(): try: daemon_settings = load_daemon_config(sys.argv[1]) except SystemExit: sys.exit(1) start_daemon(daemon_settings) if __name__ == "__main__": run()
noche/noche.py +63 −67 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ class Noche: self._update() def fill_keyword(self, k, val): def fill_keyword(self, k, val, silent=False): """ Fill new header keyword with its value. Why use this function instea of simply self.header[keyword] = value? Loading @@ -146,13 +146,14 @@ class Noche: val = self._parse(val) # log.debug(f"{val}, {typ}, {fmt}") if typ.strip() == "float": with custom_float(): val = header_round(val, int(fmt)) self.header[k] = val log.info(f"{k:<11}: filled with {val} as {typ:<5}, {fmt:<1} digits") if not silent: log.info(f"{k:<11} : filled with value : {val} as {typ:<5}, {fmt:<1} digits") def load_noctis_observatory(self, name='oarpaf', fits_file=None): Loading Loading @@ -214,8 +215,8 @@ class Noche: log.warning(f"{k:<8} : fixed value missing! Leave blank") pass else: log.info(f"{k:<11} : set to fixed value, value: {val:<28}") self.fill_keyword(k, val) log.info(f"{k:<11} : fixed to the value : {val:<28}") self.fill_keyword(k, val, silent=True) if fits_file: self.fill_from_fits_file(path, fits_file) Loading Loading @@ -262,8 +263,8 @@ class Noche: try: val = fits_file_header[fits_keyword] self.fill_keyword(k, val) log.info(f"{k:<11} : mapped to {fits_keyword:<11}, value: {val:<28}") self.fill_keyword(k, val, silent=True) log.info(f"{k:<11} : mapped to {fits_keyword:<11} : {val:<28}") except TypeError as e: log.debug(e) log.warning(f"{k:<8} : mapped to {fits_keyword:<11}, but empty! Leave empty.") Loading @@ -279,8 +280,8 @@ class Noche: x = self.header[k] # i.e. value of RA: x=12.345 new_val = eval(pre_formulas[k]) try: self.fill_keyword(k, new_val) log.warning(f"{k:<11}: pre-formula from {x:<28} to {self.header[k]:<28}") self.fill_keyword(k, new_val, silent=True) log.warning(f"{k:<8} : pre-formula from value : {x:<11} to {self.header[k]:<11}") except Exception as e: log.error(f"Failed to evaluate pre-formula for {k}: {e}") Loading @@ -294,8 +295,8 @@ class Noche: x = self.header[k] new_val = eval(formula) try: self.fill_keyword(k, new_val) log.warning(f"{k:<8}: tweak from {x:<28} to {self.header[k]:<28}") self.fill_keyword(k, new_val, silent=True) log.warning(f"{k:<8} : tweak from value : {x:11} to {self.header[k]:<11}") except Exception as e: log.error(f"Failed to evaluate tweak for {k}: {e}") else: Loading Loading @@ -413,7 +414,6 @@ class Noche: time = Time(obstime) self.set_obstime(time) with custom_float(): self.fill_keyword("RA", coord.ra.to_string(unit=u.hourangle, sep=':', pad=True, precision=1) ) Loading Loading @@ -444,7 +444,6 @@ class Noche: altaz = self._coord.altaz # Altitudine and Azimuth with custom_float(): self.fill_keyword("ALT", altaz.alt.deg) self.fill_keyword("AZ", altaz.az.deg) Loading Loading @@ -497,7 +496,6 @@ class Noche: _, xsize = map(int, x_str.split(":")) _, ysize = map(int, y_str.split(":")) with custom_float(): crpix = [xsize/self.header["XBINNING"]/2, ysize/self.header["YBINNING"]/2] cdelt1 = self.header["PIXSCALE"]*self.header["XBINNING"]*u.arcsec.to(u.deg) cdelt2 = self.header["PIXSCALE"]*self.header["YBINNING"]*u.arcsec.to(u.deg) Loading @@ -515,7 +513,6 @@ class Noche: flip = -1 # East to the left with custom_float(): self.fill_keyword("CRPIX1", crpix[0]) self.fill_keyword("CRPIX2", crpix[1]) self.fill_keyword("CRVAL1", crval_ra) Loading Loading @@ -552,9 +549,6 @@ class Noche: moon = get_body("moon", time) moon.location = loc with custom_float(): # MOONDIST: angular distance between target and Moon moondist = moon.separation(self._coord, origin_mismatch="ignore").deg self.fill_keyword("MOONDIST", moondist) Loading @@ -579,6 +573,7 @@ class Noche: if self.header[k] == None: log.warning(f"{k:<8}: still empty ({self.header[k]})") def load_fits(self, fits_file): log.debug(sys._getframe().f_code.co_name) Loading @@ -593,6 +588,7 @@ class Noche: noche_hdu.writeto(filename, overwrite=overwrite, checksum=True) @staticmethod def _load_config(path): log.debug(sys._getframe().f_code.co_name) Loading
pyproject.toml +49 −0 Original line number Diff line number Diff line [build-system] requires = ["setuptools>=42", "wheel", "watchdog"] build-backend = "setuptools.build_meta" [project] name = "noche" version = "0.1.0" authors = [ { name="Davide Ricci", email="davide.ricci@inaf.it" }, ] description = "NOCTIS common header." readme = "README.md" requires-python = ">=3.12" #license = { file="LICENSE" } # If you have a LICENSE file classifiers = [ "Programming Language :: Python :: 3", # "License :: OSI Approved :: MIT License", # Choose your license "Operating System :: OS Independent", "Topic :: Scientific/Engineering :: Astronomy", "Intended Audience :: Developers", "Development Status :: 3 - Alpha", # Or appropriate status ] dependencies = [ "astropy", "numpy", ] [project.urls] "Homepage" = "https://www.ict.inaf.it/gitlab/noctis/noche" # "Bug Tracker" = "..." [project.scripts] noche-daemon = "noche.daemon:run" [tool.setuptools.packages.find] where = ["."] # list of folders that contain the packages (["."] by default) include = ["noche"] # package names should match these glob patterns (["*"] by default) exclude = [] # exclude packages matching these glob patterns (empty by default) namespaces = false # to disable scanning PEP 420 namespaces (true by default) [tool.setuptools.package-data] noche = [ "headers/*.ini", "observatories/*.ini", "daemon_config.ini" ]