Skip to content

Commit

Permalink
bug fix for numpy 2.0 and single exp obs
Browse files Browse the repository at this point in the history
  • Loading branch information
MJWeberg committed Jan 17, 2025
1 parent 098b0e6 commit 2c0ef04
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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?
32 changes: 30 additions & 2 deletions docs/guide/06-acknowledge.rst
Original file line number Diff line number Diff line change
@@ -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}
}
9 changes: 6 additions & 3 deletions eispac/core/read_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion eispac/core/read_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions eispac/core/save_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2c0ef04

Please sign in to comment.