-
Notifications
You must be signed in to change notification settings - Fork 24
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
Bard14 Spectra #439
Bard14 Spectra #439
Conversation
https://docs.astropy.org/en/stable/io/fits/index.html Not sure how to read in a folder into data for python to read. Looking up ideas of converting fits and png files into csv data then ingesting them (via loop) |
You can use the pre-existing google sheet. Check out lines 8-13 in this script: scripts/spectra_convert/convert_bard14_spectra.py |
Is this the link to the sheet you mean? "https://bdnyc.s3.amazonaws.com/SpeX/Prism/" It's broken/non existent to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed, use the google sheet.
# Ingest SPECTRAL TYPES, loop through data | ||
ingest_spectra(db, | ||
sources = "Source", | ||
spectrum= "Spectrum", | ||
original_spectrum= "Original Spectrum", | ||
regimes = "regime", | ||
telescope= "telescope", | ||
instrument= "instrument", | ||
mode= "mode", | ||
observation_date= "observation date", | ||
spectrum_comments= "spectrum comments", | ||
spectrum_reference= "spectrum reference", | ||
ra= "ra", | ||
dec= "dec", | ||
aperture= "aperture", | ||
raise_error=True, | ||
search_db= True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this particular case, since we are updating the spectra entries and not adding entirely new ones, we can't use this function.
# Ingest SPECTRAL TYPES, loop through data | |
ingest_spectra(db, | |
sources = "Source", | |
spectrum= "Spectrum", | |
original_spectrum= "Original Spectrum", | |
regimes = "regime", | |
telescope= "telescope", | |
instrument= "instrument", | |
mode= "mode", | |
observation_date= "observation date", | |
spectrum_comments= "spectrum comments", | |
spectrum_reference= "spectrum reference", | |
ra= "ra", | |
dec= "dec", | |
aperture= "aperture", | |
raise_error=True, | |
search_db= True, | |
) |
Instead of using the
Do this row-by-row inside the loop. |
updating_spectra(db) | ||
|
||
with db.engine.begin() as conn: | ||
for entry in update_all_spectra: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an extra loop. You already have the loop starting on line 38.
regime_value = entry["regime"] | ||
telescope_value = entry["telescope"] | ||
instrument_value = entry["instrument"] | ||
mode_value = entry["mode"] | ||
observation_date_value = entry["observation date"] | ||
spectrum_comments_value = entry["spectrum comments"] | ||
spectrum_reference_value = entry["spectrum reference"] | ||
ra_value = entry["ra"] | ||
dec_value = entry["dec"] | ||
aperture_value = entry["aperture"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only fields that need updating are the spectrum and original_spectrum so you don't need any of these other fields.
regime_value = entry["regime"] | |
telescope_value = entry["telescope"] | |
instrument_value = entry["instrument"] | |
mode_value = entry["mode"] | |
observation_date_value = entry["observation date"] | |
spectrum_comments_value = entry["spectrum comments"] | |
spectrum_reference_value = entry["spectrum reference"] | |
ra_value = entry["ra"] | |
dec_value = entry["dec"] | |
aperture_value = entry["aperture"] | |
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.regime == regime_value)\ | ||
.values(regime = regime_value)) | ||
|
||
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.telescope == telescope_value)\ | ||
.values(telescope = telescope_value)) | ||
|
||
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.instrument == instrument_value)\ | ||
.values(instrument = instrument_value)) | ||
|
||
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.mode == mode_value)\ | ||
.values(mode = mode_value)) | ||
|
||
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.observation_date == observation_date_value)\ | ||
.values(observation_date = observation_date_value)) | ||
|
||
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.comments == spectrum_comments_value)\ | ||
.values(comments = spectrum_comments_value)) | ||
|
||
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.reference == spectrum_reference_value)\ | ||
.values(reference = spectrum_reference_value)) | ||
|
||
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.ra == ra_value)\ | ||
.values(ra = ra_value)) | ||
|
||
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.dec == dec_value)\ | ||
.values(dec = dec_value)) | ||
|
||
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.aperture == aperture_value)\ | ||
.values(aperture = aperture_value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These fields don't need updating.
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.regime == regime_value)\ | |
.values(regime = regime_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.telescope == telescope_value)\ | |
.values(telescope = telescope_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.instrument == instrument_value)\ | |
.values(instrument = instrument_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.mode == mode_value)\ | |
.values(mode = mode_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.observation_date == observation_date_value)\ | |
.values(observation_date = observation_date_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.comments == spectrum_comments_value)\ | |
.values(comments = spectrum_comments_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.reference == spectrum_reference_value)\ | |
.values(reference = spectrum_reference_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.ra == ra_value)\ | |
.values(ra = ra_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.dec == dec_value)\ | |
.values(dec = dec_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.aperture == aperture_value)\ | |
.values(aperture = aperture_value)) | |
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.source == source_value)\ | ||
.values(source = source_value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.source == source_value)\ | |
.values(source = source_value)) | |
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.source == source_value)\ | |
.values(spectrum = spectrum_value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the magic sauce. Study this command. You'll need another command like this to update the original_spectrum
field.
|
||
#Loop through data and update spectra | ||
#def updating_spectra(db): | ||
# for row in bard14_table[0:19]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the right way to do the loop.
# for row in bard14_table[0:19]: | |
# for row in bard14_table[0:19]: |
#updating_spectra(db) | ||
|
||
with db.engine.begin() as conn: | ||
for entry in update_all_spectra: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work. update_all_spectra
is the name of the function....it's not a list or table which you can loop over.
for entry in update_all_spectra: | |
for entry in update_all_spectra: |
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.original_spectrum == source_value)\ | ||
.values(original_spectrum = original_spectrum_value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not quite right. It's trying to find spectra files that are set to the source name.
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.original_spectrum == source_value)\ | |
.values(original_spectrum = original_spectrum_value)) | |
conn.execute(db.Spectra.update()\ | |
.where(db.Spectra.c.source == source_value)\ | |
.values(original_spectrum = original_spectrum_value)) |
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.c.source == source_value)\ | ||
.values(spectrum = spectrum_value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you added the _table
bit. The text here needs to correspond exactly to the name of the table you're trying to modify.
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.c.source == source_value)\ | |
.values(spectrum = spectrum_value)) | |
conn.execute(db.Spectra.update()\ | |
.where(db.Spectra.c.source == source_value)\ | |
.values(spectrum = spectrum_value)) |
conn.execute(db.Spectra_table.update()\ | ||
.where(db.Spectra_table.spectrum == spectrum_value)\ | ||
.values(spectrum = spectrum_value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this. The code on 69-71 updates the spectrum field.
conn.execute(db.Spectra_table.update()\ | |
.where(db.Spectra_table.spectrum == spectrum_value)\ | |
.values(spectrum = spectrum_value)) |
Once you get the loop working, I also want to check that the spectra links are valid. Here's some code to get you started.
|
|
||
|
||
# The website is up if the status code is 200 (checking validity of links) | ||
request_response = requests.head(spectrum_value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the line which actually checks if the URL is valid. It currently only checks the spectrum_value
URL. It is not checking the original_spectrum
.
msg = f"Link invalid:{spectrum_value}" | ||
raise SimpleError(msg) | ||
|
||
if status_code != 200: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This status_code
corresponds to the spectrum_value
link, not the original_spectrum_value
link.
status_code = (request_response1.status_code) | ||
status_code = (request_response2.status_code) | ||
|
||
if status_code != 200: | ||
msg = f"Link invalid:{spectrum_value}" | ||
msg2 = f"Link invalid:{original_spectrum_value}" | ||
raise SimpleError(msg, msg2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this code only checks the original spectrum and not the spectrum. line 55 overwrites the status_code
variable in line 54. You need two different variable names. and you need to check them both.
Will be ingesting converted spectra from bard14.
Info from issue:
"Spectra (17) converted in #365. Now we need to upload and ingest.
bard14.zip
Filenames have spaces in it. Not sure if that will be thing or not.
Spectra uploaded to: https://bdnyc.s3.amazonaws.com/SpeX/Prism/
AWS converted spaces to plus signs ('+') in the filenames."
Link to relevant issue: Closes #366
For data ingests: