diff --git a/ApplyDataCube.html b/ApplyDataCube.html index 73c0000..49d7fac 100644 --- a/ApplyDataCube.html +++ b/ApplyDataCube.html @@ -1,3 +1,8 @@ + + + + +

This example will guide you through the process of applying a pre-trained network (i.e. the weights have been trained), to a SITELLE data cube. This example will use the network trained to predict velocity and broadening values, therefore, @@ -38,4 +43,100 @@ output_name = 'output_name' # output file prefix deep_file = '/full/path/to/deep/fits' # Path to deep image fits file: required for header - \ No newline at end of file + + +

+ Now we will load the model. In this case, we are loading the velocity and broadening predictor from the firs paper. + The model and weights are in the `SITELLE-PREDICTOR-I` repository. +

+ +
+  
+    model = keras.models.load_model('SITELLE-PREDICTOR-I')
+  
+
+ +

+ We will now load the data cube, extract a background region, calculate the indices corresponding to + certain wavelengths (this is required for the interpolation), and read in the reference spectrum +

+ +
+  
+    cube = SpectralCube(cube_dir+'/'+cube_name+'.hdf5')
+    # We first need to extract a random spectrum to get the x-axis (Wavenumbers) for the observation
+    axis, spectrum = cube.extract_spectrum(1000, 1000, 1)
+    # We need to find the min and max wavenumber that match our min/max from our synthetic spectra
+    min_ = np.argmin(np.abs(np.array(axis)-14400))
+    max_ = np.argmin(np.abs(np.array(axis)-15700))
+    # LOAD IN SPECTRAL INFORMATION
+    x_min = 0
+    x_max = cube.shape[0]
+    y_min = 0
+    y_max = cube.shape[1]
+    # Now pull data
+    dat = cube.get_data(x_min,x_max,y_min,y_max,min_,max_)
+    # Open our nominal spectrum and get its wavenumbers
+    ref_spec = fits.open('Reference-Spectrum.fits')
+    wavenumbers_syn = []
+    spec_ref_axis = [val[0] for val in ref_spec[1].data]
+    min_w = np.argmin(np.abs(np.array(spec_ref_axis)-14700))  # For intepolation purposes
+    max_w =np.argmin(np.abs(np.array(spec_ref_axis)-15600))
+    x_min = 0
+    x_max = cube.shape[0]
+    y_min = 0
+    y_max = cube.shape[1]
+    # Now pull data
+    dat = cube.get_data(x_min,x_max,y_min,y_max,min_,max_)
+    spec_ref_axis = np.array(spec_ref_axis)[min_w:max_w]
+    for i in range(len(spec_ref_axis)):
+        wavenumbers_syn.append(spec_ref_axis[i])
+  
+
+ +

+ Now for the main functionality. We are going to define our bounds (in the example it is the entire cube). We will + then step through the cube and apply the network to each spaxel. +

+ +
+  
+    # Define Background Region -- you may need to change the background region!!
+    sky_axis, sky_spectrum = cube.extract_spectrum(1806, 1846, 10, median=True, mean_flux=True)
+    # Create empty 2D numpy array corresponding to x/y pixels
+    vels = np.zeros((x_max, y_max))
+    broads = np.zeros((x_max, y_max))
+    start_time = time.time()
+    for i in range(x_max-x_min):
+        for j in range(y_max-y_min):
+            counts = np.zeros((1,len(wavenumbers_syn)))
+            # Interpolate to get only points equivalent to what we have in our synthetic data
+            f = interpolate.interp1d(axis[min_:max_], dat[i,j] - sky_spectrum, kind='slinear')
+            # Get fluxes of interest
+            coun = f(wavenumbers_syn)
+            max_con = np.max(coun)
+            coun = [con/max_con for con in coun]
+            counts[0] = coun
+            # Get into correct format for predictions
+            Spectrum = counts
+            Spectrum = Spectrum.reshape(1, Spectrum.shape[1], 1)
+            predictions = model.predict(Spectrum)
+            vels[i][j] = predictions[0][0]
+            broads[i][j] = predictions[0][1]
+    print(time.time()-start_time)
+  
+
+ +

+ And now we can finally save the velocity and broadening data as fits files. +

+ +
+  
+    # Save as Fits File
+    reg_fits = fits.open(deep_file'.fits')
+    header = reg_fits[0].header
+    fits.writeto(output_dir+'/'+output_name+'_vel.fits', vels.T, header, overwrite=True)
+    fits.writeto(output_dir+'/'+output_name+'_broad.fits', broads.T, header, overwrite=True)
+  
+
diff --git a/SITELLE-PREDICTOR-I/saved_model.pb b/SITELLE-PREDICTOR-I/saved_model.pb new file mode 100644 index 0000000..5e794b4 Binary files /dev/null and b/SITELLE-PREDICTOR-I/saved_model.pb differ diff --git a/SITELLE-PREDICTOR-I/variables/variables.data-00000-of-00001 b/SITELLE-PREDICTOR-I/variables/variables.data-00000-of-00001 new file mode 100644 index 0000000..6ac5801 Binary files /dev/null and b/SITELLE-PREDICTOR-I/variables/variables.data-00000-of-00001 differ diff --git a/SITELLE-PREDICTOR-I/variables/variables.index b/SITELLE-PREDICTOR-I/variables/variables.index new file mode 100644 index 0000000..d3b6267 Binary files /dev/null and b/SITELLE-PREDICTOR-I/variables/variables.index differ diff --git a/examples.html b/examples.html index 58b6bad..6b830fd 100644 --- a/examples.html +++ b/examples.html @@ -11,9 +11,6 @@ - - -