This repository was archived by the owner on Dec 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Add convenience functions and example notebook for datasource CRUD #67
Merged
aaronxsu
merged 5 commits into
develop
from
feature/asu/add-convenience-funcs-and-example-notebooks
Sep 27, 2018
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
abdffa3
Start on datasources
aaronxsu eb22872
Make progress on datasource
aaronxsu ffad9d9
Finish datasource crud funcs and notebook
aaronxsu 6383c64
Update datasource notebook
aaronxsu 19d6dca
Update spec version and function calls
aaronxsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Datasources" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\n", | ||
"sys.path.append('/path/to/raster-foundry-python-client')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from rasterfoundry.api import API\n", | ||
"from rasterfoundry.models.datasource import Datasource\n", | ||
"refresh_token = '<refresh_token>'\n", | ||
"api = API(refresh_token=refresh_token)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## List datasources" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"api.get_datasources()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Create datasource bands" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"band_one = Datasource.create_datasource_band('red', '0', 100.0)\n", | ||
"band_two = Datasource.create_datasource_band('green', '1', 200.0)\n", | ||
"band_three = Datasource.create_datasource_band('blue', '2', 300.0)\n", | ||
"bands = [band_one, band_two, band_three]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Add a new datasource" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"new_datasource = Datasource.create(api, 'Test Datasource 1', bands)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Get datasource by ID" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"new_datasource_back = api.get_datasource_by_id(new_datasource.id)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Update a datasource" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"new_datasource_back.name = new_datasource_back.name + ' updated'\n", | ||
"datasource_dict = vars(new_datasource_back)['_Model__dict']\n", | ||
"Datasource.update(api, new_datasource_back.id, datasource_dict)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Delete a datasource" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"Datasource.delete(api, new_datasource_back.id)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"""A Datasource is a source of data a scene uses""" | ||
|
||
|
||
class Datasource(object): | ||
"""A Raster Foundry datasource""" | ||
|
||
def __repr__(self): | ||
return '<Datasource - {}>'.format(self.name) | ||
|
||
def __init__(self, datasource, api): | ||
"""Instantiate a new Datasource | ||
|
||
Args: | ||
datasource (Datasource): generated Datasource object from specification | ||
api (API): api used to make requests on behalf of a datasource | ||
""" | ||
self._datasource = datasource | ||
self.api = api | ||
|
||
# A few things we care about | ||
self.name = datasource.name | ||
self.id = datasource.id | ||
|
||
@classmethod | ||
def create_datasource_band(cls, name, number, wavelength): | ||
"""Create a datasource band | ||
|
||
Args: | ||
name (str): name of band, e.g. 'read', 'blue', 'infrared', etc. | ||
number (str): band number | ||
wavelength (str): wavelength | ||
|
||
Returns: | ||
dict: a band definition of a datasource band | ||
""" | ||
return dict( | ||
name=name, | ||
number=number, | ||
wavelength=wavelength | ||
) | ||
|
||
@classmethod | ||
def create(cls, api, name, bands, visibility='PRIVATE', extras={}): | ||
"""Post an upload to Raster Foundry for processing | ||
|
||
Args: | ||
api (API): API to use for requests | ||
name (str): name of datasource | ||
bands (array): an array of create_datasource_band | ||
visibility (str): datasource visibility, 'PRIVATE' by default | ||
extras (dict): additional related information for a datasource, {} by default | ||
|
||
Returns: | ||
Datasource: created datasource object in Raster Foundry | ||
""" | ||
datasource_created = dict( | ||
name=name, | ||
bands=bands, | ||
visibility=visibility, | ||
extras=extras, | ||
composites={ | ||
'natural': { | ||
'label': 'Default', | ||
'value': { | ||
'redBand': 0, | ||
'greenBand': 1, | ||
'blueBand': 2 | ||
} | ||
} | ||
} | ||
) | ||
return api.client.Datasources.post_datasources(datasource=datasource_created).result() | ||
|
||
@classmethod | ||
def update(cls, api, datasource_id, datasource): | ||
return api.client.Datasources.put_datasources_datasourceID( | ||
datasourceID=datasource_id, datasource=datasource).result() | ||
|
||
@classmethod | ||
def delete(cls, api, datasource_id): | ||
return api.client.Datasources.delete_datasources_datasourceID( | ||
datasourceID=datasource_id).result() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For user's who've
pip install
ed, this won't be necessary, since pip will have put the library in their path. For users in development, if they've donescripts/update
and are in the resulting virtualenv, it also won't be necessary, since that script installsrasterfoundry
into the virtualenv. So this cell can be removed.