In [1]:
from astropy import units as u
In [2]:
# Define a quantity length
# print it
In [3]:
# Type of quantity
In [4]:
# Type of unit
In [5]:
# Quantity
In [6]:
# value
In [7]:
# unit
In [8]:
# information
Quantities can be converted to other units systems or factors by using to()
In [9]:
# Convert it to: km, lyr
We can do arithmetic operations when the quantities have the compatible units:
In [10]:
# arithmetic with distances
Quantities can also be combined, for example to measure speed
In [11]:
# calculate a speed
In [12]:
# decompose it
In [13]:
#1
In [14]:
#2
In [15]:
#3
In [16]:
# create a composite unit
In [17]:
# and in the imperial system
and others are already a composition:
In [18]:
# what can be converted from s-1?
In [19]:
# or Jules?
In [20]:
# Unity of R
Sometime we get no units quantitites
In [21]:
# no units
What happen if we add a number to this?
In [22]:
# arithmetic with no units
In [23]:
# final value of a no unit quantity
In [24]:
# converting spectral quantities
In [25]:
# but doing it right
Other built-in equivalencies are:
parallax()
dopplr_radio
, doppler_optical
, doppler_relativistic
)
In [26]:
# finding the equivalencies
In [27]:
# but also using other systems
In [28]:
# Printing values with different formats
In [29]:
# different ways of defining a quantity for a single value
In [30]:
# now with lists
# and arrays
# and its arithmetics
In [31]:
# angles are smart!
In [32]:
# allowing for plotting
from astropy.visualization import quantity_support
quantity_support()
# loading matplotlib
%matplotlib inline
from matplotlib import pyplot as plt
In [33]:
# Ploting the previous array
In [34]:
# Create a function for the Kinetic energy
In [35]:
# run with and without units
In [36]:
#4
In [37]:
# run it for some values
In [38]:
# on Mars:
In [39]:
# Create units for a laugh scale
In [40]:
#5