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

Run it all the time with fit_spectra #95

Open
zhenxuanSUN opened this issue Jul 11, 2024 · 2 comments
Open

Run it all the time with fit_spectra #95

zhenxuanSUN opened this issue Jul 11, 2024 · 2 comments

Comments

@zhenxuanSUN
Copy link

zhenxuanSUN commented Jul 11, 2024

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
Copy link
Collaborator

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
Copy link
Author

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

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