From 2c0ef0429ba7301544243fc8b3b3c97b9d9e0a61 Mon Sep 17 00:00:00 2001 From: MJWeberg Date: Fri, 17 Jan 2025 15:05:50 -0500 Subject: [PATCH] bug fix for numpy 2.0 and single exp obs --- README.md | 8 +++++--- docs/guide/06-acknowledge.rst | 32 ++++++++++++++++++++++++++++++-- eispac/core/read_cube.py | 9 ++++++--- eispac/core/read_fit.py | 5 ++++- eispac/core/save_fit.py | 6 +++--- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 525a75c..0faf21a 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ Python environment. The general approach is as follows: template files and underlying methodology that is used in the IDL SolarSoft environment. +## Citing EISPAC + +If you use EISPAC in your reaserch, please consider citing the +[JOSS paper](https://joss.theoj.org/papers/10.21105/joss.04914). + ## Getting Started * Install using PIP (recommended) or by manually downloading this repo. @@ -120,8 +125,5 @@ Here, in no particular order, is a list of some things that may be added in futu * Expanded documentation * More unit and integration tests * More detailed logging (with option to send all log information to a file) -* Scripts for quickly viewing data and spectra fits -* Scripts and routines for creating new fit templates * Consider adding a subclass of `NDCubeSequence` which can hold multiple spectral windows * Consider storing the output fit parameters in another `NDCube` -* Restructure project to use the Sunpy affiliated package template? diff --git a/docs/guide/06-acknowledge.rst b/docs/guide/06-acknowledge.rst index 5e7969e..fdf62d7 100644 --- a/docs/guide/06-acknowledge.rst +++ b/docs/guide/06-acknowledge.rst @@ -1,6 +1,34 @@ -Acknowledgments -=============== +Acknowledgments and Citation +============================ This work was sponsored by NASA’s Hinode project. Hinode is a Japanese mission developed and launched by ISAS/JAXA, with NAOJ as domestic partner and NASA and STFC (UK) as international partners. + +Citing EISPAC +------------- + +If you use EISPAC in a research project, please cite the code in any +publications or presentations of that work. This can be as simple as adding +"this research used version X.Y.Z of the of EISPAC software (citation)" to +your methods, software, or acknowledgements section. + +Below is the bibtex code for the current EISPAC paper. + +.. code:: bibtex + + @ARTICLE{Weberg2023, + author = {{Weberg}, Micah and {Warren}, Harry and {Crump}, Nicholas and {Barnes}, Will}, + title = "{EISPAC - The EIS Python Analysis Code}", + journal = {The Journal of Open Source Software}, + keywords = {Python, astronomy, solar physics, spectroscopy}, + year = 2023, + month = may, + volume = {8}, + number = {85}, + eid = {4914}, + pages = {4914}, + doi = {10.21105/joss.04914}, + adsurl = {https://ui.adsabs.harvard.edu/abs/2023JOSS....8.4914W}, + adsnote = {Provided by the SAO/NASA Astrophysics Data System} + } \ No newline at end of file diff --git a/eispac/core/read_cube.py b/eispac/core/read_cube.py index b8b9b3d..039e425 100644 --- a/eispac/core/read_cube.py +++ b/eispac/core/read_cube.py @@ -343,9 +343,12 @@ def read_cube(filename=None, window=0, exp_set='sum', apply_radcal=True, radcal= ### (7) Calculate average exposure time and cadence avg_exptime = np.mean(meta['duration']) - diff_date_obs = np.diff(meta['date_obs'].astype('datetime64')) - diff_date_obs = diff_date_obs / np.timedelta64(1, 's') - avg_cad = np.mean(np.abs(diff_date_obs)) + if index['nexp'] > 1: + diff_date_obs = np.diff(meta['date_obs'].astype('datetime64')) + diff_date_obs = diff_date_obs / np.timedelta64(1, 's') + avg_cad = np.mean(np.abs(diff_date_obs)) + else: + avg_cad = avg_exptime # default for single exposure obs ### (8) Create a new header dict updated values # Note: the order of axes here is the same as the original fits index diff --git a/eispac/core/read_fit.py b/eispac/core/read_fit.py index 5ab649d..1ac66c4 100644 --- a/eispac/core/read_fit.py +++ b/eispac/core/read_fit.py @@ -123,8 +123,11 @@ def read_fit(filename, verbose=False): # Restore the fit function fit_result.fit_func = getattr(fit_fns, fit_result.func_name) - # Make sure the .fit['Line_ids'] is ALWAYS an array (for code consistency) + # Make sure certain metadata are ALWAYS kept as arrays (for code consistency) fit_result.fit['line_ids'] = np.atleast_1d(fit_result.fit['line_ids']) + for META_KEY in ['date_obs', 'duration']: + if META_KEY in fit_result.meta.keys(): # need check for very old files + fit_result.meta[META_KEY] = np.atleast_1d(fit_result.meta[META_KEY]) # If version number is missing, try to guess it if 'eispac_version' not in top_key_list: diff --git a/eispac/core/save_fit.py b/eispac/core/save_fit.py index f2ed0bf..d3f160d 100644 --- a/eispac/core/save_fit.py +++ b/eispac/core/save_fit.py @@ -90,9 +90,9 @@ def walk_and_save(hdf5_group, data_obj, data_key, print_str, verbose=False): if verbose: print(' ', print_str) temp_data = data_obj - if isinstance(data_obj, (np.ndarray, np.str_)): - if str(data_obj.dtype).startswith('U', 1): - temp_data = data_obj.astype(np.string_) + if hasattr(data_obj, 'dtype'): + if 'U' in str(data_obj.dtype): + temp_data = data_obj.astype(np.bytes_) hdf5_group.create_dataset(str(data_key), data=temp_data) # function to save fit dictionary