gemini3d / pygemini

Python interface for Gemini3D
Apache License 2.0
8 stars 3 forks source link

Error reading in electron temperature from frame #12

Closed ljlamarche closed 2 years ago

ljlamarche commented 2 years ago

The read.frame() function will read in "ne" and "Ti" successfully, but throws an error for "Te". This occurred reading output from aurora_EISCAT3D_simple_wide.

Minimum Working Example:

from gemini3d.grid.gridmodeldata import model2pointsgeogcoords
import gemini3d.read as read

gemini_output_dir = 

cfg = read.config(gemini_output_dir)
xg = read.grid(gemini_output_dir)

# This succeeds
dat = read.frame(gemini_output_dir, cfg['time'][-1], var='ne')

# This produces an error
dat = read.frame(gemini_output_dir, cfg['time'][-1], var='Te')

Error:

Traceback (most recent call last):
  File "/Users/e30737/miniconda3/envs/py39/lib/python3.9/site-packages/xarray/core/dataset.py", line 1393, in _construct_dataarray
    variable = self._variables[name]
KeyError: 'ns'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/e30737/Desktop/Software/pygemini/src/gemini3d/read.py", line 327, in frame
    return data(
  File "/Users/e30737/Desktop/Software/pygemini/src/gemini3d/read.py", line 194, in data
    dat["ne"] = (("x1", "x2", "x3"), dat["ns"][LSP - 1, :, :, :].data)
  File "/Users/e30737/miniconda3/envs/py39/lib/python3.9/site-packages/xarray/core/dataset.py", line 1497, in __getitem__
    return self._construct_dataarray(key)
  File "/Users/e30737/miniconda3/envs/py39/lib/python3.9/site-packages/xarray/core/dataset.py", line 1395, in _construct_dataarray
    _, name, variable = _get_virtual_variable(
  File "/Users/e30737/miniconda3/envs/py39/lib/python3.9/site-packages/xarray/core/dataset.py", line 168, in _get_virtual_variable
    ref_var = variables[ref_name]
KeyError: 'ns'
scivision commented 2 years ago

Thanks for reporting I'll look into this!

mattzett commented 2 years ago

@ljlamarche as a workaround you can do :

dat=gemini3d.read.frame(direc,cfg["time"][-1])

and it will read all variables into dat, but of course that wastes time if all you want is one parameter so we'll fix this.

mattzett commented 2 years ago

This was bad logic in read.frame, it is fixed as of: https://github.com/gemini3d/pygemini/commit/c958d3d97274f1bb71aad25e9ddd136c9a2a855c