Skip to content

Commit

Permalink
Enable saving of FVCOM element areas
Browse files Browse the repository at this point in the history
  • Loading branch information
jimc101 committed Dec 14, 2023
1 parent b9495c7 commit 04d3453
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pylag/grid_metrics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,23 @@ def create_fvcom_grid_metrics_file(fvcom_file_name: str,
nbe_data = nbe_data.T
nv_data = nv_data.T
sort_adjacency_array(nv_data, nbe_data)

# Save element areas
print('\nCalculating element areas ', end='... ')
lon_nodes = fvcom_dataset.variables[lon_var_name][:].astype(DTYPE_FLOAT)
lat_nodes = fvcom_dataset.variables[lat_var_name][:].astype(DTYPE_FLOAT)
areas = compute_element_areas(nv_data, lon_nodes, lat_nodes,
coordinate_system='geographic')
area_attrs = {'standard_name' : 'areas',
'units' : 'm^2',
'long_name' : 'Element areas'}

# Save areas
gm_file_creator.create_variable('area', areas, ('element',),
DTYPE_FLOAT, attrs=area_attrs)
print('done')

# Transpose back to original shape as expected by PyLag
nbe_data = nbe_data.T
nv_data = nv_data.T

Expand Down

0 comments on commit 04d3453

Please sign in to comment.