From 5d2aa55ee5b6a3ca5358b0aad5931fbc0abe1505 Mon Sep 17 00:00:00 2001 From: lesliech1004 Date: Mon, 21 Jul 2025 11:51:52 -0400 Subject: [PATCH 1/3] Ingest code for calamari samples' ages Only ingests ages for starts from Deac14.119 and non-GaiaEDR3 publications. --- .../calamari_samples/calamari_data.csv | 65 ++++ .../calamari_samples/calamari_refs.csv | 35 +++ .../calamari_samples/ingest_calamari_ages.py | 297 ++++++++++++++++++ 3 files changed, 397 insertions(+) create mode 100644 scripts/ingests/calamari_samples/calamari_data.csv create mode 100644 scripts/ingests/calamari_samples/calamari_refs.csv create mode 100644 scripts/ingests/calamari_samples/ingest_calamari_ages.py diff --git a/scripts/ingests/calamari_samples/calamari_data.csv b/scripts/ingests/calamari_samples/calamari_data.csv new file mode 100644 index 000000000..686ef11bb --- /dev/null +++ b/scripts/ingests/calamari_samples/calamari_data.csv @@ -0,0 +1,65 @@ +Object,Primary,RA,Dec,SpT_Secondary,SpT_Primary,d_Primary (pc),Separation (arcsec),Proj_Sep (AU),Age (Gyr),Ref,Parallax (mas),ePlx +2MASS J00193275+4018576,LP 192-58,4.8859931,40.3151441,L2,K7,55.21 $\pm$ 0.11,58.5,3990,0.3-10,"1, 2",18.1127,0.0358 +2MASS J00302476+2244492,BD+21 55,7.6042199,22.7461537,L0.5,K2,37.91 $\pm$ 0.14,117.1,3970,0.5-10,"1, 2",26.3748,0.0965 +HD 3651 B,HD 3651,9.829614,21.254559,T7.5,K0.5V,11.14 $\pm$ 0.01,43,480,0.7-4.7,"1, 2, 8, 9, 23",89.7891,0.0581 +HD 4113 C,HD 4113,10.8025,-37.9826306,T9,G5V+M1V,41.92 $\pm$ 0.09,0.535,22,3-6,27,23.8531,0.0536 +HD 4747 B,HD 4747,12.361505,-23.212463,L/T,G8/K0V,18.85 $\pm$ 0.01,0.61,10,0.9-3.7,18,53.0526,0.0282 +ULAS J014016.91+015054.7,BD+01 299,25.071311,1.8484382,T5,K5,38.56 $\pm$ 0.03,31,35-45,6.5-13.5,"3, 12",25.93338328,0.019936247 +2MASS J01591078+3312313,HD 12051,29.7959843,33.207192,L6,G9V,24.77 $\pm$ 0.02,52.1,1300,2.2-10.2,"1, 2",40.3763,0.0425 +HD 13724 B,HD 13724,33.086156,-46.816377,T4,G3/5V,43.48 $\pm$ 0.06,0.24,26.3,0.05-1.5,26,23,0.03 +2MASS J02233667+5240066,HD 14647,35.902796,52.668514,L1.5,F5,80.41 $\pm$ 0.46,47.7,3300,0.5-2.4,2,12.43641025,0.07154321 +2MASS J02355993-2331205,HD 16270,39.00019195,-23.52224277,L1,K2.5Vk,21.22 $\pm$ 0.02,11.95,250,<1,"1, 3",47.1279,0.0475 +HD 19467 B,HD 19467,46.827,-13.762028,T5.5,G3V,32.03 $\pm$ 0.02,1.6,51,4-10,13,31.21913928,0.023966862 +HIP 21152 B,HIP 21152,68.019917,5.409944,L/T,F5V,43.21 $\pm$ 0.05,408,17.5,0.65-0.85,"1, 29",, +HD 33632 Ab,HD 33632 Aa,78.3208,37.2808,L9.5,F8V,26.39 $\pm$ 0.02,0.75,20,1.2-4.5,19,37.8953,0.0263 +2MASS J05394952+525352,HD 37216,84.9566683,52.8992533,L5,G5V,28.08 $\pm$ 0.04,27,753,1.1-9.3,"1, 2",35.6141,0.0464 +2MASS J06135342+1514062,HD 253662,93.4725944,15.234332,L0.5,G8IV,86.46 $\pm$ 0.34,20.1,$>$ 1252,$<$ 10,"1, 2",11.5667,0.0461 +AB Pic B,AB Pic,94.804162,-58.055611,L1,K1V,50.14 $\pm$ 0.03,5.5,250-270,0.03,"1, 16, 23",19.9452,0.0124 +2MASS J06324849+5053351,LSPM J0632+5053,98.202075,50.893106,L1.5,G2,82.58 $\pm$ 0.13,47.4,4499,0.2-10,2,12.10950754,0.019127956 +2MASS J06462756+7935045,HD 46588,101.6121946,79.5818179,L9,F7V,18.21 $\pm$ 0.04,79.2,1420,1.3-4.3,"1, 2",54.9292,0.1076 +HD 47197 B,HD 47197,102.339167,43.759194,L4,F5V,41.47 $\pm$ 0.05,0.8,43,0.26-0.79,"1, 15",24.1155,0.0318 +2MASS J07580132-2538587,HD 65486,119.5073205,-25.6508698,T4.5,K4Vk,18.48 $\pm$ 0.01,88,1630,0.3-2.8,"1, 2",54.1012,0.0386 +eta Cnc B,eta Cnc,128.132502,20.449967,L3.5,K3III,97.48 $\pm$ 0.83,2.2-3.5,154,15000,"1, 17",10.258,0.088 +HD 72946 B,HD 72946,128.963611,6.62277,L5,G8V,25.87 $\pm$ 0.08,6.5,10,1-2,"1, 28",, +2MASS J10221489+4114266,HD 89744,155.5623583,41.2457764,L0,F7V,38.68 $\pm$ 0.11,2460,63,1.5-3,"1, 2, 23",25.8537,0.0716 +2MASS J11102921-2925186,CD-28 8692,167.621714,-29.4221669,L2,K5V,39.79 $\pm$ 0.07,50.8,2026,9.5-13.5,"1, 25",25.1329,0.0417 +2MASS J12173646+1427119,HD 106888,184.4015804,14.4531479,L1,F8,67.18 $\pm$ 0.57,38.1,2170,0.3-2.5,"1, 4",14.8863,0.1274 +WISE J124332.17+600126.6,BD+60 1417,190.88386,60.023957,L8$\gamma$,K0,44.96 $\pm$ 0.03,37,1662,0.01-0.15,11,22.24367115,0.013506583 +2MASS J13005061+4214473,BD+42 2363,195.2084201,42.246548,L1,K6V,44.15 $\pm$ 0.06,132.8,5640,0.3-10,"1, 2",22.6476,0.0297 +GJ 499 C,GJ 499 AB,196.420872,20.7779818,L4,K5+M4,19.65 $\pm$ 0.02,516,9708,3-5,"1, 5",50.9035,0.0435 +2MASS J13204427+0409045,HD 116012,200.1820776,4.1522243,L5,K0V,30.31 $\pm$ 0.046,516,9708,12-14,"1, 5",32.9938,0.0504 +ULAS J13300249+0914321,TYC 892-36-1,202.5102524,9.2422718,L2,K-type,246.85 $\pm$ 2.80,260.4,...,0.2-1.5,"1, 4",4.0511,0.0464 +2MASS J13324530+7459441,BD+75 510,203.188635,74.995628,L2,K8,35.40 $\pm$ 0.01,38.3,1364,0.2-1.4,5,28.2493,0.0117 +HD 118865 B,HD 118865,204.9323213,1.0766982,T5,F7V,60.80 $\pm$ 0.20,148,9200,1.5-4.9,"1, 2",16.4485,0.0554 +2MASS J14165987+5006258,HD 125141,214.2474598,50.1080132,L4,G5,47.11 $\pm$ 0.06,570,...,8.5-11,"1, 34",21.2259,0.0256 +ULAS J142320.79+011638.2,HD 126053,215.8371027,1.276492,T8,G1.5V,17.44 $\pm$ 0.01,152.8,2630,2.3-14.4,"1, 33",57.3445,0.0362 +2MASS J14284235-4628393,CD-45 9206,217.1761684,-46.4784943,T4.5,K7Vk,24.07 $\pm$ 0.02,377.3,9000,1-5,"1, 7",41.5387,0.0424 +HD 130948 BC,HD 130948,222.566667,23.911611,L4+L4,G2V,18.20 $\pm$ 0.01,2.64,46.5,0.4-0.9,"20, 21",54.9502,0.0343 +HD 130948 C,HD 130948,222.566667,23.911611,L4,G2V,18.20 $\pm$ 0.01,2.64,46.5,0.4-0.9,"20, 21",54.9502,0.0343 +HD 130948 B,HD 130948,222.566667,23.911611,L4,G2V,18.20 $\pm$ 0.01,2.64,46.5,0.4-0.9,"20, 21",54.9502,0.0343 +GJ 570 D,GJ 570,224.3175381,-21.3712191,T7,K4V,5.88 $\pm$ 0.002,261.7,1525,2-10,"1, 10, 23",170.0112,0.0851 +ULAS J150457.65+053800.8,BD+06 2986,226.2388579,5.632459,T6,K8V,19.02 $\pm$ 0.02,63.8,1230,$>$ 1.6,"1, 2",52.5873,0.0668 +2MASS J15232263+3014562,* eta CrB,230.8449168,30.2481943,L8,G2V+G2V,17.86 $\pm$ 0.25,195.3,3635,3-5,6,55.98,0.78 +2MASS J17262235-0502110,* 47 Oph,261.59315,-5.0364,L5.5,F3V*,32.27 $\pm$ 0.16,294.1,1890,1.6-1.9,2,30.98630848,0.15813722 +2MASS J18005854+1505198,HD 164507,270.2436883,15.08842874,L1,G5IV,45.44 $\pm$ 0.07,25.5,1136,3-4,"1, 25",22.0086,0.0363 +2MASS J19073307+3015304,V* V478 Lyr,286.8884528,30.258925,L1,G6V,27.12 $\pm$ 0.02,17,...,11.5-13.5,1,36.8771,0.0259 +HR 7672 B,HR 7672,301.025833,17.070278,L4,G0V,17.77 $\pm$ 0.01,0.79,14,1-3,"1, 22",56.2693,0.0433 +HD 203030 B,HD 203030,319.74572,26.22948,L7.5,K0V,39.29 $\pm$ 0.09,11,487,0.13-0.4,"1, 2, 6, 23",25.4488,0.061 +2MASS J21442847+1446077,V* HN Peg,326.1198745,14.7683382,T2.5,G0V$+$,18.13 $\pm$ 0.02,42.9,795,0.1-0.5,"1, 8, 23",55.1631,0.0608 +ε Indi Ba,ε Indi A,331.0767776,-56.793953,T1.5+T6,K5V,3.64 $\pm$ 0.003,,1459,0.8-2.0,"1, 14, 23",274.8048,0.2494 +2MASS J22461844+3319304,BD+32 4510,341.576865,33.325119,L1.5,K2*,64.68 $\pm$ 3.23,16,1040,0.1-10,2,15.45979861,0.81259197 +CatWISE J005635.48-240401.9,HIP 4417,14.1478506,-24.0672083,L8,K0,67.60 $\pm$ 0.08,102,6924,...,"1, 24",14.7937,0.0168 +CatWISE J030005.73-062218.6,BPS CS 22963-0014,45.0238923,-6.371848,L9,K7,67.13 $\pm$ 0.08,63,4200,...,"1, 24",14.8971,0.0168 +CatWISE J055909.00-384219.8,HD 40781,89.787502,-38.7055027,L4,G0V,60.65 $\pm$ 1.30,54.5,3259,$<$ 1,"1, 24",16.4877,0.3623 +CatWISE J065752.45+163350.2,HD 51400,104.46857,16.563966,L6,G5,37.08 $\pm$ 0.78,64,2254,...,"1, 24",26.9694,0.5771 +CatWISE J085131.24-603056.2,PM J08515-6029,132.8801846,-60.5156128,L3,K7,30.93 $\pm$ 0.01,95.3,2948,$<$ 1,"1, 24",32.3313,0.0137 +CatWISE J133427.70-273053.1,HD 117987,203.61543,-27.514766,L0,K3V,36.95 $\pm$ 0.46,50,1772,...,"1, 24",27.0633,0.3387 +CatWISE J183207.94-540943.3,HD 170573,278.03311,-54.162028,T7,K4.5Vk,19.12 $\pm$ 0.01,619.3,11843,9-13.5,"1, 24",52.2903,0.0223 +2MASS J00250365+4759191,HD 2057,6.2669728,47.9877566,L4+L4,F8,54.01 $\pm$ 0.40,210,8800,$<$ 1,32,18.5162,0.1365 +HD 8291 B,HD 8291,20.5708829,3.522572,L1+T3,G5V,50.38 $\pm$ 0.35,44.9,2570,0.5-10,"1, 2",19.8488,0.1403 +Gl 337 CD,Gl 337,138.0584919,14.9956706,L8.5+L7.5,G8V+K1V,20.35 $\pm$ 0.14,43,881,0.6-3.4,"1, 31",49.1493,0.3467 +Gl 337 C,Gl 337,138.0584919,14.9956706,L8.5,G8V+K1V,20.35 $\pm$ 0.14,43,881,0.6-3.4,"1, 31",49.1493,0.3467 +Gl 337 D,Gl 337,138.0584919,14.9956706,L7.5,G8V+K1V,20.35 $\pm$ 0.14,43,881,0.6-3.4,"1, 31",49.1493,0.3467 +Gl 417 BC,Gl 417,168.1055653,35.8028953,L4.5+L6,G2,22.65 $\pm$ 0.02,90,2000,0.08-0.3,"1, 30",44.1428,0.0383 +Gl 417 B,Gl 417,168.1055653,35.8028953,L4.5,G2,22.65 $\pm$ 0.02,90,2000,0.08-0.3,"1, 30",44.1428,0.0383 +Gl 417 C,Gl 417,168.1055653,35.8028953,L6,G2,22.65 $\pm$ 0.02,90,2000,0.08-0.3,"1, 30",44.1428,0.0383 \ No newline at end of file diff --git a/scripts/ingests/calamari_samples/calamari_refs.csv b/scripts/ingests/calamari_samples/calamari_refs.csv new file mode 100644 index 000000000..7f3fab0ab --- /dev/null +++ b/scripts/ingests/calamari_samples/calamari_refs.csv @@ -0,0 +1,35 @@ +ID,Ref,ADS,Link +1,Gaia DR3,https://www.aanda.org/articles/aa/full_html/2021/05/aa39734-20/aa39734-20.html,https://doi.org/10.1051/0004-6361/202039657 +2,Deacon+2014,https://ui.adsabs.harvard.edu/abs/2014ApJ...792..119D/abstract, +3,Burningham+2018,https://ui.adsabs.harvard.edu/abs/2018RNAAS...2..207B/abstract, +4,Marocco+2017,https://ui.adsabs.harvard.edu/abs/2017MNRAS.470.4885M/abstract, +5,Gomes+2013,https://academic.oup.com/mnras/article/431/3/2745/1079721?login=false,https://doi.org/10.1093/mnras/stt371 +6,Pinfield+2006,https://academic.oup.com/mnras/article/368/3/1281/1024040?login=false,https://doi.org/10.1111/j.1365-2966.2006.10213.x +7,Lodieu+2014,https://www.aanda.org/articles/aa/full_html/2014/09/aa24210-14/aa24210-14.html,https://doi.org/10.1111/j.1365-2966.2006.10213.x +8,Luhman+2007,https://ui.adsabs.harvard.edu/abs/2007ApJ...654..570L/abstract, +9,Mugrauer+2006,https://ui.adsabs.harvard.edu/abs/2006MNRAS.373L..31M/abstract, +10,Burgasser+2000,https://iopscience.iop.org/article/10.1086/312522/pdf, +11,Faherty+2022,https://ui.adsabs.harvard.edu/abs/2021ApJ...923...48F/abstract, +12,Skrzypek+2016,https://ui.adsabs.harvard.edu/abs/2016A%26A...589A..49S/abstract, +13,Crepp+2014,https://ui.adsabs.harvard.edu/abs/2014ApJ...781...29C/abstract, +14,Scholz+2003,https://simbad.u-strasbg.fr/simbad/sim-ref?bibcode=2003A%26A...398L..29S, +15,Metchev+2004,https://iopscience.iop.org/article/10.1086/425410/pdf, +16,Chauvin+2005,https://www.aanda.org/articles/aa/abs/2005/30/aahc231/aahc231.html,https://doi.org/10.1051/0004-6361:200500111 +17,Zhang+2010,https://ui.adsabs.harvard.edu/abs/2010MNRAS.404.1817Z/abstract, +18,Crepp+2016,https://ui.adsabs.harvard.edu/abs/2016ApJ...831..136C/abstract, +19,Currie+2020,, +20,Dupuy+2009,https://iopscience.iop.org/article/10.1088/0004-637X/692/1/729, +21,Potter+2002,https://iopscience.iop.org/article/10.1086/339999, +22,Liu+2002,https://ui.adsabs.harvard.edu/abs/2002ApJ...571..519L/abstract, +23,Faherty+2010,https://iopscience.iop.org/article/10.1088/0004-6256/139/1/176, +24,Rothermich+2024,, +25,Marocco+2020,https://academic.oup.com/mnras/article/494/4/4891/5820239,https://doi.org/10.1093/mnras/staa1007 +26,Rickman+2020,https://www.aanda.org/articles/aa/full_html/2020/03/aa37524-20/aa37524-20.html,https://doi.org/10.1051/0004-6361/202037524 +27,Cheetham+2018,https://ui.adsabs.harvard.edu/abs/2018A%26A...614A..16C/abstract, +28,Maire+2020,https://www.aanda.org/articles/aa/full_html/2020/01/aa37134-19/aa37134-19.html,https://doi.org/10.1051/0004-6361/201937134 +29,Kuzuhara+2022,https://ui.adsabs.harvard.edu/abs/2022ApJ...934L..18K/abstract, +30,Kirkpatrick+2000,https://iopscience.iop.org/article/10.1086/301427, +31,Wilson+2001,https://iopscience.iop.org/article/10.1086/323134, +32,Reid+2006,https://iopscience.iop.org/article/10.1086/505626, +33,Pinfield+2012,https://academic.oup.com/mnras/article/422/3/1922/1040924?login=true,https://doi.org/10.1111/j.1365-2966.2012.20549.x +34,Chiu+2006,https://iopscience.iop.org/article/10.1086/501431, \ No newline at end of file diff --git a/scripts/ingests/calamari_samples/ingest_calamari_ages.py b/scripts/ingests/calamari_samples/ingest_calamari_ages.py new file mode 100644 index 000000000..fc4eae716 --- /dev/null +++ b/scripts/ingests/calamari_samples/ingest_calamari_ages.py @@ -0,0 +1,297 @@ +import sys +import logging +import sqlalchemy +sys.path.append(".") +from astropy.io import ascii +from simple import REFERENCE_TABLES +from astrodb_utils import load_astrodb +from astrodb_utils.sources import ( + find_source_in_db, + ingest_source, + logger, + AstroDBError, + ingest_name +) + +from astrodb_utils.publications import ( + find_publication, +) + +astrodb_utils_logger = logging.getLogger("astrodb_utils") +logger.setLevel(logging.DEBUG) # Set logger to INFO/DEBUG/WARNING/ERROR/CRITICAL level +astrodb_utils_logger.setLevel(logging.DEBUG) + +SAVE_DB = False # save the data files in addition to modifying the .db file +RECREATE_DB = True # recreates the .db file from the data files +SCHEMA_PATH = "simple/schema.yaml" +db = load_astrodb( + "SIMPLE.sqlite", + recreatedb=RECREATE_DB, + reference_tables=REFERENCE_TABLES, + felis_schema=SCHEMA_PATH, +) + +link = ( + "scripts/ingests/calamari_samples/calamari_data.csv" +) +link_2 = ( + "scripts/ingests/calamari_samples/calamari_refs.csv" +) +calamari_table = ascii.read( + link, + format="csv", + data_start=1, + header_start=0, + guess=False, + fast_reader=False, + delimiter=",", +) + +ref_table = ascii.read( + link_2, + format="csv", + data_start=0, + header_start=0, + guess=False, + fast_reader=False, + delimiter=",", +) + +age_ingested = 0 +age_already_exists = 0 +skipped = 0 + +#helper method to retrieve the publication links from calamari_data +def getRef(ref_index): + ref = ref_index.split(',')[0] + ref_link = ref_table[int(ref)]['ADS'] + if 'iopscience' not in ref_link or 'harvard.edu' not in ref_link: + ref_link = ref_table[int(ref)]['Link'] + return ref_link + +#helper method to retrieve the bibcode from a link +def extractADS(link): + start = link.find('abs/')+4 + end = link.find('/abstract') + ads = link[start:end] + ads = ads.replace("%26", "&") + return ads + +#helper method to retrieve the doi from a link +def extractDOI(link): + link = str(link) + if 'iopscience' in link: + start = link.find('article/')+8 + doi = link[start:] + doi = doi.replace("/pdf", "") + else: + start = link.find('doi.org/')+8 + doi=link[start:] + return doi + +def otherReferencesList(ref): + #get all the ids/indexes of the references + ids = ref.split(", ") + result = [] + #for each reference... + for id in ids: + link = ref_table[int(id)]['ADS'] + #if bibcode or doi is not directly in the link... go to Link column + if 'iopscience' not in link or 'harvard.edu' not in link: + link = ref_table[int(id)]['Link'] + #if bibcode is directly in the link + if 'harvard.edu' in link: + bibcode = extractADS(link) + pub_result=find_publication( + db=db, + bibcode=bibcode + ) + if pub_result[0]: + result.append(pub_result[1]) + else: + print(f"Warning: Publication not found for bibcode {bibcode}") + #if doi code is found directly in the link + elif 'iopscience' in link or 'doi.org' in link: + doi=extractDOI(link) + pub_result=find_publication( + db=db, + doi=doi + ) + if pub_result[0]: + result.append(pub_result[1]) + else: + print(f"Warning: Publication not found for doi {doi}") + #use reference name to find reference + else: + reference= ref_table[int(id)]['Ref'] + reference= reference.replace("+", "") + reference=reference[0:4] + reference[-2:] + pub_result=find_publication( + db=db, + reference=reference + ) + if pub_result[0]: + result.append(pub_result[1]) + else: + print(f"Warning: Publication not found for reference {reference}") + #return list of references + return result + +def age_exists(db, source, companion): + exists = False + #check if age exists + age_search = db.search_object( + name = source, + output_table="CompanionParameters", + ) + if len(age_search) > 0: + for row in age_search: + if ((row["companion"] == companion) and (row["parameter"] == "age")): + exists = True + break + + return exists + +def ingest_ages( + db, + source: str, + companion: str, + age: float, + reference: str, + comment: str = None, + upper_error: float = None, + lower_error: float = None, + ): + #check if the age is already in the database + already_in_db = age_exists(db=db, source = source, companion=companion) + #if the age is not in the database... ingest the new age + if not already_in_db: + # Construct data to be added + age_data = [ + { + "source": source, + "companion": companion, + "reference": reference, + "parameter": "age", + "value": age, + "unit": "Gyr", + "comments": comment, + "upper_error": upper_error, + "lower_error": lower_error, + } + ] + logger.debug(f" Data: {age_data}.") + + # Try to add the source to the database + try: + with db.engine.connect() as conn: + conn.execute(db.CompanionParameters.insert().values(age_data)) + conn.commit() + msg = f"Added {age_data}" + logger.info(f"Added {companion} age") + logger.debug(msg) + except sqlalchemy.exc.IntegrityError: + msg = f"Not ingesting {companion} age. Not sure why. \n" + msg2 = f" {age_data} " + logger.warning(msg) + logger.debug(msg2) + return + +def getAge(ageString): + """ + returns: + age: float + upper bound: float + lower bound: float + range: string + """ + age = None + upperBound = None + lowerBound = None + range = None + + if '-' in ageString: + ageRange = ageString.split('-') + age = (float(ageRange[0])+float(ageRange[1]))/2 + upperBound = float(ageRange[1])-age + lowerBound = age-float(ageRange[0]) + range = ageString + elif '$<$ 1' in ageString or '<1' in ageString: + age = 0.7 + upperBound = 0.3 + lowerBound = 0.3 + range = "0.4-1.0" + else: + age = ageString + + return age, upperBound, lowerBound, range + +for row in calamari_table: + references = otherReferencesList(row["Ref"]) + source = row["Object"] + companion = row["Primary"] + ageRow = row["Age (Gyr)"] + + #skip all the weird cases for now... + if '$<$ 10' in ageRow or '$>$ 1.6' in ageRow or '...' in ageRow: + skipped+=1 + continue + + age_results = getAge(ageRow) + age = age_results[0] + upper_error = age_results[1] + lower_error = age_results[2] + comment = age_results[3] + + #all cases with Deac14.119 in references uses this publication for the age. + if("Deac14.119" in references): + age_in_db = age_exists(db = db, + source = source, + companion = companion,) + if not age_in_db: + ingest_ages( + db=db, + source = source, + companion = companion, + age = age, + upper_error=upper_error, + lower_error=lower_error, + reference = "Deac14.119", + comment=comment + ) + age_ingested+=1 + else: + age_already_exists+=1 + + # for cases with 2 references with GaiaEDR3 as one of them, use the other reference + elif len(references) == 2 and 'GaiaEDR3' in references: + references = references.remove('GaiaEDR3') + age_in_db = age_exists(db = db, + source = source, + companion = companion,) + if not age_in_db: + ingest_ages( + db=db, + source = source, + companion = companion, + age = age, + upper_error=upper_error, + lower_error=lower_error, + reference = references, + comment=comment + ) + age_ingested+=1 + else: + age_already_exists+=1 + else: + skipped+=1 + continue + + +logger.info(f"ages ingested:{age_ingested}") # 36 ages ingested +logger.info(f"ages already exists:{age_already_exists}") # 0 due to preexisting data +logger.info(f"ages skpped:{skipped}") # 28 skipped +logger.info(f"total ages:{age_ingested+age_already_exists+ skipped}") # 64 ages total +# WRITE THE JSON FILES +if SAVE_DB: + db.save_database(directory="data/") \ No newline at end of file From 276f05a101ecc65dc445e60e9475ad3eef87a132 Mon Sep 17 00:00:00 2001 From: lesliech1004 Date: Mon, 21 Jul 2025 13:45:11 -0400 Subject: [PATCH 2/3] Debugging --- .../calamari_samples/ingest_calamari_ages.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/ingests/calamari_samples/ingest_calamari_ages.py b/scripts/ingests/calamari_samples/ingest_calamari_ages.py index fc4eae716..7ab15860a 100644 --- a/scripts/ingests/calamari_samples/ingest_calamari_ages.py +++ b/scripts/ingests/calamari_samples/ingest_calamari_ages.py @@ -176,8 +176,8 @@ def ingest_ages( "value": age, "unit": "Gyr", "comments": comment, - "upper_error": upper_error, - "lower_error": lower_error, + "upper_error": "{:.2f}".format(upper_error), + "lower_error": "{:.2f}".format(lower_error), } ] logger.debug(f" Data: {age_data}.") @@ -190,8 +190,9 @@ def ingest_ages( msg = f"Added {age_data}" logger.info(f"Added {companion} age") logger.debug(msg) - except sqlalchemy.exc.IntegrityError: - msg = f"Not ingesting {companion} age. Not sure why. \n" + except sqlalchemy.exc.IntegrityError as e: + msg = f"Not ingesting {companion} age. IntegrityError: {str(e)}" + #msg = f"Not ingesting {companion} age. Not sure why. \n" msg2 = f" {age_data} " logger.warning(msg) logger.debug(msg2) @@ -206,8 +207,8 @@ def getAge(ageString): range: string """ age = None - upperBound = None - lowerBound = None + upperBound = 0.0 + lowerBound = 0.0 range = None if '-' in ageString: From af1385125452e3f8d98c7d1f8712426d3c987fb9 Mon Sep 17 00:00:00 2001 From: lesliech1004 Date: Mon, 21 Jul 2025 14:40:39 -0400 Subject: [PATCH 3/3] Debugging --- .../calamari_samples/ingest_calamari_ages.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/ingests/calamari_samples/ingest_calamari_ages.py b/scripts/ingests/calamari_samples/ingest_calamari_ages.py index 7ab15860a..1335d857d 100644 --- a/scripts/ingests/calamari_samples/ingest_calamari_ages.py +++ b/scripts/ingests/calamari_samples/ingest_calamari_ages.py @@ -137,16 +137,17 @@ def otherReferencesList(ref): #return list of references return result -def age_exists(db, source, companion): +def age_exists(db, companion, reference): exists = False #check if age exists age_search = db.search_object( - name = source, + name = companion, output_table="CompanionParameters", + table_names={'CompanionRelationships':['companion_name']} ) if len(age_search) > 0: for row in age_search: - if ((row["companion"] == companion) and (row["parameter"] == "age")): + if ((row["reference"] == reference) and (row["parameter"] == "age")): exists = True break @@ -163,7 +164,7 @@ def ingest_ages( lower_error: float = None, ): #check if the age is already in the database - already_in_db = age_exists(db=db, source = source, companion=companion) + already_in_db = age_exists(db=db, companion=companion, reference=reference) #if the age is not in the database... ingest the new age if not already_in_db: # Construct data to be added @@ -247,8 +248,8 @@ def getAge(ageString): #all cases with Deac14.119 in references uses this publication for the age. if("Deac14.119" in references): age_in_db = age_exists(db = db, - source = source, - companion = companion,) + companion = companion, + reference="Deac14.119") if not age_in_db: ingest_ages( db=db, @@ -266,10 +267,11 @@ def getAge(ageString): # for cases with 2 references with GaiaEDR3 as one of them, use the other reference elif len(references) == 2 and 'GaiaEDR3' in references: - references = references.remove('GaiaEDR3') + references_copy = references.copy() + references_copy.remove('GaiaEDR3') age_in_db = age_exists(db = db, - source = source, - companion = companion,) + companion = companion, + reference = references_copy[0]) if not age_in_db: ingest_ages( db=db, @@ -278,7 +280,7 @@ def getAge(ageString): age = age, upper_error=upper_error, lower_error=lower_error, - reference = references, + reference = references_copy[0], comment=comment ) age_ingested+=1