|
44 | 44 | import sliderule
|
45 | 45 | from sliderule import version
|
46 | 46 | import os
|
| 47 | +import time |
47 | 48 |
|
48 | 49 | ###############################################################################
|
49 | 50 | # GLOBALS
|
@@ -718,38 +719,47 @@ def atl06p(parm, asset=DEFAULT_ASSET, version=DEFAULT_ICESAT2_SDP_VERSION, callb
|
718 | 719 | # Make API Processing Request
|
719 | 720 | rsps = sliderule.source("atl06p", rqst, stream=True, callbacks=callbacks)
|
720 | 721 |
|
| 722 | + start_time = time.perf_counter() |
721 | 723 | # Flatten Responses
|
722 | 724 | columns = {}
|
| 725 | + rectype = None |
| 726 | + num_rows = 0 |
| 727 | + sample_rec = None |
723 | 728 | if len(rsps) <= 0:
|
724 |
| - logger.debug("no response returned") |
725 |
| - elif (rsps[0]['__rectype'] != 'atl06rec' and rsps[0]['__rectype'] != 'atl06rec-compact'): |
726 |
| - logger.debug("invalid response returned: %s", rsps[0]['__rectype']) |
| 729 | + logger.debug("No response returned") |
727 | 730 | else:
|
728 |
| - # Determine Record Type |
729 |
| - if rsps[0]['__rectype'] == 'atl06rec': |
730 |
| - rectype = 'atl06rec.elevation' |
731 |
| - else: |
732 |
| - rectype = 'atl06rec-compact.elevation' |
733 |
| - # Count Rows |
734 |
| - num_rows = 0 |
735 | 731 | for rsp in rsps:
|
| 732 | + # Determine Record Type |
| 733 | + if rectype == None: |
| 734 | + if rsp['__rectype'] == 'atl06rec': |
| 735 | + rectype = 'atl06rec.elevation' |
| 736 | + sample_rec = rsp |
| 737 | + elif rsp['__rectype'] == 'atl06rec-compact': |
| 738 | + rectype = 'atl06rec-compact.elevation' |
| 739 | + sample_rec = rsp |
| 740 | + # Count Rows |
736 | 741 | num_rows += len(rsp["elevation"])
|
| 742 | + # Check Valid ATL06 Record Returned |
| 743 | + if rectype == None: |
| 744 | + raise RuntimeError("Invalid record types returned for this api") |
737 | 745 | # Build Columns
|
738 |
| - for field in rsps[0]["elevation"][0].keys(): |
| 746 | + for field in sample_rec["elevation"][0].keys(): |
739 | 747 | fielddef = sliderule.get_definition(rectype, field)
|
740 | 748 | if len(fielddef) > 0:
|
741 | 749 | columns[field] = numpy.empty(num_rows, fielddef["nptype"])
|
742 | 750 | # Populate Columns
|
743 | 751 | elev_cnt = 0
|
744 | 752 | for rsp in rsps:
|
745 | 753 | for elevation in rsp["elevation"]:
|
746 |
| - for field in elevation.keys(): |
747 |
| - if field in columns: |
748 |
| - columns[field][elev_cnt] = elevation[field] |
| 754 | + for field in columns: |
| 755 | + columns[field][elev_cnt] = elevation[field] |
749 | 756 | elev_cnt += 1
|
750 | 757 |
|
751 | 758 | # Return Response
|
752 |
| - return __todataframe(columns, "delta_time", "lon", "lat") |
| 759 | + gdf = __todataframe(columns, "delta_time", "lon", "lat") |
| 760 | + end_time = time.perf_counter() |
| 761 | + print("Execution Time: {} seconds".format(end_time - start_time)) |
| 762 | + return gdf |
753 | 763 |
|
754 | 764 | # Handle Runtime Errors
|
755 | 765 | except RuntimeError as e:
|
|
0 commit comments