Skip to content

Commit

Permalink
Merge pull request #58 from hydroshare/57-upgrade-to-pydantic-v2
Browse files Browse the repository at this point in the history
[#57] upgrade to pydantic v2
  • Loading branch information
sblack-usu authored Feb 19, 2024
2 parents 4800e51 + a87444e commit 712cf01
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 80 deletions.
1 change: 1 addition & 0 deletions docs/api/geo_feature_aggregation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:::hsclient.hydroshare.GeoFeatureAggregation
1 change: 1 addition & 0 deletions docs/api/geo_raster_aggregation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:::hsclient.hydroshare.GeoRasterAggregation
1 change: 1 addition & 0 deletions docs/api/netcdf_aggregation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:::hsclient.hydroshare.NetCDFAggregation
1 change: 1 addition & 0 deletions docs/api/time_series_aggregation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:::hsclient.hydroshare.TimeseriesAggregation
8 changes: 7 additions & 1 deletion docs/examples/Aggregation_Data_Object_Operations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"\n",
"\n",
"The following code snippets show examples for how to use the hsclient HydroShare Python Client to load certain aggregation data types to relevant data processing objects to view data properties as well as be able to modify the data. The aggregation data object feature is available for the following HydroShare's content type aggregations:\n",
"\n",
" * Time series\n",
" * Geographic feature\n",
" * Geographic raster\n",
Expand All @@ -24,7 +25,12 @@
"source": [
"## Install the hsclient Python Client\n",
"\n",
"The hsclient Python Client for HydroShare may not be installed by default in your Python environment, so it has to be installed first before you can work with it. Use the following command to install hsclient via the Python Package Index (PyPi)."
"The hsclient Python Client for HydroShare may not be installed by default in your Python environment, so it has to be installed first before you can work with it. Use the following command to install hsclient via the Python Package Index (PyPi). This will install the hsclient as well as all the python packages to work with aggregation data as data processing objects. The following packages will be installed in addition to hsclient:\n",
"\n",
"* pandas\n",
"* fiona\n",
"* rasterio\n",
"* xarray"
],
"metadata": {
"collapsed": false
Expand Down
124 changes: 74 additions & 50 deletions docs/examples/Aggregation_Operations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "HHsuQMMJyms4"
},
"source": [
"# hsclient HydroShare Python Client Resource Aggregation Operation Examples\n",
"\n",
Expand All @@ -13,18 +10,21 @@
"\n",
"\n",
"The following code snippets show examples for how to use the hsclient HydroShare Python Client to manipulate aggregations of known content types in HydroShare. HydroShare's content type aggregations include individual file, fileset, time series, geographic feature, geographic raster, and multidimensional NetCDF."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"metadata": {
"id": "b_Tj5gJx0fRj"
},
"source": [
"## Install the hsclient Python Client\n",
"\n",
"The hsclient Python Client for HydroShare may not be installed by default in your Python environment, so it has to be installed first before you can work with it. Use the following command to install hsclient via the Python Package Index (PyPi)."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -39,14 +39,14 @@
},
{
"cell_type": "markdown",
"metadata": {
"id": "CZNOazcn9-23"
},
"source": [
"## Authenticating with HydroShare\n",
"\n",
"Before you start interacting with resources in HydroShare you will need to authenticate."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -64,16 +64,16 @@
},
{
"cell_type": "markdown",
"metadata": {
"id": "TH3UUihSojIb"
},
"source": [
"## Create a New Empty Resource\n",
"\n",
"A \"resource\" is a container for your content in HydroShare. Think of it as a \"working directory\" into which you are going to organize the code and/or data you are using and want to share. The following code can be used to create a new, empty resource within which you can create content and metadata.\n",
"\n",
"This code creates a new resource in HydroShare. It also creates an in-memory object representation of that resource in your local environment that you can then manipulate with further code."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -96,9 +96,6 @@
},
{
"cell_type": "markdown",
"metadata": {
"id": "rcrEJDQkOtI8"
},
"source": [
"## Resource Aggregation Handling\n",
"\n",
Expand All @@ -112,18 +109,21 @@
"* File set\n",
"\n",
"The general process for creating an aggregation within a resource requires adding files to the resource and then applying the appropriate aggregation type. For some of the aggregation types, some of the aggregation metadata fields will be automatically extracted from the files you upload. You can then set the values of the other aggregation-level metadata elements. "
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"metadata": {
"id": "7yUSEF_tOySg"
},
"source": [
"## Create a Single File Aggregation\n",
"\n",
"A single file aggregation in a HydroShare is any individual file to which you want to add extra metadata. "
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand Down Expand Up @@ -153,23 +153,27 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Add Metadata to the Aggregation\n",
"\n",
"Once you have created an aggregation, you can edit and add metadata elements. For a single file aggregation, you can add a title, subject keywords, extended metadata as key-value pairs, and spatial and temporal coverage. \n",
"\n",
"All of the metadata edits are stored locally until you call the `save()` function on the aggregation to write the edits you have made to HydroShare."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Title and Keywords\n",
"\n",
"The title of an aggregation is a string. Subject keywords are handled as a list of strings."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -191,12 +195,14 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Extended Metadata Elements\n",
"\n",
"Extended metadata elements for an aggregation are handled using a Python dictionary. You can add new elements using key-value pairs."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand Down Expand Up @@ -230,12 +236,14 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Spatial and Temporal Coverage\n",
"\n",
"Spatial and temporal coverage for an aggregation are handled in the same way they are handled for resource level metadata. Initially the spatial and temporal coverage for an aggregation are empty. To set them, you have to create a coverage object of the right type and set the spatial or temporal coverage to that object."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand Down Expand Up @@ -289,19 +297,23 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating Other Aggregation Types"
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Geographic Feature Aggregation\n",
"\n",
"Geographic feature aggregations are created in HydroShare from the set of files that make up an ESRI Shapefile. You need to upload the shapefile and then HydroShare will automatically set the aggregation on the set of files you upload. You can then retrieve the aggregation using its title or by searching for one of the files it contains."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -323,12 +335,14 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you upload all of the files of a shapefile together as shown above, HydroShare automatically recognizes the files as a shapefile and auto-aggregates the files into a geographic feature aggregation for you. So, you then just need to get the aggregation that was created if you want to further operate on it - e.g., to modify the aggregation-level metadata.\n",
"\n",
"Metadata for a geographic feature aggregation includes a title, subject keywords, extended key-value pairs, temporal coverage, spatial coverage, geometry information, spatial reference, and attribute field information. When HydroShare creates the aggregation on the shapefile, the spatial coverage, geometry information, spatial reference, and attribute field information metadata will be automatically set for you. You can then set all of the other metadata elements as shown above for the single file aggregation if you need to."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -352,14 +366,16 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Geographic Raster Aggregation\n",
"\n",
"Geographic raster aggregations are created in HydroShare from one or more raster data files that make up a raster dataset. HydroShare uses GeoTiff files for raster datasets. Like the geographic feature aggregation, when you upload all of the files for a geographic raster dataset (all .tif and a .vrt file) at once, HydroShare will automatically create the aggregation for you. You can then get the aggregation and set the other metadata elements as shown above for the single file aggregation.\n",
"\n",
"HydroShare initially sets the title of the geographic raster aggregation to the first .tif file that appears in the .vrt file. The spatial coverage, spatial reference, and cell information are set automatically based on information extracted from the dataset. "
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -382,12 +398,14 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Multidimensional NetCDF Aggregation\n",
"\n",
"Multidimensional aggregations are created in HydroShare from a NetCDF file. Like the other aggregation types, you can upload the NetCDF file and HydroShare will automatically create the aggregation for you. HydroShare also automatically extracts metadata from the NetCDF file to populate the aggregation metadata. Some of this metadata may get propagated to the resource level if you haven't set things like the title and keywords. You can then get the aggregation and set the other metadata elements as shown above for the single file aggregation."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -408,12 +426,14 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Time Series Aggregation\n",
"\n",
"Time series aggregations are created in HydroShare from an ODM2 SQLite database file. The ODM2 SQLite database contain one or more time series "
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -434,12 +454,14 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### File Set Aggregation\n",
"\n",
"A file set aggregation is any folder within a resource to which you want to add metadata. If you want to create a file set aggregation, you first have to create a folder, then upload files to it. After that, you can set the aggregation on the folder."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand All @@ -459,12 +481,14 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get Aggregation Properties\n",
"\n",
"Each aggregation in a resource has metadata properties associated with it. You can query/retrieve those properties for display. The following shows an example for the time series aggregation that was created above."
]
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
Expand Down Expand Up @@ -524,8 +548,8 @@
"# Get a list of aggregations searching by a nested metadata attribute (__)\n",
"aggregations = new_resource.aggregations(period_coverage__name=\"period_coverage name\")\n",
" \n",
"# Get a list of aggregations by combining field searching, filtered with AND\n",
"aggrregations = new_resource.aggregations(period_coverage__name=\"period_coverage name\", title=\"watersheds\")"
"# Get a list of aggregations by combining field searching, filtered with \"AND\"\n",
"aggregations = new_resource.aggregations(period_coverage__name=\"period_coverage name\", title=\"watersheds\")"
]
},
{
Expand Down
Loading

0 comments on commit 712cf01

Please sign in to comment.