Skip to content

Commit

Permalink
updted integration of raster zonal statistics into icesat2 plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jpswinski committed Jan 10, 2023
1 parent 3128c18 commit c488310
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/geo/VrtRaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ int VrtRaster::luaCreate( lua_State* L )
/* Get Parameters */
const char* raster_name = getLuaString(L, 1);
const char* dem_sampling = getLuaString(L, 2, true, NEARESTNEIGHBOUR_ALGO);
const int sampling_radius = getLuaInteger(L, 3, true, 1);
const int zonal_stats = getLuaBoolean(L, 4, true, 1);
const int sampling_radius = getLuaInteger(L, 3, true, 0);
const int zonal_stats = getLuaBoolean(L, 4, true, false);

/* Get Factory */
factory_t _create = NULL;
Expand Down
14 changes: 11 additions & 3 deletions plugins/icesat2/endpoints/atl06.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,17 @@ if samples then
local elevation_rec_type = parms["compact"] and "atl06rec-compact.elevation" or "atl06rec.elevation"
sampler_disp = core.dispatcher(rspq, 1) -- 1 thread required until VrtRaster is thread safe
for key,raster in pairs(samples) do
local vrt = geo.vrt(raster["source"], raster["radius"], raster["algorithm"])
local sampler = icesat2.sampler(vrt, key, rspq, elevation_rec_type, "extent_id", "lon", "lat")
sampler_disp:attach(sampler, atl06_rec_type)
local vrt = geo.vrt(raster["asset"], raster["algorithm"], raster["radius"], raster["zonal_stats"])
if vrt then
local sampler = icesat2.sampler(vrt, key, rspq, elevation_rec_type, "extent_id", "lon", "lat")
if sampler then
sampler_disp:attach(sampler, atl06_rec_type)
else
userlog:sendlog(core.CRITICAL, string.format("request <%s> failed to create sampler %s for %s", rspq, key, resource))
end
else
userlog:sendlog(core.CRITICAL, string.format("request <%s> failed to create raster %s for %s", rspq, key, resource))
end
end
sampler_disp:run()
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/icesat2/plugin/RasterSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const RecordObject::fieldDef_t RasterSampler::zsSampleRecDef[] = {
{"mad", RecordObject::DOUBLE, offsetof(VrtRaster::sample_t, stats.mad), 1, NULL, NATIVE_FLAGS}
};

