Skip to content

Commit

Permalink
Move PypeIt's scriptbase into our utils
Browse files Browse the repository at this point in the history
Having difficulties installing on the observer machines (too old)
because of PypeIt's requirement of PyQt6.  Since the only general use
of `pypeit` is for the scripts (the scrubber still needs the full
package), this commit copies the relevant pieces of PypeIt into the
utils module.

	modified:   doc/conf.py
	modified:   doc/scripts/build_dependency_rst.py
	modified:   obstools/__init__.py
	modified:   obstools/deveny_collfocus.py
	modified:   obstools/deveny_grangle.py
	modified:   obstools/dfocus.py
	modified:   obstools/fix_ldt_header.py
	modified:   obstools/lmi_etc.py
	modified:   obstools/neocp_ephem.py
	modified:   obstools/scrub_deveny_pickup.py
	modified:   obstools/utils.py
	modified:   setup.cfg
  • Loading branch information
tbowers7 committed Nov 10, 2023
1 parent d747050 commit 1c38b78
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 28 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@
"sphinx": ("https://www.sphinx-doc.org/en/master/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"pypeit": ("https://pypeit.readthedocs.io/en/release/", None),
"stomp": ("https://jasonrbriggs.github.io/stomp.py/", None)
"stomp": ("https://jasonrbriggs.github.io/stomp.py/", None),
}
7 changes: 6 additions & 1 deletion doc/scripts/build_dependency_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ def write_dependency_table(setup_file: pathlib.Path, path: pathlib.Path):

user_requires = np.sort(setup["options"]["install_requires"].split("\n")[1:])
dev_requires = np.sort(setup["options.extras_require"]["dev"].split("\n")[1:])
pypeit_requires = np.sort(setup["options.extras_require"]["pypeit"].split("\n")[1:])
required_python = setup["options"]["python_requires"]

