Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPL reader breaks in newer environment of xarray, numpy etc. #864

Open
zssherman opened this issue Oct 21, 2024 · 2 comments
Open

MPL reader breaks in newer environment of xarray, numpy etc. #864

zssherman opened this issue Oct 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@zssherman
Copy link
Collaborator

def test_io_mpldataset():
    mpl_ds = act.io.mpl.read_sigma_mplv5(act.tests.EXAMPLE_SIGMA_MPLV5)

    # Tests fields
    assert 'channel_1' in mpl_ds.variables.keys()
    assert 'temp_0' in mpl_ds.variables.keys()
    assert mpl_ds.channel_1.values.shape == (102, 1000)

    # Tests coordinates
    assert 'time' in mpl_ds.coords.keys()
    assert 'range' in mpl_ds.coords.keys()
    assert mpl_ds.coords['time'].values.shape == (102,)
    assert mpl_ds.coords['range'].values.shape == (1000,)
    assert '_arm_standards_flag' in mpl_ds.attrs.keys()

    # Tests attributes
    assert '_datastream' in mpl_ds.attrs.keys()
    mpl_ds.close()

Returns:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[9], line 1
----> 1 test_io_mpldataset()

Cell In[8], line 2, in test_io_mpldataset()
      1 def test_io_mpldataset():
----> 2     mpl_ds = act.io.mpl.read_sigma_mplv5(act.tests.EXAMPLE_SIGMA_MPLV5)
      4     # Tests fields
      5     assert 'channel_1' in mpl_ds.variables.keys()

File ~\dev\ACT\act\io\mpl.py:75, in read_sigma_mplv5(filename, save_nc, out_nc_path, afterpulse, dead_time, overlap, **kwargs)
     62 for f in filename:
     63     task.append(
     64         dask.delayed(proc_sigma_mplv5_read)(
     65             f,
   (...)
     72         )
     73     )
---> 75 results_ds = dask.compute(*task)
     77 ds = xr.concat(results_ds, 'time')
     79 return ds

File ~\mambaforge\envs\act-docs\Lib\site-packages\dask\base.py:660, in compute(traverse, optimize_graph, scheduler, get, *args, **kwargs)
    657     postcomputes.append(x.__dask_postcompute__())
    659 with shorten_traceback():
--> 660     results = schedule(dsk, keys, **kwargs)
    662 return repack([f(r, *a) for r, (f, a) in zip(results, postcomputes)])

File ~\dev\ACT\act\io\mpl.py:147, in proc_sigma_mplv5_read(f, save_nc, out_nc_path, afterpulse, dead_time, overlap, **kwargs)
    140     #os.remove(tmpfile2)
    141 
    142 # Calculate range in meters
    143 #ds['range'] = 0.5 * 1* 1 * (ds.range + 0.5)
    144 
    145 # Swap the coordinates to be time and range
    146 ds = ds.swap_dims({'profile': 'time'})
--> 147 ds = ds.assign_coords({'time': ds.time, 'range': ds.range})
    149 # Add metadata
    150 is_arm_file_flag = check_arm_standards(ds)

File ~\mambaforge\envs\act-docs\Lib\site-packages\xarray\core\common.py:300, in AttrAccessMixin.__getattr__(self, name)
    298         with suppress(KeyError):
    299             return source[name]
--> 300 raise AttributeError(
    301     f"{type(self).__name__!r} object has no attribute {name!r}"
    302 )

AttributeError: 'Dataset' object has no attribute 'range'
@zssherman
Copy link
Collaborator Author

We didn't catch this in newer versions because there is a try and except exception catch

@zssherman zssherman added the bug Something isn't working label Oct 21, 2024
@zssherman
Copy link
Collaborator Author

It seems the issue is mpl2nc is producing files with barely anything in them..

xarray.Dataset

Dimensions:
profile: 0

Coordinates: (0)

Data variables:
unit
(profile)
uint16
...



Indexes: (0)

Attributes: (0)
``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant