Skip to content

Commit

Permalink
Initial commit of all files
Browse files Browse the repository at this point in the history
  • Loading branch information
dwest77a committed Aug 19, 2024
0 parents commit a34b9c8
Show file tree
Hide file tree
Showing 8 changed files with 3,902 additions and 0 deletions.
31 changes: 31 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
BSD 3-Clause License

Copyright (c) 2023-2024, Centre of Environmental Data Analysis Developers,
Scientific and Technical Facilities Council (STFC),
UK Research and Innovation (UKRI).
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or other
materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# DataPoint package

A package to be installed into Jaspy that enables the use of CEDA search and cloud data services:
- Search the CEDA STAC catalog for relevant data.
- Port the data into an Xarray object from multiple sources.
1 change: 1 addition & 0 deletions datapoint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .core import DataPoint
11 changes: 11 additions & 0 deletions datapoint/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

class DataPoint:

def __init__(self):
pass

def search(self, **kwargs):
return None

def to_xarray(self, **kwargs):
return None
135 changes: 135 additions & 0 deletions demo/datapoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CEDA DataPoint - Demonstration\n",
"\n",
"The CEDA DataPoint module wraps both the ``pystac_client`` and ``xarray`` packages into a single container for searching and accessing data. This notebook shows how methods function in DataPoint."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"from datapoint import DataPoint\n",
"\n",
"client = DataPoint() # All public connection kwargs are known by default for CEDA"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"# Same as normal for pystac_client\n",
"\n",
"for coll in client.get_collections():\n",
" print(f\"{coll.id}: {coll.description}\")\n",
"\n",
"# Return a new client with a specified collection to search for - or results from pystac_client? (Could load lazily?)\n",
"sentinel2_ard = client.get_collection('sentinel2_ard')\n",
"\n",
"# Make this a function or similar.\n",
"sentinel2_ard.extent.spatial.bboxes"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"# Returns a new datapoint.SearchResult object. Inheritance for DataPoint, SearchResult from a general object type.\n",
"item_search = client.search(\n",
" collections=['sentinel2_ard'],\n",
" datetime=\"2023-01-01/2023-02-28\",\n",
" max_items=10,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"items = list(item_search.items())\n",
"items"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"# Make all the properties into actual class properties?\n",
"for item in items:\n",
" print(item.properties[\"start_datetime\"], item.properties[\"end_datetime\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"# Useful method for matching to catalog\n",
"item_search.url_with_parameters()\n",
"item_search.get_dois() # List item DOIs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"# Assemble xarray and other datasets\n",
"item_search.get_datasets()\n",
"\n",
"# Could have datasets from multiple sources in the same Xarray object?"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit a34b9c8

Please sign in to comment.