Exemplo n.º 1
0
def update_station_list(txt, jsn):

    if util.age(txt) < util.age(jsn):
        return

    # rebuild the json file
    initialize_stations(txt, jsn)
    logging.debug(f"rebuilt {jsn} from {txt}")
Exemplo n.º 2
0
    def update_history(self, tx_history):
        from util import format_satoshis, age

        self.history_list.empty()

        for item in tx_history[-10:]:
            tx_hash, conf, is_mine, value, fee, balance, timestamp = item
            label = self.actuator.wallet.get_label(tx_hash)[0]
            #amount = D(value) / 10**8
            v_str = format_satoshis(value, True)
            self.history_list.append(label, v_str, age(timestamp))
Exemplo n.º 3
0
def main():

    # Global Variables
    config_path = 'physics_settings/configb.sh'
    config = updated_config(config_path)
    lambda1 = 1000
    lambda2 = 12000
    infileb = 'sed/ssp_pf.cat'
    infiled = 'sed/exp9_pf.cat'

    # Derived names
    z = float(config['fixed_redshift'])
    outfileb = 'sed/ssp_pf_interpolated_z{}.csv'.format(z)
    outfiled = 'sed/exp9_pf_interpolated_z{}.csv'.format(z)

    # Parameters
    age = util.age(4.0) - util.age(z)
    age = int(round(age))  # Nearest Gyr
    age = age - 1  # column 0 is 1 Gyr
    age = abs(age)

    # Interpolate
    interpolate_flux(config, infileb, outfileb, lambda1, lambda2)
    interpolate_flux(config, infiled, outfiled, lambda1, lambda2)
Exemplo n.º 4
0
def interpolate_flux(config, infile, outfile, lambda1, lambda2):
    """ Interpolate the sed file in step of 1 Angstrom."""
    z = float(config['fixed_redshift'])
    age1 = util.age(z) - util.age(4.0)
    age = abs(int(round(age1)))  # Nearest Gyr

    # Get columns of sed file.
    wave, flux_z, flux12 = np.loadtxt(infile,
                                      skiprows=15,
                                      unpack=True,
                                      dtype='float',
                                      usecols=(0, age, 12))

    # wavelength range to interpolate
    nums = int(lambda2 - lambda1) + 1
    waverange = np.linspace(lambda1, lambda2, num=nums, endpoint=True)

    # interpolation
    #print('{} {} {}'.format('\nInterpolating flux from the file : ', infile, ' \n...'))
    iflux_z = sp.interpolate.interp1d(wave, flux_z, kind='cubic')(waverange)
    iflux12 = sp.interpolate.interp1d(wave, flux12, kind='cubic')(waverange)

    # write to a file
    # second column must be flux_z, it will be read by another program.
    hdr = '%-14s %-14s %+18s' % ('wavelength', 'flux_z'.format(age), 'flux12')
    np.savetxt(outfile,
               list(map(list, zip(*[waverange, iflux_z, iflux12]))),
               fmt=['%-13d', '%.13e', '%.13e'],
               delimiter='\t',
               newline='\n',
               header=hdr)

    # output info
    print('Interpolating from %d to %d from file: %s' %
          (lambda1, lambda2, infile))
    print('Writing interpolated file to:', outfile, '\n')

    # Galaxy and Universe Ages
    print('Age of Universe for z = {:4.1f} is  {:4.2f} Gyr'.format(
        0, util.age(0)))
    print('Age of Universe for z = {:4.1f} is  {:4.2f} Gyr'.format(
        z, util.age(z)))
    print('Age of Universe for z = {:4.1f} is  {:4.2f} Gyr'.format(
        4, util.age(4)))
    print('Difference                   is  {:4.2f} Gyr'.format(
        util.age(z) - util.age(4)))
    print('Age of Galaxy   for z = {:4.1f} is  {:4d} Gyr'.format(z, age))
Exemplo n.º 5
0
def test_age():
    now = time.time()
    assert_equals(util.age(now - util.MINUTE * 1.5), "about 1 minute ago")