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

Spectral_smooth does not work #577

Closed
hongliliu opened this issue Sep 16, 2019 · 4 comments
Closed

Spectral_smooth does not work #577

hongliliu opened this issue Sep 16, 2019 · 4 comments

Comments

@hongliliu
Copy link

Dear developer:
Recently, I tried smoothing my raw data cube in velocity axis with a Gaussian keneral using the function cube.spectral_smooth. However, I always received a error message. Below, I list my scripts and the associated error message after the code runs. Please help me out on how to solve this problem. Thank you very much in advance.
cube = sc.read('t13_reg1.fits')
fwhm_factor = np.sqrt(8*np.log(2))
current_resolution = 0.26569 * u.km/u.s
target_resolution = 0.5 * u.km/u.s
pixel_scale = 0.26569 * u.km/u.s
gaussian_width = ((target_resolution2 - current_resolution2)**0.5 /
pixel_scale / fwhm_factor)
kernel = Gaussian1DKernel(gaussian_width)
new_cube = cube.spectral_smooth(kernel)

---error message---
---> 10 new_cube = cube.spectral_smooth(kernel)

~/anaconda3/lib/python3.6/site-packages/spectral_cube/spectral_cube.py in spectral_smooth(self, kernel, convolve, verbose, use_memmap, num_cores, **kwargs)
2949 use_memmap=use_memmap,
2950 verbose=verbose,
-> 2951 **kwargs)
2952
2953 def spectral_interpolate(self, spectral_grid,

~/anaconda3/lib/python3.6/site-packages/spectral_cube/spectral_cube.py in apply_function_parallel_spectral(self, function, num_cores, verbose, use_memmap, parallel, **kwargs)
2882 verbose=verbose,
2883 num_cores=num_cores,
-> 2884 **kwargs
2885 )
2886

~/anaconda3/lib/python3.6/site-packages/spectral_cube/spectral_cube.py in _apply_function_parallel_base(self, iteration_data, function, applicator, num_cores, verbose, use_memmap, parallel, memmap_dir, update_function, **kwargs)
2762
2763 for arg in iteration_data:
-> 2764 applicator(arg, outcube, function, **kwargs)
2765 pbu()
2766

~/anaconda3/lib/python3.6/site-packages/spectral_cube/spectral_cube.py in _apply_spectral_function(arguments, outcube, function, **kwargs)
108
109 if np.any(includemask):
--> 110 outcube[:,jj,ii] = function(spec, **kwargs)
111 else:
112 outcube[:,jj,ii] = spec

~/anaconda3/lib/python3.6/site-packages/astropy/nddata/decorators.py in wrapper(data, *args, **kwargs)
244 AstropyUserWarning)
245
--> 246 result = func(data, *args, **kwargs)
247
248 if unpack and repack:

~/anaconda3/lib/python3.6/site-packages/astropy/convolution/convolve.py in convolve(array, kernel, boundary, fill_value, nan_treatment, normalize_kernel, mask, preserve_nan, normalization_zero_tol)
336 if normalize_kernel:
337 if not nan_interpolate:
--> 338 result /= kernel_sum
339 else:
340 if nan_interpolate:

~/anaconda3/lib/python3.6/site-packages/astropy/units/quantity.py in array_ufunc(self, function, method, *inputs, **kwargs)
473 return result
474
--> 475 return self._result_as_quantity(result, unit, out)
476
477 def _result_as_quantity(self, result, unit, out):

~/anaconda3/lib/python3.6/site-packages/astropy/units/quantity.py in _result_as_quantity(self, result, unit, out)
512 # the output is of the correct Quantity subclass, as it was passed
513 # through check_output.
--> 514 out._set_unit(unit)
515 return out
516

AttributeError: 'numpy.ndarray' object has no attribute '_set_unit'

@e-koch
Copy link
Contributor

e-koch commented Sep 16, 2019

@hongliliu -- Can you try changing the second last line to kernel = Gaussian1DKernel(gaussian_width.value) and see if that works?

@hongliliu
Copy link
Author

@hongliliu -- Can you try changing the second last line to kernel = Gaussian1DKernel(gaussian_width.value) and see if that works?

It works now following your suggestion. Thank you very much for your kind help.

@e-koch
Copy link
Contributor

e-koch commented Sep 16, 2019

This issue also came up in #514, but it wasn't fixed by #507.

@e-koch
Copy link
Contributor

e-koch commented Nov 21, 2019

Addressed in #578

@e-koch e-koch closed this as completed Nov 21, 2019
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