Skip to content

Feature: diag_manager#10

Merged
fmalatino merged 35 commits intomainfrom
feature/diag_manager
Apr 10, 2025
Merged

Feature: diag_manager#10
fmalatino merged 35 commits intomainfrom
feature/diag_manager

Conversation

@fmalatino
Copy link
Copy Markdown
Owner

@fmalatino fmalatino commented Mar 10, 2025

Description
This PR brings in the currently available diag_manager modules in cFMS and removes the use of set_multipointer.

How Has This Been Tested?
Current CI is awaiting update to container.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • New check tests, if applicable, are included

@fmalatino fmalatino requested a review from mlee03 March 10, 2025 14:34
@fmalatino fmalatino linked an issue Mar 26, 2025 that may be closed by this pull request
@fmalatino fmalatino marked this pull request as ready for review March 27, 2025 16:54
@fmalatino fmalatino marked this pull request as draft March 28, 2025 16:22
@fmalatino fmalatino marked this pull request as ready for review March 28, 2025 17:14
Comment thread pyfms/__init__.py Outdated
from .py_diag_manager.pyfms_diag_manager import pyFMS_diag_manager
from .py_field_manager.py_field_manager import FieldTable
from .py_horiz_interp.py_horiz_interp import HorizInterp
from .py_horiz_interp.py_horiz_interp import pyFMS_horiz_interp
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to match the names of the other modules. If desired it can be changed back.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change it back, the other modules need to be changed

self,
diag_model_subset: int = None,
time_init: NDArray = None,
err_msg: str = None,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err_msg is an out, it doesn't need to be a function argument

def diag_send_complete(
self,
diag_field_id: int,
err_msg: str = None,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise with err_msg

_cfms_diag_send_complete(diag_field_id_c, err_msg_c)

if err_msg is not None:
return err_msg_c.value.decode("utf-8")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need if else here?

minute: int,
second: int = None,
tick: int = None,
err_msg: str = None,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err_msg here too

diag axis init z
"""

z = np.empty(shape=NZ, dtype=np.float64, order="C")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise with np.arange

field=var3,
)

for itime in range(24):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was overlooked in cFMS, ntime=24 should be defined and the loop should become for itime in range(ntime)


ij = 0
for i in range(NX):
for j in range(NY):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these loops are not needed, they can be var2 = - var2?

diag_manager.diag_send_complete(diag_field_id=id_var2)

diag_manager.diag_end()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was also overlooked in cFMS but the test should in the future have a check to read in the netcdf files and check values

Comment thread tests/py_mpp/test_define_domains.py Outdated
mpp.set_current_pelist(coarse_pelist)
name = "test coarse domain"
maskmap = np.full(shape=(2, 4), fill_value=True, dtype=np.bool_, order="C")
maskmap = np.full(shape=8, fill_value=True, order="C")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this change needed? cFMS should work with multidimensional numpy arrays

@fmalatino fmalatino requested a review from mlee03 March 28, 2025 19:43
Comment thread pyfms/__init__.py Outdated
from .py_diag_manager.pyfms_diag_manager import pyFMS_diag_manager
from .py_field_manager.py_field_manager import FieldTable
from .py_horiz_interp.py_horiz_interp import HorizInterp
from .py_horiz_interp.py_horiz_interp import pyFMS_horiz_interp
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change it back, the other modules need to be changed


class DiagManager:

DIAG_ALL = 2
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be retrieved from cfms

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have raised an issue for future handling of this; Issue 28

multiple_send_data: bool = None,
) -> int:

module_name = module_name[:64]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module_name[:NAME_LENGTH]

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also need to be amended post closing of Issue 28

realm_c, realm_t = set_Cchar(realm)
multiple_send_data_c, multiple_send_data_t = setscalar_Cbool(multiple_send_data)

if range.dtype == np.int32:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

range is an optional argument, might not be the best argument to check for types

NZ = 2

domain_id = 0
calendar_type = 4
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calendar related parameters should be imported from cfms

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also related to Issue 28

x = np.arange(NX, dtype=np.float64)

for i in range(NX):
x[i] = i
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.arange handles this. this for loop is not needed.

y = np.arange(NY, dtype=np.float64)

for j in range(NY):
y[j] = j
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise, this for loop is not needed


z = np.arange(NZ, dtype=np.float64)

for k in range(NZ):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this for loop as well.

register diag field var3
"""

axes_3d = np.array([id_x, id_y, id_z, 0, 0], dtype=np.int32)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

axes array in cfms was declared to have 5 elements t avoid having 2d-5d flavors of the same subroutine. There is no need for this to be true in python. Users should be able to use axes_3d = [id_x, id_y, id_z] and the conversion to have five elements be handled inside the python function

for i in range(NX):
for j in range(NY):
for k in range(NZ):
var3[ijk] = -1.0 * var3[ijk]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a short hand notation to replace this expanded set of for loops? This explicitness is required in C but not in python?

var3 = np.empty(shape=NX * NY * NZ, dtype=np.float32)

ijk = 0
for i in range(NX):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from python, the variables can be declared as multidimensional

@fmalatino fmalatino requested review from bensonr and mlee03 April 2, 2025 16:56
@fmalatino fmalatino merged commit 821baa3 into main Apr 10, 2025
1 check passed
mlee03 pushed a commit to mlee03/pyFMS_old that referenced this pull request Apr 21, 2025
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

Successfully merging this pull request may close these issues.

Remove set_multipointer

2 participants