def calculate_callback(self): """ Callback for when they hit calculate :return: """ # Determine the data component and order order = int(self.order_combobox.currentText()) data_name = self.data_combobox.currentText() # Grab spectral-cube import spectral_cube cube = spectral_cube.SpectralCube(self.data[data_name], wcs=self.data.coords.wcs) # Use the package asteval to do the calculation, we are going to # assume here that the lhs of the equals sign is going to be the output named variable try: cube_moment = cube.moment(order=order, axis=0) label = '{}-moment-{}'.format(data_name, order) self.parent.add_overlay(cube_moment.value, label) except Exception as e: print('Error {}'.format(e)) self.close()
def collapse_cube(data_component, data_name, wcs, operation, start_index, end_index): """ :param data_component: Component from the data object :param wcs: :param operation: :param start: :param end: :return: """ # Grab spectral-cube import spectral_cube # Create a spectral cube instance cube = spectral_cube.SpectralCube(data_component, wcs=wcs) # Do collapsing of the cube sub_cube = cube[start_index:end_index] calculated = sub_cube.apply_numpy_function(operations[operation], axis=0) wavelengths = sub_cube.spectral_axis # Send collapsed cube back to cubeviz return wavelengths, calculated
def test_moment_maps_2(moment_maps_gui, cubeviz_layout): # Create GUI mm = moment_maps_gui mm.display() mm.order_combobox.setCurrentIndex(1) mm.data_combobox.setCurrentIndex(0) # Call calculate function and get result mm.calculate_callback() moment_component_id = [ str(x) for x in cubeviz_layout._data.container_2d.component_ids() if str(x).startswith('018.DATA-moment-2') ][0] np_result = cubeviz_layout._data.container_2d[moment_component_id] # Expected result np_data = cubeviz_layout._data[DATA_LABELS[0]] import spectral_cube cube = spectral_cube.SpectralCube(np_data, wcs=cubeviz_layout._data.coords.wcs) order = int(mm.order_combobox.currentText()) cube_moment = np.asarray(cube.moment(order=order, axis=0)) # cube_moment - np_result <= atol + rtol * absolute(np_result) assert np.allclose(cube_moment, np_result, rtol=0.01, equal_nan=True) assert cubeviz_layout.cube_views[1]._widget.cubeviz_unit.unit == 'm2'
def do_calculation(self, order, data_name): # Grab spectral-cube import spectral_cube cube = spectral_cube.SpectralCube(self.data[data_name], wcs=self.data.coords.wcs) cube_moment = cube.moment(order=order, axis=0) self.label = '{}-moment-{}'.format(data_name, order) # Add new overlay/component to cubeviz. We add this both to the 2D # container Data object and also as an overlay. In future we might be # able to use the 2D container Data object for the overlays directly. add_to_2d_container(self.parent, self.data, cube_moment.value, self.label) self.parent.add_overlay(cube_moment.value, self.label, display_now=False)
def do_calculation(self, order, data_name): # Grab spectral-cube import spectral_cube cube = spectral_cube.SpectralCube(self.data[data_name], wcs=self.data.coords.wcs) cube_moment = cube.moment(order=order, axis=0) self.label = '{}-moment-{}'.format(data_name, order) # Add new overlay/component to cubeviz. We add this both to the 2D # container Data object and also as an overlay. In future we might be # able to use the 2D container Data object for the overlays directly. add_to_2d_container(self.parent, self.data, cube_moment.value, cube_moment.unit, self.label) # Going to pass in just the value into the overlay as the units aren't # currently used for the overlay area. BUT, this is probably not the # best way to do this. self.parent.add_overlay(cube_moment.value, self.label, display_now=False)