Accessing stellar spectra
Define a base Frame object to interface with the observations.
This ensures that ASTRA is fully agnostic to the instrument that we are using, as long as our data is properly loaded in the children classes of the Frame object.
It will also provide a common set of names for commonly used header values.
Frame
Bases: Spectrum
, Spectral_Modelling
, Spectral_Normalization
Base Class for the different instruments.
Providing a shared interface to spectral data and header information.
This class defines a set of Keywords, consistent for all ASTRA supported Instruments, which can be accessed
through the proper methods. The internal keywords are initialized to a default value, which the Frame will use
if the instrument does not provide that metric/value. Furthermore, all RV-related metrics are returned as
astropy.Quantity objects (or lists of such objects). For such cases, one can use
:func:~ASTRAutils.units.convert_data
to convert data to different units and/or to floats
The supported list of keywords, and the default initialization values is:
Internal KW name | Default intialization |
---|---|
BERV | np.nan * kilometer_second |
previous_SBART_RV | np.nan * kilometer_second |
previous_SBART_RV_ERR | np.nan * kilometer_second |
DRS_CCF_MASK | "" |
DRS_FLUX_CORRECTION_TEMPLATE | "" |
DRS_RV | np.nan * kilometer_second |
DRS_RV_ERR | np.nan * kilometer_second |
drift | np.nan * kilometer_second |
drift_ERR | np.nan * kilometer_second |
relative_humidity | np.nan, # for telfi |
ambient_temperature | np.nan [Kelvin], # for telfi |
airmass | np.nan |
orderwise_SNRs | [] |
OBJECT | None |
MAX_BERV | np.nan * kilometer_second |
BJD | None |
MJD | None |
DRS-VERSION | None |
MD5-CHECK | None |
ISO-DATE | None |
CONTRAST | 0 |
CONTRAST_ERR | 0 |
FWHM | 0, # Store this as km/ |
FWHM_ERR | 0, # Store this as km/ |
BIS SPAN | 0, # Store this as km/ |
BIS SPAN_ERR | 0, # Store this as km/ |
EXPTIME | 0 |
RA | None |
DEC | None |
SPEC_TYPE "None", # This keyword is simply loading the CCF mask.. | |
DET_BINX | None |
DET_BINY | None |
seeing | None |
MOON PHASE | 0 |
MOON DISTANCE | 0 |
INS MODE | "None" |
INS NAME | "None" |
PROG ID | "None" |
DATE_NIGHT | "None" |
Source code in src/ASTRA/base_models/Frame.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 |
|
bare_fname
property
Returns the file name without the _S2D (and similar) parts.
The children classes must overload this property. Otherwise, returns the full filename
fname
property
Get filename.
has_warnings
property
Check if Frame has any warnings.
is_S1D
property
Check if Frame is of S1D format.
is_S2D
property
Check if Frame is of S2D format.
is_SA_corrected
property
Check if the frame was corrected from secular acceleration.
min_pixel_in_order
property
Minimum number of pixels in order to be a valid one.
previous_RV_measurements
property
Get previous DRS RV and uncertainty.
spectrum_information
property
Get general instrument and spectra information.
status
property
Return the Status of the entire Frame.
add_to_status(new_flag)
Add a new Flag to the Status of this Frame.
Source code in src/ASTRA/base_models/Frame.py
assess_bad_orders()
Evaluate the orders and Frames that can be fully rejected.
Goals: 1) Check if any order rejects more than reject_order_percentage % of the pixels. If so, rejects it 2) Apply SNR cut of minimum_order_SNR 3) if a Frame rejects more than *MAX_ORDER_REJECTION * % of all orders, it is rejected from the analysis.
Source code in src/ASTRA/base_models/Frame.py
build_mask(bypass_QualCheck=False, assess_bad_orders=True)
Build a pixel-wise mask for rejection purposes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bypass_QualCheck
|
bool
|
If True, Bypass using the QUAL_DATA from the DRS. Defaults to False. |
False
|
assess_bad_orders
|
bool
|
if True, reject entire spectral orders based on the assess_bad_orders() This can be used if we want to run more pixel-rejection methods before we evaluate bad orders. |
True
|
Source code in src/ASTRA/base_models/Frame.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
|
check_header_QC(header)
Check if the header keywords are in accordance with their default value.
Each instrument should do this check on its own
This function will check for two things: 1. Fatal keywords - will mark the Frame as invalid 2. Warning Keywords - the frame is still valid, but it has a warning issued in the logs
If any of those conditions is met, make sure that the flags meet the following naming conditions (so that we can filter by them later on):
For fatal flags
For warnings:
Source code in src/ASTRA/base_models/Frame.py
copy_into_S2D(new_S2D_size=None)
Return a new object which contains the S1D that that has been converted into a S2D.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_S2D_size
|
Optional[Tuple[int, int]]
|
Size of the new S2D size, should be a tuple with two |
None
|
elements
|
(number orders, pixel in order). If it is None, then uses the standard size of S2D files of this |
required |
Raises:
Type | Description |
---|---|
InvalidConfiguration
|
If it is already in S2D format |
Returns:
Name | Type | Description |
---|---|---|
Frame |
Frame
|
new Frame |
Source code in src/ASTRA/base_models/Frame.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
finalize_data_load(bad_flag=None)
Run for all Instruments, even those that do not need an external data load.
Checks if the non-fatal Flag "LOADING_EXTERNAL_DATA" exists in the Status. If so, add the fatal Flag "MISSING_EXTERNAL_DATA". Otherwise, does nothing
Source code in src/ASTRA/base_models/Frame.py
finalized_external_data_load()
Mark frame after everything is loaded into memory.
The frames that need external data will have a Flag of "LOADING_EXTERNAL_DATA" that will translate into a rejection of the Frame (if it is not removed).
This call will remove that flag from Status and sinalizes that this Frame managed to load everything that it needed
Source code in src/ASTRA/base_models/Frame.py
find_instrument_type()
Compare the date of observation with pre-defined sub-Instruments to see where it fits.
Source code in src/ASTRA/base_models/Frame.py
get_KW_value(KW)
get_S1D_name()
Build the S1D name that should be associated with this Frame.
If it is already a S1D, returns the actual name. If it is not, remove "blaze" from the filename and replaces "S2D" with "S1D"
Source code in src/ASTRA/base_models/Frame.py
get_header_value(kw)
Directly retrieves a KW from the header.
After this is called, the frame will keep the header stored in memory until the object is deleted
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kw
|
str
|
Keyword name, present in the fits header |
required |
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
Header value |
Source code in src/ASTRA/base_models/Frame.py
get_spectral_type()
Check the filename to see if we are using an S1D or S2D file.
Raises:
Type | Description |
---|---|
InternalError
|
If it is not possible to recognize the filename |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
S1D or S2D |
Source code in src/ASTRA/base_models/Frame.py
import_KW_from_outside(KW, value, optional)
Allow to manually override header parameters (in memory) from the outside.
This can be used if an instrument has data stored in multiple files. This allows a post-setup update of header values (for the keywords stored in observation_info)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
KW
|
str
|
keyword name, as defined by the Frame interface |
required |
value
|
Any
|
New value |
required |
optional
|
bool
|
if it is optional, it can be a non-finite value |
required |
Raises:
Type | Description |
---|---|
FrameError
|
If we attempt to load a optional=False keyword that has a non-finite value |
Source code in src/ASTRA/base_models/Frame.py
is_Instrument(Instrument)
is_SubInstrument(sub_instrument)
Check if the current instrument is from the given time_block (e.g ESPRESSO18/ESPRESSO19).
Parameters
sub_instrument : str Name of the time block that is going to be checked
Returns
[bool] Results from the comparison
Source code in src/ASTRA/base_models/Frame.py
load_S1D_data()
To be overriden by the children classes.
load_S2D_data()
To be overriden by the children classes.
load_data()
Abstraction to load all data of this Frame.
If the Frame is already open, it does nothing. Calls the S1D or S2D version of the data load, depending on file type Can remove BERV correction at run time, if properly configured to do so.
Raises:
Type | Description |
---|---|
InternalError
|
If it is neither S2D or S1D |
FrameError
|
If the frame is no longer valid after loading |
Source code in src/ASTRA/base_models/Frame.py
load_header_info()
Open the header of the fits file and load the necessary keywords.
Does the following operations: 1) Load header assuming fits file 2) Parse through the _KW_map to load header keywords 3) Call self.load_instrument_specific_KWs 4) Call check_header_QC(hdu) 5) Call find_instrument_type() 6) Call assess_bad_orders()
Source code in src/ASTRA/base_models/Frame.py
load_instrument_specific_KWs(header)
Load instrument-specific KW values that can't be loaded in a general fashion.
To be overriden by the different instruments
Parameters:
Name | Type | Description | Default |
---|---|---|---|
header
|
Mapping[str, Any]
|
header unit of this observation |
required |
Source code in src/ASTRA/base_models/Frame.py
mark_wavelength_region(reason, wavelength_blocks)
Add wavelength regions to be removed whenever the S2D file is opened.
When rejecting wavelengths through this function, we only have to specify wavelength intervels, allowing to account for possible order overlap. When loading the Frame, we search through all orders to find any occurence of this wavelength blocks.
Parameters
reason : Flag Flag for the removal type wavelength_blocks : list[tuple[int, int]] List with lists of wavelength limits. [[lambda_0, lambda_1], [lambda_2, lambda_3]] to reject.z
Source code in src/ASTRA/base_models/Frame.py
plot_spectra(which_orders=None, axis=None)
Plot the spectra.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
which_orders
|
None | DETECTOR_DEFINITION | list[int]
|
Either a pre-configured |
None
|
axis
|
_type_
|
if None, create a new figure. Otherwise, use this one. Defaults to None. |
None
|
Source code in src/ASTRA/base_models/Frame.py
reject_wavelength_region_from_order(order, region)
Flag a wavelength region from specific order to be marked as invalid during the creation of the stellar mask.
This will not account for order overlaps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
order
|
_type_
|
description |
required |
region
|
_type_
|
description |
required |
Raises:
Type | Description |
---|---|
InvalidConfiguration
|
|
Source code in src/ASTRA/base_models/Frame.py
select_wavelength_region(order, wavelength_blocks)
Reject all wavelengths that are not part of the provided intervals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
order
|
int
|
Spectral order |
required |
wavelength_blocks
|
list[list[int]]
|
List of tuples, each containing wavelength of start and end |
required |
Source code in src/ASTRA/base_models/Frame.py
Currently available interfaces to spectrographs
ESPRESSO
Bases: ESO_PIPELINE
Interface to handle ESPRESSO observations (S2D and S1D).
With ESPRESSO data we are considering 3 sub-Instruments:
- ESPRESSO18 - Before 2019-06-27
- ESPRESSO19 - Before 2020-12-18
- ESPRESSO21 - Until the ends of time (hopefully)
User parameters:
================================ ================ ================ ================ ================ Parameter name Mandatory Default Value Valid Values Comment ================================ ================ ================ ================ ================ ================================ ================ ================ ================ ================
.. note:: Also check the User parameters of the parent classes for further customization options of SBART
Source code in src/ASTRA/Instruments/ESPRESSO.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
HARPS
Bases: ESO_PIPELINE
Interface to handle HARPS data; S1D not supported.
This class also defines 2 sub-Instruments:
- HARPSpre - Before 2015-05-29
- HARPSpost - Until the ends of time (hopefully)
The steps to load the S2D data are described in the HARPS DRS manual <https://www.eso.org/sci/facilities/lasilla/instruments/harps/doc/DRS.pdf>
_. The summary is:
- Construct the wavelength solution & correct from BERV
- Load instrumental drift
- Construct flux noises:
- Table 10 of `the user manual <https://www.eso.org/sci/facilities/lasilla/instruments/harps/doc/manual/HARPS-UserManual2.4.pdf>`_ gives max RON of 7.07 for red detector
- Noise = sqrt(obj + sky + n*dark*expTime + nBinY*ron^2)
User parameters:
Currently there are no HARPS-specific parameters
Note: Check the User parameters of the parent classes for further customization options of SBART
Source code in src/ASTRA/Instruments/HARPS.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
build_HARPS_wavelengths(hdr)
Compute the wavelength solution to this given spectra (EQ 4.1 of DRS manual) Convert from air wavelenbgths to vacuum
Source code in src/ASTRA/Instruments/HARPS.py
find_files(file_name)
Find the CCF and S2D files and BIS files, which should be stored inside the same folder
Source code in src/ASTRA/Instruments/HARPS.py
load_ccf_data()
Load the necessarfy CCF data from the file!
Source code in src/ASTRA/Instruments/HARPS.py
load_old_DRS_S2D()
Loads the spectra
Returns
Source code in src/ASTRA/Instruments/HARPS.py
load_telemetry_info(header)
Loads (at least) the following keywords:
- relative humidity
- ambient temperature, in Celsius
- airmass
- Detector
Parameters
header