Package: cdspyreadme
ReadMe Generator Python libraryThe cdspyreadme library is a Python package dedicated for authors who want to submit data in VizieR or AAS.The package builts ReadMe, standardized tables (in ASCII aligned format) or MRT tables from tables which
can be in different formats (CSV, votable, FITS, astropy table, MRT)by G.Landais (CDS) 24 june 2016RequirementsThe cdspyreadme library works with Python3 and requires :astropynumpyNotes: for large tables, we recommend to use the C- anafile packageAnafile download:http://cdsarc.unistra.fr/ftp/sw/anafile.tar.gzAnafile documentation:http://cdsarc.unistra.fr/doc/anafile.htxInstallpython3 setup.py install --userExamplesimportcdspyreadmetablemaker=cdspyreadme.CDSTablesMaker()# add a tabletable=tablemaker.addTable("table.csv",description="my CSV table")# write table in CDS-ASCII aligned format (required)tablemaker.writeCDSTables()# Customize ReadMe outputtablemaker.title="catalogue title"tablemaker.author='G.Landais'tablemaker.date=2020tablemaker.abstract="This is my abstract..."tablemaker.more_description="Additional information of the data context."tablemaker.putRef("II/246","2mass catalogue")tablemaker.putRef("http://...","external link")# Print ReadMetablemaker.makeReadMe()# Save ReadMe into a filewithopen("ReadMe","w")asfd:tablemaker.makeReadMe(out=fd)add astropy tablefromastropy.tableimportTableimportcdspyreadmeastropy_table=Table([(1.4845,1.4835,-1.234),(24.5,18.2401,23.426),('HD100','HD101',None)],names=['ra','dec','name'])tablemaker=cdspyreadme.CDSTablesMaker()tablemaker.addTable(astropy_table,name="table1")# add an other local table (in VOTable)table2=Table.read("table.vot")tablemaker.addTable(table2,name="table2")tablemaker.writeCDSTables()tablemaker.makeReadMe()use astropy Masked Column to remove values according criteriafromastropy.tableimportTable,MaskedColumnimportcdspyreadmetablemaker=cdspyreadme.CDSTablesMaker()csv=Table.read("table.csv")csv.columns[0]=MaskedColumn(csv.columns[0],mask=[(val>10)forvalincsv.columns[0]])tablemaker.addTable(csv,name="data.cds")tablemaker.writeCDSTables()tablemaker.makeReadMe()Sexagesimal columnsFlag sexagesimal columns in ReadMe.The method transforms string columns (ie: ra_sexa, de_sexa) in columns RAh, Ram, RAs, DEsign, DEd, DEm, DEs.fromastropy.tableimportTableimportcdspyreadmetablemaker=cdspyreadme.CDSTablesMaker()csv=Table.read("table.csv")table=tablemaker.addTable(csv,name="data.cds")ra=table.get_column("ra_sexa")ra.setSexaRa()de=table.get_column("dec_sexa")de.setSexaDe()tablemaker.writeCDSTables()tablemaker.makeReadMe()add ASCII aligned tablefromastropy.tableimportTableimportcdspyreadmetablemaker=cdspyreadme.CDSTablesMaker()ascii=cdspyreadme.CDSAsciiTable("table.ascii","table1",description="ascii table")table=tablemaker.addTable(ascii)tablemaker.writeCDSTables()tablemaker.makeReadMe()MRT exampleThe following example builds MRT table from a CSV tablefromastropy.tableimportTableimportcdspyreadmetablemaker=cdspyreadme.CDSTablesMaker()tablemaker.title="catalogue title"tablemaker.author='G.Landais'csv=Table.read("table.csv")# rename columnscolra=csv["ra"]colra.name="RAdeg"colra.description="Right ascension"colra.unit='deg'...table=tablemaker.addTable(ascii,name='table.mrt',description='csv file')tablemaker.toMRT()update column...table=tablemaker.addTable(...)column=table.get_column("ra")# modify formatcolumn.set_format("F10.6")# modify name and descriptioncolumn.name="raj2000"column.description="right ascension in ICRS"tablemaker.writeCDSTables()tablemaker.makeReadMe()FITS updateHow to add columns description using TCOMMx cards -fromastropy.ioimportfitsfromastropy.tableimportTableimportcdspyreadmetab=Table.read("catalogue.fits")fitstable=fits.open("catalogue.fits")hdu=fitstable[1]# update description from FITS headerforiinrange(len(tab.columns)):tab.columns[i].description=hdu.header["TCOMM"+str(i+1)]fits.close()tablemaker=cdspyreadme.CDSTablesMaker()table=tablemaker.addTable(tab)tablemaker=cdspyreadme.CDSTablesMaker()table=tablemaker.addTable(tab)tablemaker.writeCDSTables()