pyemir 0.24__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 (134) hide show
  1. emirdrp/__init__.py +20 -0
  2. emirdrp/_version.py +24 -0
  3. emirdrp/core/__init__.py +48 -0
  4. emirdrp/core/correctors.py +161 -0
  5. emirdrp/core/extra.py +42 -0
  6. emirdrp/core/recipe.py +61 -0
  7. emirdrp/core/utils.py +18 -0
  8. emirdrp/datamodel.py +128 -0
  9. emirdrp/decorators.py +55 -0
  10. emirdrp/drp.yaml +264 -0
  11. emirdrp/instrument/__init__.py +0 -0
  12. emirdrp/instrument/channels.py +57 -0
  13. emirdrp/instrument/components/__init__.py +0 -0
  14. emirdrp/instrument/components/csu.py +190 -0
  15. emirdrp/instrument/components/dtu.py +217 -0
  16. emirdrp/instrument/components/dtuaxis.py +128 -0
  17. emirdrp/instrument/configs/Oliva_etal_2013.dat +342 -0
  18. emirdrp/instrument/configs/__init__.py +0 -0
  19. emirdrp/instrument/configs/bars_nominal_positions_test.txt +113 -0
  20. emirdrp/instrument/configs/component-1ac26dff-4c3f-43d8-a069-7470357120d6.json +11 -0
  21. emirdrp/instrument/configs/component-5dcdda56-3a5f-4bb8-b88c-776f7eee6cfe.json +12 -0
  22. emirdrp/instrument/configs/component-82b66c4d-e0c7-4395-9cea-c7cd753a5c06.json +11 -0
  23. emirdrp/instrument/configs/component-bc90ac77-2fd4-47c0-97ff-88a278a12785.json +11 -0
  24. emirdrp/instrument/configs/instrument-225fcaf2-7f6f-49cc-972a-70fd0aee8e96.json +11 -0
  25. emirdrp/instrument/configs/instrument-443fc0d1-e09a-48cc-a0fd-02be6f399da2.json +12 -0
  26. emirdrp/instrument/configs/lines_argon_neon_xenon_empirical.dat +205 -0
  27. emirdrp/instrument/configs/lines_argon_neon_xenon_empirical_LR.dat +153 -0
  28. emirdrp/instrument/configs/setup-715c7ced-f989-42a6-bb74-a5b5cda0495c.json +678 -0
  29. emirdrp/instrument/constants/__init__.py +32 -0
  30. emirdrp/instrument/csu_configuration.py +304 -0
  31. emirdrp/instrument/csuconf.py +322 -0
  32. emirdrp/instrument/distortions.py +130 -0
  33. emirdrp/instrument/tests/__init__.py +0 -0
  34. emirdrp/loader.py +14 -0
  35. emirdrp/processing/__init__.py +0 -0
  36. emirdrp/processing/bardetect.py +246 -0
  37. emirdrp/processing/bars.py +243 -0
  38. emirdrp/processing/checkers.py +32 -0
  39. emirdrp/processing/combine.py +515 -0
  40. emirdrp/processing/corr.py +180 -0
  41. emirdrp/processing/flatfield.py +66 -0
  42. emirdrp/processing/wavecal/__init__.py +0 -0
  43. emirdrp/processing/wavecal/apply_rectwv_coeff.py +370 -0
  44. emirdrp/processing/wavecal/get_islitlet.py +42 -0
  45. emirdrp/processing/wavecal/islitlet_progress.py +34 -0
  46. emirdrp/processing/wavecal/median_slitlets_rectified.py +230 -0
  47. emirdrp/processing/wavecal/overplot_boundary_model.py +432 -0
  48. emirdrp/processing/wavecal/rectwv_coeff_add_longslit_model.py +319 -0
  49. emirdrp/processing/wavecal/rectwv_coeff_from_arc_image.py +796 -0
  50. emirdrp/processing/wavecal/rectwv_coeff_from_mos_library.py +460 -0
  51. emirdrp/processing/wavecal/rectwv_coeff_to_ds9.py +439 -0
  52. emirdrp/processing/wavecal/refine_rectwv_coeff.py +344 -0
  53. emirdrp/processing/wavecal/retrieve_catlines.py +63 -0
  54. emirdrp/processing/wavecal/set_wv_parameters.py +136 -0
  55. emirdrp/processing/wavecal/slitlet2d.py +499 -0
  56. emirdrp/processing/wavecal/slitlet2darc.py +1395 -0
  57. emirdrp/processing/wavecal/synthetic_lines_rawdata.py +178 -0
  58. emirdrp/processing/wavecal/useful_mos_xpixels.py +134 -0
  59. emirdrp/processing/wcs.py +90 -0
  60. emirdrp/products.py +465 -0
  61. emirdrp/recipes/__init__.py +0 -0
  62. emirdrp/recipes/acquisition/__init__.py +0 -0
  63. emirdrp/recipes/acquisition/bargrad.py +115 -0
  64. emirdrp/recipes/acquisition/centering.py +139 -0
  65. emirdrp/recipes/acquisition/maskcheck.py +715 -0
  66. emirdrp/recipes/aiv/__init__.py +130 -0
  67. emirdrp/recipes/aiv/common.py +103 -0
  68. emirdrp/recipes/aiv/pointsources.py +184 -0
  69. emirdrp/recipes/aiv/procedures.py +20 -0
  70. emirdrp/recipes/aiv/sky.py +78 -0
  71. emirdrp/recipes/aiv/slits.py +130 -0
  72. emirdrp/recipes/auxiliary/__init__.py +234 -0
  73. emirdrp/recipes/auxiliary/load.py +28 -0
  74. emirdrp/recipes/auxiliary/mtwflat.py +272 -0
  75. emirdrp/recipes/calibration/__init__.py +0 -0
  76. emirdrp/recipes/calibration/arc.py +92 -0
  77. emirdrp/recipes/engineering/__init__.py +0 -0
  78. emirdrp/recipes/engineering/cosmetics.py +186 -0
  79. emirdrp/recipes/engineering/detectorgain.py +114 -0
  80. emirdrp/recipes/image/__init__.py +0 -0
  81. emirdrp/recipes/image/checks.py +197 -0
  82. emirdrp/recipes/image/dither.py +1406 -0
  83. emirdrp/recipes/image/join.py +940 -0
  84. emirdrp/recipes/image/micro.py +152 -0
  85. emirdrp/recipes/image/naming.py +53 -0
  86. emirdrp/recipes/image/nodded.py +76 -0
  87. emirdrp/recipes/image/shared.py +938 -0
  88. emirdrp/recipes/image/stare.py +281 -0
  89. emirdrp/recipes/image/tests/__init__.py +0 -0
  90. emirdrp/recipes/spec/__init__.py +0 -0
  91. emirdrp/recipes/spec/abba.py +1087 -0
  92. emirdrp/recipes/spec/coadd.py +136 -0
  93. emirdrp/recipes/spec/flatlowfreq.py +526 -0
  94. emirdrp/recipes/spec/flatpix2pix.py +662 -0
  95. emirdrp/recipes/spec/sky.py +71 -0
  96. emirdrp/recipes/spec/stare.py +474 -0
  97. emirdrp/recipes/spec/subs.py +293 -0
  98. emirdrp/recipes/spec/tests/__init__.py +0 -0
  99. emirdrp/requirements.py +128 -0
  100. emirdrp/simulation/__init__.py +0 -0
  101. emirdrp/simulation/spagna-J.dat +26 -0
  102. emirdrp/simulation/spagna-K.dat +26 -0
  103. emirdrp/simulation/starcounts.py +292 -0
  104. emirdrp/testing/__init__.py +0 -0
  105. emirdrp/testing/create_base.py +33 -0
  106. emirdrp/testing/create_headers.py +56 -0
  107. emirdrp/testing/create_ob.py +93 -0
  108. emirdrp/testing/create_scenes.py +35 -0
  109. emirdrp/testing/create_wcs.py +66 -0
  110. emirdrp/tools/__init__.py +0 -0
  111. emirdrp/tools/apply_rectification_only.py +202 -0
  112. emirdrp/tools/continuum_flatfield.py +552 -0
  113. emirdrp/tools/convert_refined_multislit_bound_param.py +80 -0
  114. emirdrp/tools/display_slitlet_arrangement.py +485 -0
  115. emirdrp/tools/fit_boundaries.py +1604 -0
  116. emirdrp/tools/generate_yaml_for_abba.py +281 -0
  117. emirdrp/tools/generate_yaml_for_dithered_image.py +147 -0
  118. emirdrp/tools/list_slitlets_from_string.py +86 -0
  119. emirdrp/tools/merge2images.py +132 -0
  120. emirdrp/tools/merge_bounddict_files.py +82 -0
  121. emirdrp/tools/nscan_minmax_frontiers.py +54 -0
  122. emirdrp/tools/overplot_bounddict.py +223 -0
  123. emirdrp/tools/rect_wpoly_for_mos.py +435 -0
  124. emirdrp/tools/save_ndarray_to_fits.py +131 -0
  125. emirdrp/tools/select_unrectified_slitlets.py +254 -0
  126. emirdrp/tools/slitlet_boundaries_from_continuum.py +725 -0
  127. emirdrp/util/__init__.py +0 -0
  128. pyemir-0.24.dist-info/METADATA +93 -0
  129. pyemir-0.24.dist-info/RECORD +134 -0
  130. pyemir-0.24.dist-info/WHEEL +5 -0
  131. pyemir-0.24.dist-info/entry_points.txt +24 -0
  132. pyemir-0.24.dist-info/licenses/AUTHORS.rst +7 -0
  133. pyemir-0.24.dist-info/licenses/LICENSE.txt +674 -0
  134. pyemir-0.24.dist-info/top_level.txt +1 -0
emirdrp/__init__.py ADDED
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright 2008-2023 Universidad Complutense de Madrid
3
+ #
4
+ # This file is part of PyEmir
5
+ #
6
+ # SPDX-License-Identifier: GPL-3.0-or-later
7
+ # License-Filename: LICENSE.txt
8
+ #
9
+
10
+ """The EMIR Data Reduction Pipeline"""
11
+
12
+ import logging
13
+
14
+ import emirdrp._version
15
+
16
+ __version__ = emirdrp._version.__version__
17
+
18
+
19
+ # Top level NullHandler
20
+ logging.getLogger("emirdrp").addHandler(logging.NullHandler())
emirdrp/_version.py ADDED
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.24'
22
+ __version_tuple__ = version_tuple = (0, 24)
23
+
24
+ __commit_id__ = commit_id = None
@@ -0,0 +1,48 @@
1
+ #
2
+ # Copyright 2016-2023 Universidad Complutense de Madrid
3
+ #
4
+ # This file is part of PyEmir
5
+ #
6
+ # SPDX-License-Identifier: GPL-3.0-or-later
7
+ # License-Filename: LICENSE.txt
8
+ #
9
+
10
+ EMIR_BIAS_MODES = ["simple", "bias", "single"]
11
+ EMIR_READ_MODES = ["simple", "bias", "single", "cds", "fowler", "ramp"]
12
+
13
+ EMIR_PLATESCALE = 0.1944 # arcsec/pixel
14
+
15
+ # plate scale, focal plane NASMYTH_A, arcsec / mm
16
+ # keyword PSCFP
17
+ NASMYTH_A_PS = 1.212 # arcsec / mm
18
+ EMIR_CSU_PS = 1.1746 # arcsec / mm
19
+
20
+ # plate scale, detector, arcsec / mm
21
+ EMIR_DETECTOR_PS = 10.8
22
+ # plate scale, detector, arcsec / pix
23
+ EMIR_PS_PIX = EMIR_PLATESCALE
24
+ # Pixel size, mm
25
+ # PXSZDET
26
+ EMIR_PIXSCALE = 18.0 # um
27
+ EMIR_PIXSIZE_DETECTOR = EMIR_PIXSCALE * 1e-3
28
+
29
+ # Pixel projected in FP, mm
30
+ # keyword PXSZCSU
31
+ EMIR_PIXSIZE_CSU = EMIR_PLATESCALE / EMIR_CSU_PS
32
+
33
+ # plate scale, detector, arcsec / pix
34
+ EMIR_DET_PS_PIX = EMIR_DETECTOR_PS * EMIR_PIXSIZE_DETECTOR
35
+
36
+ EMIR_GAIN = 5.0 # ADU / e-
37
+ EMIR_RON = 5.69 # ADU
38
+
39
+ EMIR_NBARS = 55
40
+ EMIR_NAXIS1 = 2048
41
+ EMIR_NAXIS1_ENLARGED = 3400
42
+ EMIR_NAXIS2 = 2048
43
+
44
+ EMIR_NPIXPERSLIT_RECTIFIED = 38
45
+ EMIR_MINIMUM_SLITLET_WIDTH_MM = 0.0
46
+ EMIR_MAXIMUM_SLITLET_WIDTH_MM = 1000.0
47
+ EMIR_VALID_GRISMS = ["J", "H", "K", "LR"]
48
+ EMIR_VALID_FILTERS = ["J", "H", "Ksp", "YJ", "HK"]
@@ -0,0 +1,161 @@
1
+ #
2
+ # Copyright 2008-2019 Universidad Complutense de Madrid
3
+ #
4
+ # This file is part of PyEmir
5
+ #
6
+ # SPDX-License-Identifier: GPL-3.0-or-later
7
+ # License-Filename: LICENSE.txt
8
+ #
9
+
10
+
11
+ import logging
12
+
13
+ import numpy
14
+ import numina.util.node
15
+ import numina.datamodel as dm
16
+ import numina.processing as proc
17
+
18
+ import emirdrp.core as c
19
+
20
+ _logger = logging.getLogger(__name__)
21
+
22
+
23
+ def get_corrector_p(rinput, meta, ins, datamodel):
24
+ key = "master_bpm"
25
+ info = meta.get(key)
26
+ corrector_class = proc.BadPixelCorrector
27
+
28
+ if info is not None:
29
+ inputval = getattr(rinput, key)
30
+ with inputval.open() as hdul:
31
+ _logger.info('loading "%s"', key)
32
+ _logger.debug("info: %s", info)
33
+ corrector = corrector_class(
34
+ hdul[0].data,
35
+ datamodel=datamodel,
36
+ calibid=dm.get_imgid(hdul, prefix=True),
37
+ )
38
+ else:
39
+ _logger.info('"%s" not provided, ignored', key)
40
+ corrector = numina.util.node.IdNode()
41
+
42
+ return corrector
43
+
44
+
45
+ def get_corrector_b(rinput, meta, ins, datamodel):
46
+ iinfo = meta["obresult"]
47
+ if iinfo:
48
+ mode = iinfo[0]["readmode"]
49
+ if mode.lower() in c.EMIR_BIAS_MODES:
50
+ use_bias = True
51
+ _logger.info("readmode is %s, bias required", mode)
52
+ else:
53
+ use_bias = False
54
+ _logger.info("readmode is %s, bias not required", mode)
55
+ else:
56
+ # raise ValueError('cannot gather images info')
57
+ use_bias = False
58
+
59
+ # Loading calibrations
60
+ if use_bias:
61
+ bias_info = meta["master_bias"]
62
+ with rinput.master_bias.open() as hdul:
63
+ _logger.info("loading bias")
64
+ _logger.debug("bias info: %s", bias_info)
65
+ mbias = hdul[0].data
66
+ bias_corrector = proc.BiasCorrector(mbias, datamodel=datamodel, calibid=dm.get_imgid(hdul, prefix=True))
67
+ else:
68
+ _logger.info("ignoring bias")
69
+ bias_corrector = numina.util.node.IdNode()
70
+
71
+ return bias_corrector
72
+
73
+
74
+ def get_corrector_s(rinput, meta, ins, datamodel):
75
+ sky_info = meta.get("master_sky")
76
+
77
+ if sky_info is None:
78
+ return numina.util.node.IdNode()
79
+ else:
80
+ with rinput.master_sky.open() as hdul:
81
+ _logger.info("loading sky")
82
+ _logger.debug("sky info: %s", sky_info)
83
+ sky_corrector = proc.SkyCorrector(
84
+ hdul[0].data,
85
+ datamodel=datamodel,
86
+ calibid=dm.get_imgid(hdul, prefix=True),
87
+ )
88
+ return sky_corrector
89
+
90
+
91
+ def get_corrector_f(rinput, meta, ins, datamodel):
92
+ """Corrector for intensity flat"""
93
+ from emirdrp.processing.flatfield import FlatFieldCorrector
94
+
95
+ flat_info = meta["master_flat"]
96
+ with rinput.master_flat.open() as hdul:
97
+ _logger.info("loading intensity flat")
98
+ _logger.debug("flat info: %s", flat_info)
99
+ mflat = hdul[0].data
100
+ # Check NaN and Ceros
101
+ mask1 = mflat < 0
102
+ mask2 = ~numpy.isfinite(mflat)
103
+ if numpy.any(mask1):
104
+ _logger.warning("flat has %d values below 0", mask1.sum())
105
+ if numpy.any(mask2):
106
+ _logger.warning("flat has %d NaN", mask2.sum())
107
+ flat_corrector = FlatFieldCorrector(mflat, datamodel=datamodel, calibid=dm.get_imgid(hdul, prefix=True))
108
+
109
+ return flat_corrector
110
+
111
+
112
+ def get_corrector_sf(rinput, meta, ins, datamodel):
113
+ """Corrector for spectral flat"""
114
+ from emirdrp.processing.flatfield import FlatFieldCorrector
115
+
116
+ flat_info = meta["master_flat"]
117
+ with rinput.master_flat.open() as hdul:
118
+ _logger.info("loading spectral flat")
119
+ _logger.debug("flat info: %s", flat_info)
120
+ mflat = hdul[0].data
121
+ # Check NaN and Ceros
122
+ mask1 = mflat < 0
123
+ mask2 = ~numpy.isfinite(mflat)
124
+ if numpy.any(mask1):
125
+ _logger.warning("flat has %d values below 0", mask1.sum())
126
+ if numpy.any(mask2):
127
+ _logger.warning("flat has %d NaN", mask2.sum())
128
+ flat_corrector = FlatFieldCorrector(mflat, datamodel=datamodel, calibid=dm.get_imgid(hdul, prefix=True))
129
+
130
+ return flat_corrector
131
+
132
+
133
+ def get_corrector_d(rinput, meta, ins, datamodel):
134
+ key = "master_dark"
135
+
136
+ corrector = get_corrector_gen(rinput, datamodel, proc.DarkCorrector, key)
137
+ return corrector
138
+
139
+
140
+ def get_corrector_gen(rinput, datamodel, CorrectorClass, key):
141
+ value = getattr(rinput, key)
142
+ req = rinput.stored()[key]
143
+ if value is None:
144
+ if req.optional:
145
+ _logger.info('"%s" not provided, ignored', key)
146
+ corrector = numina.util.node.IdNode()
147
+ return corrector
148
+ else:
149
+ msg = '"{}" not provided, is required'.format(key)
150
+ raise ValueError(msg)
151
+ else:
152
+ with value.open() as hdul:
153
+ datac = hdul["primary"].data
154
+ corrector = CorrectorClass(datac, calibid=dm.get_imgid(hdul, prefix=True), datamodel=datamodel)
155
+ return corrector
156
+
157
+
158
+ def get_checker(rinput, meta, ins, datamodel):
159
+ from emirdrp.processing.checkers import Checker
160
+
161
+ return Checker()
emirdrp/core/extra.py ADDED
@@ -0,0 +1,42 @@
1
+ #
2
+ # Copyright 2011-2023 Universidad Complutense de Madrid
3
+ #
4
+ # This file is part of PyEmir
5
+ #
6
+ # SPDX-License-Identifier: GPL-3.0-or-later
7
+ # License-Filename: LICENSE.txt
8
+ #
9
+
10
+
11
+ """
12
+ Extra functions
13
+ """
14
+
15
+ import logging
16
+
17
+ import numpy
18
+ import astropy.io.fits as fits
19
+
20
+ _logger = logging.getLogger(__name__)
21
+
22
+
23
+ def generate_bpm_hdu(hdu):
24
+ """Generate a BPM extension copying an existing HDU"""
25
+ return generate_bpm_data(hdu.data, dtype="uint8", header=hdu.header)
26
+
27
+
28
+ def generate_empty_bpm_hdu(hdu, dtype="uint8"):
29
+ """Generate a BPM extension filled with zeros"""
30
+ data = numpy.zeros_like(hdu.data, dtype)
31
+ return generate_bpm_data(data)
32
+
33
+
34
+ def generate_bpm_data(data, dtype="uint8", header=None):
35
+ """Generate a BPM extension from data."""
36
+ # Mask is assumed to be UINT8
37
+ # casting here
38
+ data = data.astype(dtype)
39
+ hdu_bpm = fits.ImageHDU(data, header=header)
40
+
41
+ hdu_bpm.header["EXTNAME"] = "BPM"
42
+ return hdu_bpm
emirdrp/core/recipe.py ADDED
@@ -0,0 +1,61 @@
1
+ #
2
+ # Copyright 2008-2025 Universidad Complutense de Madrid
3
+ #
4
+ # This file is part of PyEmir
5
+ #
6
+ # SPDX-License-Identifier: GPL-3.0-or-later
7
+ # License-Filename: LICENSE.txt
8
+ #
9
+
10
+ import logging
11
+
12
+ import numina.core.recipes as recipes
13
+
14
+ import emirdrp.core.correctors as cor
15
+ import emirdrp.products as prods
16
+ import emirdrp.datamodel
17
+
18
+
19
+ class EmirRecipe(recipes.BaseRecipe):
20
+ """Base class for all EMIR Recipes"""
21
+
22
+ logger = logging.getLogger(__name__)
23
+ datamodel = emirdrp.datamodel.EmirDataModel()
24
+
25
+ def types_getter(self):
26
+ imgtypes = [
27
+ prods.MasterBadPixelMask,
28
+ prods.MasterBias,
29
+ prods.MasterDark,
30
+ prods.MasterIntensityFlat,
31
+ prods.MasterSpectralFlat,
32
+ prods.MasterSky,
33
+ ]
34
+ getters = [
35
+ cor.get_corrector_p,
36
+ cor.get_corrector_b,
37
+ cor.get_corrector_d,
38
+ [cor.get_corrector_f, cor.get_checker],
39
+ cor.get_corrector_sf,
40
+ cor.get_corrector_s,
41
+ ]
42
+
43
+ return imgtypes, getters
44
+
45
+ def create_getters(self):
46
+ imgtypes, getters = self.types_getter()
47
+ getters = self.get_filters(imgtypes, getters)
48
+ getters_seq = [getters]
49
+ return getters_seq
50
+
51
+ def aggregate_result(self, result, rinput):
52
+ return result
53
+
54
+ def init_filters(self, rinput, ins=None):
55
+ # TODO: we overload this method to
56
+ # avoid rewriting all the calls like
57
+ # flow = self.init_filters(rinput)
58
+ # to
59
+ # flow = self.init_filters(rinput)[0]
60
+ # we should do it in the future
61
+ return super().init_filters(rinput, ins)[0]
emirdrp/core/utils.py ADDED
@@ -0,0 +1,18 @@
1
+ #
2
+ # Copyright 2020-2023 Universidad Complutense de Madrid
3
+ #
4
+ # This file is part of PyEmir
5
+ #
6
+ # SPDX-License-Identifier: GPL-3.0-or-later
7
+ # License-Filename: LICENSE.txt
8
+ #
9
+
10
+ import numpy
11
+ import math
12
+
13
+
14
+ def create_rot2d(angle):
15
+ """Create 2D rotation matrix"""
16
+ ca = math.cos(angle)
17
+ sa = math.sin(angle)
18
+ return numpy.array([[ca, -sa], [sa, ca]])
emirdrp/datamodel.py ADDED
@@ -0,0 +1,128 @@
1
+ #
2
+ # Copyright 2016-2025 Universidad Complutense de Madrid
3
+ #
4
+ # This file is part of PyEmir
5
+ #
6
+ # SPDX-License-Identifier: GPL-3.0-or-later
7
+ # License-Filename: LICENSE.txt
8
+ #
9
+
10
+ """Datamodel for EMIR and related functions"""
11
+
12
+ import logging
13
+ import warnings
14
+
15
+ import numina.datamodel as dm
16
+ from numina.keydef import QueryAttribute
17
+
18
+ _logger = logging.getLogger(__name__)
19
+
20
+
21
+ class EmirDataModel(dm.DataModel):
22
+ """Data model of EMIR."""
23
+
24
+ # These keywords are used by gather_info_hdu
25
+ meta_dinfo_headers = [
26
+ "readmode",
27
+ "exptime",
28
+ "grism",
29
+ "filter",
30
+ "mode",
31
+ "tstamp",
32
+ "uuid1",
33
+ "uuid2",
34
+ "skyadd",
35
+ ]
36
+
37
+ query_attrs = {
38
+ "filter": QueryAttribute("filter", str),
39
+ "grism": QueryAttribute("grism", str),
40
+ "insconf": QueryAttribute("insconf", str),
41
+ }
42
+
43
+ def __init__(self):
44
+ defaults = self.default_mappings()
45
+ # FIXME: this should be computed
46
+ defaults["darktime"] = "exptime"
47
+
48
+ instrument_mappings = {
49
+ "readmode": ("READMODE", "undefined"),
50
+ "grism": ("GRISM", "undefined"),
51
+ "filter": ("FILTER", "undefined"),
52
+ "tstamp": ("TSTAMP", "undefined"),
53
+ "uuid1": ("UUID", "undefined"),
54
+ "uuid2": ("EMIRUUID", "undefined"),
55
+ "skyadd": ("SKYADD", True),
56
+ "insconf": ("INSCONF", None),
57
+ }
58
+
59
+ defaults.update(instrument_mappings)
60
+
61
+ super(EmirDataModel, self).__init__("EMIR", defaults)
62
+
63
+ @property
64
+ def shape(self):
65
+ return (2048, 2048)
66
+
67
+ def do_sky_correction(self, img):
68
+ header = img["primary"].header
69
+ return header.get("SKYADD", True)
70
+
71
+ def add_computation_time(self, img, time1, time2):
72
+ """Deprecated, the results of the recipes record the computation time"""
73
+ warnings.warn(
74
+ "EmirDataModel.add_computation_time is deprecated, "
75
+ "the results of the recipes record the computation time",
76
+ DeprecationWarning,
77
+ stacklevel=2,
78
+ )
79
+ img[0].header["NUMUTC1"] = time1.isoformat()
80
+ img[0].header["NUMUTC2"] = time2.isoformat()
81
+ return img
82
+
83
+
84
+ def get_mecs_header(hdulist):
85
+ if "MECS" in hdulist:
86
+ return hdulist["MECS"].header
87
+ else:
88
+ return hdulist[0].header
89
+
90
+
91
+ def get_dtur_from_img(hdulist):
92
+ mecs_header = get_mecs_header(hdulist)
93
+ return get_dtur_from_header(mecs_header)
94
+
95
+
96
+ def get_dtur_from_header(hdr):
97
+ from emirdrp.instrument.dtuconf import DtuConf
98
+
99
+ dtuconf = DtuConf.from_header(hdr)
100
+ return dtuconf.coor, dtuconf.coor_r
101
+
102
+
103
+ def get_csup_from_header(hdr):
104
+ # CSUP keys
105
+ default = 0.0
106
+ first_idx = 1
107
+ last_idx = 110
108
+ _logger.info("getting CSUP keys from header")
109
+ values = []
110
+ for idx in range(first_idx, last_idx + 1):
111
+ key = "CSUP{}".format(idx)
112
+ values.append(hdr.get(key, default))
113
+
114
+ return values
115
+
116
+
117
+ def get_cs_from_header(hdr):
118
+ # CS keys
119
+ default = 0.0
120
+ first_idx = 0
121
+ last_idx = 439
122
+ _logger.info("getting CS keys from header")
123
+ values = []
124
+ for idx in range(first_idx, last_idx + 1):
125
+ key = "CS_{}".format(idx)
126
+ values.append(hdr.get(key, default))
127
+
128
+ return values
emirdrp/decorators.py ADDED
@@ -0,0 +1,55 @@
1
+ #
2
+ # Copyright 2008-2024 Universidad Complutense de Madrid
3
+ #
4
+ # This file is part of PyEmir
5
+ #
6
+ # SPDX-License-Identifier: GPL-3.0-or-later
7
+ # License-Filename: LICENSE.txt
8
+ #
9
+
10
+ """Decorator for EMIR Recipes"""
11
+
12
+ from numina.core import DataFrame, ObservationResult
13
+ from emirdrp.datamodel import EmirDataModel
14
+
15
+
16
+ def loginfo(method):
17
+ """Log the contents of Recipe Input"""
18
+
19
+ # FIXME: datamodel is probably already defined in method
20
+ # or in rinput
21
+ datamodel = EmirDataModel()
22
+
23
+ def loginfo_method(self, rinput):
24
+
25
+ klass = rinput.__class__
26
+ for key in klass.stored():
27
+ val = getattr(rinput, key)
28
+ if isinstance(val, DataFrame):
29
+ self.logger.debug("DataFrame %s", datamodel.gather_info(val))
30
+ elif isinstance(val, ObservationResult):
31
+ for msg in datamodel.gather_info_oresult(val):
32
+ self.logger.debug("OB DataFrame %s", msg)
33
+ else:
34
+ pass
35
+
36
+ result = method(self, rinput)
37
+
38
+ return result
39
+
40
+ return loginfo_method
41
+
42
+
43
+ def aggregate(method):
44
+
45
+ def agregate_method(self, rinput):
46
+
47
+ result = method(self, rinput)
48
+
49
+ aggregate_m = getattr(self, "aggregate_result")
50
+
51
+ new_result = aggregate_m(self, result, rinput)
52
+
53
+ return new_result
54
+
55
+ return agregate_method