Skip to content

Commit 84825d4

Browse files
committed
fmk - bug fix for HPC usage, importlib and regional_event need passing to create_event
1 parent 437f7a1 commit 84825d4

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

modules/performRegionalMapping/GISSpecifiedEvents/GISSpecifiedEvent.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,20 @@ def create_event(asset_file: str, event_grid_file: str, workflow_input: str, do_
7474

7575
event_grid_file_path = os.path.dirname(event_grid_file)
7676

77+
#
78+
# open input file & get Regional Event data
79+
#
80+
81+
json_path = os.path.join(os.getcwd(), workflow_input)
82+
print(json_path)
83+
84+
with open(json_path, 'r') as f:
85+
data = json.load(f)
86+
87+
regional_event = data.get("RegionalEvent")
88+
7789
if is_raster_file(event_grid_file):
78-
create_raster_event(asset_file, event_grid_file, 0, do_parallel)
90+
create_raster_event(asset_file, event_grid_file, 0, do_parallel, regional_event)
7991
elif is_xml_file(event_grid_file): # noqa: RET505
8092
# Here you would call a function to handle XML files
8193
# For now, we'll just raise a NotImplementedError
@@ -85,15 +97,6 @@ def create_event(asset_file: str, event_grid_file: str, workflow_input: str, do_
8597
f'{event_grid_file} is not a raster. Only rasters are currently supported.' # noqa: EM102
8698
)
8799

88-
#
89-
# open input file, see if other raster files to deal with
90-
#
91-
92-
# path to file and open it
93-
json_path = os.path.join(os.path.dirname(os.getcwd()), workflow_input)
94-
with open(json_path, 'r') as f:
95-
data = json.load(f)
96-
97100
#
98101
# If multiple exists, update event_file
99102
# note: create_raster_event modified for this purpose
@@ -107,11 +110,11 @@ def create_event(asset_file: str, event_grid_file: str, workflow_input: str, do_
107110
# is this assumption correct on file paths?
108111
next_file = data['RegionalEvent']['multiple'][i]['eventFile']
109112
next_file_path = os.path.join(event_grid_file_path, next_file)
110-
create_raster_event(asset_file, next_file_path, i+1, do_parallel)
111-
113+
create_raster_event(asset_file, next_file_path, i+1, do_parallel, regional_event)
112114

113-
114-
115+
#
116+
# main function
117+
#
115118

116119
if __name__ == '__main__':
117120
parser = argparse.ArgumentParser()

modules/performRegionalMapping/GISSpecifiedEvents/RasterEvent.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import rasterio
4545
import pyproj
4646
from rasterio.transform import rowcol
47+
import importlib
4748

4849

4950
def sample_raster_at_latlon(src, lat, lon): # noqa: D103
@@ -62,7 +63,7 @@ def sample_raster_at_latlon(src, lat, lon): # noqa: D103
6263
return raster_values # noqa: RET504
6364

6465

65-
def create_event(asset_file, event_grid_file, num_entry, do_parallel): # noqa: C901, D103, N803, RUF100
66+
def create_event(asset_file, event_grid_file, num_entry, do_parallel, regional_event): # noqa: C901, D103, N803, RUF100
6667

6768
#print(f'asset_file: {asset_file}, entry: {num_entry}')
6869
#print(f'event_grid_file: {event_grid_file}, entry: {num_entry}')
@@ -126,11 +127,11 @@ def create_event(asset_file, event_grid_file, num_entry, do_parallel): # noqa:
126127
asset_data = json.load(asset_file)
127128

128129
if num_entry == 0:
129-
im_tag = asset_data['RegionalEvent']['intensityMeasures']
130-
units = asset_data['RegionalEvent']['units']
130+
im_tag = regional_event['intensityMeasures']
131+
units = regional_event['units']
131132
else:
132-
im_tag = asset_data['RegionalEvent']['multiple'][num_entry-1]['intensityMeasures']
133-
units = asset_data['RegionalEvent']['multiple'][num_entry-1]['units']
133+
im_tag = regional_event['multiple'][num_entry-1]['intensityMeasures']
134+
units = regional_event['multiple'][num_entry-1]['units']
134135

135136

136137
# Extract the latitude and longitude

0 commit comments

Comments
 (0)