-
Notifications
You must be signed in to change notification settings - Fork 25
Convert and ingest WISE-1810 #644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d4f1666
Convert and ingest WISE-1810
ying2212 b9c29d1
add more header info on fits file
ying2212 0eadf32
update on ingesting script
ying2212 3793ca4
remove gitignore and SAVEDB=TRUE
ying2212 8318d02
clean script
ying2212 c44cfb2
fix wavelength range
ying2212 fb464e4
add descriptions on instrument and telescope table
ying2212 93abe85
update FITS URL link
ying2212 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,3 @@ | |
| *.egg-info | ||
| build/ | ||
| simple/version.py | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import logging | ||
| from astrodb_utils import load_astrodb, AstroDBError | ||
| from astrodb_utils.instruments import ingest_instrument | ||
| from simple import REFERENCE_TABLES | ||
| from simple.utils.spectra import ingest_spectrum | ||
| from datetime import datetime | ||
|
|
||
| # set up logging for ASTRODB | ||
| astrodb_utils_logger = logging.getLogger("astrodb_utils") | ||
| astrodb_utils_logger.setLevel(logging.INFO) | ||
|
|
||
| # set up logging for this ingest script | ||
| logger = logging.getLogger("astrodb_utils.WISE_1810") | ||
| logger.setLevel(logging.INFO) | ||
|
|
||
| # Load Database | ||
| recreate_db = True | ||
| save_db = True | ||
|
|
||
| SCHEMA_PATH = "simple/schema.yaml" | ||
| db = load_astrodb( | ||
| "SIMPLE.sqlite", | ||
| recreatedb=recreate_db, | ||
| reference_tables=REFERENCE_TABLES, | ||
| felis_schema=SCHEMA_PATH | ||
| ) | ||
|
|
||
| # Ingest Instruments ---- | ||
| def add_instrument(): | ||
| """ | ||
| Telescope: GTC (existed) | ||
| Instrument: EMIR (ingestion needed) | ||
| """ | ||
| try: | ||
| ingest_instrument( | ||
| db, | ||
| telescope="GTC", | ||
| instrument="EMIR", | ||
| mode="Missing", | ||
| raise_error=True | ||
| ) | ||
| print ("Instrument added successfully") | ||
|
|
||
|
|
||
| except AstroDBError as e: | ||
| logger.error(f"Error adding instruments: {e}") | ||
|
|
||
| # convert obs date format | ||
| format_str = "%Y-%m-%d %H:%M:%S0000" | ||
|
|
||
| # same sources with different instruments and FITS file | ||
| spectra_data = [{ | ||
| "access_url": "https://bdnyc.s3.us-east-1.amazonaws.com/WISE1810m10_OB0001_R1000R_06Sept2020.fits", | ||
| "regime": "optical", | ||
| "instrument": 'OSIRIS', | ||
| "observation_date": datetime.strptime("2020-09-06 00:00:000000", format_str) | ||
| }, | ||
| { | ||
| "access_url": "https://bdnyc.s3.us-east-1.amazonaws.com/data_target_WISE1810_comb_Jun2021_YJ_STD_bb.fits", | ||
| "regime": "nir", | ||
| "instrument": 'EMIR', | ||
| "observation_date":datetime.strptime("2021-06-01 00:00:000000", format_str) | ||
| } | ||
| ] | ||
|
|
||
| # Ingest Spectra ---- | ||
| def add_spectra(): | ||
| for data in spectra_data: | ||
| try: | ||
| ingest_spectrum( | ||
| db, | ||
| source="CWISEP J181006.00-101001.1", | ||
| spectrum=data["access_url"], | ||
| regime=data["regime"], | ||
| mode="Missing", | ||
| telescope="GTC", | ||
| instrument=data["instrument"], | ||
| obs_date=data["observation_date"], | ||
| reference="Lodi22" | ||
| ) | ||
| logger.info(f"Successfully ingested spectrum for CWISEP J181006.00-101001.1 with {data['instrument']}") | ||
| except AstroDBError as e: | ||
| logger.error(f"Error ingesting spectrum: {e}") | ||
|
|
||
| # Run ingestion function | ||
| add_instrument() | ||
| add_spectra() | ||
|
|
||
| if save_db: | ||
| db.save_database(directory="data/") | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import astropy.units as u | ||
| from astropy.io.fits import getheader, Header | ||
| from astropy.io import fits | ||
| from astrodb_utils.spectra import check_spectrum_plottable | ||
| from astrodb_utils.fits import add_wavelength_keywords | ||
| from specutils import Spectrum1D | ||
| import numpy as np | ||
| from astroquery.simbad import Simbad | ||
| import os | ||
|
|
||
|
|
||
| file= ["/Users/guanying/SIMPLE_Archive/SIMPLE-db/scripts/spectra_convert/data_target_WISE1810_comb_Jun2021_YJ_STD_bb.txt", | ||
| "/Users/guanying/SIMPLE_Archive/SIMPLE-db/scripts/spectra_convert/WISE1810m10_OB0001_R1000R_06Sept2020.txt"] | ||
|
|
||
| for filename in file: | ||
|
|
||
| # Read the data, there are 2 columns: wavelength and flux | ||
| data = np.loadtxt(filename, comments="#") | ||
| if "data_target_" in filename: | ||
| print("Reading", filename) | ||
|
|
||
| # select the range limit from tested file handle_WISE1810_txt.ipynb | ||
| wave = data[224:1380, 0] * u.AA | ||
| flux = data[224:1380, 1] * (u.erg / u.cm**2 / u.s / u.AA) | ||
|
|
||
| # create spectrum object | ||
| spectrum = Spectrum1D(spectral_axis=wave, flux=flux) | ||
|
|
||
| # convert spectrum | ||
| header = Header() | ||
| header.set('DATE-OBS', "2021-06-01T00:00:00") | ||
| header.set('INSTRUME', "EMIR") | ||
|
|
||
|
|
||
| else: | ||
| print(f"Reading {filename}\n") | ||
|
|
||
| wave = data[:1870, 0] * u.AA | ||
| flux = data[:1870, 1] * (u.erg / u.cm**2 / u.s / u.AA) | ||
|
|
||
| # create spectrum object | ||
| spectrum = Spectrum1D(spectral_axis=wave, flux=flux) | ||
|
|
||
| # convert spectrum | ||
| header = Header() | ||
| header.set('DATE-OBS', "2020-09-06T00:00:00") | ||
| header.set('INSTRUME', "OSIRIS") | ||
|
|
||
|
|
||
| # --- modify the following header to both spectrum --- ## | ||
| header.set('OBJECT', "CWISEP J181006.00-101001.1") | ||
| header.set('BUNIT', "erg / (cm2 s Angstrom)") | ||
| header.set('TELESCOP', "GTC") | ||
| header.set('VOREF', "2022A&A...663A..84L") | ||
| header.set('TITLE', "Physical properties and trigonometric distance of the peculiar dwarf WISE J181005.5 101002.3") | ||
| header.set("AUTHOR", "N. Lodieu, et al.") | ||
| header.set("CONTRIB1", "Guan Ying Goh, converted to SIMPLE format") | ||
|
|
||
|
|
||
| # get RA and DEC from Simbad | ||
| try: | ||
| result = Simbad.query_object("CWISEP J181006.00-101001.1") | ||
| header["RA_TARG"] = result[0]["ra"] | ||
| header["DEC_TARG"] = result[0]["dec"] | ||
| except Exception as e: | ||
| print(f"Error getting ra/deg: {e}") | ||
|
|
||
| header.set('RA_TARG', 272.52575) # got from simbad | ||
| header.set('DEC_TARG', -10.16675) | ||
|
|
||
| spectrum.meta["header"] = header | ||
|
|
||
| # add Spectrum to FITS file | ||
| output_file = os.path.splitext(filename)[0] + ".fits" | ||
| spectrum.write(output_file, format="tabular-fits", overwrite=True) | ||
| print(f"Wrote to fits format") | ||
|
|
||
| output_dir = os.path.dirname(output_file) | ||
| new_files = os.listdir(output_dir) | ||
| new_files = [f for f in new_files if f.endswith('.fits')] | ||
|
|
||
| # check header and spectrum | ||
| for file in new_files: | ||
| new_file_path = os.path.join(output_dir, file) | ||
| spectrum = Spectrum1D.read(new_file_path, format="tabular-fits") | ||
|
|
||
| header = spectrum.meta["header"] | ||
| add_wavelength_keywords(header, spectrum.spectral_axis) | ||
| spectrum.meta["header"] = header | ||
| spectrum.write(new_file_path, format="tabular-fits", overwrite=True) | ||
|
|
||
| if check_spectrum_plottable(spectrum, show_plot=True): | ||
| print(f"{file} is plottable.") |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.