Skip to content

Commit c264e7b

Browse files
Fixed all other occurrences of scape.fitting that I could find and conformed to the scikits.fitting as fit convention.
1 parent 91bfddd commit c264e7b

File tree

9 files changed

+60
-56
lines changed

9 files changed

+60
-56
lines changed

AR1/reductions/tipping_curve/jupyter_analysis/Tipping curve for SKA prototype report.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
" for val_el,ra,dec,el in zip(sort_ind,self.ra,self.dec,self.elevation):\n",
419419
" self.T_sky.append( T_sky(ra,dec))\n",
420420
" self.Tsys_sky[pol].append(tipping_mu[val_el]-T_sky(ra,dec))\n",
421-
" TmpSky = scape.fitting.PiecewisePolynomial1DFit()\n",
421+
" TmpSky = fit.PiecewisePolynomial1DFit()\n",
422422
" TmpSky.fit(self.elevation, self.T_sky)\n",
423423
" self.Tsky = TmpSky\n",
424424
"\n",
@@ -661,7 +661,7 @@
661661
" else: \n",
662662
" tau = 0.01078\n",
663663
" print(\"atmospheric_opacity = %f at %f MHz\"%(tau,freqs))\n",
664-
" tip = scape.fitting.NonLinearLeastSquaresFit(None, [0, 0.00]) # nonsense Vars\n",
664+
" tip = fit.NonLinearLeastSquaresFit(None, [0, 0.00]) # nonsense Vars\n",
665665
" def know_quant(x):\n",
666666
" rx = T_rx.rec[pol](freqs)\n",
667667
" sky = T_sys.Tsky(x)\n",

