def _load(self, config): """ Load this config from an existing config Parameters: ----------- config : filename, config object, or dict to load Returns: -------- params : configuration parameters """ if isstring(config): self.filename = config params = yaml.safe_load(open(config)) elif isinstance(config, Config): # This is the copy constructor... self.filename = config.filename params = copy.deepcopy(config) elif isinstance(config, dict): params = copy.deepcopy(config) elif config is None: params = {} else: raise Exception('Unrecognized input') return params
def load_infiles(infiles,columns=None,multiproc=False): if isstring(infiles): infiles = [infiles] logger.debug("Loading %s files..."%len(infiles)) args = list(zip(infiles,len(infiles)*[columns])) if multiproc: from multiprocessing import Pool processes = multiproc if multiproc > 0 else None p = Pool(processes,maxtasksperchild=1) out = p.map(load,args) else: out = [load(arg) for arg in args] dtype = out[0].dtype for i,d in enumerate(out): if d.dtype != dtype: # ADW: Not really safe... logger.warn("Casting input data to same type.") out[i] = d.astype(dtype) logger.debug('Concatenating arrays...') return np.concatenate(out)
def load_infiles(infiles, columns=None, multiproc=False): if isstring(infiles): infiles = [infiles] logger.debug("Loading %s files..." % len(infiles)) args = list(zip(infiles, len(infiles) * [columns])) if multiproc: from multiprocessing import Pool processes = multiproc if multiproc > 0 else None p = Pool(processes, maxtasksperchild=1) out = p.map(load, args) else: out = [load(arg) for arg in args] dtype = out[0].dtype for i, d in enumerate(out): if d.dtype != dtype: # ADW: Not really safe... logger.warn("Casting input data to same type.") out[i] = d.astype(dtype) logger.debug('Concatenating arrays...') return np.concatenate(out)
def _load(self, config): """ Load this config from an existing config Parameters: ----------- config : filename, config object, or dict to load Returns: -------- params : configuration parameters """ if isstring(config): self.filename = config params = yaml.load(open(config)) elif isinstance(config, Config): # This is the copy constructor... self.filename = config.filename params = copy.deepcopy(config) elif isinstance(config, dict): params = copy.deepcopy(config) elif config is None: params = {} else: raise Exception('Unrecognized input') return params
def dms2dec(dms): """Convert latitude from degrees,minutes,seconds in string or 3-array format to decimal degrees. ADW: This really should be replaced by astropy """ DEGREE = 360. HOUR = 24. MINUTE = 60. SECOND = 3600. # Be careful here, degree needs to be a float so that negative zero # can have its signbit set: # http://docs.scipy.org/doc/numpy-1.7.0/reference/c-api.coremath.html#NPY_NZERO if isstring(dms): degree, minute, second = np.array(re.split('[dms]', dms))[:3].astype(float) else: degree, minute, second = dms.T sign = np.copysign(1.0, degree) decimal = np.abs(degree) + minute * 1. / MINUTE + second * 1. / SECOND decimal *= sign return decimal
def hms2dec(hms): """ Convert longitude from hours,minutes,seconds in string or 3-array format to decimal degrees. ADW: This really should be replaced by astropy """ DEGREE = 360. HOUR = 24. MINUTE = 60. SECOND = 3600. if isstring(hms): hour,minute,second = np.array(re.split('[hms]',hms))[:3].astype(float) else: hour,minute,second = hms.T decimal = (hour + minute * 1./MINUTE + second * 1./SECOND)*(DEGREE/HOUR) return decimal
def hms2dec(hms): """ Convert longitude from hours,minutes,seconds in string or 3-array format to decimal degrees. ADW: This really should be replaced by astropy """ DEGREE = 360. HOUR = 24. MINUTE = 60. SECOND = 3600. if isstring(hms): hour, minute, second = np.array(re.split('[hms]', hms))[:3].astype(float) else: hour, minute, second = hms.T decimal = (hour + minute * 1. / MINUTE + second * 1. / SECOND) * (DEGREE / HOUR) return decimal
def dms2dec(dms): """ Convert latitude from degrees,minutes,seconds in string or 3-array format to decimal degrees. """ DEGREE = 360. HOUR = 24. MINUTE = 60. SECOND = 3600. # Be careful here, degree needs to be a float so that negative zero # can have its signbit set: # http://docs.scipy.org/doc/numpy-1.7.0/reference/c-api.coremath.html#NPY_NZERO if isstring(dms): degree,minute,second = np.array(re.split('[dms]',hms))[:3].astype(float) else: degree,minute,second = dms.T sign = np.copysign(1.0,degree) decimal = np.abs(degree) + minute * 1./MINUTE + second * 1./SECOND decimal *= sign return decimal