Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
088e468
Staging GridObj changes
fmalatino Jan 22, 2025
8e23e53
Changed method of access and added methods to GridObj
fmalatino Jan 22, 2025
2c77aea
Merged in main
fmalatino Jan 30, 2025
563011f
Beginning changes to make_hgrid and change of entry point for make_topog
fmalatino Feb 5, 2025
038a976
Added todos to gridobj.py: remove metadata from write out, access to …
fmalatino Feb 7, 2025
cb87c5d
Switching over to hold_hgrid branch
fmalatino Feb 11, 2025
e3ac3ce
Changes as of 16:01 11 Feb 2025 on feature/hgrid branch
fmalatino Feb 11, 2025
a227658
Added in main functionality for make_hgrid
fmalatino Feb 12, 2025
787b449
Added to make_hgrid_utils create_regular_lonlat_grid and create_tripo…
fmalatino Feb 12, 2025
9dcab22
Added in wrappers for create_regular_lonlat_grid, create_tripolar_gri…
fmalatino Feb 12, 2025
a9435c3
Switching over to fix gridobj branch
fmalatino Feb 13, 2025
df1e9b7
Adding None initialization to from_file GridObj method
fmalatino Feb 13, 2025
cfd59ce
Merged in fix/grid_obj
fmalatino Feb 13, 2025
d516331
Merged in fix/grid_obj branch
fmalatino Feb 13, 2025
f669851
Addition of h-grid obj prelim
fmalatino Feb 18, 2025
a0f4a3f
Removed empty attributes from GridObj, left access only from gridfile…
fmalatino Feb 18, 2025
fd8af15
Amended GridObj from_file method
fmalatino Feb 18, 2025
807ce1d
Merge branch 'fix/grid_obj' into feature/hgrid
fmalatino Feb 18, 2025
7bffc35
Switching over to fix/grid_obj branch
fmalatino Feb 19, 2025
b198f92
Made properties of GridObj all default to None when there is no dataset
fmalatino Feb 19, 2025
5fe927a
Merge branch 'fix/grid_obj' into feature/hgrid
fmalatino Feb 19, 2025
983ae1d
Switching over to fix/grid_obj branch
fmalatino Feb 19, 2025
b921395
Changed GridObj attribute grid_data to dataset
fmalatino Feb 19, 2025
febaa28
Merge branch 'fix/grid_obj' into feature/hgrid
fmalatino Feb 19, 2025
b28821d
Main functionality for make_hgrid added
fmalatino Feb 20, 2025
b20602d
Merged main
fmalatino Feb 20, 2025
a3d9e63
Merge branch 'main' into feature/hgrid
fmalatino Feb 21, 2025
d3c475b
Added doc strings to make_hgrid
fmalatino Feb 24, 2025
7ca91d9
Changing over to fix/grid_obj
fmalatino Feb 27, 2025
b890c62
Switching to main
fmalatino Mar 5, 2025
5b50391
Merged main
fmalatino Mar 5, 2025
e2f06bb
Beginning stages of testing make_hgrid
fmalatino Mar 5, 2025
5014c5d
Testing make_hgrid up to write out for regular_lonlat_grid
fmalatino Mar 8, 2025
2102d0e
Passing make_hgrid example 1
fmalatino Mar 13, 2025
744bde1
Merging in main
fmalatino Apr 1, 2025
8d0e8ac
Using data_handling module until replaced - comments
fmalatino Apr 2, 2025
e8b3b94
Adding in access to provenance data in make_hgrid
fmalatino Apr 2, 2025
c3ee653
Adding TODO for access to make_hgrid through fmsgridtools
fmalatino Apr 2, 2025
9cdd612
Removing test variable from create_lonlat_grid.c
fmalatino Apr 2, 2025
0d00389
Updating pyFMS
fmalatino Apr 2, 2025
b99c80b
Changes needed for updates to pyFMS
fmalatino Apr 2, 2025
262062a
Edits to checking of variables to write to file in hgridobj.py
fmalatino Apr 10, 2025
b633aee
Removed functionality for tripolar grid in make_hgrid
fmalatino Apr 10, 2025
a511adc
Removing Optionals from gridobj, make_hgrid, adding type hinting to h…
fmalatino Apr 11, 2025
ad97d17
Using instance variable of hgridobj tile for write_out
fmalatino Apr 11, 2025
63bde7e
Refactor of methods in hgridobj
fmalatino Apr 11, 2025
eb3d6aa
Refactor of setting tile dataarray in hgridobj
fmalatino Apr 11, 2025
f8944c2
Merge main
fmalatino Apr 24, 2025
f22a34c
Adding in loading methods of pyfrenctools
fmalatino Apr 24, 2025
b44404c
Hook for pyfrenctools
fmalatino Apr 24, 2025
4d4c015
Removed weird space
fmalatino Apr 24, 2025
aad2c7b
Adding back in .gitkeep
fmalatino Apr 24, 2025
5c2596f
Switching over to hold/hgrid
fmalatino Apr 24, 2025
115d3be
Removing comments
fmalatino Apr 24, 2025
ac5eeec
Under construction rework of make_hgrid to match format for other mod…
fmalatino Apr 24, 2025
438ac57
Removed redundant install of clib.so from top level setup.py
fmalatino Apr 25, 2025
ed58d50
Accessing new location for compile_log in CI workflow
fmalatino Apr 25, 2025
5d16d26
Trying again to access compile_log
fmalatino Apr 25, 2025
fdb447b
Pre-lim structure for make_hgrid:make_lonlat_grid, non-working
fmalatino Apr 25, 2025
0b9c305
Pre-lim working make_lonlat
fmalatino Apr 25, 2025
0b3b5f7
Consolidating hgrid utils in hgridobj.py
fmalatino Apr 25, 2025
ce35f9f
Added in verbose flags for make_hgrid
fmalatino Apr 28, 2025
0153736
Removed hgrid_util file
fmalatino Apr 28, 2025
f1dcf6a
Changes to hgrid write_out_grid looping for multiple file output
fmalatino Apr 29, 2025
df769dd
Small typo
fmalatino Apr 29, 2025
e8a5f8c
Merge branch 'main' into feature/hgrid
fmalatino May 1, 2025
153fae5
Merging in main
fmalatino May 1, 2025
597eb45
Merge branch 'main' into feature/hgrid
fmalatino May 14, 2025
745dc8b
Updating pyFMS
fmalatino May 15, 2025
738d662
Merging main
fmalatino May 15, 2025
ef683c4
In flux change to main branch
fmalatino May 19, 2025
0cdbb37
Merging main
fmalatino May 19, 2025
4624878
Switching to main
fmalatino May 22, 2025
037427c
Merge branch 'main' into feature/hgrid
fmalatino May 22, 2025
fa84c4d
Addressing comments from reviews on 15 May 2025
fmalatino May 23, 2025
e7c1826
Amending test_libs for new file location
fmalatino May 23, 2025
d1f4daf
Removing comments
fmalatino May 23, 2025
51a8b07
Removing even more comments
fmalatino May 23, 2025
57506b2
Overriding build instead of build_py in pyfrenctools setup.py
fmalatino May 24, 2025
24e7126
Added unit tests for current state of make_hgrid
fmalatino May 27, 2025
1f2709d
Merge branch 'main' into feature/hgrid
fmalatino May 29, 2025
4b13f1a
Beginning of make_hgrid:gnomonic
fmalatino May 30, 2025
f2ce46d
Calls to wrappers for gnomonic grid generation
fmalatino May 30, 2025
3aff5d7
Majority of gnomonic grid generation
fmalatino Jun 2, 2025
440c818
Changes for case when out_halo is passed for gnomonic grid write out
fmalatino Jun 2, 2025
0123657
Square layout only gnomonic grid generation
fmalatino Jun 4, 2025
5585531
Adding transpose of data option to make_hgrid::gnomonic
fmalatino Jun 18, 2025
6606ba5
Merge branch 'main' into feature/hgrid
fmalatino Jun 18, 2025
120e942
Adding 'ordering' attribute for tracking of layout for output data fr…
fmalatino Jul 1, 2025
a1ec667
Merging in main
fmalatino Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fmsgridtools/make_hgrid/gnomonic_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def make(
output_length_angle: bool,
do_schmidt: bool,
do_cube_transform: bool,
transpose: bool,
verbose: bool,
):

Expand Down Expand Up @@ -183,5 +184,6 @@ def make(
conformal=conformal,
out_halo=out_halo,
output_length_angle=output_length_angle,
transpose=transpose,
verbose=verbose,
)
65 changes: 38 additions & 27 deletions fmsgridtools/make_hgrid/hgridobj.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import sys
import ctypes
import sys

import numpy as np
from numpy.typing import NDArray
import xarray as xr
from numpy.typing import NDArray

from fmsgridtools.shared.gridtools_utils import get_provenance_attrs
from fmsgridtools.shared.gridobj import GridObj

def fill_cubic_grid_halo(
nx: int,
ny: int,
halo: int,
data: NDArray[np.float64],
nx: int,
ny: int,
halo: int,
data: NDArray[np.float64],
data1_all: NDArray[np.float64],
data2_all: NDArray[np.float64],
tile: int,
Expand All @@ -22,17 +23,17 @@ def fill_cubic_grid_halo(
nyp = ny + joff
nxph = nx + ioff + 2*halo
nyph = ny + joff + 2*halo

for i in range(nxph*nyph):
data[i] = -9999.

# first copy computing domain data
for j in range (1, nyp+1):
for i in range(1, nxp+1):
data[j*nxph+i] = data1_all[tile*nxp*nyp+(j-1)*nxp+(i-1)]

ntiles = 6

if tile%2 == 1:
lw = (tile+ntiles-1)%ntiles
le = (tile+ntiles+2)%ntiles
Expand Down Expand Up @@ -216,9 +217,10 @@ def write_out_hgrid(
conformal: bool=True,
out_halo: int=0,
output_length_angle: bool=True,
transpose: bool=False,
verbose: bool=False,
):

var_dict={}
pos_c = 0
pos_e = 0
Expand Down Expand Up @@ -267,7 +269,7 @@ def write_out_hgrid(
)

var_dict['arcx'] = arcx

"""define dimension"""
nx = self.nxl[n]
ny = self.nyl[n]
Expand All @@ -283,20 +285,20 @@ def write_out_hgrid(
if n > 0:
print(f"[INFO] XARRAY: n: {n} x[0]: {self.x[pos_c]} x[-1]: {self.x[pos_c-1]} x[-2]: {self.x[pos_c-2]} x[-3]: {self.x[pos_c-3]} x[-4]: {self.x[pos_c-4]} x[-5]: {self.x[pos_c-5]} x[-10]: {self.x[pos_c-10]}", file=sys.stderr)
x = xr.DataArray(
data=self.x[pos_c:pos_c+nyp*nxp].reshape((nyp,nxp)),
data=self.x[pos_c:pos_c+nyp*nxp].reshape((nyp,nxp)).T if transpose else self.x[pos_c:pos_c+nyp*nxp].reshape((nyp,nxp)),
dims=["nyp", "nxp"],
attrs=dict(
units="degree_east",
units="degree_east",
standard_name="geographic_longitude",
)
)
var_dict['x'] = x

y = xr.DataArray(
data=self.y[pos_c:pos_c+nyp*nxp].reshape((nyp, nxp)),
data=self.y[pos_c:pos_c+nyp*nxp].reshape((nyp, nxp)).T if transpose else self.y[pos_c:pos_c+nyp*nxp].reshape((nyp, nxp)),
dims=["nyp", "nxp"],
attrs=dict(
units="degree_north",
units="degree_north",
standard_name="geographic_latitude",
)
)
Expand All @@ -317,7 +319,7 @@ def write_out_hgrid(
data=self.dx[pos_n:pos_n+nyp*nx].reshape((nyp, nx)),
dims=["nyp", "nx"],
attrs=dict(
units="meters",
units="meters",
standard_name="grid_edge_x_distance",
)
)
Expand All @@ -327,7 +329,7 @@ def write_out_hgrid(
data=self.dy[pos_e:pos_e+ny*nxp].reshape((ny, nxp)),
dims=["ny", "nxp"],
attrs=dict(
units="meters",
units="meters",
standard_name="grid_edge_y_distance",
)
)
Expand All @@ -354,7 +356,7 @@ def write_out_hgrid(
)
var_dict['angle_dy'] = angle_dy
else:
if grid_type is not "gnomonic_ed":
if grid_type != "gnomonic_ed":
raise RuntimeError("make_hgrid: out_halo > 0, only working for grid_type = 'gnomonic_ed'")

if verbose:
Expand All @@ -363,10 +365,10 @@ def write_out_hgrid(
tmp_x = np.zeros(shape=(nxp+2*out_halo)*(nyp+2*out_halo), dtype=np.float64)
fill_cubic_grid_halo(nx, ny, out_halo, tmp_x, self.x, self.x, n, 1, 1)
x = xr.DataArray(
data=tmp_x.reshape((nyp+2*out_halo,nxp+2*out_halo)),
data=tmp_x.reshape((nyp+2*out_halo,nxp+2*out_halo)).T if transpose else tmp_x.reshape((nyp+2*out_halo,nxp+2*out_halo)),
dims=["nyp", "nxp"],
attrs=dict(
units="degree_east",
units="degree_east",
standard_name="geographic_longitude",
_FillValue=-9999.,
)
Expand All @@ -376,10 +378,10 @@ def write_out_hgrid(
tmp_y = np.zeros(shape=(nxp+2*out_halo)*(nyp+2*out_halo), dtype=np.float64)
fill_cubic_grid_halo(nx, ny, out_halo, tmp_y, self.y, self.y, n, 1, 1)
y = xr.DataArray(
data=tmp_y.reshape((nyp+2*out_halo, nxp+2*out_halo)),
data=tmp_y.reshape((nyp+2*out_halo, nxp+2*out_halo)).T if transpose else tmp_y.reshape((nyp+2*out_halo, nxp+2*out_halo)),
dims=["nyp", "nxp"],
attrs=dict(
units="degree_north",
units="degree_north",
standard_name="geographic_latitude",
_FillValue = -9999.,
)
Expand All @@ -406,7 +408,7 @@ def write_out_hgrid(
data=tmp_dx.reshape((nyp+2*out_halo, nx+2*out_halo)),
dims=["nyp", "nx"],
attrs=dict(
units="meters",
units="meters",
standard_name="grid_edge_x_distance",
_FillValue=-9999.,
)
Expand All @@ -419,7 +421,7 @@ def write_out_hgrid(
data=tmp_dy.reshape((ny+2*out_halo, nxp+2*out_halo)),
dims=["ny", "nxp"],
attrs=dict(
units="meters",
units="meters",
standard_name="grid_edge_y_distance",
_FillValue=-9999.,
)
Expand Down Expand Up @@ -453,6 +455,17 @@ def write_out_hgrid(
)
var_dict['angle_dy'] = angle_dy

if transpose:
ordering = xr.DataArray(
["row_major"],
)
else:
ordering = xr.DataArray(
["column_major"],
)

var_dict['ordering'] = ordering

nx = self.nxl[n]
ny = self.nyl[n]
nxp = nx + 1
Expand All @@ -470,7 +483,7 @@ def write_out_hgrid(
if verbose:
print(f"About to close {outfile}")

prov_attrs = get_provenance_attrs(great_circle_algorithm=True)
prov_attrs = get_provenance_attrs(great_circle_algorithm=True)

dataset = xr.Dataset(
data_vars=var_dict
Expand Down Expand Up @@ -539,5 +552,3 @@ def make_gridobj(self) -> "GridObj":
else:
dataset=self.dataset
return GridObj(dataset=dataset)


8 changes: 8 additions & 0 deletions fmsgridtools/make_hgrid/make_hgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ def lonlat(
be set: --stretch_factor, --target_lon, and --target_lat.
""",
)
@click.option(
"--transpose",
is_flag=True,
default=False,
help="This flag will transpose the x(lon) and y(lat) output arrays"
)
@click.option(
"--verbose",
is_flag=True,
Expand All @@ -250,6 +256,7 @@ def gnomonic(
output_length_angle: bool,
do_schmidt: bool,
do_cube_transform: bool,
transpose: bool,
verbose: bool
):
gnomonic_grid.make(
Expand All @@ -272,5 +279,6 @@ def gnomonic(
output_length_angle=output_length_angle,
do_schmidt=do_schmidt,
do_cube_transform=do_cube_transform,
transpose=transpose,
verbose=verbose,
)