AR1/reductions/tipping_curve/red_tipping_curve_AR1.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def __init__(self,d,freqs=1822,freq_index=0,elevation=None,ra=None,dec=None ,sur
269269
for val_el,ra,dec,el in zip(sort_ind,self.ra,self.dec,self.elevation):
270270
self.T_sky.append( T_sky(ra,dec))
271271
self.Tsys_sky[pol].append(tipping_mu[val_el]-T_sky(ra,dec))
272-
TmpSky = scape.fitting.PiecewisePolynomial1DFit()
272+
TmpSky = fit.PiecewisePolynomial1DFit()
273273
TmpSky.fit(self.elevation, self.T_sky)
274274
self.Tsky = TmpSky
275275

@@ -421,7 +421,7 @@ def fit_tipping(T_sys,SpillOver,pol,freqs,T_rx,fixopacity=False):
421421
else:
422422
tau = 0.01078
423423
print("atmospheric_opacity = %f at %f MHz"%(tau,freqs))
424-
tip = scape.fitting.NonLinearLeastSquaresFit(None, [0, 0.00]) # nonsense Vars
424+
tip = fit.NonLinearLeastSquaresFit(None, [0, 0.00]) # nonsense Vars
425425
def know_quant(x):
426426
rx = T_rx.rec[pol](freqs)
427427
sky = T_sys.Tsky(x)
@@ -673,7 +673,7 @@ def find_nearest(array,value):
673673
#print ('Chi square for HH at %s MHz is: %6f ' % (np.mean(d.freqs),fit_H['chisq'],))
674674
#print ('Chi square for VV at %s MHz is: %6f ' % (np.mean(d.freqs),fit_V['chisq'],))
675675
length = len(T_SysTemp.elevation)
676-
Tsky_spec = 2.725 + 1.6*(d.freqs[i]/1e3)**-2.75 # T_SysTemp.Tsys_sky is Tsys-(Tsky-cmb) . We then add the spec sky aproxx (T_gal+Tcmb)
676+
Tsky_spec = 2.725 + 1.6*(d.freqs[i]/1e3)**-2.75 # T_SysTemp.Tsys_sky is Tsys-(Tsky-cmb) . We then add the spec sky aproxx (T_gal+Tcmb)
677677
tsys[0:length,i,0] = (np.array(T_SysTemp.Tsys_sky['HH'])+Tsky_spec)/aperture_efficiency.eff['HH'](d.freqs[i])
678678
tsys[0:length,i,1] = (np.array(T_SysTemp.Tsys_sky['VV'])+Tsky_spec)/aperture_efficiency.eff['VV'](d.freqs[i])
679679
tsys[0:length,i,2] = T_SysTemp.elevation
@@ -728,7 +728,7 @@ def find_nearest(array,value):
728728
according to ITU-R P.676-9. $T_{\mathrm{ant}}$ is the excess temperature since the other components are
729729
known. """
730730

731-
text += r"""The green solid lines in the figures reflect the modelled $T_{\mathrm{sys}}(\mathrm{el})$ or $T_{\mathrm{sys}}(\mathrm{freq})$, with the
731+
text += r"""The green solid lines in the figures reflect the modelled $T_{\mathrm{sys}}(\mathrm{el})$ or $T_{\mathrm{sys}}(\mathrm{freq})$, with the
732732
broken green lines indicating a $\pm10\%$ margin."""
733733

734734
params = {'font.size': 10}

RTS/2.1-Tipping_Curve/red_tipping_curve.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def __init__(self,d,freqs=1822,freq_index=0,elevation=None,ra=None,dec=None ,sur
277277
for val_el,ra,dec,el in zip(sort_ind,self.ra,self.dec,self.elevation):
278278
self.T_sky.append( T_sky(ra,dec))
279279
self.Tsys_sky[pol].append(tipping_mu[val_el]-T_sky(ra,dec))
280-
TmpSky = scape.fitting.PiecewisePolynomial1DFit()
280+
TmpSky = fit.PiecewisePolynomial1DFit()
281281
TmpSky.fit(self.elevation, self.T_sky)
282282
self.Tsky = TmpSky
283283

@@ -307,16 +307,16 @@ def remove_rfi(d,width=3,sigma=5,axis=1):
307307
def load_cal(filename, baseline, nd_models, freq_channel=None,channel_bw=10.0,channel_mask='',n_chan = 4096,channel_range=None,band_input=None):
308308
""" Load the dataset into memory """
309309
print('Loading noise diode models')
310-
310+
311311
try:
312312
d = scape.DataSet(filename, baseline=baseline, nd_models=nd_models,band=band_input)
313313
except IOError:
314314
nd = scape.gaincal.NoiseDiodeModel(freq=[800,2000],temp=[20,20])
315315
warnings.warn('Warning: Failed to load/find Noise Diode Models, setting models to 20K ')
316316
print('Warning: Failed to load/find Noise Diode Models, setting models to 20K ')
317317
d = scape.DataSet(filename, baseline=baseline, nd_h_model = nd, nd_v_model=nd ,band=band_input)
318-
319-
318+
319+
320320
if not channel_range is None :
321321
start_freq_channel = int(channel_range.split(',')[0])
322322
end_freq_channel = int(channel_range.split(',')[1])
@@ -438,7 +438,7 @@ def fit_tipping(T_sys,SpillOver,pol,freqs,T_rx,fixopacity=False):
438438
else:
439439
tau = 0.01078
440440
print("atmospheric_opacity = %f at %f MHz"%(tau,freqs))
441-
tip = scape.fitting.NonLinearLeastSquaresFit(None, [0, 0.00]) # nonsense Vars
441+
tip = fit.NonLinearLeastSquaresFit(None, [0, 0.00]) # nonsense Vars
442442
def know_quant(x):
443443
rx = T_rx.rec[pol](freqs)
444444
sky = T_sys.Tsky(x)
@@ -480,7 +480,7 @@ def plot_data_el(Tsys,Tant,title='',units='K',line=42,aperture_efficiency=None,f
480480
for error_margin in [0.9,1.1]:
481481
plt.hlines(recLim_apEffH*error_margin,elevation.min(), elevation.max(), lw=1.1,colors='g',linestyle='--')
482482
plt.hlines(recLim_apEffV*error_margin,elevation.min(), elevation.max(), lw=1.1,colors='g',linestyle='--')
483-
483+
484484
plt.grid()
485485
plt.ylabel('$T_{sys}/\eta_{ap}$ (K)')
486486
return fig
@@ -524,7 +524,7 @@ def plot_data_freq(frequency,Tsys,Tant,title='',aperture_efficiency=None):
524524
plt.plot(frequency,recLim_apEffV,lw=1.1,color='limegreen',linestyle='-')
525525
for error_margin in [0.9,1.1]:
526526
plt.plot(frequency,recLim_apEffH*error_margin, lw=1.1,color='g',linestyle='--')
527-
plt.plot(frequency,recLim_apEffV*error_margin, lw=1.1,color='g',linestyle='--')
527+
plt.plot(frequency,recLim_apEffV*error_margin, lw=1.1,color='g',linestyle='--')
528528

529529
low_lim = (r_lim(Tsys[:,0:2]),r_lim(Tant[:,0:2]) )
530530
low_lim = np.min(low_lim)
@@ -536,7 +536,7 @@ def tmp(x):
536536
high_lim = np.max((high_lim , 46*1.3))
537537
plt.ylim(low_lim,high_lim)
538538
plt.vlines(900,low_lim,high_lim,lw=1.1,color='darkviolet',linestyle='--')
539-
plt.vlines(1680,low_lim,high_lim,lw=1.1,color='darkviolet',linestyle='--')
539+
plt.vlines(1680,low_lim,high_lim,lw=1.1,color='darkviolet',linestyle='--')
540540
if np.min(frequency) <= 1420 :
541541
plt.hlines(42, np.min((frequency.min(),1420)), 1420, colors='k')
542542
if np.max(frequency) >=1420 :
@@ -569,7 +569,7 @@ def tmp(x):
569569

570570
parser.add_option( "--fix-opacity",action="store_true", default=False,
571571
help="The opacity is fixed to 0.01078 (Van Zee et al.,1997) or it is calculated according to ITU-R P.676-9.")
572-
parser.add_option("-c", "--channel-mask", default='/var/kat/katsdpscripts/RTS/rfi_mask.pickle',
572+
parser.add_option("-c", "--channel-mask", default='/var/kat/katsdpscripts/RTS/rfi_mask.pickle',
573573
help="Optional pickle file with boolean array specifying channels to mask (default is no mask)")
574574

575575
(opts, args) = parser.parse_args()
@@ -610,9 +610,9 @@ def find_nearest(array,value):
610610
Band,SN = h5.receivers.get(ant.name,'l.4').split('.') # A safe Default
611611
else:
612612
Band = 'L'
613-
SN = h5.sensor['Antennas/'+ant.name+'/rsc_rxl_serial_number'][0] # Try get the serial no. only used for noise&recever model
614-
615-
613+
SN = h5.sensor['Antennas/'+ant.name+'/rsc_rxl_serial_number'][0] # Try get the serial no. only used for noise&recever model
614+
615+
616616
receiver_model_H = str("{}/Rx{}_SN{:0>4d}_calculated_noise_H_chan.dat".format(opts.receiver_models,str.upper(Band),int(SN)))
617617
receiver_model_V = str("{}/Rx{}_SN{:0>4d}_calculated_noise_V_chan.dat".format(opts.receiver_models,str.upper(Band),int(SN)))
618618
aperture_efficiency_h = "%s/ant_eff_%s_H_AsBuilt.csv"%(opts.aperture_efficiency,str.upper(Band))
@@ -625,8 +625,8 @@ def find_nearest(array,value):
625625
freq_list = np.zeros((len(chunks)))
626626
for j,chunk in enumerate(chunks):freq_list[j] = h5.channel_freqs[chunk].mean()/1e6
627627
print("Selecting channel data to form %f MHz Channels"%(channel_bw) )
628-
d = load_cal(filename, "%s" % (ant.name,), nd_models, chunks,channel_mask=channel_mask,n_chan=n_chans,channel_range=freq_chans,band_input=Band.lower())
629-
628+
d = load_cal(filename, "%s" % (ant.name,), nd_models, chunks,channel_mask=channel_mask,n_chan=n_chans,channel_range=freq_chans,band_input=Band.lower())
629+
630630
for j in xrange(len(d.freqs)):freq_list[j] = d.freqs[j]
631631

632632
tsys = np.zeros((len(d.scans),len(freq_list),5 ))#*np.NaN
@@ -659,7 +659,7 @@ def find_nearest(array,value):
659659
#print ('Chi square for HH at %s MHz is: %6f ' % (np.mean(d.freqs),fit_H['chisq'],))
660660
#print ('Chi square for VV at %s MHz is: %6f ' % (np.mean(d.freqs),fit_V['chisq'],))
661661
length = len(T_SysTemp.elevation)
662-
Tsky_spec = 2.725 + 1.6*(d.freqs[i]/1e3)**-2.75 # T_SysTemp.Tsys_sky is Tsys-(Tsky-cmb) . We then add the spec sky aproxx (T_gal+Tcmb)
662+
Tsky_spec = 2.725 + 1.6*(d.freqs[i]/1e3)**-2.75 # T_SysTemp.Tsys_sky is Tsys-(Tsky-cmb) . We then add the spec sky aproxx (T_gal+Tcmb)
663663
tsys[0:length,i,0] = (np.array(T_SysTemp.Tsys_sky['HH'])+Tsky_spec)/aperture_efficiency.eff['HH'](d.freqs[i])
664664
tsys[0:length,i,1] = (np.array(T_SysTemp.Tsys_sky['VV'])+Tsky_spec)/aperture_efficiency.eff['VV'](d.freqs[i])
665665
tsys[0:length,i,2] = T_SysTemp.elevation
@@ -695,26 +695,26 @@ def find_nearest(array,value):
695695
#break
696696

697697
fig = plt.figure(None,figsize = (8,8))
698-
text =r"""The 'tipping curve' is calculated according to the expression below, with the parameters
699-
of $T_{\mathrm{ant}}$ and $\tau_{0}$, the Antenna temperature and the atmospheric opacity respectively. All the
698+
text =r"""The 'tipping curve' is calculated according to the expression below, with the parameters
699+
of $T_{\mathrm{ant}}$ and $\tau_{0}$, the Antenna temperature and the atmospheric opacity respectively. All the
700700
variables are also functions of frequency.
701701
702702
$T_{\mathrm{sys}}(\mathrm{el}) = T_{\mathrm{cmb}}(\mathrm{ra,dec}) + T_{\mathrm{gal}}(\mathrm{ra,dec}) + T_{\mathrm{atm}}*(1-\exp\left(\frac{-\tau_{0}}{\sin(\mathrm{el})}\right)) + T_{\mathrm{spill}}(\mathrm{el}) + T_{\mathrm{ant}} + T_{\mathrm{rx}}$
703703
704704
$T_{\mathrm{sys}}(\mathrm{el})$ is determined from the noise diode calibration so it is $\frac{T_{\mathrm{sys}}(\mathrm{el})}{\eta_{_{\mathrm{illum}}}}$
705705
706-
We assume the opacity and $T_{\mathrm{ant}}$ is the residual after the tipping curve function is calculated.
706+
We assume the opacity and $T_{\mathrm{ant}}$ is the residual after the tipping curve function is calculated.
707707
$T_{\mathrm{cmb}}$ + $T_{\mathrm{gal}}$ is obtained from the Sky model. """
708708
if fix_opacity :
709-
text += r"""$\tau_{0}$, the zenith opacity, is set to 0.01078
710-
(Van Zee et al., 1997). $T_{\mathrm{ant}}$ is the excess temperature since the other components are
709+
text += r"""$\tau_{0}$, the zenith opacity, is set to 0.01078
710+
(Van Zee et al., 1997). $T_{\mathrm{ant}}$ is the excess temperature since the other components are
711711
known. """
712712
else:
713-
text += r"""$\tau_{0}$, the zenith opacity, is the calculated opacity
714-
according to ITU-R P.676-9. $T_{\mathrm{ant}}$ is the excess temperature since the other components are
713+
text += r"""$\tau_{0}$, the zenith opacity, is the calculated opacity
714+
according to ITU-R P.676-9. $T_{\mathrm{ant}}$ is the excess temperature since the other components are
715715
known. """
716716

717-
text += r"""The green solid lines in the figures reflect the modelled $T_{\mathrm{sys}}(\mathrm{el})$ or $T_{\mathrm{sys}}(\mathrm{freq})$, with the
717+
text += r"""The green solid lines in the figures reflect the modelled $T_{\mathrm{sys}}(\mathrm{el})$ or $T_{\mathrm{sys}}(\mathrm{freq})$, with the
718718
broken green lines indicating a $\pm10\%$ margin."""
719719

720720
params = {'font.size': 10}

katsdpscripts/reduction/analyse_point_source_scans.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import katpoint
1818
import logging
1919
import pickle
20-
import scikits.fitting as fitting
20+
import scikits.fitting as fit
2121

2222
try:
2323
import matplotlib.pyplot as plt
@@ -33,7 +33,7 @@ def interp_sensor(compscan, quantity, default):
3333
except KeyError:
3434
return (lambda times: default)
3535
else:
36-
interp = fitting.PiecewisePolynomial1DFit(max_degree=0)
36+
interp = fit.PiecewisePolynomial1DFit(max_degree=0)
3737
interp.fit(sensor['timestamp'], sensor['value'])
3838
return interp
3939

@@ -224,7 +224,7 @@ def reduce_and_plot(dataset, current_compscan, reduced_data, opts, fig=None, **k
224224
plt.close('all')
225225
#return the recarray
226226
to_keep=[]
227-
for field in output_field_names:
227+
for field in output_field_names:
228228
to_keep.append([data[field] for data in reduced_data if data and data['keep']])
229229
output_data = np.rec.fromarrays(to_keep, dtype=zip(output_field_names,[np.array(tk).dtype for tk in to_keep]))
230230
return (dataset.antenna, output_data,)
@@ -505,14 +505,14 @@ def done_callback(event):
505505
plt.show()
506506

507507

508-
def batch_mode_analyse_point_source_scans(filename, outfilebase=None, keepfilename=None, baseline='sd',
509-
mc_iterations=1, time_offset=0.0, pointing_model=None, freq_chans=None, old_loader=None, nd_models=None,
508+
def batch_mode_analyse_point_source_scans(filename, outfilebase=None, keepfilename=None, baseline='sd',
509+
mc_iterations=1, time_offset=0.0, pointing_model=None, freq_chans=None, old_loader=None, nd_models=None,
510510
ku_band=False, channel_mask=None,keep_all=None,remove_spikes=False,freq_centre=None):
511511

512512
class FakeOptsForBatch(object):
513513
batch = True #always batch
514514
plot_spectrum = False #never plot
515-
def __init__(self, outfilebase, keepfilename, baseline,
515+
def __init__(self, outfilebase, keepfilename, baseline,
516516
mc_iterations, time_offset, pointing_model, freq_chans, old_loader, nd_models, ku_band, channel_mask,keep_all,remove_spikes,freq_centre):
517517
self.outfilebase=outfilebase
518518
self.keepfilename=keepfilename
@@ -530,12 +530,12 @@ def __init__(self, outfilebase, keepfilename, baseline,
530530
self.remove_spikes=remove_spikes
531531
self.freq_centre = freq_centre
532532

533-
fake_opts = FakeOptsForBatch(outfilebase=outfilebase, keepfilename=keepfilename, baseline=baseline,
533+
fake_opts = FakeOptsForBatch(outfilebase=outfilebase, keepfilename=keepfilename, baseline=baseline,
534534
mc_iterations=mc_iterations, time_offset=time_offset, pointing_model=pointing_model, freq_chans=freq_chans,
535535
old_loader=old_loader, nd_models=nd_models, ku_band=ku_band, channel_mask=channel_mask,keep_all=keep_all,
536536
remove_spikes=remove_spikes,freq_centre=freq_centre)
537537
(dataset_antenna, output_data,) = analyse_point_source_scans(filename, fake_opts)
538-
538+
539539
return dataset_antenna, output_data
540540

541541

reduction/fit_tipping_curve.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import scape
2323
from katpoint import rad2deg, deg2rad, construct_azel_target
2424
from math import *
25+
import skikits.fitting as fit
2526

2627
class Sky_temp:
2728
"""
@@ -101,8 +102,8 @@ def __init__(self,nu,path=''):
101102
elif (nu >= 1200) and (nu <= 1600):
102103
spilloverH_nu = (nu-1200)/(1600-1200)*spillover_1600H[1] + (1 - (nu-1200)/(1600-1200))*spillover_1200H[1]
103104
spilloverV_nu = (nu-1200)/(1600-1200)*spillover_1600V[1] + (1 - (nu-1200)/(1600-1200))*spillover_1200V[1]
104-
T_HH = scape.fitting.PiecewisePolynomial1DFit()
105-
T_VV = scape.fitting.PiecewisePolynomial1DFit()
105+
T_HH = fit.PiecewisePolynomial1DFit()
106+
T_VV = fit.PiecewisePolynomial1DFit()
106107
T_HH.fit(elH, spilloverH_nu[sort_ind])
107108
T_VV.fit(elV, spilloverV_nu[sort_ind])
108109
self.spill = {}
@@ -147,7 +148,7 @@ def __init__(self,d,path='~/comm/catalogues/TBGAL_CONVL.FITS'):#d, nu, pol
147148
for val_el,ra,dec,el in zip(sort_ind,self.ra,self.dec,self.elevation):
148149
self.T_sky.append( T_sky(ra,dec))
149150
self.Tsys_sky[pol].append(tipping_mu[val_el]-T_sky(ra,dec))
150-
TmpSky = scape.fitting.PiecewisePolynomial1DFit()
151+
TmpSky = fit.PiecewisePolynomial1DFit()
151152
TmpSky.fit(self.elevation, self.T_sky)
152153
self.Tsky = TmpSky
153154
T_skytemp.plot_sky(self.ra,self.dec)
@@ -189,7 +190,7 @@ def fit_tipping(T_sys,SpillOver,pol):
189190
#T_sky = np.average(T_sys.T_sky)# T_sys.Tsky(x)
190191
func = lambda p, x: p[0] + T_sys.Tsky(x) + SpillOver.spill[pol](x) + T_atm * (1 - np.exp(-p[1] / np.sin(deg2rad(x))))
191192
# Initialise the fitter with the function and an initial guess of the parameter values
192-
tip = scape.fitting.NonLinearLeastSquaresFit(func, [70, 0.005])
193+
tip = fit.NonLinearLeastSquaresFit(func, [70, 0.005])
193194
tip.fit(T_sys.elevation, T_sys.Tsys[pol])
194195
logger.info('Fit results for %s polarisation:' % (pol,))
195196
logger.info('T_ant = %.2f K' % (tip.params[0],))

reduction/image_reduction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1046,12 +1046,12 @@ def save_fits_image(filename, x, y, Z, target_name='', coord_system='radec',
10461046
# vis, model_vis, uvd = vis_samples[n:n + solint_size], model_vis_samples[n:n + solint_size], uvdist[n:n + solint_size]
10471047
# good_uv = (uvd >= uv_dist_range[0]) & (uvd <= uv_dist_range[1])
10481048
# if selfcal_type == 'P':
1049-
# fitter = scape.fitting.NonLinearLeastSquaresFit(lambda p, x: apply_phases(p, x, model_vis[good_uv]), initial_phases)
1049+
# fitter = NonLinearLeastSquaresFit(lambda p, x: apply_phases(p, x, model_vis[good_uv]), initial_phases)
10501050
# fitter.fit(np.tile(input_pairs, bins_per_solint)[:, good_uv], np.vstack((vis.real, vis.imag))[:, good_uv])
10511051
# phase_params[phase_params_to_fit] = fitter.params
10521052
# gainsol = np.exp(1j * phase_params).astype(np.complex64)
10531053
# else:
1054-
# fitter = scape.fitting.NonLinearLeastSquaresFit(lambda p, x: apply_gains(p, x, model_vis[good_uv]), initial_gains)
1054+
# fitter = NonLinearLeastSquaresFit(lambda p, x: apply_gains(p, x, model_vis[good_uv]), initial_gains)
10551055
# fitter.fit(np.tile(input_pairs, bins_per_solint)[:, good_uv], np.vstack((vis.real, vis.imag))[:, good_uv])
10561056
# full_params[params_to_fit] = fitter.params * np.sign(fitter.params[2 * ref_input_index])
10571057
# gainsol = full_params.view(np.complex128).astype(np.complex64)

0 commit comments

Comments
 (0)