|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Uploading imagery" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": null, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "from rasterfoundry.api import API\n", |
| 17 | + "from rasterfoundry.models.upload import Upload\n", |
| 18 | + "refresh_token = '<your refresh token>'\n", |
| 19 | + "api = API(refresh_token=refresh_token)" |
| 20 | + ] |
| 21 | + }, |
| 22 | + { |
| 23 | + "cell_type": "markdown", |
| 24 | + "metadata": {}, |
| 25 | + "source": [ |
| 26 | + "The python client makes it easy to upload imagery to Raster Foundry\n", |
| 27 | + "from a variety of sources. There are three ways Raster Foundry can\n", |
| 28 | + "import data -- from local files, from S3, or from the Planet Labs API.\n", |
| 29 | + "\n", |
| 30 | + "This notebook will walk through creating uploads from local files.\n", |
| 31 | + "\n", |
| 32 | + "You'll need to make sure that Raster Foundry has permission to read from\n", |
| 33 | + "the bucket. This is easy using the `aws` module:" |
| 34 | + ] |
| 35 | + }, |
| 36 | + { |
| 37 | + "cell_type": "code", |
| 38 | + "execution_count": null, |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [], |
| 41 | + "source": [ |
| 42 | + "from rasterfoundry.aws import s3\n", |
| 43 | + "bucket_name = '<your bucket name here>'\n", |
| 44 | + "s3.authorize_bucket(bucket_name)" |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "cell_type": "markdown", |
| 49 | + "metadata": {}, |
| 50 | + "source": [ |
| 51 | + "You'll also need a little bit more information about the upload you're planning:\n", |
| 52 | + "\n", |
| 53 | + "- the path to your data (as a glob string or as a list)\n", |
| 54 | + "- the id of the datasource to link the upload to\n", |
| 55 | + "- your organization id\n", |
| 56 | + "- optionally a project id\n", |
| 57 | + "\n", |
| 58 | + "For this example, I'll use the UAV 3 Band datasource. You can browse more\n", |
| 59 | + "datasources in the Raster Foundry web application under `Imports`." |
| 60 | + ] |
| 61 | + }, |
| 62 | + { |
| 63 | + "cell_type": "code", |
| 64 | + "execution_count": null, |
| 65 | + "metadata": { |
| 66 | + "collapsed": true |
| 67 | + }, |
| 68 | + "outputs": [], |
| 69 | + "source": [ |
| 70 | + "# id for UAV 3 Band datasource\n", |
| 71 | + "datasource_id = 'c14c8e97-ba85-4677-ac9c-069cfef1f0b1'\n", |
| 72 | + "source_files = 'path/to/data/*.tif'\n", |
| 73 | + "# or:\n", |
| 74 | + "# source_files = ['path1', 'path2', 'path3', ...]" |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "markdown", |
| 79 | + "metadata": {}, |
| 80 | + "source": [ |
| 81 | + "Fill in your organization id below and desired S3 bucket and prefix below (you can just reuse `bucket_name` if you used it above):" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "code", |
| 86 | + "execution_count": null, |
| 87 | + "metadata": { |
| 88 | + "collapsed": true |
| 89 | + }, |
| 90 | + "outputs": [], |
| 91 | + "source": [ |
| 92 | + "organization_id = ''\n", |
| 93 | + "s3_bucket = '' or bucket_name\n", |
| 94 | + "s3_prefix = 'raster-foundry-imagery'" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "markdown", |
| 99 | + "metadata": {}, |
| 100 | + "source": [ |
| 101 | + "If you leave `dry_run=True`, this won't actually upload the files to S3. This is useful if they're already there, or if you're just experimenting. If you'd like to upload the files to S3, either remove `dry_run` or set it to `False`." |
| 102 | + ] |
| 103 | + }, |
| 104 | + { |
| 105 | + "cell_type": "code", |
| 106 | + "execution_count": null, |
| 107 | + "metadata": {}, |
| 108 | + "outputs": [], |
| 109 | + "source": [ |
| 110 | + "uc = Upload.upload_create_from_files(\n", |
| 111 | + " datasource=datasource_id,\n", |
| 112 | + " organization=organization_id,\n", |
| 113 | + " paths_to_tifs=source_files,\n", |
| 114 | + " dest_bucket=s3_bucket,\n", |
| 115 | + " dest_prefix=s3_prefix,\n", |
| 116 | + " dry_run=True\n", |
| 117 | + ")\n", |
| 118 | + "uc" |
| 119 | + ] |
| 120 | + }, |
| 121 | + { |
| 122 | + "cell_type": "markdown", |
| 123 | + "metadata": {}, |
| 124 | + "source": [ |
| 125 | + "You can then `POST` your upload to kick off processing:" |
| 126 | + ] |
| 127 | + }, |
| 128 | + { |
| 129 | + "cell_type": "code", |
| 130 | + "execution_count": null, |
| 131 | + "metadata": {}, |
| 132 | + "outputs": [], |
| 133 | + "source": [ |
| 134 | + "Upload.create(api, uc)" |
| 135 | + ] |
| 136 | + } |
| 137 | + ], |
| 138 | + "metadata": { |
| 139 | + "kernelspec": { |
| 140 | + "display_name": "Python 2", |
| 141 | + "language": "python", |
| 142 | + "name": "python2" |
| 143 | + }, |
| 144 | + "language_info": { |
| 145 | + "codemirror_mode": { |
| 146 | + "name": "ipython", |
| 147 | + "version": 2 |
| 148 | + }, |
| 149 | + "file_extension": ".py", |
| 150 | + "mimetype": "text/x-python", |
| 151 | + "name": "python", |
| 152 | + "nbconvert_exporter": "python", |
| 153 | + "pygments_lexer": "ipython2", |
| 154 | + "version": "2.7.12" |
| 155 | + } |
| 156 | + }, |
| 157 | + "nbformat": 4, |
| 158 | + "nbformat_minor": 2 |
| 159 | +} |
0 commit comments