How do we define a Quantity and which parts does it have?
from astropy import units as u
# Define a quantity length
# print it
# Type of quantity
# Type of unit
# Quantity
# value
# unit
# information
Quantities can be converted to other units systems or factors by using to()
# Convert it to: km, lyr
We can do arithmetic operations when the quantities have the compatible units:
# arithmetic with distances
Quantities can also be combined, for example to measure speed
# calculate a speed
# decompose it
from astropy.units import imperial
Something strange? Check what deffinition of pint astropy is using.
#1
#2
#3
Many units are compositions of others, for example, one could create new combinationes for ease of use:
# create a composite unit
# and in the imperial system
and others are already a composition:
# what can be converted from s-1?
# or Jules?
# Unity of R
Sometime we get no units quantitites
# no units
What happen if we add a number to this?
# arithmetic with no units
# final value of a no unit quantity
Some conversions are not done by a conversion factor as between miles and kilometers, for example converting between wavelength and frequency.
# converting spectral quantities
# but doing it right
Other built-in equivalencies are:
parallax()
dopplr_radio
, doppler_optical
, doppler_relativistic
)# finding the equivalencies
# but also using other systems
# Printing values with different formats
Quantities can also be applied to arrays
# different ways of defining a quantity for a single value
# now with lists
# and arrays
# and its arithmetics
# angles are smart!
To work nicely with matplotlib we need to do as follows:
# allowing for plotting
from astropy.visualization import quantity_support
quantity_support()
# loading matplotlib
%matplotlib inline
from matplotlib import pyplot as plt
# Ploting the previous array
We want to have functions that contain the information of the untis, and with them we can be sure that we will be always have the right result.
# Create a function for the Kinetic energy
# run with and without units
#4
# run it for some values
# on Mars:
Some times we want to create our own units:
# Create units for a laugh scale
#5