{ "nbformat_minor": 0, "nbformat": 4, "cells": [ { "source": [ "# Units and Quantities\n", "\n", "## Objectives\n", "\n", "- Use units\n", "- Create functions that accept quantities as arguments\n", "- Create new units" ], "cell_type": "markdown", "metadata": {} }, { "source": [ "## Basics\n", "\n", "How do we define a Quantity and which parts does it have?" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": 1, "cell_type": "code", "source": [ "from astropy import units as u\n" ], "outputs": [], "metadata": { "collapsed": false, "keep": true } }, { "execution_count": 2, "cell_type": "code", "source": [ "# Define a quantity length\n", "# print it\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "execution_count": 3, "cell_type": "code", "source": [ "# Type of quantity\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "execution_count": 4, "cell_type": "code", "source": [ "# Type of unit\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "execution_count": 5, "cell_type": "code", "source": [ "# Quantity\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "execution_count": 6, "cell_type": "code", "source": [ "# value\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "execution_count": 7, "cell_type": "code", "source": [ "# unit\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "execution_count": 8, "cell_type": "code", "source": [ "# information\n" ], "outputs": [], "metadata": { "scrolled": true, "collapsed": false } }, { "source": [ "Quantities can be converted to other units systems or factors by using `to()`" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": 9, "cell_type": "code", "source": [ "# Convert it to: km, lyr\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "We can do arithmetic operations when the quantities have the compatible units:" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": 10, "cell_type": "code", "source": [ "# arithmetic with distances\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "Quantities can also be combined, for example to measure speed" ], "cell_type": "markdown", "metadata": {} }, { "execution_count": 11, "cell_type": "code", "source": [ "# calculate a speed\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "execution_count": 12, "cell_type": "code", "source": [ "# decompose it\n" ], "outputs": [], "metadata": { "collapsed": false } }, { "source": [ "