@@ -341,6 +341,25 @@ def species(self, species):
341341
342342 @property
343343 def fid_object (self ):
344+ try :
345+ self .__fid_object .raw_data = self .data .tolist ()
346+ except AttributeError :
347+ print ('Warning: Fid.data is not yet set. Raw data will not be updated.' )
348+ try :
349+ self .__fid_object .nmr_parameters = Parameters (
350+ acquisition_time = self ._params ['at' ],
351+ relaxation_time = self ._params ['d1' ],
352+ repetition_time = self ._params ['rt' ],
353+ number_of_transients = self ._params ['nt' ],
354+ acquisition_times_array = self ._params ['acqtime' ],
355+ spectral_width_ppm = self ._params ['sw' ],
356+ spectral_width_hz = self ._params ['sw_hz' ],
357+ spectrometer_frequency = self ._params ['sfrq' ],
358+ reference_frequency = self ._params ['reffrq' ],
359+ spectral_width_left = self ._params ['sw_left' ],
360+ )
361+ except AttributeError :
362+ print ('Warning: Fid._params is not yet set. NMR parameters will not be updated.' )
344363 return self .__fid_object
345364
346365 @fid_object .setter
@@ -496,7 +515,7 @@ def deconvoluted_integrals(self):
496515 if peak_object .peak_integral != integral :
497516 peak_object .peak_integral = float (integral )
498517 return integrals
499-
518+
500519 def _get_plots (self ):
501520 """
502521 Return a list of all :class:`~nmrpy.plotting.Plot` objects owned by this :class:`~nmrpy.data_objects.Fid`.
@@ -699,10 +718,13 @@ def phase_correct(self, method='leastsq', verbose = True):
699718 raise ValueError ('Only Fourier-transformed data can be phase-corrected.' )
700719 if verbose :
701720 print ('phasing: %s' % self .id )
702- self .data = Fid ._phase_correct ((self .data , method , verbose ))
721+ phased_data , p0 , p1 = Fid ._phase_correct ((self .data , method , verbose ))
722+ self .data = phased_data
703723 # Update data model
704724 if getattr (self , 'fid_object' , None ) is not None :
705725 self .fid_object .processing_steps .is_phased = True
726+ self .fid_object .processing_steps .zero_order_phase = p0
727+ self .fid_object .processing_steps .first_order_phase = p1
706728
707729 @classmethod
708730 def _phase_correct (cls , list_params ):
@@ -717,18 +739,18 @@ def _phase_correct(cls, list_params):
717739 ('p1' , 0.0 , True ),
718740 )
719741 mz = lmfit .minimize (Fid ._phased_data_sum , p , args = ([data ]), method = method )
720- phased_data = Fid ._ps (data , p0 = mz .params ['p0' ].value , p1 = mz .params ['p1' ].value )
742+ phased_data , p0 , p1 = Fid ._ps (data , p0 = mz .params ['p0' ].value , p1 = mz .params ['p1' ].value )
721743 if abs (phased_data .min ()) > abs (phased_data .max ()):
722744 phased_data *= - 1
723745 if sum (phased_data ) < 0.0 :
724746 phased_data *= - 1
725747 if verbose :
726748 print ('Zero order: %d\t First order: %d\t (In degrees)' % (mz .params ['p0' ].value , mz .params ['p1' ].value ))
727- return phased_data
749+ return phased_data , p0 , p1
728750
729751 @classmethod
730752 def _phased_data_sum (cls , pars , data ):
731- err = Fid ._ps (data , p0 = pars ['p0' ].value , p1 = pars ['p1' ].value ).real
753+ err = Fid ._ps (data , p0 = pars ['p0' ].value , p1 = pars ['p1' ].value )[ 0 ] .real
732754 return numpy .array ([abs (err ).sum ()]* 2 )
733755
734756 @classmethod
@@ -750,7 +772,7 @@ def _ps(cls, data, p0=0.0, p1=0.0):
750772 p1 = p1 * numpy .pi / 180.0
751773 size = len (data )
752774 ph = numpy .exp (1.0j * (p0 + (p1 * numpy .arange (size )/ size )))
753- return ph * data
775+ return ph * data , p0 , p1
754776
755777 def ps (self , p0 = 0.0 , p1 = 0.0 ):
756778 """
@@ -1527,7 +1549,7 @@ def concentrations(self, concentrations):
15271549 if not all (len (concentrations [species ]) == len (self .t ) for species in concentrations .keys ()):
15281550 raise ValueError ('Length of concentrations must match length of FID data.' )
15291551 for v in concentrations .values ():
1530- if not all (isinstance (i , (int , float )) for i in v ):
1552+ if not all (isinstance (i , (in4t , float )) for i in v ):
15311553 raise ValueError ('Concentrations must be a list of integers or floats.' )
15321554 self .__concentrations = concentrations
15331555
@@ -1912,11 +1934,13 @@ def phase_correct_fids(self, method='leastsq', mp=True, cpus=None, verbose=True)
19121934 list_params = [[fid .data , method , verbose ] for fid in fids ]
19131935 phased_data = self ._generic_mp (Fid ._phase_correct , list_params , cpus )
19141936 for fid , datum in zip (fids , phased_data ):
1915- fid .data = datum
1937+ fid .data = datum [ 0 ]
19161938 # Update data model
19171939 if getattr (fid , 'fid_object' , None ) is not None :
19181940 fid .fid_object .processed_data = [str (data ) for data in datum ]
19191941 fid .fid_object .processing_steps .is_phased = True
1942+ fid .fid_object .processing_steps .zero_order_phase = datum [1 ]
1943+ fid .fid_object .processing_steps .first_order_phase = datum [2 ]
19201944 else :
19211945 for fid in self .get_fids ():
19221946 fid .phase_correct (method = method , verbose = verbose )
0 commit comments