maserlib / maser4py

GNU General Public License v3.0
9 stars 3 forks source link

Voyager test or example #35

Closed OwenJohnsons closed 11 months ago

OwenJohnsons commented 1 year ago

Hello folks,

I am trying to read in some Voyager data using the VgPra3RdrLowband6secV1Data class but there is no documentation so I am getting bogged down in the source code. The data I want to work with is the 6sec Uranus data (VG2_URN_PRA_6SEC.TAB) any pointers would be much appreciated.

i.e. the following

`from maser.data.pds.vg.sweeps import VgPra3RdrLowband6secV1Sweep

header = 'DATA/VG2_URN_PRA_6SEC.LBL' main_file = 'DATA/VG2_URN_PRA_6SEC.TAB' data = VgPra3RdrLowband6secV1Sweep(header, main_file)`

yields

'/Users/oj/Desktop/Uranus Lightning/data-reader.py in line 14 12 header = 'DATA/VG2_URN_PRA_6SEC.LBL' 13 main_file = 'DATA/VG2_URN_PRA_6SEC.TAB' ---> 14 data = VgPra3RdrLowband6secV1Sweep(header, main_file) 15 # data = Vg2NPra3RdrLowband6secV1Data()

File ~/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/pds/vg/sweeps.py:10, in VgPra3RdrLowband6secV1Sweep.init(self, header, data) 8 def init(self, header, data): 9 super().init(header, data) ---> 10 self._frequencies = header["frequencies"] 11 self._time = header["time"] 12 self.header["sweep_type"] = self._get_sweep_type()

TypeError: string indices must be integers, not 'str''

BaptisteCecconi commented 1 year ago

Hi @OwenJohnsons,

As mentioned in the first lines of the repository front page readme, the documentation is available here: https://maser.pages.obspm.fr/maser4py/

And on that page, you can check the User Guide/Read radio data with maser-data

Be sure to check also the installation section.

In your specific case, you need to do the following:

>>> from maser.data import Data
>>> lbl_file =  'DATA/VG2_URN_PRA_6SEC.LBL'
>>> data = Data(lbl_file)

This loads your file, from its label (the corresponding data file must be in the same directory). The data objects has several methods, such as the .sweeps attribute which returns an iterator on sweeps, if you need to access to those sequentially.

>>> for s in data.sweeps:
>>>    print(s.header)
>>>    print(s.data)

There is also a .as_xarray() method, which provides that data as a dictionary, with a Xarray.DataArray object for each variable.

>>> xr = data.as_xarray()

(this method is a bit slow at this point and probably requires optimisation of some sort)

>>> xr.keys()
dict_keys(['R', 'L', 'any'])
>>> xr['R'].sortby("time").plot()
>>> from matplotlib import pyplot as plt
>>> plt.show()

I need to fix a bit the building of the Xarray objects to set the axes right, but at least you can play with it.

I'd be glad to have extra feedback after this message, of course !

Let me know if anything goes wrong.

OwenJohnsons commented 1 year ago

Hello my apologies, I completely missed this page: I am trying to trouble shoot this described method, but it seems that the class is not present, is this a residual issue with the way maser may have been installed that not all classes have been loaded or can I manually point to the class in someway. Note: I have installed maser4py by using poetry


