Skip to content

Commit

Permalink
added io driver for gedi assets in lpdaac
Browse files Browse the repository at this point in the history
  • Loading branch information
jpswinski committed Mar 6, 2024
1 parent 2480aed commit eb1085d
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 3 deletions.
2 changes: 2 additions & 0 deletions plugins/gedi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ target_sources(gedi
${CMAKE_CURRENT_LIST_DIR}/plugin/Gedi01bReader.cpp
${CMAKE_CURRENT_LIST_DIR}/plugin/Gedi02aReader.cpp
${CMAKE_CURRENT_LIST_DIR}/plugin/Gedi04aReader.cpp
${CMAKE_CURRENT_LIST_DIR}/plugin/GediIODriver.cpp
${CMAKE_CURRENT_LIST_DIR}/plugin/GediParms.cpp
)

Expand Down Expand Up @@ -82,6 +83,7 @@ install (
${CMAKE_CURRENT_LIST_DIR}/plugin/Gedi03Raster.h
${CMAKE_CURRENT_LIST_DIR}/plugin/Gedi04aReader.h
${CMAKE_CURRENT_LIST_DIR}/plugin/Gedi04bRaster.h
${CMAKE_CURRENT_LIST_DIR}/plugin/GediIODriver.h
${CMAKE_CURRENT_LIST_DIR}/plugin/GediParms.h
DESTINATION
${INSTALLDIR}/include/sliderule/gedi
Expand Down
112 changes: 112 additions & 0 deletions plugins/gedi/plugin/GediIODriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2021, University of Washington
* 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 University of Washington 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 UNIVERSITY OF WASHINGTON 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 UNIVERSITY OF WASHINGTON 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.
*/

/******************************************************************************
* INCLUDES
******************************************************************************/

#include "GediIODriver.h"
#include "S3CurlIODriver.h"
#include "core.h"

/******************************************************************************
* STATIC DATA
******************************************************************************/

const char* GediIODriver::FORMAT = "s3gedi";

/******************************************************************************
* FILE IO DRIVER CLASS
******************************************************************************/

/*----------------------------------------------------------------------------
* create
*----------------------------------------------------------------------------*/
Asset::IODriver* GediIODriver::create (const Asset* _asset, const char* resource)
{
return new GediIODriver(_asset, resource);
}

/*----------------------------------------------------------------------------
* Constructor
*
* Examples:
* /GEDI02_A.002/GEDI02_A_2023075201011_O24115_03_T08796_02_003_02_V002/GEDI02_A_2023075201011_O24115_03_T08796_02_003_02_V002.h5
* /GEDI01_B.002/GEDI01_B_2023075201011_O24115_04_T08796_02_005_02_V002/GEDI01_B_2023075201011_O24115_04_T08796_02_005_02_V002.h5
*----------------------------------------------------------------------------*/
GediIODriver::GediIODriver (const Asset* _asset, const char* resource):
S3CurlIODriver(_asset)
{
/* Build Updated Resource Path Name */
const int NUM_ELEMENTS = 10;
char elements[NUM_ELEMENTS][MAX_STR_SIZE];
char version_buffer[8];
char resource_buffer[57];

int num_toks = StringLib::tokenizeLine(resource, MAX_STR_SIZE, '_', NUM_ELEMENTS, elements);
if(num_toks < NUM_ELEMENTS) throw RunTimeException(CRITICAL, RTE_ERROR, "Invalid gedi s3 resource: %s", resource);

const char* product = elements[0];
const char* level = elements[1];
StringLib::copy(version_buffer, elements[9], 8);
version_buffer[4] = '\0';
const char* version = &version_buffer[1];

StringLib::copy(resource_buffer, resource, 57);
resource_buffer[54] = '\0';
const char* subdirectory = resource_buffer;

FString resourcepath("%s/%s_%s.%s/%s/%s", asset->getPath(), product, level, version, subdirectory, resource);

/*
* Determine ioBucket and ioKey
*/
ioBucket = (char*)resourcepath.c_str(true);

/*
* Differentiate Bucket and Key
* <bucket_name>/<path_to_file>/<filename>
* | |
* ioBucket ioKey
*/
ioKey = ioBucket;
while(*ioKey != '\0' && *ioKey != '/') ioKey++;
if(*ioKey == '/') *ioKey = '\0';
else throw RunTimeException(CRITICAL, RTE_ERROR, "invalid S3 url: %s", resource);
ioKey++;
}

/*----------------------------------------------------------------------------
* Destructor
*----------------------------------------------------------------------------*/
GediIODriver::~GediIODriver (void)
{
}
72 changes: 72 additions & 0 deletions plugins/gedi/plugin/GediIODriver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2021, University of Washington
* 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 University of Washington 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 UNIVERSITY OF WASHINGTON 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 UNIVERSITY OF WASHINGTON 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.
*/

#ifndef __gedi_io_driver__
#define __gedi_io_driver__

/******************************************************************************
* INCLUDES
******************************************************************************/

#include "Asset.h"
#include "S3CurlIODriver.h"

/******************************************************************************
* S3 IO DRIVER CLASS
******************************************************************************/

class GediIODriver: S3CurlIODriver
{
public:

/*--------------------------------------------------------------------
* Constants
*--------------------------------------------------------------------*/

static const char* FORMAT;

/*--------------------------------------------------------------------
* Methods
*--------------------------------------------------------------------*/

static Asset::IODriver* create (const Asset* _asset, const char* resource);

private:

/*--------------------------------------------------------------------
* Methods
*--------------------------------------------------------------------*/

GediIODriver (const Asset* _asset, const char* resource);
~GediIODriver (void);
};

#endif /* __gedi_io_driver__ */
3 changes: 3 additions & 0 deletions plugins/gedi/plugin/gedi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ void initgedi (void)
Gedi04aReader::init();
Gedi04bRaster::init();

/* Register GEDI IO Driver */
Asset::registerDriver(GediIODriver::FORMAT, GediIODriver::create);

/* Register Rasters */
RasterObject::registerRaster(LUA_GEDI_L03_ELEVATION_RASTER_NAME, Gedi03Raster::create);
RasterObject::registerRaster(LUA_GEDI_L03_CANOPY_RASTER_NAME, Gedi03Raster::create);
Expand Down
3 changes: 2 additions & 1 deletion plugins/gedi/plugin/gedi.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
******************************************************************************/

#include "FootprintReader.h"
#include "GediParms.h"
#include "Gedi01bReader.h"
#include "Gedi02aReader.h"
#include "Gedi03Raster.h"
#include "Gedi04aReader.h"
#include "Gedi04bRaster.h"
#include "GediIODriver.h"
#include "GediParms.h"

/******************************************************************************
* PROTOTYPES
Expand Down
4 changes: 2 additions & 2 deletions targets/slideruleearth-aws/asset_directory.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ gedil3-canopy, ornl-cloud, s3, /vsis3/ornl-cumulus-prod
gedil3-elevation-stddev, ornl-cloud, s3, /vsis3/ornl-cumulus-prod-protected/gedi/GEDI_L3_LandSurface_Metrics_V2/data, GEDI03_elev_lowestmode_stddev_2019108_2022019_002_03.tif, us-west-2, https://s3.us-west-2.amazonaws.com
gedil3-canopy-stddev, ornl-cloud, s3, /vsis3/ornl-cumulus-prod-protected/gedi/GEDI_L3_LandSurface_Metrics_V2/data, GEDI03_rh100_stddev_2019108_2022019_002_03.tif, us-west-2, https://s3.us-west-2.amazonaws.com
gedil3-counts, ornl-cloud, s3, /vsis3/ornl-cumulus-prod-protected/gedi/GEDI_L3_LandSurface_Metrics_V2/data, GEDI03_counts_2019108_2022019_002_03.tif, us-west-2, https://s3.us-west-2.amazonaws.com
gedil2a, iam-role, s3, sliderule/data/GEDI, nil, us-west-2, https://s3.us-west-2.amazonaws.com
gedil1b, iam-role, s3, sliderule/data/GEDI, nil, us-west-2, https://s3.us-west-2.amazonaws.com
gedil2a, lpdaac-cloud, s3gedi, lp-prod-protected, nil, us-west-2, https://s3.us-west-2.amazonaws.com
gedil1b, lpdaac-cloud, s3gedi, lp-prod-protected, nil, us-west-2, https://s3.us-west-2.amazonaws.com
merit-dem, iam-role, s3, sliderule/data/MERIT, nil, us-west-2, https://s3.us-west-2.amazonaws.com
swot-sim-ecco-llc4320, podaac-cloud, s3, podaac-ops-cumulus-protected/SWOT_SIMULATED_L2_KARIN_SSH_ECCO_LLC4320_CALVAL_V1, nil, us-west-2, https://s3.us-west-2.amazonaws.com
swot-sim-glorys, podaac-cloud, s3, podaac-ops-cumulus-protected/SWOT_SIMULATED_L2_KARIN_SSH_GLORYS_CALVAL_V1, nil, us-west-2, https://s3.us-west-2.amazonaws.com
Expand Down

0 comments on commit eb1085d

Please sign in to comment.