const char* RasterSampler::zsExtentRecType = "zssrec";
const char* RasterSampler::zsExtentRecType = "zsrec";
const RecordObject::fieldDef_t RasterSampler::zsExtentRecDef[] = {
{"extent_id", RecordObject::UINT64, offsetof(zs_extent_t, extent_id), 1, NULL, NATIVE_FLAGS},
{"key", RecordObject::STRING, offsetof(zs_extent_t, raster_key), RASTER_KEY_MAX_LEN, NULL, NATIVE_FLAGS},
Expand Down
20 changes: 12 additions & 8 deletions plugins/icesat2/plugin/RqstParms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ const char* RqstParms::DISTANCE_IN_SEGMENTS = "dist_in_seg";
const char* RqstParms::ATL03_GEO_FIELDS = "atl03_geo_fields";
const char* RqstParms::ATL03_PH_FIELDS = "atl03_ph_fields";
const char* RqstParms::RASTERS_TO_SAMPLE = "samples";
const char* RqstParms::RASTERS_SOURCE = "source";
const char* RqstParms::RASTERS_ASSET = "asset";
const char* RqstParms::RASTERS_RADIUS = "radius";
const char* RqstParms::RASTERS_ALGORITHM = "algorithm";
const char* RqstParms::RASTERS_ZONAL_STATS = "zonal_stats";
const char* RqstParms::RQST_TIMEOUT = "rqst-timeout";
const char* RqstParms::NODE_TIMEOUT = "node-timeout";
const char* RqstParms::READ_TIMEOUT = "read-timeout";
Expand Down Expand Up @@ -965,7 +966,6 @@ void RqstParms::get_lua_rasters (lua_State* L, int index, rasters_t** rasters_li
*provided = true;

/* Iterate over rasters in list */
lua_pushvalue(L, index); // -1 => table
lua_pushnil(L); // -1 => nil; -2 => table
while (lua_next(L, -2)) // -1 => value; -2 => key; -3 => table
{
Expand All @@ -977,21 +977,26 @@ void RqstParms::get_lua_rasters (lua_State* L, int index, rasters_t** rasters_li
rss_t rss;
bool field_provided;

lua_getfield(L, index, RqstParms::RASTERS_SOURCE);
rss.source = LuaObject::getLuaString(L, -1);
mlog(DEBUG, "Sampling %s for %s", rss.source.getString(), key);
lua_getfield(L, -2, RqstParms::RASTERS_ASSET);
rss.asset = LuaObject::getLuaString(L, -1);
mlog(DEBUG, "Sampling %s for %s", rss.asset.getString(), key);
lua_pop(L, 1);

lua_getfield(L, index, RqstParms::RASTERS_RADIUS);
lua_getfield(L, -2, RqstParms::RASTERS_RADIUS);
rss.radius = LuaObject::getLuaFloat(L, -1, true, 0.0, &field_provided);
if(field_provided) mlog(DEBUG, "Setting %s to %lf for %s", RqstParms::RASTERS_RADIUS, rss.radius, key);
lua_pop(L, 1);

lua_getfield(L, index, RqstParms::RASTERS_ALGORITHM);
lua_getfield(L, -2, RqstParms::RASTERS_ALGORITHM);
rss.sampling_algorithm = LuaObject::getLuaString(L, -1, true, VrtRaster::NEARESTNEIGHBOUR_ALGO, &field_provided);
if(field_provided) mlog(DEBUG, "Setting %s to %s for %s", RqstParms::RASTERS_ALGORITHM, rss.sampling_algorithm.getString(), key);
lua_pop(L, 1);

lua_getfield(L, -2, RqstParms::RASTERS_ZONAL_STATS);
rss.zonal_stats = LuaObject::getLuaBoolean(L, -1, true, false, &field_provided);
if(field_provided) mlog(DEBUG, "Setting %s to %s for %s", RqstParms::RASTERS_ZONAL_STATS, rss.zonal_stats ? "true" : "false", key);
lua_pop(L, 1);

/* Add raster entry to list */
(*rasters_list)->add(key, rss);
}
Expand All @@ -1001,7 +1006,6 @@ void RqstParms::get_lua_rasters (lua_State* L, int index, rasters_t** rasters_li
}
lua_pop(L, 2); // -1 => key; -2 => table
} // -1 => table
lua_pop(L, 1); // stack restored to how it was
}
else if(!lua_isnil(L, index))
{
Expand Down
6 changes: 4 additions & 2 deletions plugins/icesat2/plugin/RqstParms.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ class RqstParms: public LuaObject
static const char* ATL03_GEO_FIELDS;
static const char* ATL03_PH_FIELDS;
static const char* RASTERS_TO_SAMPLE;
static const char* RASTERS_SOURCE;
static const char* RASTERS_ASSET;
static const char* RASTERS_RADIUS;
static const char* RASTERS_ALGORITHM;
static const char* RASTERS_ZONAL_STATS;
static const char* RQST_TIMEOUT;
static const char* NODE_TIMEOUT;
static const char* READ_TIMEOUT;
Expand Down Expand Up @@ -220,9 +221,10 @@ class RqstParms: public LuaObject

/* Raster Sampling Settings */
typedef struct {
SafeString source;
SafeString asset;
double radius;
SafeString sampling_algorithm;
bool zonal_stats;
} rss_t;

/* Rasters to Sample */
Expand Down
5 changes: 0 additions & 5 deletions scripts/endpoints/version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ local json = require("json")
local version, commit, environment, launch, duration, packages = sys.version()

local rsps = {server={version=version, commit=commit, environment=environment, launch=launch, duration=duration, packages=packages}}
print(version)
print(commit)
print(environment)
print(launch)
print(duration)

for _,package in ipairs(packages) do
local package_exists = global.check(package)
Expand Down

0 comments on commit c488310

Please sign in to comment.