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

replace_fillval_by_nan could not handle int type data #204

Open
Beforerr opened this issue Mar 6, 2025 · 3 comments
Open

replace_fillval_by_nan could not handle int type data #204

Beforerr opened this issue Mar 6, 2025 · 3 comments

Comments

@Beforerr
Copy link
Contributor

Beforerr commented Mar 6, 2025

Data like the_efw_l1.the_efw is of integer type., so res[res == fill_value] = np.nan raises error.

Since the data is not in speasy cdaweb, I attach a yaml file

the_efw_l1:
  inventory_path: spdf/THEMIS/THE/L1/EFW
  master_cdf: https://spdf.gsfc.nasa.gov/pub/data/themis/the/l1/efw/2021/the_l1_efw_20210102_v01.cdf
  split_frequency: daily
  split_rule: regular
  url_pattern: https://spdf.gsfc.nasa.gov/pub/data/themis/the/l1/efw/{Y}/the_l1_efw_{Y}{M:02d}{D:02d}_v\d+.cdf
  use_file_list: true
@Beforerr
Copy link
Contributor Author

Beforerr commented Mar 6, 2025

I tried to fix but somehow numpy does not support NaN Integer, maybe we could log a warning instead?

@jeandet
Copy link
Member

jeandet commented Mar 6, 2025

@Beforerr, I'm not sure a warning is what we want here since replace_fillval_by_nan is really meant to be used only on floating values. The NaN concept only exists for floating values.
What you can do instead, is always cast your variable to floating type before using replace_fillval_by_nan like this:

import speasy as spz
import numpy as np

np.astype(spz.get_data( spz.inventories.data_tree.cda.Cluster.C1.FGM_SPIN.C1_CP_FGM_SPIN.B_vec_xyz_gse__C1_CP_FGM_SPIN , "2012-03-02", "2012-03-03"),np.float32).replace_fillval_by_nan()

@Beforerr
Copy link
Contributor Author

Beforerr commented Mar 8, 2025

@jeandet Thank you for your suggestion! You’re right, explicitly casting the data to a floating type before applying replace_fillval_by_nan() makes sense.

Ideally, I think the user just want to replace the fill value with NaN to clean the data. So a united interface would be helpful. Maybe we could put something like this to sanitized_with_nan (like santize but keep nan)

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

2 participants