Skip to content

import from iode #1032

Open
Open
@gdementen

Description

@gdementen

Should implement both read_av and read_var. See also #503 for export.

For read_av, see demo_python...\demo_code\util\util.py:du_iode_to_larray

Here is the latest version I used for read_var:

def read_var(fpath, variables=None):
    if isinstance(fpath, Path):
        fpath = str(fpath)
    if not os.path.exists(fpath):
        raise FileNotFoundError(fpath)
    if variables is None:
        arr = iode.wsloadvarpy(fpath)
        time_labels = arr.time.labels
        int_time_labels = time_labels.astype(int)
        if (time_labels == int_time_labels).all():
            arr = arr.set_labels('time', int_time_labels)
        return arr.rename('vars', 'variable')
    else:
        if not isinstance(variables, (tuple, list)):
            raise ValueError("variables argument should be either None or a tuple/list")

        iode.wsloadvar(fpath)
        sample = iode.samplelist()
        int_sample = sample.astype(int)
        if (sample == int_sample).all():
            sample = int_sample
        time = Axis(sample, 'time')
        variable = Axis(variables, 'variable')
        return stack({k: Array(iode.getvector(k), time) for k in variables}, variable).T

PS: the iode module should really be improved, especially concerning its documentation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions