Skip to content

Commit

Permalink
Merge pull request #91 from ghrcdaac/Lucy-GHRCCLOUD-5796-exradimpacts…
Browse files Browse the repository at this point in the history
…-CloudOnly

Lucy ghrccloud 5796 exradimpacts cloud only -- Deleted exradimpacts.zip_2020_2022
  • Loading branch information
camposeddie authored Apr 15, 2024
2 parents 47f801e + 2c21d69 commit 6aefcc8
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# create lookup zip for parprbimpacts
# for all future collections
from datetime import datetime, timedelta
from utils.mdx import MDX
import cProfile
import time
import math
import re

from netCDF4 import Dataset
import numpy as np

short_name = "exradimpacts"
provider_path = "exradimpacts/fieldCampaigns/impacts/EXRAD/data/"
file_type = "HDF-5"


class MDXProcessing(MDX):

def __init__(self):
super().__init__()

def process(self, filename, file_obj_stream) -> dict:
"""
Individual collection processing logic for spatial and temporal
metadata extraction
:param filename: name of file to process
:type filename: str
:param file_obj_stream: file object stream to be processed
:type file_obj_stream: botocore.response.StreamingBody
"""
return self.get_nc_metadata(filename, file_obj_stream)


def get_nc_metadata(self, filename, file_obj_stream):
"""
Extract temporal and spatial metadata from HDF-5 files
"""
datafile = Dataset("in-mem-file", mode='r', memory=file_obj_stream.read())
lat = h5.groups['Navigation'].groups['Data'].variables['Latitude'][:]
lon = h5.groups['Navigation'].groups['Data'].variables['Longitude'][:]
tm = h5.groups['Time'].groups['Data'].variables['TimeUTC'][:]

north, south, east, west = [np.max(lat), np.min(lat),
np.max(lon), np.min(lon)]

start_time = datetime(1970,1,1) + timedelta(seconds=float(np.min(tm)))
end_time = datetime(1970,1,1) + timedelta(seconds=float(np.max(tm)))


datafile.close()
return {
"start": start_time,
"end": end_time,
"north": north,
"south": south,
"east": east,
"west": west,
"format": file_type
}


def main(self):
# start_time = time.time()
self.process_collection(short_name, provider_path)
# elapsed_time = time.time() - start_time
# print(f"Elapsed time in seconds: {elapsed_time}")
self.shutdown_ec2()


if __name__ == '__main__':
MDXProcessing().main()
# The below can be use to run a profiler and see which functions are
# taking the most time to process
# cProfile.run('MDXProcessing().main()', sort='tottime')
Binary file modified mdx/granule_metadata_extractor/src/helpers/exradimpacts.zip
Binary file not shown.

0 comments on commit 6aefcc8

Please sign in to comment.