Skip to content

Preserving dtype of element properties (continuation of #1496) #1655

@vincentcasseau

Description

@vincentcasseau

Hello,

In opendrift/elements/elements.py, there are a few places where the variable dtype is not preserved. This happens whenever np.ones is called. I am wondering if this is by design and if so why that is.

For instance:

# Status must always be array
if not type(self.status) == np.ndarray:
    self.status = self.status*np.ones(self.lon.shape)

could become

# Status must always be array
if not isinstance(self.status, np.ndarray):
    dtype = self.variables['status']['dtype']
    self.status = self.status*np.ones(self.lon.shape, dtype=dtype)

This prevents self.status from being an np.float64.

I am attaching a file showing all instances (please diff against current version of this file).

elements.txt

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions