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

error in igrf base.py #15

Open
cnsnln opened this issue Sep 2, 2024 · 1 comment
Open

error in igrf base.py #15

cnsnln opened this issue Sep 2, 2024 · 1 comment

Comments

@cnsnln
Copy link

cnsnln commented Sep 2, 2024

I received the following error when I tried to run the test example. I would appreciate it if someone could help me.

import igrf
mag = igrf.igrf('2010-07-12', glat=65, glon=-148, alt_km=100)
I received the error message :
TypeError: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property.

details:
Cell In[35], line 3
1 import igrf
----> 3 mag = igrf.igrf('2010-07-12', glat=65, glon=-148, alt_km=100)

File ~/miniconda3/lib/python3.8/site-packages/igrf/base.py:144, in igrf(time, glat, glon, alt_km, isv, itype)
131 mag = xarray.Dataset(
132 {
133 "north": ("alt_km", Bnorth),
(...)
139 attrs={"time": time, "isv": isv, "itype": itype, "glat": glat, "glon": glon},
140 )
142 decl, incl = mag_vector2incl_decl(mag.north, mag.east, mag.down)
--> 144 mag["incl"] = ("alt_km", incl)
145 mag["decl"] = ("alt_km", decl)
147 return mag

File ~/miniconda3/lib/python3.8/site-packages/xarray/core/variable.py:123, in as_variable(obj, name)
121 elif isinstance(obj, tuple):
122 if isinstance(obj[1], DataArray):
--> 123 raise TypeError(
124 "Using a DataArray object to construct a variable is"
125 " ambiguous, please extract the data using the .data property."
126 )
127 try:
128 obj = Variable(*obj)

TypeError: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property.

@cnsnln
Copy link
Author

cnsnln commented Sep 2, 2024

The error was corrected after I re-installed igrf and run build() in Python.
However, I have to change the commands described in the documentation to make it work. I am running Linux.

  1. after installation, run Python and
    import igrf
    igrf.base.build()

  2. run the example
    from igrf.base import igrf
    mag = igrf ('2010-07-12', glat=65, glon=-148, alt_km=100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant