<jupyter_start><jupyter_text>Reading data into Astropy Tables Objectives - Read ASCII files with a defined format - Learn basic operations with `astropy.tables` - Ingest header information - VOTables  Reading dataOur first task with python was to read a `csv` file using `np.loadtxt()`.That function has few properties to define the dlimiter of the columns, skip rows, read commented lines, convert values while reading, etc.However, the result is an array, without the information of the metadata that file may have included (name, units, ...).Astropy offers a ascii reader that improves many of these steps while provides templates to read common ascii files in astronomy.<jupyter_code>from astropy.io import ascii
# Read a sample file: sources.dat<jupyter_output><empty_output><jupyter_text>Automatically, read has identified the header and the format of each column. The result is a `Table` object, and that brings some additional properties.<jupyter_code># Show the info of the data read

# Get the name of the columns

# Get just the values of a particular column

# get the first element<jupyter_output><empty_output><jupyter_text>Astropy [can read a variety of formats](http://astropy.readthedocs.org/en/stable/io/ascii/index.htmlsupported-formats) easily.The following example uses a quite<jupyter_code># Read the data from the source
table = ascii.read("ftp://cdsarc.u-strasbg.fr/pub/cats/VII/253/snrs.dat",
                   readme="ftp://cdsarc.u-strasbg.fr/pub/cats/VII/253/ReadMe")
# See the stats of the table

# If we want to see the first 10 entries

# the units are also stored, we can extract them too

# Adding values of different columns

# adding values of different columns but being aware of column units

# Create a new column in the table

# Show table's new column 

# add a description to the new column

# Now it does show the values

# Using numpy to calculate the sin of the RA

# Let's change the units...

# does the sin now works?<jupyter_output><empty_output><jupyter_text>Properties when readingthe reading of the table has many properties, let's imagine the following easy example:<jupyter_code>weather_data = """
# Country = Finland
# City = Helsinki
# Longitud = 24.9375
# Latitud = 60.170833
# Week = 32
# Year = 2015
day, precip, type
Mon,1.5,rain
Tues,,
Wed,1.1,snow
Thur,2.3,rain
Fri,0.2,
Sat,1.1,snow
Sun,5.4,snow
"""
# Read the table

# Blank values are interpreted by default as bad/missing values

# Let's define missing values for the columns we want:

# Use filled to show the value filled.

# We can see the meta as a dictionary, but not as key, value pairs

# To get it the header as a table<jupyter_output><empty_output><jupyter_text>When the values are not empty, then the keyword `fill_values` on `read` has [to be used](http://astropy.readthedocs.org/en/stable/io/ascii/read.htmlbad-or-missing-values).  Reading VOTablesVOTables are an special type of tables which should be self-consistent and can be tied to a particular scheme.This mean the file will contain where the data comes from (and which query produced it) and the properties for each field, making it easier to ingest by a machine.<jupyter_code>from astropy.io.votable import parse_single_table
# Read the example table from HELIO (hfc_ar.xml)

# See the fields of the table

# extract one  (NOAA_NUMBER) or all of the columns

# Show the data

# See the mask

# Shee the whole array.

# Convert the table to an astropy table

# See the table

# Different results because quantities are not 

# And it can also be converted to other units<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07334076965978807, 'fraction_numerical': 0.011154489682097044, 'mean_word_length': 4.476335877862596, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '81085', 'license': 'MIT', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1043, 'n_words': 466, 'path': '07-Tables/reading_tables.ipynb', 'repo_name': 'OpenAstronomy/workshop_sunpy_astropy', 'size': '3586'}