├── .DS_Store ├── LICENSE ├── README.md ├── figureset ├── README.md ├── figureset.py ├── figureset.zip ├── macros.tex ├── make_translation.sh ├── test1set.tex ├── translation.csv └── translation.yaml ├── fits └── aasfits.py ├── mrt ├── README.md └── aasmrt.py ├── names ├── aas-names.py └── aas-simbad_tap.py └── tex ├── README.md ├── adsbibparser.py ├── datareview.sh └── doi2ads.py /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AASJournals/Tools/7bfb13b78f3c5da85b3dca37f3ca43fe60b06913/.DS_Store -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tools 2 | Author tools for AAS Journals. 3 | 4 | ``figureset:`` Python script to write out the AASTeX 6 Figure Set markup for online (HTML) figures. 5 | 6 | ``mrt:`` a set of tools for working with the ADS/CDS machine readable table format. 7 | 8 | ``fits:`` tool(s) for inspecting and transforming FITS tables. 9 | 10 | ``names:`` tool(s) for looking up preferred object names in NED and Simbad. 11 | 12 | ``tex:`` tools for working with latex files, data reviewing, bibtex, bibcodes. 13 | -------------------------------------------------------------------------------- /figureset/README.md: -------------------------------------------------------------------------------- 1 | The `figureset.py` script is a simple python3 tool to create figure set markup using a YAML configuration 2 | file (`translation.yaml`) and CSV input translation table. The script assumes each the captions of all the figure set elements are structured the same, but this can be modified in how the CSV translation and YAML files are setup. 3 | 4 | File | Explanation 5 | :--- | :---------- 6 | `figureset.py` | The main scrip run by `> python figureset.py translation.yaml` 7 | `translation.yaml` | Figure set configuration parameters 8 | `translation.csv` | Example CSV input to translation.yaml 9 | `figset.tex` | AASTeX < 6 macros. Add these macros to the header of your main .tex file. 10 | `test1set.tex` | Example Figure Set. Running `> python figureset.py translation.yaml` should produce a file `fig1set.tex` that is identical to `test1set.tex` 11 | `make_translation.sh` | Table parsing script 12 | 13 | -------------------------------------------------------------------------------- /figureset/figureset.py: -------------------------------------------------------------------------------- 1 | 2 | # coding: utf-8 3 | import sys 4 | import csv, yaml 5 | 6 | 7 | # import yaml config 8 | with open(sys.argv[1], "r") as stream: 9 | y = yaml.load(stream, Loader=yaml.FullLoader) 10 | 11 | # open translation table 12 | t = [] 13 | with open(y['translationfile'], "r") as tfile: 14 | treader = csv.reader(tfile) 15 | for row in treader: 16 | t.append(row) 17 | 18 | # pad table rows to same length with strings 19 | lt = max([len(row) for row in t]) 20 | 21 | markup = [] 22 | markup.append("\\figsetstart") 23 | markup.append("\\figsetnum{{{0}}}".format(y['fignum'])) 24 | markup.append("\\figsettitle{{{0}}}".format(y['settitle'])) 25 | markup.append("") 26 | 27 | ft = [] 28 | fn = 1 29 | for i, row in enumerate(t): 30 | if row[1] == ft: 31 | markup.insert(len(markup)-3, "\\figsetplot{{{0}}}".format(row[0])) 32 | else: 33 | if len(row) < lt: 34 | row.extend((lt - len(row)) * [""]) 35 | caption = "" 36 | else: 37 | caption = y['caption'].strip("\n") 38 | markup.append("\\figsetgrpstart") 39 | markup.append("\\figsetgrpnum{{{0}.{1}}}".format(y['fignum'], fn)) 40 | markup.append("\\figsetgrptitle{{{0}}}".format(row[1])) 41 | markup.append("\\figsetplot{{{0}}}".format(row[0])) 42 | markup.append("\\figsetgrpnote{{{0}}}".format(caption.format(*row))) 43 | markup.append("\\figsetgrpend") 44 | markup.append("") 45 | fn = fn + 1 46 | ft = row[1] 47 | 48 | markup.append("\\figsetend") 49 | 50 | # write out 51 | with open('fig{0}set.tex'.format(y['fignum']), mode='w', encoding='utf-8') as ofile: 52 | ofile.write('\n'.join(markup)) 53 | ofile.write('\n') 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /figureset/figureset.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AASJournals/Tools/7bfb13b78f3c5da85b3dca37f3ca43fe60b06913/figureset/figureset.zip -------------------------------------------------------------------------------- /figureset/macros.tex: -------------------------------------------------------------------------------- 1 | %% For manuscripts created with AASTeX < 6.0 2 | %% 3 | %% You can integrate this mark up directly into your ms.tex file 4 | %% by placing the new commands below before your \begin{document} 5 | %% command and everything that follows within the run of text 6 | %% where you want the figure set to appear. 7 | 8 | % FIGSET-MACROS-BEGIN 9 | \newcommand{\noprint}[1]{} 10 | \newcommand{\figsetstart}{{\bf Fig. Set} } 11 | \newcommand{\figsetend}{} 12 | \newcommand{\figsetgrpstart}{} 13 | \newcommand{\figsetgrpend}{} 14 | \newcommand{\figsetnum}[1]{{\bf #1.}} 15 | \newcommand{\figsettitle}[1]{ {\bf #1} } 16 | \newcommand{\figsetgrpnum}[1]{\noprint{#1}} 17 | \newcommand{\figsetgrptitle}[1]{\noprint{#1}} 18 | \newcommand{\figsetplot}[1]{\noprint{#1}} 19 | \newcommand{\figsetgrpnote}[1]{\noprint{#1}} 20 | % FIGSET-MACROS-END 21 | -------------------------------------------------------------------------------- /figureset/make_translation.sh: -------------------------------------------------------------------------------- 1 | # example script to turn datatable into translation table 2 | grep JW datafile1.txt | awk '{print$1".pdf,"$1","$7"\n"$1"rgb.pdf,"$1","$7}' >| translation.csv 3 | -------------------------------------------------------------------------------- /figureset/test1set.tex: -------------------------------------------------------------------------------- 1 | \figsetstart 2 | \figsetnum{1} 3 | \figsettitle{Young Stellar Object Scrapbook} 4 | 5 | \figsetgrpstart 6 | \figsetgrpnum{1.1} 7 | \figsetgrptitle{LkHa823} 8 | \figsetplot{protostar1.pdf} 9 | \figsetgrpnote{LkHa823 is a Class III object and displays forbidden lines, Halpha in emission.} 10 | \figsetgrpend 11 | 12 | \figsetgrpstart 13 | \figsetgrpnum{1.2} 14 | \figsetgrptitle{Ori32-5} 15 | \figsetplot{protostar2a.pdf} 16 | \figsetplot{protostar2b.pdf} 17 | \figsetgrpnote{Ori32-5 is a Class II object and is completely featureless.} 18 | \figsetgrpend 19 | 20 | \figsetgrpstart 21 | \figsetgrpnum{1.3} 22 | \figsetgrptitle{1} 23 | \figsetplot{fig1.ps} 24 | \figsetgrpnote{} 25 | \figsetgrpend 26 | 27 | \figsetgrpstart 28 | \figsetgrpnum{1.4} 29 | \figsetgrptitle{2} 30 | \figsetplot{fig2.ps} 31 | \figsetgrpnote{} 32 | \figsetgrpend 33 | 34 | \figsetgrpstart 35 | \figsetgrpnum{1.5} 36 | \figsetgrptitle{3} 37 | \figsetplot{fig3.ps} 38 | \figsetgrpnote{} 39 | \figsetgrpend 40 | 41 | \figsetgrpstart 42 | \figsetgrpnum{1.6} 43 | \figsetgrptitle{4} 44 | \figsetplot{fig4.ps} 45 | \figsetgrpnote{} 46 | \figsetgrpend 47 | 48 | \figsetgrpstart 49 | \figsetgrpnum{1.7} 50 | \figsetgrptitle{5} 51 | \figsetplot{fig5a.ps} 52 | \figsetplot{fig5b.ps} 53 | \figsetplot{fig5c.ps} 54 | \figsetgrpnote{} 55 | \figsetgrpend 56 | 57 | \figsetend 58 | -------------------------------------------------------------------------------- /figureset/translation.csv: -------------------------------------------------------------------------------- 1 | protostar1.pdf,LkHa823,III,"displays forbidden lines, Halpha in emission." 2 | protostar2a.pdf,Ori32-5,II,"is completely featureless." 3 | protostar2b.pdf,Ori32-5,II 4 | fig1.ps,1 5 | fig2.ps,2 6 | fig3.ps,3 7 | fig4.ps,4 8 | fig5a.ps,5 9 | fig5b.ps,5 10 | fig5c.ps,5 11 | -------------------------------------------------------------------------------- /figureset/translation.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # yaml configuration file for newfigureset.py 3 | # 4 | # the required elements are: 5 | # 6 | # fignum: The figure number of the figure set. 7 | # setttitle: The title for the figure set 8 | # translationfile: A comma delimited translation table (see below) 9 | # caption: A caption string for the set. 10 | # 11 | # The csv translation file must contain a list of files and figure titles, 12 | # one on each row, along with an optional list of attributes for each row: 13 | # 14 | # filename, figure title [, attribute1, attribute2...attributeN] 15 | # 16 | #, e.g., 17 | # 18 | # protostar1.pdf,LkHa823,III,"displays forbidden lines, Halpha in emission." 19 | # protostar2a.pdf,Ori32-5,II,"is completely featureless." 20 | # protostar2b.pdf,Ori32-5,II 21 | # 22 | # to assign multiple figure files to a single figure in the set, give them the 23 | # same figure title, e.g., Ori32-5 above. 24 | # 25 | # the caption is built using a Python3 formatting string to map elements of 26 | # each row of the csv file to caption variable attributes. Given the example 27 | # above a caption string of 28 | # 29 | # caption: {1} is a Class {2} object and {3} 30 | # 31 | # would write captions of 32 | # 33 | # LkHa823 is a Class III object and displays forbidden lines, Halpha in emission. 34 | # Ori32-5 is a Class II object and is completely featureless. 35 | # 36 | # YAML/Python3 notes on caption strings: 37 | # - "{" double escape {{ to pass through LaTeX commands 38 | # - "\" pass through safely 39 | # - YAML string paragraph formatting rules are in effect 40 | # 41 | fignum: 1 42 | settitle: Young Stellar Object Scrapbook 43 | translationfile: "translation.csv" 44 | caption: > 45 | {1} is a Class {2} object and {3} 46 | ... 47 | -------------------------------------------------------------------------------- /fits/aasfits.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | import os, sys 4 | 5 | from astropy.table import Table 6 | 7 | def main(): 8 | """ 9 | Main script for reviewing FITS tables with astropy. 10 | 11 | aasfits.py infile 12 | 13 | Parameters 14 | ---------- 15 | infile : str, a FITS file 16 | options: 17 | data : print data table to terminal 18 | html : open data table in browser 19 | csv : dump data to csv version of input 20 | : if no option given then print astropy table info to terminal 21 | 22 | """ 23 | if len(sys.argv) < 2: 24 | print("") 25 | print("-------------------------------------------------------------------------------") 26 | print(" This toolkit is checking or converting a FITS table. ") 27 | print("") 28 | print(" > aasfits.py infile >") 29 | print("") 30 | print(" options ") 31 | print(" csv : dump data to csv version of input") 32 | print(" data : print data table to terminal") 33 | print(" html : open data table in browser") 34 | print(" info : print table and column") 35 | print(" : if no option given then print basic table info to terminal") 36 | print("-------------------------------------------------------------------------------") 37 | print("") 38 | return 39 | 40 | v = sys.argv[1] 41 | p = len(sys.argv) > 2 and sys.argv[2] or "" 42 | 43 | data = Table.read(v, format="fits", hdu=1) 44 | 45 | print("") 46 | print("-------------------------------------------------------------------------------") 47 | print("aasfits.py checking...") 48 | print("") 49 | print("Type: ",p) 50 | print("File: ",v) 51 | print("Rows: ",len(data)) 52 | print("Cols: ",len(data.colnames)) 53 | print("") 54 | if p == 'html': 55 | data.show_in_browser() 56 | elif p == 'data': 57 | print(data) 58 | elif p == 'csv': 59 | sur, ext = os.path.splitext(v) 60 | data.write(sur+".csv", format="ascii.csv", overwrite=False) 61 | elif p == 'info': 62 | print(data.info) 63 | else: 64 | print("") 65 | 66 | if __name__ == '__main__': 67 | main() 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /mrt/README.md: -------------------------------------------------------------------------------- 1 | The scripts provided here allow you to work with the [AAS](http://journals.aas.org/authors/MRT/ 2 | )/[CDS](http://cds.u-strasbg.fr/doc/catstd.htx 3 | ) machine readable format. 4 | 5 | The simplest way to read the AAS/CDS format with `astropy` is: 6 | 7 | ``` 8 | from astropy.table import Table 9 | data = Table.read("dbf1.txt", format="ascii.cds") 10 | ``` 11 | 12 | File | Explanation 13 | :--- | :---------- 14 | `aasmrt.py` | A python3 script to check, view, or convert the AAS MRT format using [astropy](http://www.astropy.org/). 15 | -------------------------------------------------------------------------------- /mrt/aasmrt.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | import os, sys 4 | 5 | from astropy.table import Table 6 | 7 | def main(): 8 | """ 9 | Main script for processing ADS/CDS MRT files. 10 | 11 | aasmrt.py infile 12 | 13 | Parameters 14 | ---------- 15 | infile : str, an ADS/CDS MRT file 16 | options: 17 | data : print data table to terminal 18 | html : open data table in browser 19 | csv : dump data to csv version of input 20 | : if no option given then print astropy table info to terminal 21 | 22 | """ 23 | if len(sys.argv) < 2: 24 | print("") 25 | print("-------------------------------------------------------------------------------") 26 | print(" This toolkit is checking or converting an AAS/CDS table in astropy. ") 27 | print("") 28 | print(" > aasmrt.py infile >") 29 | print("") 30 | print(" options ") 31 | print(" csv : dump data to csv version of input") 32 | print(" data : print data table to terminal") 33 | print(" html : open data table in browser") 34 | print(" info : print table and column") 35 | print(" : if no option given then print basic table info to terminal") 36 | print("-------------------------------------------------------------------------------") 37 | print("") 38 | return 39 | 40 | v = sys.argv[1] 41 | p = len(sys.argv) > 2 and sys.argv[2] or "" 42 | 43 | data = Table.read(v, format="ascii.cds") 44 | 45 | print("") 46 | print("-------------------------------------------------------------------------------") 47 | print("aasmrt.py checking...") 48 | print("") 49 | print("Type: ",p) 50 | print("File: ",v) 51 | print("Rows: ",len(data)) 52 | print("Cols: ",len(data.colnames)) 53 | print("") 54 | if p == 'html': 55 | data.show_in_browser() 56 | elif p == 'data': 57 | print(data) 58 | elif p == 'csv': 59 | sur, ext = os.path.splitext(v) 60 | data.write(sur+".csv", format="ascii.csv", overwrite=False) 61 | elif p == 'tex': 62 | sur, ext = os.path.splitext(v) 63 | data.write(sur+".tex", format="ascii.aastex", overwrite=False) 64 | elif p == 'info': 65 | print(data.info) 66 | else: 67 | print("") 68 | 69 | if __name__ == '__main__': 70 | main() 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /names/aas-names.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | import os, sys 4 | 5 | from astroquery.ipac.ned import Ned 6 | from astroquery.simbad import Simbad 7 | 8 | def main(): 9 | """ 10 | Main script for validating names with astroquery. 11 | 12 | aas-names.py objectname 13 | 14 | Parameters 15 | ---------- 16 | objectname : str 17 | options: 18 | ned : only print NED object information to terminal 19 | simbad : only print Simbad object information to terminal 20 | show : dump data to terminal 21 | quiet : print tersely to the terminal 22 | csv : dump data to csv version [not implemented] 23 | 24 | : if no option given then summarize object found info to terminal 25 | 26 | """ 27 | if len(sys.argv) < 2: 28 | print("") 29 | print("-------------------------------------------------------------------------------") 30 | print(" This toolkit is for . ") 31 | print("") 32 | print(" > aas-names.py objectname >") 33 | print("") 34 | print(" options ") 35 | print(" ned : print summary NED object information to the terminal") 36 | print(" simbad : print summary Simbad object information to the terminal") 37 | print(" show : dump data to terminal.") 38 | print(" sameAs : dump what the repository thinks the object is called.") 39 | print(" verbose : print verbosely to the terminal.") 40 | print(" csv : dump data to csv version [not implemented]") 41 | print("-------------------------------------------------------------------------------") 42 | print("") 43 | return 44 | 45 | v = sys.argv[1] 46 | p = len(sys.argv) > 2 and sys.argv[2:] or "" 47 | 48 | if 'verbose' in p: 49 | print("") 50 | print("-------------------------------------------------------------------------------") 51 | print("aas-name.py checking...") 52 | print("") 53 | print("Object: ",v) 54 | print("Type: ",p) 55 | print("") 56 | 57 | if 'ned' in p: 58 | try: 59 | neddata = Ned.query_object(v) 60 | except: 61 | # this is slightly wrong. The NED query can return an empty 62 | # result or an error from the server. I'm not clear on why there 63 | # is a difference. 64 | neddata = [] 65 | if len(neddata) > 0: 66 | if 'sameAs' in p: 67 | print(v," sameAs ", neddata[0]['Object Name'], " in NED.") 68 | elif 'verbose' in p: 69 | print("NED Objects: ",len(neddata)) 70 | else: print(len(neddata)) 71 | if 'show' in p: print(neddata) 72 | else: 73 | if 'verbose': 74 | print(v," is not in NED.") 75 | else: 76 | print(0) 77 | elif 'simbad' in p: 78 | try: 79 | simdata = Simbad.query_object(v) 80 | except: 81 | simdata = [] 82 | if simdata is not None: 83 | if 'sameAs' in p: 84 | print(v, " sameAs ", simdata[0]['MAIN_ID'].decode(), "in Simbad.") 85 | elif 'verbose' in p: 86 | print("Simbad Objects: ",len(simdata)) 87 | else: print(len(simdata)) 88 | if 'show' in p: print(simdata) 89 | else: 90 | if 'verbose': 91 | print(v," is not in Simbad.") 92 | else: 93 | print(0) 94 | elif 'csv' in p: 95 | print("not implemented") 96 | # sur, ext = os.path.splitext(v) 97 | # data.write(sur+".csv", format="ascii.csv", overwrite=False) 98 | else: 99 | print("") 100 | 101 | if __name__ == '__main__': 102 | main() 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /names/aas-simbad_tap.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | # Ver: Tue Sep 8 21:30:50 UTC 2020 4 | 5 | # todo 6 | # - overcome 2000 row limit from astroquery 7 | # - add \object tag creation option 8 | # - fix? output byte strings maybe 9 | # - fix "perfect" comparison to remove extra spaces from Input & Simbad names 10 | # - move from astroquery.utils.tap.core to pyvo 11 | 12 | import os, sys 13 | 14 | from astropy.table import Table 15 | from astroquery.utils.tap.core import TapPlus 16 | 17 | 18 | def main(): 19 | """ 20 | Main script for validating names with astroquery. 21 | 22 | simbad-tap.py filename 23 | 24 | Parameters 25 | ---------- 26 | filename : file with 1 column that is a list of object names. no header 27 | options: 28 | stats : print summary stats on exit 29 | nosave : skip saving the output 30 | """ 31 | if len(sys.argv) < 2: 32 | print("") 33 | print("-------------------------------------------------------------------------------") 34 | print(" This toolkit is for . ") 35 | print("") 36 | print(" > simbad-tap.py filename ") 37 | print("") 38 | print(" options ") 39 | print(" stats : dump matching stats to command line.") 40 | print(" nosave : skip saving output.") 41 | print("-------------------------------------------------------------------------------") 42 | print("") 43 | return 44 | 45 | p = len(sys.argv) > 2 and sys.argv[2:] or "" 46 | 47 | verbose = 'verbose' in p and True or False 48 | 49 | # check input 50 | filename = sys.argv[1] 51 | if os.path.isfile(filename): 52 | if verbose: 53 | print ("File {:s} exists".format(filename)) 54 | else: 55 | print ("File does not exist") 56 | return 57 | # check output 58 | ofile = 'simbad-tap-output.csv' 59 | if os.path.isfile(ofile) and ('nosave' not in p): 60 | print ("Ouptut file {:s} exists. Disabling save".format(ofile)) 61 | p.append('nosave') 62 | 63 | 64 | # this is for Simbad which accepts anonymous public uploads for joins 65 | tapurl = "http://simbad.u-strasbg.fr:80/simbad/sim-tap" 66 | simbad = TapPlus(url=tapurl, verbose=verbose) 67 | 68 | # this is the topcat query I wrote from the Simbad ADQL example. 69 | # "sources" the input table name 70 | # "inputnames" is the column of sources with the names 71 | query = "SELECT sources.inputnames AS MyID, ident.id AS SimbadId, basic.coo_bibcode \ 72 | FROM TAP_UPLOAD.sources LEFT OUTER JOIN ident ON ident.id = sources.inputnames \ 73 | LEFT OUTER JOIN basic ON ident.oidref = basic.oid" 74 | 75 | # the data are typically a undelimited list of names with no header line. 76 | # trick is a useless delimiter 77 | sources = Table.read(filename, format="ascii.no_header", delimiter="|", names=["inputnames"]) 78 | 79 | # simbad.upload_table(upload_resource=sources, table_name='sources') 80 | j = simbad.launch_job(query=query, upload_resource=sources, upload_table_name='sources', verbose=verbose) 81 | 82 | r = j.get_results() 83 | 84 | # save if we can 85 | if 'nosave' not in p: 86 | r.write("simbad-tap-output.csv", format="ascii.csv", overwrite=True) 87 | 88 | # simple stats 89 | if 'stats' in p: 90 | print("-------------------------------------------------------------------------------") 91 | print("") 92 | bad = sum(r['simbadid'] == b'') # blank matches == no alias matches 93 | perfect = sum(r['simbadid'] == r['myid']) 94 | good = len(r) # some kind of match. I could check to see MyID == SimbadId 95 | inlen = len(sources) 96 | print('TAP output contained {:d} of the {:d} input rows.'.format(good, inlen)) 97 | print('There were {:d} matches ({:2.1%}) and {:d} unmatched ({:2.1%}).'.format(inlen-bad, (inlen-bad)/inlen, bad, (bad)/inlen)) 98 | print('Of the matches {:d} ({:2.1%}) were exact name matches.'.format(perfect, perfect/(inlen-bad))) 99 | print('The remaining matches were to Simbad aliases ({:d}, {:2.1%}).'.format(inlen-bad-perfect, (inlen-bad-perfect)/(inlen-bad))) 100 | print("") 101 | print("-------------------------------------------------------------------------------") 102 | 103 | 104 | 105 | 106 | if __name__ == '__main__': 107 | main() 108 | -------------------------------------------------------------------------------- /tex/README.md: -------------------------------------------------------------------------------- 1 | The scripts provided here are for parsing author latex files. 2 | 3 | File | Explanation 4 | :--- | :---------- 5 | `adsbibparser.py` | A python3 script try to read a bibtex library and look up ADS bibcodes. 6 | `doi2ads.py` | A python3 script to convert DOIs to ADS bibcodes. 7 | `datareview.sh` | A python3 script to parse author latex files for data, software or other key terms. 8 | -------------------------------------------------------------------------------- /tex/adsbibparser.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | import sys 4 | from pybtex.database.input import bibtex 5 | 6 | def bibclean(bibcode): 7 | URLs = ["http://adsabs.harvard.edu/abs/", 8 | "https://ui.adsabs.harvard.edu/\#abs/", 9 | "http://cdsads.u-strasbg.fr/abs/", 10 | "http://ads.bao.ac.cn/abs/" 11 | ] 12 | for URL in URLs: 13 | if URL in bibcode: bibcode = bibcode.strip(URL) 14 | return bibcode 15 | 16 | def main(): 17 | """ 18 | Main script for processing ADS bibtex 19 | 20 | adsbibparser.py infile 21 | 22 | Parameters 23 | ---------- 24 | infile : str, a bibtex file from ADS 25 | options: 26 | dump : dump all the bibtex keys and ads bibcodes to the screen 27 | find : find the ads bibcode for the key. 28 | 29 | """ 30 | if len(sys.argv) < 2: 31 | print("") 32 | print("-------------------------------------------------------------------------------") 33 | print(" This toolkit is parsing ADS bibtext files") 34 | print("") 35 | print(" > absbibparser.py infile.bib 2: 47 | if sys.argv[2] not in ["dump", "find"]: 48 | doit = "dump" 49 | else: 50 | doit = sys.argv[2] 51 | else: 52 | doit = "dump" 53 | 54 | 55 | #open a bibtex file 56 | parser = bibtex.Parser() 57 | bibdata = parser.parse_file(ifile) 58 | 59 | if doit == "find": 60 | try: 61 | b = bibdata.entries[sys.argv[3]].fields 62 | print(sys.argv[3], bibclean(b["adsurl"])) 63 | except: 64 | print(sys.argv[3], "unknown") 65 | else: 66 | #loop through the individual references 67 | for bib_id in bibdata.entries: 68 | b = bibdata.entries[bib_id].fields 69 | try: 70 | # change these lines to create a SQL insert 71 | bibcode = b["adsurl"] 72 | 73 | print(bib_id, bibclean(bibcode)) 74 | # field may not exist for a reference 75 | except(KeyError): 76 | continue 77 | 78 | 79 | if __name__ == '__main__': 80 | main() 81 | 82 | -------------------------------------------------------------------------------- /tex/datareview.sh: -------------------------------------------------------------------------------- 1 | # datareview.sh 2 | # 3 | # - grep latex source for specific terms 4 | # - create HTML versions of lines for review 5 | # 6 | # LaTeX Source (change as appropriate => vi `which datareview.sh` 7 | # Reviews/new.ms.tex 8 | # 9 | # Dependencies: 10 | # gnu grep : for colors 11 | # ansi2html : to convert ANSI colors to HTML 12 | # pandoc : to convert LaTeX to other output (HTML) 13 | # latexpand : clean up files 14 | # 15 | # Written by AAMN on 2015/02/12 16 | # 2015-02-16 : added pandoc conversion of LaTeX source to HTML 17 | # 2015-02-17 : added documentation; tweaked GNU color codes 18 | # 2015-05-19 : consolidate data review editing to Reviews/ 19 | # 2016-12-02 : added 'suite' to code grep 20 | # 2018-05-01 : added 'framework' because of snoopy 21 | # 2022-01-22 : added latexpand due to eJP requirements 22 | # 23 | ############################################################################## 24 | # gnu grep params 25 | # 26 | # software: 'algorithm\|software\|suite\|code\|program\|package\|ASCL\|github\|pipeline\|routine\|framework' 27 | # data: 'FITS\|DOI\|doi\|epository\|tar\.gz\|upplementa\|figset\|nimation\|ovie\|ideo\|online' 28 | # links: 'http\|ftp\|rsync\|smtp\|ssh\|www\|\\url' 29 | # colors: 30 | # ms=01;31 {Matching string Selected line} 31 | # mc=01;37 {Matching string Context line} 32 | # sl=43 {whole Selected Lines} 33 | # cx=00;30 {whole Context Lines} 34 | # fn=35 {File Name} 35 | # ln=01;35 {Line Number} 36 | # bn=32 {Byte Number} 37 | # se=36 {SEparator} 38 | ############################################################################## 39 | 40 | export GREP_COLORS="ms=01;31:mc=01;37:sl=43:cx=00;30:fn=35:ln=01;35:bn=32:se=36" 41 | 42 | d=${PWD##*/} 43 | 44 | # setup Reviews with Review manuscript version, create web accessible figures 45 | mkdir -p Reviews 46 | wait 47 | 48 | echo "% date := `date "+%Y-%m-%d%n"` " >| Reviews/new.ms.tex ; wait 49 | echo "% editor := August Muench " >> Reviews/new.ms.tex ; wait 50 | echo "% prior version (name) := $1 " >> Reviews/new.ms.tex ; wait 51 | echo "% prior version (timestamp:iso) := `gls -l --time-style=full-iso $1 | awk '{print$6" "$7}'`" >> Reviews/new.ms.tex ; wait 52 | echo "% prior version (hash:MD5) := `md5 $1 | awk '{print$4}'` " >> Reviews/new.ms.tex ; wait 53 | echo "% processing performed := latexpand" >> Reviews/new.ms.tex ; wait 54 | echo "% " >> Reviews/new.ms.tex ; wait 55 | echo " " >> Reviews/new.ms.tex ; wait 56 | 57 | # if meta already exists then assume you had to run dos2unix and copy original meta over 58 | if [[ -e Reviews/meta.txt ]]; then 59 | sed 's/latexpand/latexpand\; dos2unix/g' Reviews/meta.txt >| Reviews/new.ms.tex ; wait 60 | fi 61 | 62 | # if meta.txt doesn't exist assume this is the first pass and save the meta 63 | if [[ ! -e Reviews/meta.txt ]]; then 64 | cp -p Reviews/new.ms.tex Reviews/meta.txt ; wait 65 | fi 66 | 67 | 68 | latexpand $1 >| Reviews/latexpand.tex; wait 69 | latexpand $1 >> Reviews/new.ms.tex; wait 70 | #cat $1 >> Reviews/new.ms.tex 71 | 72 | # grab manuscript related files, ignoring the certain types: tex, pdf 73 | echo $1 | sed 's/\.tex//g' | xargs -n 1 -I {} find . -name "{}.*" | awk '$1!~/\.tex/ && $1!~/\.pdf/' | xargs -n 1 -I {} cp {} Reviews/ 74 | wait 75 | 76 | # make sure to get the input files like tex and bib 77 | cp -p *.bib Reviews/ ; wait 78 | cp -p *.tex Reviews/ ; wait 79 | wait 80 | 81 | # try to find figures and convert to PNGs 82 | # \ls *.eps | sed 's/.eps//g' | xargs -n 1 -I {} sh -c 'echo "converting {}.eps => Reviews/{}.png"; convert {}.eps Reviews/{}.png; wait; ' 83 | \cp -p *.eps Reviews/ ; wait 84 | # \ls *.ps | sed 's/.ps//g' | xargs -n 1 -I {} sh -c 'echo "converting {}.ps => Reviews/{}.png"; convert {}.ps Reviews/{}.png; wait; ' 85 | \cp -p *.ps Reviews/ ; wait 86 | # \ls *.jpg | sed 's/.jpg//g' | xargs -n 1 -I {} sh -c 'echo "converting {}.jpg => Reviews/{}.png"; convert {}.jpg Reviews/{}.png; wait; ' 87 | \cp -p *.jpg Reviews/ ; wait 88 | \cp -p *.jpeg Reviews/ ; wait 89 | # \ls *.png | sed 's/.png//g' | xargs -n 1 -I {} sh -c 'echo "converting {}.png => Reviews/{}.png"; convert {}.png Reviews/{}.png; wait; ' 90 | \cp -p *.png Reviews/ ; wait 91 | # \gfind ./ -maxdepth 1 -iname "f*pdf" -printf '%f\n' | \ 92 | # sed 's/\.pdf//g' | \ 93 | # xargs -n 1 -I {} sh -c 'echo "converting {}.pdf => Reviews/{}.png"; convert {}.pdf Reviews/{}.png; wait;' 94 | \cp -p *.pdf Reviews/ ; wait 95 | wait 96 | 97 | echo 'finished copying files' 98 | 99 | # check for non-ascii characters 100 | if ggrep -P '[^\x00-\x7f]' Reviews/new.ms.tex; then 101 | echo '' 102 | echo '*************************************' 103 | echo '**** non-ascii characters exist *****' 104 | echo '' 105 | ggrep --line-number -P '[^\x00-\x7f]' Reviews/new.ms.tex 106 | echo '' 107 | echo '**** non-ascii characters exist *****' 108 | echo '*************************************' 109 | echo '' 110 | fi 111 | 112 | if ggrep -a -v '^.*$' Reviews/new.ms.tex; then 113 | echo '' 114 | echo '*************************************' 115 | echo '**** non-ascii characters exist *****' 116 | echo '' 117 | ggrep --line-number -a -v '^.*$' Reviews/new.ms.tex 118 | echo '' 119 | echo '**** non-ascii characters exist *****' 120 | echo '*************************************' 121 | echo '' 122 | fi 123 | 124 | echo 'finished checking for bad characters' 125 | 126 | # source 127 | #pandoc -s --verbose Reviews/new.ms.tex -t html5 -o Reviews/ms.html 128 | # wait 129 | # 130 | # echo 'finished pandoc' 131 | 132 | # software 133 | ggrep --text --ignore-case --color=never --line-number --context=2 \ 134 | 'algorithm\|software\|suite\|code\|program\|package\|ASCL\|github\|pipeline\|routine\|framework' \ 135 | Reviews/new.ms.tex >| \ 136 | Reviews/software_review.txt 137 | wait 138 | 139 | ggrep --text --ignore-case --color=always --line-number --context=2 \ 140 | 'algorithm\|software\|suite\|code\|program\|package\|ASCL\|github\|pipeline\|routine\|framework' \ 141 | Reviews/new.ms.tex | \ 142 | ansi2html --scheme=osx --title='Software: '$d --light-background --markup-lines >| \ 143 | Reviews/software_review.html 144 | wait 145 | 146 | # data 147 | ggrep --text --color=never --line-number --context=2 \ 148 | 'FITS\|DOI\|doi\|epository\|tar\.gz\|upplementa\|figset\|nimation\|ovie\|ideo\|online' \ 149 | Reviews/new.ms.tex >| \ 150 | Reviews/data_review.txt 151 | wait 152 | 153 | ggrep --text --color=always --line-number --context=2 \ 154 | 'FITS\|DOI\|doi\|epository\|tar\.gz\|upplementa\|figset\|nimation\|ovie\|ideo\|online' \ 155 | Reviews/new.ms.tex | \ 156 | ansi2html --scheme=osx --title='Data: '$d --light-background >| \ 157 | Reviews/data_review.html 158 | wait 159 | 160 | # links 161 | ggrep --text --ignore-case --color=never --line-number --context=2 \ 162 | 'http\|ftp\|rsync\|smtp\|ssh\|www\|\\url' \ 163 | Reviews/new.ms.tex >| \ 164 | Reviews/links_review.txt 165 | wait 166 | 167 | ggrep --text --ignore-case --color=always --line-number --context=2 \ 168 | 'http\|ftp\|rsync\|smtp\|ssh\|www\|\\url' \ 169 | Reviews/new.ms.tex | \ 170 | ansi2html --linkify --scheme=osx --title='Links: '$d --light-background >| \ 171 | Reviews/links_review.html 172 | wait 173 | 174 | # echo 'opening pandoc file' 175 | # open Reviews/ms.html 176 | # sleep 0.5 177 | 178 | echo 'opening reviews' 179 | open Reviews/links_review.html 180 | sleep 0.5 181 | 182 | echo 'opening reviews' 183 | open Reviews/software_review.html 184 | sleep 0.5 185 | 186 | echo 'opening reviews' 187 | open Reviews/data_review.html 188 | sleep 0.5 189 | 190 | echo 'done with '$d 191 | 192 | -------------------------------------------------------------------------------- /tex/doi2ads.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | # from astropy.table import Table 4 | import sys 5 | import ads 6 | from pprint import pprint 7 | 8 | def doiclean(doi): 9 | prefs = ["doi:", 10 | "https://doi.org/", 11 | "https://dx.doi.org/", 12 | "doi.og", 13 | ] 14 | for pref in prefs: 15 | if pref in doi: doi = doi.strip(pref) 16 | return doi 17 | 18 | 19 | def main(): 20 | """ 21 | Main script for getting bibcodes from ADS 22 | 23 | doi2ads.py doi 24 | 25 | Parameters 26 | ---------- 27 | doi : str, digital object identifier in parsed (non-url) form 28 | options: 29 | dump : dump all the predefined keys 30 | bibcode : find the ads bibcode for the DOI 31 | 32 | 33 | """ 34 | if len(sys.argv) < 2: 35 | print("") 36 | print("-------------------------------------------------------------------------------") 37 | print(" This toolkit is for getting ADS keys from a DOI") 38 | print("") 39 | print(" > doi2ads.py doi 2: 51 | if sys.argv[2] == 'dump': 52 | doit = "dump" 53 | elif sys.argv[2] not in fl: 54 | fl.append(sys.argv[2]) 55 | doit = sys.argv[2] 56 | else: 57 | doit = sys.argv[2] 58 | else: 59 | doit = "bibcode" 60 | 61 | doi = sys.argv[1] 62 | 63 | q = ads.SearchQuery(doi=doiclean(doi), fl=fl) 64 | 65 | for p in q: 66 | p 67 | 68 | if doit == "dump": 69 | pprint(p.__dict__) 70 | else: 71 | pprint(p.__getattribute__(doit)) 72 | 73 | if __name__ == '__main__': 74 | main() 75 | 76 | --------------------------------------------------------------------------------