def _load_pointing_data(self): file = DATA_DIR + 'f13_aid.fits' f = fits.open(file) altitude = f[1].data['targetalt'].byteswap().newbyteorder() time = f[1].data['stime'].byteswap().newbyteorder() ra = f[1].data['TargetRA'].byteswap().newbyteorder() dec = f[1].data['TargetDEC'].byteswap().newbyteorder() az = f[1].data['TargetAz'].byteswap().newbyteorder() times = [ timedelta(seconds=t) - timedelta(seconds=60 * 60 * 24 * 2730 + 8 * 60 * 60) + datetime.datetime(2013, 9, 21) for t in time ] target = { 'time': times, 'ra': ra, 'dec': dec, 'az': az, 'alt': altitude } target.units = (u('deg'), u('deg'), u('deg'), u('deg')) target = pandas.DataFrame(dict) target.index = target['time'] return target
def _load_location_data(self): file = DATA_DIR + 'f13_gps.fits' f = fits.open(file) time = f[1].data['time'] height = f[1].data['height'] longitude = f[1].data['longitude'] latitude = f[1].data['latitude'] times = [convert_time(t) for t in time] dict = {'time': times, 'height': height, 'latitude': latitude, 'longitude': longitude} d = pandas.DataFrame(dict) d.index = d['time'] d.units = (u('m'), u('deg'), u('deg')) return d
def _load_pointing_data(self): file = DATA_DIR + 'f13_aid.fits' f = fits.open(file) altitude = f[1].data['targetalt'].byteswap().newbyteorder() time = f[1].data['stime'].byteswap().newbyteorder() ra = f[1].data['TargetRA'].byteswap().newbyteorder() dec = f[1].data['TargetDEC'].byteswap().newbyteorder() az = f[1].data['TargetAz'].byteswap().newbyteorder() times = [timedelta(seconds=t) - timedelta(seconds=60*60*24*2730+8*60*60) + datetime.datetime(2013, 9, 21) for t in time] target = {'time': times, 'ra':ra, 'dec': dec, 'az':az, 'alt':altitude} target.units = (u('deg'), u('deg'), u('deg'), u('deg')) target = pandas.DataFrame(dict) target.index = target['time'] return target
def test_scipy(data, z, plot=False): f_tau = get_tau_funtcion(data) tau = f_tau(z, nu).T print(tau) if plot is True: plt.ion() E = nu * u('Hz').to('TeV', equivalencies=spectral()) plt.loglog(E, np.exp(-tau), '-') plt.grid() plt.show()
def __repr__(self): if self._c is not None: s = '%s' % self._c elif self._DL_cm is not None: x = self._DL_cm * u('cm') s = 'cosmology is not defined, the luminosity distance has been set to %s' % x else: s = 'you have to define either an astropy comoslogy model or set a luminosity distance in cm' return s
def pixel_to_world(self, pixelxy): """Convert a pixel position to physical coordinates Parameters ---------- pixelxy : `astropy.units.Quantity` (pixels) Returns ------- result : `astropy.units.Quantity` (physical) """ return (pixelxy - self.raw_center + 0.5 * u('pix')) * self.plate_scale
def _load_location_data(self): file = DATA_DIR + 'f13_gps.fits' f = fits.open(file) time = f[1].data['time'] height = f[1].data['height'] longitude = f[1].data['longitude'] latitude = f[1].data['latitude'] times = [convert_time(t) for t in time] dict = { 'time': times, 'height': height, 'latitude': latitude, 'longitude': longitude } d = pandas.DataFrame(dict) d.index = d['time'] d.units = (u('m'), u('deg'), u('deg')) return d
def get_DL_cm(self, z=None): if self._c is not None: #THIS IS FIXING THE ERROR WITH PICKLED COSMO #TODO open issue on astropy! try: _d = self._c.luminosity_distance(z).to('cm').value except: _d = self._c.luminosity_distance(z) _d = _d.value * u(str(_d.unit)) _d = _d.to('cm').value else: _d = self._DL_cm return _d
def __init__(self, isFront): if isFront: self.clock_angle = -32.425 self.center_offset_mils = np.array([124.68, -74.64]) self.twist = 180.0 else: self.clock_angle = -52.175 self.center_offset_mils = np.array([-105.59, -48.64]) self.twist = 0.0 self.pixel_number = np.array([966, 1296]) self.arcsec_per_mil = 1.72 self.micron_per_mil = 25.4 self.pixel_size_um = 6.45 * u('micron') self.focal_length_m = 2 self.screen_radius_mil = 3000
def get_pyas_aspect(front=True): if front: file = DATA_DIR + 'SAS1_pointing_data.csv' else: file = DATA_DIR + 'SAS2_pointing_data.csv' names = ('ctl_az', 'ctl_el', 'offset_r', 'offset_x', 'offset_y', 'pointing_x', 'pointing_y') data = pandas.read_csv(file, names=names, parse_dates=True, index_col=0, skiprows=1) data.units = (u('arcsec'), u('arcsec'), u('arcsec'), u('arcsec'), u('arcsec'), u('arcsec'), u('arcsec')) return data
def __init__(self, x_values, y_values, z_values, log_input_grid=False, log_log_interp=False, x_in_units=None, y_in_units=None, x_out_units='Hz', y_out_units='erg cm-2 s-1', z_in_units=None, z_out_units=None, nu_size=100, name='TableModel2D', zero=1E-100): """ """ super(TemplateTable2D, self).__init__(name=name) self._zero=zero self._log_log_interp = log_log_interp if log_input_grid is False: self.x_values = x_values self.y_values = y_values self.z_values = z_values else: self.z_values = np.power(10., z_values) self.x_values = np.power(10., x_values) self.y_values = np.power(10., y_values) if x_in_units is not None: self.x_values *= u(x_in_units).to(x_out_units, equivalencies=spectral()) if hasattr(self.x_values,'value'): _x = self.x_values.value else: _x = self.x_values if y_in_units is not None: self.y_values *= u(y_in_units).to(y_out_units, equivalencies=spectral()) if hasattr(self.y_values,'value'): _y = self.y_values.value else: _y = self.y_values if z_in_units is not None: self.z_values *= u(z_in_units).to(z_out_units, equivalencies=spectral()) if hasattr(self.z_values, 'value'): _z = self.z_values.value else: _z = self.z_values if log_log_interp is True: self._scale='log-log' _x[_x<self._zero]=self._zero self._x_grid = np.log10(_x) self._y_grid = np.log10(_y) self._z_grid = np.log10(_z) else: self._scale='lin-lin' self._x_grid = _x self._y_grid = _y self._z_grid = _z self.interp_func = interpolate.RectBivariateSpline(self._x_grid, self._y_grid, self._z_grid) self.nu_size = nu_size self.name = name self.model_type = 'table2D'
import heroespy.science.spectrum as spec from astropy.units import Unit as u print(spec.atmospheric_column_density(40 * u('km')))
from astropy.table import Table from astropy.units import Unit as u from astropy.units import spectral import glob import numpy as np from astropy.io import fits f_list = glob.glob('tau_modelC_total*.dat') _c_tau = [] _n_tau = [] _tau = [] z_array = [] for ID, f_name in enumerate(f_list): z = f_name.split('_z')[1] z = z.replace('z', '') z = z.replace('.dat', '') d = np.loadtxt(f_name) if ID == 0: E = d[:, 0] * u('TeV') _c_tau.append(E) _n_tau.append('energies') _n_tau.append('z_%s' % z) z_array.append(z) _c_tau.append(d[:, 1]) t_tau = Table(data=_c_tau, names=_n_tau, meta={'redshift': z_array}) t_tau.write('tau_finke_2010.fits', format='fits', overwrite=True)
with pytest.raises(ValueError): hist.get_axis('y') assert (x_axis == hist.get_axis('x')).all assert hist.dim == 1 data = np.arange(15) with pytest.raises(ValueError): hist.data = data data = [random.expovariate(hist.axes[0][_].value + 1) for _ in range(10)] hist.data = data # Find nodes on x-axis with pytest.raises(ValueError): hist.find_node(x=[14 * u('s')]) idx = hist.get_axis('x').find_node(12 * u('m')) assert idx[0] == 1 idx = hist.get_axis('x').find_node(1200 * u('cm')) assert idx[0] == 1 vals = [13 * u('m'), 2500 * u('cm'), 600 * u('dm')] idx = hist.get_axis('x').find_node(vals) assert idx[0] == np.array([1, 2, 6]).all() # Find nodes using array with pytest.raises(ValueError): hist.find_node(energy=5) idx = hist.find_node(x=[12 * u('m'), 67 * u('m')]) assert idx[0][0] == 1
from astropy.table import Table from astropy.units import Unit as u from astropy.units import spectral import glob import numpy as np from astropy.io import fits _c_tau = [] _n_tau = [] _tau = [] z_array = [] data = np.loadtxt('tau_fran08.dat', usecols=(0, 2)) E = data[0:50, 0] * u('TeV') _n_tau.append('energies') _c_tau.append(E) for i in range(int(len(data[:, 1]) / len(E))): tau = data[i * 50:i * 50 + 50, 1] _c_tau.append(tau.flatten()) z = 1e-3 * (i + 1.) z_array.append(z) _n_tau.append('z_%2.8f' % z) #print(z,E,tau) #MUST use ascii, fits forma can not handle table with more than 1000 cols t_tau = Table(data=_c_tau, names=_n_tau, meta={'redshift': z_array}) t_tau.write( 'tau_franceschini_2008.dat', format='ascii.ecsv', overwrite=True, )
with pytest.raises(ValueError): hist.get_axis('y') assert (x_axis == hist.get_axis('x')).all assert hist.dim == 1 data = np.arange(15) with pytest.raises(ValueError): hist.data = data data = [random.expovariate(hist.axes[0][_].value+1) for _ in range(10)] hist.data = data # Find nodes on x-axis with pytest.raises(ValueError): hist.find_node(x = [14 * u('s')]) idx = hist.get_axis('x').find_node(12 * u('m')) assert idx[0] == 1 idx = hist.get_axis('x').find_node(1200 * u('cm')) assert idx[0] == 1 vals = [13 * u('m'), 2500*u('cm'), 600 * u('dm')] idx = hist.get_axis('x').find_node(vals) assert idx[0] == np.array([1, 2, 6]).all() # Find nodes using array with pytest.raises(ValueError): hist.find_node(energy = 5) idx = hist.find_node(x = [12 * u('m'), 67 * u('m')]) assert idx[0][0] == 1