Skip to content

IO for active cells #414

Open
Open

Description

@dccowan

Summary

The write_model_UBC for TensorMesh and TreeMesh do not work properly for UBC-GIF active cells models. In SimPEG, active cells are a boolean array, which cannot be written directly. For UBC-GIF, they are binary values. Even if you convert the SimPEG boolean array to dtype=int, write_model_UBC will write the values in scientific notation.

Suggestion

Make write_active_cells_UBC and read_active_cells_UBC. I think its clearer to separate from write_model_UBC and read_model_UBC. However, I think we can get each to call a core piece of functionality smart enough to handle either.

Activity

  1. self-assigned this
    on Jun 25, 2026
  2. jcapriot commented on Jun 25, 2026

    @jcapriot
    Member

    What point do the `write_model_UBC’ style functions change the dtype of the array?

  3. dccowan commented on Jun 25, 2026

    @dccowan
    MemberAuthor

    What point do the `write_model_UBC’ style functions change the dtype of the array?

    If I first convert from a boolean array to int array, it happen when calling np.savetxt, since it uses the default format option. This is something that could be changed. If you want the least amount of change to the code, we could add code which 1) checks to see if the array is a boolean array, then 2) convert to 0s and 1s, then 3) writes with the proper formatting. Do you want to do that?

    I just keep running into this as I move between SimPEG and UBC-GIF stuff

  4. jcapriot commented on Jun 25, 2026

    @jcapriot
    Member

    Ah, I see... Maybe then we should just do a format string that depends on the dtype of the input:

    if np.issubdtype(arr.dtype, np.inexact):
        fmt  = "%.18e"
    elif np.issubdtype(arr.dtype, np.integer) or np.issubdtype(arr.dtype, np.bool_):
        fmt = "%i"
    else:
        fmt = "%s"
    • assuming that an array of bools should be written as 0's and 1's.
  5. dccowan commented on Jun 25, 2026

    @dccowan
    MemberAuthor

    That's probably the easiest fix. I'm happy to do this.

  6. jcapriot commented on Jun 25, 2026

    @jcapriot
    Member

    Would it also be helpful to add a ‘dtype’ option to the corresponding read in values as well that forces a data type on `np.loadtxt’?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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