def setup(self): """Load the beam transfer matrices. Returns ------- tel : TransitTelescope Object describing the telescope. bt : BeamTransfer BeamTransfer manager. feed_info : list, optional Optional list providing additional information about each feed. """ import os from drift.core import beamtransfer if not os.path.exists(self.product_directory): raise RuntimeError('BeamTransfers do not exist.') bt = beamtransfer.BeamTransfer(self.product_directory) tel = bt.telescope try: return tel, bt, tel.feeds except AttributeError: return tel, bt
fpa = focalplane.FocalPlaneArray(latitude=0) fpa.beam_spacing_u = 0.0 fpa.beam_spacing_v = 0.0 fpa.beam_num_u = 1 fpa.beam_num_v = 1 fpa.beam_size = 5.0 fpa.positive_m_only = True fpa.num_freq = 5 fpa.freq_lower = 460.0 fpa.freq_upper = 540.0 bt = beamtransfer.BeamTransfer("cylinder/fpatest/", telescope=fpa) # bt.generate() klt = kltransform.KLTransform(bt) # klt.generate() pse = psestimation.PSEstimation(klt) pse.bands = np.linspace(0.0, 1.0, 5) # pse.genbands() # pse.fisher_mpi()
cyl.num_cylinders = 2 cyl.feed_spacing = 0.5 cyl.num_feeds = 5 # Set the thermal noise (T_sys flat across spectrum) cyl.tsys_flat = 10.0 # cyl.tsys_flat = 0.0 cyl.l_boost = 1.2 cyl.auto_correlations = False cyl.positive_m_only = False # cyl.in_cylinder = False # Generate all the beam transfer functions bt = beamtransfer.BeamTransfer(teldir, telescope=cyl) bt.generate() # Perform the KL transform (saving all modes) klt = kltransform.KLTransform(bt) klt.subset = False klt.inverse = True klt.use_foregrounds = True klt.generate() # Performing DoubleKL transform # dk = doublekl.DoubleKL(bt, subdir="dk1") # dk.subset = False # dk.generate() # Perform the power spectrum estimations # ps = psmc.PSMonteCarlo(klt)
import numpy as np import h5py from drift.core import beamtransfer, manager from drift.pipeline import timestream from simplearray import DishArray ### Make the analysis products for the telescope. This examples focuses only ### on the m-mode products for mapmaking # Create telescope object and set zenith tel = DishArray(latitude=30.0, longitude=0.0) # Create Beam Transfer manager, and generate products bt = beamtransfer.BeamTransfer("pydriver/btdir/", telescope=tel) bt.generate() ### Simulate and make a map froma timestream # Create an empty ProductManager m = manager.ProductManager() # Set the Beam Transfers m.beamtransfer = bt # Create a timestream with no noise (ndays=0) from a given map (could be a list of maps) ts = timestream.simulate(m, "pydriver/ts1/", ["simulated_map.hdf5"], ndays=0) # Make m-mode from the timestream ts.generate_mmodes()
} if teltype not in teltype_dict: raise Exception("Unsupported telescope type.") telescope = teltype_dict[teltype].from_config(yconf["telescope"]) if "reionisation" in yconf["config"]: if yconf["config"]["reionisation"]: skymodel._reionisation = True ## Beam transfer generation if "nosvd" in yconf["config"] and yconf["config"]["nosvd"]: bt = beamtransfer.BeamTransferNoSVD(outdir + "/bt/", telescope=telescope) else: bt = beamtransfer.BeamTransfer(outdir + "/bt/", telescope=telescope) ## Set the singular value cut for the beamtransfers if "svcut" in yconf["config"]: bt.svcut = float(yconf["config"]["svcut"]) if yconf["config"]["beamtransfers"]: bt.generate() ## KLTransform configuration kltype_dict = { "KLTransform": kltransform.KLTransform, "DoubleKL": doublekl.DoubleKL } klobj_dict = {}
## Read arguments in. parser = argparse.ArgumentParser( description="Filter a map using S/N eigenmodes.") parser.add_argument("teldir", help="The telescope directory to use.") parser.add_argument("mapfile", help="Input map.") parser.add_argument("outfile", help="Output map.") parser.add_argument("threshold", help="Threshold S/N value to cut at.", type=float) parser.add_argument("-e", "--evsubdir", help="The subdirectory containing the eigensystem files.") args = parser.parse_args() ## Read in cylinder system bt = beamtransfer.BeamTransfer(args.teldir) # klt = kltransform.KLTransform(bt, subdir=args.evsubdir) cyl = bt.telescope ntel = bt.ntel * bt.nfreq mmax = cyl.mmax cut = args.threshold def blackman_harris(N): k = np.arange(N) # w = 0.3635819 - 0.4891775*np.cos(2*np.pi*k/(N-1)) + 0.1365995*np.cos(4*np.pi*k/(N-1)) -0.0106411*np.cos(6*np.pi*k/(N-1)) w = (0.35875 - 0.48829 * np.cos(2 * np.pi * k / (N - 1)) + 0.14128 * np.cos(4 * np.pi * k /
import sys import numpy as np import h5py from cora.util import hputil from drift.core import beamtransfer from drift.util import mpiutil btdir = sys.argv[1] nside = int(sys.argv[2]) outfile = sys.argv[3] bt = beamtransfer.BeamTransfer(btdir) cyl = bt.telescope mmax = cyl.mmax print("Making map with T_sys = %f" % cyl.tsys_flat) shape = (cyl.nfreq, cyl.nbase) ind = np.indices(shape) noise = np.squeeze(cyl.noisepower(ind[1], ind[0]) / 2.0)**0.5 if not cyl.positive_m_only: shape = (shape[0], 2, shape[1]) noise2 = np.empty(shape, dtype=np.float64) noise2[:, 0] = noise noise2[:, 1] = noise noise = noise2
import sys import numpy as np import scipy.linalg as la import h5py from drift.core import beamtransfer, kltransform from drift.util import mpiutil path = sys.argv[1] bt = beamtransfer.BeamTransfer(path) # The size of the SVD output matrices svd_len = min(bt.telescope.num_pol_sky * (bt.telescope.lmax + 1), bt.ntel) def svd_func(mi): print(mi) # Open m beams for reading. sv = np.zeros((bt.nfreq, svd_len), dtype=np.float64) with h5py.File(bt._mfile(mi), "r") as fm: for fi in range(bt.nfreq): # print "fi", fi # Read the positive and negative m beams, and combine into one. bf = fm["beam_m"][fi][:].reshape(bt.ntel, bt.telescope.num_pol_sky,
def load_config(self, configfile): with open(configfile) as f: yconf = yaml.safe_load(f) ## Global configuration ## Create output directory and copy over params file. if 'config' not in yconf: raise Exception( 'Configuration file must have an \'config\' section.') self.directory = yconf['config']['output_directory'] self.directory = os.path.expanduser(self.directory) self.directory = os.path.expandvars(self.directory) if not os.path.isabs(self.directory): self.directory = os.path.normpath( os.path.join(os.path.abspath(os.path.dirname(configfile)), self.directory)) if mpiutil.rank0: print "Product directory:", self.directory ## Telescope configuration if 'telescope' not in yconf: raise Exception( 'Configuration file must have an \'telescope\' section.') teltype = yconf['telescope']['type'] telclass = _resolve_class(teltype, teltype_dict, 'telescope') self.telescope = telclass.from_config(yconf['telescope']) if 'reionisation' in yconf['config']: if yconf['config']['reionisation']: skymodel._reionisation = True ## Beam transfer generation if 'nosvd' in yconf['config'] and yconf['config']['nosvd']: self.beamtransfer = beamtransfer.BeamTransferNoSVD( self.directory + '/bt/', telescope=self.telescope) else: self.beamtransfer = beamtransfer.BeamTransfer( self.directory + '/bt/', telescope=self.telescope) ## Use the full SVD if requested if 'fullsvd' in yconf['config'] and yconf['config']['fullsvd']: self.beamtransfer = beamtransfer.BeamTransferFullSVD( self.directory + '/bt/', telescope=self.telescope) else: self.beamtransfer = beamtransfer.BeamTransfer( self.directory + '/bt/', telescope=self.telescope) ## Set the singular value cut for the beamtransfers if 'svcut' in yconf['config']: self.beamtransfer.svcut = float(yconf['config']['svcut']) ## Set the singular value cut for the *polarisation* beamtransfers if 'polsvcut' in yconf['config']: self.beamtransfer.polsvcut = float(yconf['config']['polsvcut']) if yconf['config']['beamtransfers']: self.gen_beams = True if 'skip_svd' in yconf['config'] and yconf['config']['skip_svd']: self.skip_svd = True self.kltransforms = {} if 'kltransform' in yconf: for klentry in yconf['kltransform']: kltype = klentry['type'] klname = klentry['name'] klclass = _resolve_class(kltype, kltype_dict, 'KL filter') kl = klclass.from_config(klentry, self.beamtransfer, subdir=klname) self.kltransforms[klname] = kl if yconf['config']['kltransform']: self.gen_kl = True self.psestimators = {} if yconf['config']['psfisher']: self.gen_ps = True if 'psfisher' not in yconf: raise Exception( 'Require a psfisher section if config: psfisher is Yes.') if 'psfisher' in yconf: for psentry in yconf['psfisher']: pstype = psentry['type'] klname = psentry['klname'] psname = psentry['name'] if 'name' in psentry else 'ps' psclass = _resolve_class(pstype, pstype_dict, 'PS estimator') if klname not in self.kltransforms: warnings.warn( 'Desired KL object (name: %s) does not exist.' % klname) self.psestimators[psname] = None else: self.psestimators[psname] = psclass.from_config( psentry, self.kltransforms[klname], subdir=psname)
def load_config(self, configfile): with open(configfile) as f: yconf = yaml.safe_load(f) ## Global configuration ## Create output directory and copy over params file. if "config" not in yconf: raise Exception( "Configuration file must have an 'config' section.") self.directory = yconf["config"]["output_directory"] self.directory = os.path.expanduser(self.directory) self.directory = os.path.expandvars(self.directory) if not os.path.isabs(self.directory): self.directory = os.path.normpath( os.path.join(os.path.abspath(os.path.dirname(configfile)), self.directory)) if mpiutil.rank0: print("Product directory:", self.directory) ## Telescope configuration if "telescope" not in yconf: raise Exception( "Configuration file must have an 'telescope' section.") teltype = yconf["telescope"]["type"] telclass = _resolve_class(teltype, teltype_dict, "telescope") self.telescope = telclass.from_config(yconf["telescope"]) if "reionisation" in yconf["config"]: if yconf["config"]["reionisation"]: skymodel._reionisation = True ## Beam transfer generation if "nosvd" in yconf["config"] and yconf["config"]["nosvd"]: self.beamtransfer = beamtransfer.BeamTransferNoSVD( self.directory + "/bt/", telescope=self.telescope) else: self.beamtransfer = beamtransfer.BeamTransfer( self.directory + "/bt/", telescope=self.telescope) ## Use the full SVD if requested if "fullsvd" in yconf["config"] and yconf["config"]["fullsvd"]: self.beamtransfer = beamtransfer.BeamTransferFullSVD( self.directory + "/bt/", telescope=self.telescope) else: self.beamtransfer = beamtransfer.BeamTransfer( self.directory + "/bt/", telescope=self.telescope) ## Set the singular value cut for the beamtransfers if "svcut" in yconf["config"]: self.beamtransfer.svcut = float(yconf["config"]["svcut"]) ## Set the singular value cut for the *polarisation* beamtransfers if "polsvcut" in yconf["config"]: self.beamtransfer.polsvcut = float(yconf["config"]["polsvcut"]) if yconf["config"]["beamtransfers"]: self.gen_beams = True if "skip_svd" in yconf["config"] and yconf["config"]["skip_svd"]: self.skip_svd = True self.kltransforms = {} if "kltransform" in yconf: for klentry in yconf["kltransform"]: kltype = klentry["type"] klname = klentry["name"] klclass = _resolve_class(kltype, kltype_dict, "KL filter") kl = klclass.from_config(klentry, self.beamtransfer, subdir=klname) self.kltransforms[klname] = kl if yconf["config"]["kltransform"]: self.gen_kl = True self.psestimators = {} if yconf["config"]["psfisher"]: self.gen_ps = True if "psfisher" not in yconf: raise Exception( "Require a psfisher section if config: psfisher is Yes.") if "psfisher" in yconf: for psentry in yconf["psfisher"]: pstype = psentry["type"] klname = psentry["klname"] psname = psentry["name"] if "name" in psentry else "ps" psclass = _resolve_class(pstype, pstype_dict, "PS estimator") if klname not in self.kltransforms: warnings.warn( "Desired KL object (name: %s) does not exist." % klname) self.psestimators[psname] = None else: self.psestimators[psname] = psclass.from_config( psentry, self.kltransforms[klname], subdir=psname)
if teltype not in teltype_dict: raise Exception("Unsupported telescope type.") telescope = teltype_dict[teltype].from_config(yconf['telescope']) if 'reionisation' in yconf['config']: if yconf['config']['reionisation']: skymodel._reionisation = True ## Beam transfer generation if 'nosvd' in yconf['config'] and yconf['config']['nosvd']: bt = beamtransfer.BeamTransferNoSVD(outdir + '/bt/', telescope=telescope) else: bt = beamtransfer.BeamTransfer(outdir + '/bt/', telescope=telescope) ## Set the singular value cut for the beamtransfers if 'svcut' in yconf['config']: bt.svcut = float(yconf['config']['svcut']) #if yconf['config']['beamtransfers']: # bt.generate() ## KLTransform configuration kltype_dict = { 'KLTransform' : kltransform.KLTransform, 'DoubleKL' : doublekl.DoubleKL, }
import h5py from drift.core import beamtransfer, manager from drift.pipeline import timestream from simplearray import DishArray ### Make the analysis products for the telescope. This examples focuses only ### on the m-mode products for mapmaking # Create telescope object and set zenith tel = DishArray() tel.zenith = np.radians(np.array([30.0, 0.0])) # Must be in radians # Create Beam Transfer manager, and generate products bt = beamtransfer.BeamTransfer('pydriver/btdir/', telescope=tel) bt.generate() ### Simulate and make a map froma timestream # Create an empty ProductManager m = manager.ProductManager() # Set the Beam Transfers m.beamtransfer = bt # Create a timestream with no noise (ndays=0) from a given map (could be a list of maps) ts = timestream.simulate(m, 'pydriver/ts1/', ['simulated_map.hdf5'], ndays=0) # Make m-mode from the timestream ts.generate_mmodes()