data_table = np.empty((3, 2), dtype=object)
data_table = np.empty((4, 2), dtype=object)
data_table[0, :] = ["Python Version", f"``{required_python}``"]
data_table[1, :] = [
"Required for users",
", ".join([f"``{u}``" for u in user_requires]),
]
data_table[2, :] = [
"Optional ``pypeit`` requirements",
", ".join([f"``{u}" for u in pypeit_requires]),
]
data_table[2, :] = [
"Required for developers",
", ".join([f"``{d}``" for d in dev_requires]),
Expand Down
23 changes: 12 additions & 11 deletions obstools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
from obstools.version import version

# Imports for building help docs
from obstools import deveny_collfocus
from obstools import deveny_grangle
from obstools import dfocus
from obstools import lmi_etc
from obstools import fix_ldt_header
from obstools import neocp_ephem
from obstools import scrub_deveny_pickup

try:
from obstools import deveny_collfocus
from obstools import deveny_grangle
from obstools import dfocus
from obstools import lmi_etc
from obstools import fix_ldt_header
from obstools import neocp_ephem
from obstools import scrub_deveny_pickup
except ImportError:
pass

def short_warning(message, category, filename, lineno, file=None, line=None):
"""
Expand All @@ -53,15 +55,14 @@ def script_classes() -> dict:
Dictionary of {name:class} for all script classes
"""
import numpy as np
from pypeit.scripts import scriptbase
from pypeit.utils import all_subclasses
from obstools import utils

# Recursively collect all subclasses
# Since we use PypeIt's ScriptBase, remove all classes from that package
scr_class = np.array(
[
cls
for cls in list(all_subclasses(scriptbase.ScriptBase))
for cls in list(utils.all_subclasses(utils.ScriptBase))
if "pypeit" not in cls.name()
]
)
Expand Down
3 changes: 1 addition & 2 deletions obstools/deveny_collfocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

# 3rd-Party Libraries
import numpy as np
from pypeit.scripts import scriptbase
import PySimpleGUI as sg

# Local Libraries
Expand Down Expand Up @@ -305,7 +304,7 @@ def extract_broker_values(status_dict: dict) -> tuple[str, str]:


# Command Line Script Infrastructure (borrowed from PypeIt) ==================#
class DevenyCollfocus(scriptbase.ScriptBase):
class DevenyCollfocus(utils.ScriptBase):
"""Script class for ``deveny_collfocus`` tool
Script structure borrowed from :class:`pypeit.scripts.scriptbase.ScriptBase`.
Expand Down
3 changes: 1 addition & 2 deletions obstools/deveny_grangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
# 3rd-Party Libraries
import numpy as np
import scipy.optimize
from pypeit.scripts import scriptbase
import PySimpleGUI as sg

# Local Libraries
Expand Down Expand Up @@ -374,7 +373,7 @@ def deveny_amag(grangle: float) -> float:


# Command Line Script Infrastructure (borrowed from PypeIt) ==================#
class DevenyGrangle(scriptbase.ScriptBase):
class DevenyGrangle(utils.ScriptBase):
"""Script class for ``deveny_grangle`` tool
Script structure borrowed from :class:`pypeit.scripts.scriptbase.ScriptBase`.
Expand Down
3 changes: 1 addition & 2 deletions obstools/dfocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
import numpy as np
from pypeit.scripts import scriptbase
import scipy.signal
from tqdm import tqdm

Expand Down Expand Up @@ -851,7 +850,7 @@ def find_lines_in_spectrum(filename, thresh=100.0):


# Command Line Script Infrastructure (borrowed from PypeIt) ==================#
class DFocus(scriptbase.ScriptBase):
class DFocus(utils.ScriptBase):
"""Script class for ``dfocus`` tool
Script structure borrowed from :class:`pypeit.scripts.scriptbase.ScriptBase`.
Expand Down
4 changes: 2 additions & 2 deletions obstools/fix_ldt_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

# 3rd-Party Libraries
import ccdproc
from pypeit.scripts import scriptbase

# Local Libraries
from obstools import utils

# CONSTANTS

Expand Down Expand Up @@ -65,7 +65,7 @@ def fix_ldt_header(files: str | pathlib.Path | list, keyword: str, new_value):


# Command Line Script Infrastructure (borrowed from PypeIt) ==================#
class FixLdtHeader(scriptbase.ScriptBase):
class FixLdtHeader(utils.ScriptBase):
"""Script class for ``fix_ldt_header`` tool
Script structure borrowed from :class:`pypeit.scripts.scriptbase.ScriptBase`.
Expand Down
3 changes: 1 addition & 2 deletions obstools/lmi_etc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
# 3rd-Party Libraries
import astropy.table
import numpy as np
from pypeit.scripts import scriptbase

# Local Libraries
from obstools import utils
Expand Down Expand Up @@ -530,7 +529,7 @@ def sky_count_per_sec_per_ap(


# Command Line Script Infrastructure (borrowed from PypeIt) ==================#
class LmiEtc(scriptbase.ScriptBase):
class LmiEtc(utils.ScriptBase):
"""Script class for ``lmi_etc`` tool
Script structure borrowed from :class:`pypeit.scripts.scriptbase.ScriptBase`.
Expand Down
4 changes: 2 additions & 2 deletions obstools/neocp_ephem.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@
# 3rd-Party Libraries
import astropy.coordinates
import astropy.units as u
from pypeit.scripts import scriptbase
import requests

# Local Libraries
from obstools import utils


def neocp_ephem(neocp_id):
Expand Down Expand Up @@ -184,7 +184,7 @@ def neocp_ephem(neocp_id):


# Command Line Script Infrastructure (borrowed from PypeIt) ==================#
class NeocpEphem(scriptbase.ScriptBase):
class NeocpEphem(utils.ScriptBase):
"""Script class for ``neocp_ephem`` tool
Script structure borrowed from :class:`pypeit.scripts.scriptbase.ScriptBase`.
Expand Down
3 changes: 1 addition & 2 deletions obstools/scrub_deveny_pickup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import matplotlib.pyplot as plt
import numpy as np
from pypeit import msgs
from pypeit.scripts import scriptbase
import pypeit.spec2dobj
import scipy.fft
import scipy.ndimage
Expand Down Expand Up @@ -1609,7 +1608,7 @@ def pixper_tofrom_hz(val: np.ndarray) -> np.ndarray:


# Command Line Script Infrastructure (borrowed from PypeIt) ==================#
class ScrubDevenyPickup(scriptbase.ScriptBase):
class ScrubDevenyPickup(utils.ScriptBase):
"""Script class for ``scrub_deveny_pickup`` tool
Script structure borrowed from :class:`pypeit.scripts.scriptbase.ScriptBase`.
Expand Down
Loading

0 comments on commit 1c38b78

Please sign in to comment.