Beispiel #1
0
 def __init__(self,redshift:float, velocity_dispersion:u.Quantity,
     shear: PolarVec, ellipticity:PolarVec) -> None:
     Cosmic.__init__(self,redshift)
     CalculationDependency.__init__(self)
     Jsonable.__init__(self)
     try:
         assert isinstance(shear,PolarVec)
         assert isinstance(ellipticity, PolarVec)
         assert isinstance(redshift,float)
         self._velocity_dispersion = velocity_dispersion.to('km/s')
         self._ellipticity = ellipticity
         self._shear = shear
     except:
         from mirage.parameters import ParametersError
         raise ParametersError("Could not construct a Lens instance from the supplied constructor arguments.")
Beispiel #2
0
 def json(self):
     ret = {}
     ret['ellipticity'] = self.ellipticity.json
     ret['shear'] = self.shear.json
     ret['velocity_dispersion'] = Jsonable.encode_quantity(self.velocity_dispersion)
     ret['redshift'] = self.redshift
     return ret
Beispiel #3
0
 def from_json(cls, js):
     try:
         z_s = js['source']['redshift']
         z_l = js['lens']['redshift']
         mass = Jsonable.decode_quantity(js['source']['mass'])
         special_units = Parameters.special_units(z_s, z_l, mass)
         with u.add_enabled_units(special_units):
             gal = Lens.from_json(js['lens'])
             src = Quasar.from_json(js['source'])
             rays = Vec2D.from_json(js['ray_count'])
             sg = MassFunction.from_json(js['star_generator'])
             pcnts = js['percent_stars']
             spln = Region.from_json(js['source_plane'])
             center = Vec2D.from_json(js['image_center'])
             return cls(src, gal, pcnts, center, rays, spln, sg)
     except KeyError as e:
         print(e)
         params = Parameters.from_json(js)
         with u.add_enabled_units([params.quasar.r_g, params.theta_E]):
             sg = MassFunction.from_json(js['star_generator'])
             pcnts = js['percent_stars']
             spln = Region.from_json(js['source_plane'])
             rays = params.ray_region.resolution
             center = params.ray_region.center
             return cls(params.quasar, params.lens, pcnts, center, rays,
                        spln, sg)
Beispiel #4
0
 def __init__(self, redshift: float, radius: u.Quantity,
              mass: u.Quantity) -> None:
     Cosmic.__init__(self, redshift)
     CalculationDependency.__init__(self)
     Jsonable.__init__(self)
     try:
         self._mass = mass.to('solMass')
         try:
             self._radius = radius.to('uas')
         except:
             tmp = radius.to('m') / self.ang_diam_dist.to('m')
             self._radius = u.Quantity(tmp.value, 'rad').to('uas')
     except:
         from mirage.parameters import ParametersError
         raise ParametersError(
             "Quasar could not construct itself based on the provided constructor arguments."
         )
Beispiel #5
0
 def from_json(cls, js: 'Dict') -> 'Parameters':
     z_s = js['source']['redshift']
     z_l = js['lens']['redshift']
     mass = Jsonable.decode_quantity(js['source']['mass'])
     te = Parameters.static_theta_E(z_s, z_l)
     rg = Quasar.static_r_g(mass, z_s)
     with u.add_enabled_units([te, rg]):
         gal = Lens.from_json(js['lens'])
         src = Quasar.from_json(js['source'])
         rays = PixelRegion.from_json(js['ray_region'])
         return cls(src, gal, rays)
Beispiel #6
0
 def from_json(cls,js):
     from .InitialMassFunction import Kroupa_2001, Kroupa_2001_Modified
     seed = js['seed']
     ml = js['mass_limits']
     pows = js['powers']
     velocity = Jsonable.decode_quantity(js['mean_velocity'])
     sigma = Jsonable.decode_quantity(js['stderr_velocity'])
     dt = Jsonable.decode_quantity(js['dt'])
     if 'type' in js:
         if js['type'] == "Kroupa_2001":
             imf = Kroupa_2001()
         else:
             imf = Kroupa_2001_Modified()
     else:
         if 'conversions' in js:
             convs = js['conversions']
             imf = Evolved_IMF(conversions = convs,
                 powers = pows,
                 massLimits = ml)
             return cls(imf,velocity,sigma,dt,seed)
         else:
             imf = IMF_broken_powerlaw(ml,pows)
             return cls(imf,velocity,sigma,dt,seed)
Beispiel #7
0
    def __init__(self, path):
        _PreferencesParser.__init__(self, path)
        from mirage.util import Jsonable
        defaults = _PreferencesParser(project_directory +
                                      '.default_preferences.json')

        #Load in defaults
        for k, v in defaults.items():
            if k not in self._prefMap:
                self._prefMap[k] = v

        #Convert from keywords to settings, etc.
        if self['core_count'] == 'all':
            self._prefMap['core_count'] = multiprocessing.cpu_count()
        self._prefMap['dt'] = Jsonable.decode_quantity(self['dt'])
        if self['star_generator_seed'] == None:
            self._prefMap['star_generator_seed'] = self.get_random_int()
        if self['lightcurve_rng_seed'] == None:
            self._prefMap['lightcurve_rng_seed'] == self.get_random_int()
Beispiel #8
0
 def from_json(cls, js):
     z = js['redshift']
     mass = Jsonable.decode_quantity(js['mass'])
     rad = Jsonable.decode_quantity(js['radius'])
     return cls(z, rad, mass)
Beispiel #9
0
 def json(self):
     ret = {}
     ret['redshift'] = self.redshift
     ret['mass'] = Jsonable.encode_quantity(self.mass)
     ret['radius'] = Jsonable.encode_quantity(self.radius)
     return ret
Beispiel #10
0
 def from_json(cls, js):
     el = PolarVec.from_json(js['ellipticity'])
     shear = PolarVec.from_json(js['shear'])
     vd = Jsonable.decode_quantity(js['velocity_dispersion'])
     z = js['redshift']
     return cls(z,vd,shear,el)
Beispiel #11
0
 def json(self):
     ret = self._stationaryFunc.json
     ret['mean_velocity'] = Jsonable.encode_quantity(self._velocity_characteristics[0])
     ret['stderr_velocity'] = Jsonable.encode_quantity(self._velocity_characteristics[1])
     ret['dt'] = Jsonable.encode_quantity(self._dt)
     return ret
Beispiel #12
0
 def json(self):
     ret = {}
     ret['seed'] = self.seed
     ret['num_curves'] = self.num_curves
     ret['sample_density'] = Jsonable.encode_quantity(self.sample_density)
     return ret
Beispiel #13
0
 def from_json(cls, js):
     seed = js['seed']
     num_curves = js['num_curves']
     sample_density = Jsonable.decode_quantity(js['sample_density'])
     return cls(num_curves, sample_density, seed)