{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "7919 is a prime number\n" ] } ], "source": [ "# example of importing a module \n", "# here, we want the method factorial\n", "# from the library called math\n", "from math import factorial\n", "\n", "# perform an inefficient prime number test\n", "# \n", "# Wilson's theorum \n", "# http://mathworld.wolfram.com/WilsonsTheorem.html\n", "# states that p is a prime number \n", "# iff (p-1)! == -1, mod p\n", "\n", "# test number\n", "p = 7919\n", "\n", "# calculate the factorial\n", "p1_fact = factorial(p-1)\n", "\n", "# do the comparison in modulo p\n", "is_prime = (p1_fact % p == -1 % p)\n", "\n", "if is_prime:\n", " print p,\"is a prime number\"\n", "else:\n", " print p,\"is not a prime number\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As an example of data masking, consider the QA mask in the [MODIS Leaf Area Index (LAI)](https://lpdaac.usgs.gov/products/modis_products_table/leaf_area_index_fraction_of_photosynthetically_active_radiation/8_day_l4_global_1km/mod15a2) product:\n", "\n", "\n", "
Bit number | \n", "Parameter Name | \n", "Bit combination | \n", "Interpretation | \n", "
0 | \n", "MODLAND_QC bits | \n", "0 | \n", "Good quality (main algorithm with or without saturation) | \n", "
\n", " | \n", " | 1 | \n", "Other Quality (back-up algorithm or fill values) | \n", "
1 | \n", "Sensor | \n", "0 | \n", "Terra | \n", "
\n", " | \n", " | 1 | \n", "Aqua | \n", "
2 | \n", "DeadDetector | \n", "0 | \n", "Detectors apparently fine for up to 50% of channels | \n", "
\n", " | \n", " | 1 | \n", "Dead detectors caused >50% adjacent detector retrieval | \n", "
3-4 | \n", "CloudState | \n", "00 | \n", "Significant clouds NOT present (clear) | \n", "
\n", " | \n", " | 01 | \n", "Significant clouds WERE present | \n", "
\n", " | \n", " | 10 | \n", "Mixed cloud present on pixel | \n", "
\n", " | \n", " | 11 | \n", "Cloud state not defined (assumed clear) | \n", "
5-7 | \n", "CF_QC | \n", "000 | \n", "Main (RT) method used (best result possible (no saturation)) | \n", "
\n", " | \n", " | 001 | \n", "Main (RT) method used with saturation. (usable) | \n", "
\n", " | \n", " | 010 | \n", "Main (RT) method failed due to bad geometry (empirical algorithm used) | \n", "
\n", " | \n", " | 010 | \n", "Main (RT) method failed due to problems other than geometry (empirical algorithm used) | \n", "
\n", " | \n", " | 010 | \n", "Pixel not produced at all. | \n", "