Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High-level function for gridding LMA data and assigning events to the grid #60

Open
wx4stg opened this issue Jan 15, 2025 · 0 comments
Open

Comments

@wx4stg
Copy link
Contributor

wx4stg commented Jan 15, 2025

Calling create_regular_grid, assign_regular_bins, events_to_grid and xarray.combine_by_coords is a very common workflow and it would be nice if the process were a single function call, something like a functionized version of

if grid_proj == 'xyz':
x_range = (grid_range*-1000, grid_range*1000, grid_h_res*1000)
y_range = (grid_range*-1000, grid_range*1000, grid_h_res*1000)
z_range = (0, grid_height*1000, grid_v_res*1000)
grid_edge_ranges ={
'grid_x_edge':x_range,
'grid_y_edge':y_range,
'grid_altitude_edge':z_range,
'grid_time_edge':time_range,
}
grid_center_names ={
'grid_x_edge':'grid_x',
'grid_y_edge':'grid_y',
'grid_altitude_edge':'grid_altitude',
'grid_time_edge':'grid_time',
}
event_coord_names = {
'event_x':'grid_x_edge',
'event_y':'grid_y_edge',
'event_altitude':'grid_altitude_edge',
'event_time':'grid_time_edge',
}
grid_spatial_coords=('grid_time', 'grid_altitude', 'grid_y', 'grid_x')
event_spatial_vars = ('event_time', 'event_altitude', 'event_y', 'event_x')
elif grid_proj == 'lla':
lon_range = (dataset.network_center_longitude - grid_range, dataset.network_center_longitude + grid_range, grid_h_res)
lat_range = (dataset.network_center_latitude - grid_range, dataset.network_center_latitude + grid_range, grid_h_res)
alt_range = (0, grid_height, grid_v_res)
grid_edge_ranges ={
'grid_longitude_edge':lon_range,
'grid_latitude_edge':lat_range,
'grid_altitude_edge':alt_range,
'grid_time_edge':time_range,
}
grid_center_names ={
'grid_longitude_edge':'grid_longitude',
'grid_latitude_edge':'grid_latitude',
'grid_altitude_edge':'grid_altitude',
'grid_time_edge':'grid_time',
}
event_coord_names = {
'event_longitude':'grid_longitude_edge',
'event_latitude':'grid_latitude_edge',
'event_altitude':'grid_altitude_edge',
'event_time':'grid_time_edge',
}
grid_spatial_coords=('grid_time', 'grid_altitude', 'grid_latitude', 'grid_longitude')
event_spatial_vars = ('event_time', 'event_altitude', 'event_latitude', 'event_longitude')
else:
raise ValueError('grid_proj must be \'xyz\' or \'lla\'')
empty_grid = create_regular_grid(grid_edge_ranges, grid_center_names)
binned_events = assign_regular_bins(empty_grid, clustered_lma, event_coord_names, append_indices=True)
gridded_lma = events_to_grid(binned_events, empty_grid, pixel_id_var='pixel_id', event_spatial_vars=event_spatial_vars, grid_spatial_coords=grid_spatial_coords)
combined = xr.combine_by_coords((gridded_lma, clustered_lma))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant