def update_info(zp=None): """ Update information in zeropoint file, e.g. after calibration. Call first L{cc.ivs.sed.model.calibrate} without arguments, and pass the output to this function. @param zp: updated contents from C{zeropoints.dat} @type zp: recarray """ zp_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'zeropoints.dat') zp_,comms = ascii.read2recarray(zp_file,return_comments=True) existing = [str(i.strip()) for i in zp_['photband']] resp_files = sorted(glob.glob(os.path.join(os.path.dirname(os.path.abspath(__file__)),'filters/*'))) resp_files = [os.path.basename(ff) for ff in resp_files if not os.path.basename(ff) in existing] resp_files.remove('HUMAN.EYE') resp_files.remove('HUMAN.CONES') resp_files.remove('CONES.EYE') if zp is None: zp = zp_ logger.info('No new calibrations; previous information on existing response curves is copied') else: logger.info('Received new calibrations contents of zeropoints.dat will be updated') #-- update info on previously non existing response curves new_zp = np.zeros(len(resp_files),dtype=zp.dtype) logger.info('Found {} new response curves, adding them with default information'.format(len(resp_files))) for i,respfile in enumerate(resp_files): new_zp[i]['photband'] = respfile new_zp[i]['eff_wave'] = float(eff_wave(respfile)) new_zp[i]['type'] = 'CCD' new_zp[i]['vegamag'] = np.nan new_zp[i]['ABmag'] = np.nan new_zp[i]['STmag'] = np.nan new_zp[i]['Flam0_units'] = 'erg/s/cm2/AA' new_zp[i]['Fnu0_units'] = 'erg/s/cm2/AA' new_zp[i]['source'] = 'nan' zp = np.hstack([zp,new_zp]) sa = np.argsort(zp['photband']) ascii.write_array(zp[sa],'zeropoints.dat',header=True,auto_width=True,comments=['#'+line for line in comms[:-2]],use_float='%g')
def get_info(photbands=None): """ Return a record array containing all filter information. The record arrays contains following columns: - photband - eff_wave - type - vegamag, vegamag_lit - ABmag, ABmag_lit - STmag, STmag_lit - Flam0, Flam0_units, Flam0_lit - Fnu0, Fnu0_units, Fnu0_lit, - source @param photbands: list of photbands to get the information from. The input order is equal to the output order. If C{None}, all filters are returned. @type photbands: iterable container (list, tuple, 1Darray) @return: record array containing all information on the requested photbands. @rtype: record array """ zp_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),'zeropoints.dat') zp = ascii.read2recarray(zp_file) for iph in custom_filters: if iph=='_prefer_file': continue if 'zp' in custom_filters[iph]: zp = np.hstack([zp,custom_filters[iph]['zp']]) zp = zp[np.argsort(zp['photband'])] #-- list photbands in order given, and remove those that do not have # zeropoints etc. if photbands is not None: order = np.searchsorted(zp['photband'],photbands) zp = zp[order] keep = (zp['photband']==photbands) zp = zp[keep] return zp