USNavalResearchLaboratory / eispac

Read the Docs
https://eispac.readthedocs.io/en/latest/
MIT License
23 stars 6 forks source link

Run it all the time with fit_spectra #95

Open zhenxuanSUN opened 2 months ago

zhenxuanSUN commented 2 months ago

I'm trying to fit a moment in time EIS data with dimensions (512, 123, 24) using fit_spectra, but it shows: Found a wavelength 195.12 [Angstroms] in window 8 INFO: uncertainty should have attribute uncertainty_type. [astropy.nddata.] + computing fits for 123 exposures, each with 512 spectra+ running mpfit on 24 cores (of 24)

It ran for a long time with no results, I don't know if it's a result of the amount of data or if there's something wrong with my code. But after reducing the range (raster_cutout = data_cube.crop(lower_left, upper_right)) I can get the result soon. Here is the code for my fitting part:

if name == 'main':

# Read in the fit template and EIS observation
tmplt = eispac.read_template("F:/SW_evolution_plus/data_EIS_2021_01_10_26_region_2/fe_12_195_119.2c.template.h5")
data_cube = eispac.read_cube("F:/SW_evolution_plus/data_EIS_2021_01_10_26_region_2/eis_20210117_072949.data.h5", 195.120)

# Select a cutout of the raster
# raster_cutout = data_cube.crop(lower_left, upper_right)
raster_cutout = data_cube

# Fit the data and save it to disk
fit_res = eispac.fit_spectra(raster_cutout, tmplt, ncpu='max', unsafe_mp=True, min_points=10)
MJWeberg commented 2 months ago

Hello, thanks for reaching out!

The amount of data should not be a problem, especially with that many cores. How are you running the code, are you using an interactive python session of some sort or running on a computing cluster?

My guess is that you are running into an issue with multiprocessing where it gets stuck in an infinite loop. This can happen sometimes when "unsafe_mp" is set to "True" and the code is run directly in an interactive shell or certain Jupyter notebooks (depends on the setup). It might work if you change the your "name guard" line to if __name__=='__main__' (the underscores are essential). If that does not work, please try saving your script in a separate file (including the name guard and a line to save the results to disk) and then running the script from ipython or Jupyter using the command run your_script_name.py.

As a last resort, you can try running your code above in a single thread by setting either ncpu=1 or unsafe_mp=False. The code will take longer to run (probably no more than 5 or 6 min), but it should yield the desired results.

Hope this helps!

zhenxuanSUN commented 2 months ago

Hi MJWeberg!

Thank you for your reply and detailed advice!

I underlined the "name guard" line in my programif __name__=='__main__', but forgot to add it here due to an oversight. I'm using Spyder, and it's probably the same as you're guessing with Jupyter, for example.

When I did what you said about single-core computation and set "unsafe_mp" to False, the results ran very quickly! ncpu=1 unsafe_mp=False