@@ -337,6 +337,25 @@ def species(self, species):
337337
338338 @property
339339 def fid_object (self ):
340+ try :
341+ self .__fid_object .raw_data = self .data .tolist ()
342+ except AttributeError :
343+ print ('Warning: Fid.data is not yet set. Raw data will not be updated.' )
344+ try :
345+ self .__fid_object .nmr_parameters = Parameters (
346+ acquisition_time = self ._params ['at' ],
347+ relaxation_time = self ._params ['d1' ],
348+ repetition_time = self ._params ['rt' ],
349+ number_of_transients = self ._params ['nt' ],
350+ acquisition_times_array = self ._params ['acqtime' ],
351+ spectral_width_ppm = self ._params ['sw' ],
352+ spectral_width_hz = self ._params ['sw_hz' ],
353+ spectrometer_frequency = self ._params ['sfrq' ],
354+ reference_frequency = self ._params ['reffrq' ],
355+ spectral_width_left = self ._params ['sw_left' ],
356+ )
357+ except AttributeError :
358+ print ('Warning: Fid._params is not yet set. NMR parameters will not be updated.' )
340359 return self .__fid_object
341360
342361 @fid_object .setter
@@ -492,7 +511,7 @@ def deconvoluted_integrals(self):
492511 if peak_object .peak_integral != integral :
493512 peak_object .peak_integral = float (integral )
494513 return integrals
495-
514+
496515 def _get_plots (self ):
497516 """
498517 Return a list of all :class:`~nmrpy.plotting.Plot` objects owned by this :class:`~nmrpy.data_objects.Fid`.
@@ -698,10 +717,13 @@ def phase_correct(self, method='leastsq', verbose = True):
698717 raise ValueError ('Only Fourier-transformed data can be phase-corrected.' )
699718 if verbose :
700719 print ('phasing: %s' % self .id )
701- self .data = Fid ._phase_correct ((self .data , method , verbose ))
720+ phased_data , p0 , p1 = Fid ._phase_correct ((self .data , method , verbose ))
721+ self .data = phased_data
702722 # Update data model
703723 if getattr (self , 'fid_object' , None ) is not None :
704724 self .fid_object .processing_steps .is_phased = True
725+ self .fid_object .processing_steps .zero_order_phase = p0
726+ self .fid_object .processing_steps .first_order_phase = p1
705727
706728 @classmethod
707729 def _phase_correct (cls , list_params ):
@@ -716,18 +738,18 @@ def _phase_correct(cls, list_params):
716738 ('p1' , 0.0 , True ),
717739 )
718740 mz = lmfit .minimize (Fid ._phased_data_sum , p , args = ([data ]), method = method )
719- phased_data = Fid ._ps (data , p0 = mz .params ['p0' ].value , p1 = mz .params ['p1' ].value )
741+ phased_data , p0 , p1 = Fid ._ps (data , p0 = mz .params ['p0' ].value , p1 = mz .params ['p1' ].value )
720742 if abs (phased_data .min ()) > abs (phased_data .max ()):
721743 phased_data *= - 1
722744 if sum (phased_data ) < 0.0 :
723745 phased_data *= - 1
724746 if verbose :
725747 print ('Zero order: %d\t First order: %d\t (In degrees)' % (mz .params ['p0' ].value , mz .params ['p1' ].value ))
726- return phased_data
748+ return phased_data , p0 , p1
727749
728750 @classmethod
729751 def _phased_data_sum (cls , pars , data ):
730- err = Fid ._ps (data , p0 = pars ['p0' ].value , p1 = pars ['p1' ].value ).real
752+ err = Fid ._ps (data , p0 = pars ['p0' ].value , p1 = pars ['p1' ].value )[ 0 ] .real
731753 return numpy .array ([abs (err ).sum ()]* 2 )
732754
733755 @classmethod
@@ -749,7 +771,7 @@ def _ps(cls, data, p0=0.0, p1=0.0):
749771 p1 = p1 * numpy .pi / 180.0
750772 size = len (data )
751773 ph = numpy .exp (1.0j * (p0 + (p1 * numpy .arange (size )/ size )))
752- return ph * data
774+ return ph * data , p0 , p1
753775
754776 def ps (self , p0 = 0.0 , p1 = 0.0 ):
755777 """
@@ -1526,7 +1548,7 @@ def concentrations(self, concentrations):
15261548 if not all (len (concentrations [species ]) == len (self .t ) for species in concentrations .keys ()):
15271549 raise ValueError ('Length of concentrations must match length of FID data.' )
15281550 for v in concentrations .values ():
1529- if not all (isinstance (i , (int , float )) for i in v ):
1551+ if not all (isinstance (i , (in4t , float )) for i in v ):
15301552 raise ValueError ('Concentrations must be a list of integers or floats.' )
15311553 self .__concentrations = concentrations
15321554
@@ -1863,11 +1885,13 @@ def phase_correct_fids(self, method='leastsq', mp=True, cpus=None, verbose=True)
18631885 list_params = [[fid .data , method , verbose ] for fid in fids ]
18641886 phased_data = self ._generic_mp (Fid ._phase_correct , list_params , cpus )
18651887 for fid , datum in zip (fids , phased_data ):
1866- fid .data = datum
1888+ fid .data = datum [ 0 ]
18671889 # Update data model
18681890 if getattr (fid , 'fid_object' , None ) is not None :
18691891 fid .fid_object .processed_data = [str (data ) for data in datum ]
18701892 fid .fid_object .processing_steps .is_phased = True
1893+ fid .fid_object .processing_steps .zero_order_phase = datum [1 ]
1894+ fid .fid_object .processing_steps .first_order_phase = datum [2 ]
18711895 else :
18721896 for fid in self .get_fids ():
18731897 fid .phase_correct (method = method , verbose = verbose )
0 commit comments