KeyError                                Traceback (most recent call last)
[/Users/oj/Desktop/Uranus](https://vscode-interactive+.vscode-resource.vscode-cdn.net/Users/oj/Desktop/Uranus) Lightning[/data-reader.py](https://vscode-interactive+.vscode-resource.vscode-cdn.net/data-reader.py) in line 7
      [5](file:///Users/oj/Desktop/Uranus%20Lightning/data-reader.py?line=4) from maser.data import Data
      [6](file:///Users/oj/Desktop/Uranus%20Lightning/data-reader.py?line=5) lbl_file =  'DATA[/VG2_URN_PRA_6SEC.LBL](https://vscode-interactive+.vscode-resource.vscode-cdn.net/VG2_URN_PRA_6SEC.LBL)'
----> [7](file:///Users/oj/Desktop/Uranus%20Lightning/data-reader.py?line=6) data = Data(lbl_file)

File [~/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/base/base.py:99](https://vscode-interactive+.vscode-resource.vscode-cdn.net//~/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/base/base.py:99), in Data.__new__(cls, filepath, dataset, *args, **kwargs)
     [95](file:///Users/oj/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/base/base.py?line=94) dataset = cls.get_dataset(cls, filepath)
     [97](file:///Users/oj/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/base/base.py?line=96) # get the dataset class from the registry
     [98](file:///Users/oj/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/base/base.py?line=97) # we need an explicit cast to make mypy happy
---> [99](file:///Users/oj/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/base/base.py?line=98) dataset_class = BaseData._registry[cast(str, dataset)]
    [101](file:///Users/oj/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/base/base.py?line=100) # create a new instance of the dataset class
    [102](file:///Users/oj/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/base/base.py?line=101) # ignore 'gets multiple values for keyword argument "dataset"'
    [103](file:///Users/oj/anaconda3/envs/padme/lib/python3.11/site-packages/maser/data/base/base.py?line=102) return dataset_class(filepath, dataset=None, *args, **kwargs)  # type: ignore

KeyError: 'VG2-U-PRA-3-RDR-LOWBAND-6SEC-V1.0'`
BaptisteCecconi commented 1 year ago

Can you run pip list | grep maser in your environment, and copy the result here ?

OwenJohnsons commented 1 year ago
maser-data                    0.3.5
maser4py                      0.15.2
BaptisteCecconi commented 1 year ago

mhh strange... your version should contain the relevant classes.

BaptisteCecconi commented 1 year ago

I tried to create an empty python 3.11 environment, using conda, but I can't get poetry to work on my mac... sorry, I can't debug this from here (I'm in a conference).

Since poetry is recommended for the development version, you can simply install the package using pip, but I don't see why that would be different in your case ...

OwenJohnsons commented 1 year ago

Hmm, I remade the packages in a few versions of python 3.8 and 3.10 with poetry and the same key issue. Is there a specific version of python that you recommend?

pip install maser4py[all]

Is met with a unknown package. I can install submodules using pip with the pip install maser-plot etc.

When I do a fresh build of maser with poetry and run maser --version I am met with a CDF error


(anakin) oj@Owens-MacBook-Pro-2 Uranus Lightning % python data-reader.py
Traceback (most recent call last):
  File "/Users/oj/Desktop/Uranus Lightning/data-reader.py", line 7, in <module>
    data = Data(filepath = lbl_file)
  File "/Users/oj/anaconda3/envs/anakin/lib/python3.10/site-packages/maser/data/base/base.py", line 99, in __new__
    dataset_class = BaseData._registry[cast(str, dataset)]
KeyError: 'VG2-U-PRA-3-RDR-LOWBAND-6SEC-V1.0'
(anakin) oj@Owens-MacBook-Pro-2 Uranus Lightning % maser --verion
Traceback (most recent call last):
  File "/Users/oj/anaconda3/envs/anakin/bin/maser", line 6, in <module>
    sys.exit(main())
  File "/Users/oj/Desktop/Uranus Lightning/maser4py/src/maser/script.py", line 49, in main
    from maser.tools.cdf.serializer import (
  File "/Users/oj/anaconda3/envs/anakin/lib/python3.10/site-packages/maser/tools/__init__.py", line 6, in <module>
    from maser.tools.cdf.validator import Validate  # noqa: F401
  File "/Users/oj/anaconda3/envs/anakin/lib/python3.10/site-packages/maser/tools/cdf/validator/__init__.py", line 4, in <module>
    from maser.tools.cdf.validator.validator import *  # noqa: F401, F403
  File "/Users/oj/anaconda3/envs/anakin/lib/python3.10/site-packages/maser/tools/cdf/validator/validator.py", line 13, in <module>
    from spacepy.pycdf import CDF, zAttr
  File "/Users/oj/anaconda3/envs/anakin/lib/python3.10/site-packages/spacepy/pycdf/__init__.py", line 1301, in <module>
    raise Exception(('Cannot load CDF C library; checked {0}. '
Exception: Cannot load CDF C library; checked . Try 'os.environ["CDF_LIB"] = library_directory' before import.
xbonnin commented 1 year ago

Hi @OwenJohnsons,

It looks spacepy module does not find the NASA CDF library in your system. Make sure the CDF library is installed and callable from your shell (you can use one of the definitions.* scripts files in the /bin sub-directory to load the CDF environnement). See https://cdf.gsfc.nasa.gov/ for more details about CDF installation.

BaptisteCecconi commented 1 year ago

@xbonnin I think the error is on our side. the CDF support is optional for maser.data.

The CDF library is not found when @OwenJohnsons tries

maser --verion

(and there is a typo in Owen's command: --verion should be --version)

xbonnin commented 1 year ago

@BaptisteCecconi,

CDF is indeed optional for maser.data, but not for maser.tools submodule (which is also installed when you run pip install maser4py[all]). We may think about making spacepy optional in maser.tools in a next release. For the moment, to make sure to install maser.data only (without spacepy), you can run the command: pip install maser4py[data]