Commit a3d14b96 authored by Carl Schaffer's avatar Carl Schaffer
Browse files

added basic IFU translator class

parent bb8c53d7
from kis_tools.gris.headers.ifu_translator import GrisIFUTranslator
from kis_tools.gris.headers.observationInfo import ObservationInfo
from kis_tools.gris.headers.translator_classes import *
from .translate_header import run_translate_header
from os.path import basename
from warnings import warn
from kis_tools.gris.headers import GrisTranslator, NothingToDoError
class GrisIFUTranslator(GrisTranslator):
name = "gris_ifu"
supported_instrument = "gris_ifu"
def __init__(self, *args, **kwargs):
super(GrisIFUTranslator, self).__init__(*args, **kwargs)
def can_translate(cls, header, filename=None):
"""Indicate whether this translation class can translate the
supplied header.
header : `dict`-like
Header to convert to standardized form.
filename : `str`, optional
Name of file being translated.
can : `bool`
`True` if the header is recognized by this class. `False`
if not basename(filename).startswith("gris-ifu_"):
return False
if "SOLARNET" in header:
raise NothingToDoError("This header is already up to date!")
if "TELESCOP" in header:
is_gregor = header["TELESCOP"] == "GREGOR"
if is_gregor and all([key in header.keys() for key in ["FF1WLOFF"]]):
return True
f"{cls.__name__}: got a file which does not contain FTS-fitting results or has not been split."
"This translator needs a split file created with recent routines as input."
return False
......@@ -294,6 +294,9 @@ class GrisTranslator(GREGORTranslator):
`True` if the header is recognized by this class. `False`
if not filename.startswith("gris_"):
return False
if "SOLARNET" in header:
raise NothingToDoError("This header is already up to date!")
......@@ -317,7 +320,7 @@ class GrisTranslator(GREGORTranslator):
def to_observation_id(self):
""" observation id is given by DAY_RUN"""
date = self._from_fits_date_string(self._header["DATE-OBS"]).strftime("%Y%m%d")
iobs = int(self._header["IOBS"])
iobs = gris_run_number(self.filename)
value = f"{date}_{iobs:03d}"
return value
......@@ -437,6 +440,9 @@ class GrisTranslator(GREGORTranslator):
exptime = self.to_TEXPOSUR()
return exptime * n_accumulations
def to_IOBS(self):
return gris_run_number(self.filename)
def to_EXPTIME(self):
"""Implemented for Solarsoft compatibility in seconds"""
return self.to_XPOSURE()
......@@ -15,7 +15,7 @@ EXTNAME,,Unique HDU name,,str,,new,"unique name for each header data unit, since
POINT_ID,,Unique (re-)pointing ID,,str,,new,A number that should be automatically incremented each time the telescope is significantly repointed. Can we get something like this for GREGOR?
OBSERVER,,Name of observer,,str,,new,
OBS_TRGT,,Observation Target,,str,,new,
IOBS,,Observation ID (unique within day),,int,,keep,"run number, only in split files available"
IOBS,,Observation ID (unique within day),,int,,new,"run number, only in split files available"
NMAPS,SERIES,Number of maps within observation,,int,,rename,Number of maps
IMAP,ISERIE,Map ID (unique within observation),,int,,rename,number of the map the fits file belongs to
NSTEPS,STEPS,Number of steps per map,,int,,rename,number of slit positions
......@@ -284,6 +284,7 @@ def gris_run_number(fn):
patterns = [
......@@ -670,16 +671,17 @@ def get_data_folders(base_folder):
def instrument_from_fn(path):
name = basename(path)
patterns = {
"gris": r"gris_.*",
"chrotel": r"chrotel_.*",
"lars": r"lars_.*",
"gsjc": r"gsjc\d*_.*",
"bbi": r"bbi_.*",
"gris": [r"gris_.*", r'\d{2}\w{3}\d{2}\.\d{3}(?:-\d{2})?$'],
"chrotel": [r"chrotel_.*"],
"lars": [r"lars_.*"],
"gsjc": [r"gsjc\d*_.*"],
"bbi": [r"bbi_.*"],
for instr, pattern in patterns.items():
if re.match(pattern, name):
return instr
for instr, patterns in patterns.items():
for pattern in patterns:
if re.match(pattern, name):
return instr
raise ValueError(f"Could not determine Instrument name for {path}")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment