Beispiel #1
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 #2
0
def QSO2237_ImageC(root_rays, percent_stars):
    from mirage.util import Vec2D, Region, zero_vector
    qso = QSO2237()
    src_plane = Vec2D(40, 40, qso.theta_E)
    qso.quasar.update(radius=80 * qso.quasar.r_g)
    center = zero_vector('rad')
    src_plane = Region(center, src_plane)
    img_center = Vec2D(1.4, 1.4, 'arcsec')
    ray_count = Vec2D(int(root_rays), int(root_rays))
    return MicrolensingParameters(qso.quasar, qso.lens, percent_stars,
                                  img_center, ray_count, src_plane)
Beispiel #3
0
def QSO2237():
    from astropy import units as u
    from mirage.util import Vec2D, PolarVec, PixelRegion, Region
    q = Quasar(1.69, 0.1 * u.arcsec, 1000000000 * u.solMass)
    shear = PolarVec(0.0001, 0.0)
    ellip = PolarVec(1, 0.0)
    rays = PixelRegion(Vec2D(0.0, 0.0, 'arcsec'), Vec2D(40.0, 40.0, 'arcsec'),
                       Vec2D(2000, 2000))
    lens = Lens(0.04, 177.95 * u.km / u.s, shear, ellip)
    params = Parameters(q, lens, rays)
    return params
Beispiel #4
0
 def get_curve(self):
     x, y = self.line.get_data()
     start = Vec2D(x[0], y[0], self.map_unit)
     end = Vec2D(x[1], y[1], self.map_unit)
     if start == end:
         return None
     if self.magmap:
         from mirage.lens_analysis import LightCurve
         curve = self._magmap.slice_line(start, end)
         s = start.quantity
         e = end.quantity
         return LightCurve(curve, s, e)
Beispiel #5
0
 def get_object(self,*args,**kwargs):
     from mirage.parameters import Parameters, MicrolensingParameters, Quasar, Lens
     from mirage.util import Vec2D, PolarVec, PixelRegion, zero_vector
     from mirage.calculator import getMassFunction
     #First, pull out everyhing a micro and macro object needs.
     #Pull out values for special units first
     try:
         lRedshift = self.lRedshiftInput.value()
         qRedshift = self.qRedshiftInput.value()
         qMass = self.qMassInput.value()*u.solMass
         vDispersion = self.vDispersionInput.value()*u.km/u.s
         r_g, theta_E, xi = Parameters.special_units(qRedshift,lRedshift,qMass)
         einstein_radius = Parameters.static_einstein_radius(vDispersion,qRedshift,lRedshift)
         with u.add_enabled_units([r_g,theta_E,einstein_radius]):
         #Now I can continue to pull out values and not have a unit problem.
             ellipR, ellipTheta = self.ellipRInput.value(), self.ellipThetaInput.value()
             shearR, shearTheta = self.shearRInput.value(), self.shearThetaInput.value()
             qRadius = self.qRadiusInput.value()*UserInputWidget.unitFromString(
                 self.qRadiusUnit.currentText(),r_g,theta_E)
             rayRegionLength = self.rootRayInput.value()
             shear = PolarVec(shearR,shearTheta)
             ellip = PolarVec(ellipR, ellipTheta)
             lens = Lens(lRedshift, vDispersion, shear, ellip)
             quasar = Quasar(qRedshift, qRadius, qMass)
             rayRegion = PixelRegion(zero_vector('arcsec'),
                 Vec2D(1.4,1.4,einstein_radius),
                 Vec2D(rayRegionLength,rayRegionLength))
             macro_parameters = Parameters(quasar,lens,rayRegion)
             if self.enableMicrolensing.isChecked():
                 x,y = [float(v) for v in self.imgLocInput.text()[1:-1].split(",")]
                 imgLocation = Vec2D(x,y,'arcsec')
                 minorAxis = self.sPlaneDimInput.value()*UserInputWidget.unitFromString(
                     self.sPlaneDimUnit.currentText(),r_g,theta_E)
                 mass_fn = None
                 mass_fn_seed = self.imfSeedInput.value()
                 if self.imfInput.currentText() == "Custom":
                     mass_fn = ParametersWidget._mk_mass_fn(self.imfPowersInput.text(),
                         self.imfStepsInput.text(),
                         self.imfAgingInput.text())
                 else:
                     mass_fn = self.imfInput.currentText()
                 star_generator = getMassFunction(mass_fn_seed,mass_fn)
                 micro_params = macro_parameters.to_microParams(self.pcntStarsInput.value(),
                                                                imgLocation,
                                                                minorAxis,
                                                                star_generator)
                 return micro_params
             else:
                 return macro_parameters
     except:
         UserInputWidget.warn_user("Error constructing the Parameters object. Please validate input and try again.")
Beispiel #6
0
 def on_release(self, event):
     'on release we reset the press data'
     if event.button != 3: return
     start = self.press
     end = event.xdata, event.ydata
     if not start or not end: return
     self.press = None
     sv = Vec2D(start[0], start[1], self.map_unit)
     ev = Vec2D(end[0], end[1], self.map_unit)
     if self._magmap:
         curve = 2.5 * np.log10(self._magmap.slice_line(sv, ev))
         dist = (ev - sv).magnitude.value
         x_ax = np.linspace(0, dist, len(curve))
         self.plot(curve, x_ax=x_ax)
Beispiel #7
0
 def __init__(self,
              quasar: Quasar,
              lens: Lens,
              percent_stars: float,
              image_center: Vec2D,
              ray_count: Vec2D,
              quasar_position_bounding_box: Region,
              star_generator: MassFunction = getMassFunction()):
     try:
         factor = GlobalPreferences['microlensing_window_buffer']
         tmp_p = Parameters(quasar, lens)
         conv = tmp_p.convergence(image_center)
         shear = tmp_p.shear(image_center)
         ax_ratio = (abs(1 - shear - conv) / abs(1 + shear - conv))
         ray_dims = Vec2D(
             quasar_position_bounding_box.dimensions.x.value / ax_ratio,
             quasar_position_bounding_box.dimensions.y.value,
             str(quasar_position_bounding_box.dimensions.unit))
         ray_region = PixelRegion(image_center, ray_dims * factor,
                                  ray_count)
         Parameters.__init__(self, quasar, lens, ray_region)
         self._star_generator = star_generator
         self._source_plane = quasar_position_bounding_box
         self._percent_stars = percent_stars / 100
     except:
         raise ParametersError(
             "Could not construct MicrolensingParameters from the supplied arguments."
         )
Beispiel #8
0
 def caustics_along(self, curve):
     qpts = curve.query_points
     ret = []
     for r in range(len(curve)):
         if self.is_caustic(Vec2D(qpts[r, 0], qpts[r, 1], qpts.unit)):
             ret.append(r)
     return np.array(ret)
Beispiel #9
0
 def to_microParams(
         self, pcnt_stars: float, image_center: Vec2D,
         minor_axis: u.Quantity,
         star_generator: MassFunction) -> 'MicrolensingParameters':
     bounding_box = Region(
         zero_vector('uas'),
         Vec2D(minor_axis.value, minor_axis.value, minor_axis.unit))
     return MicrolensingParameters(self.quasar, self.lens, pcnt_stars,
                                   image_center, self.ray_region.resolution,
                                   bounding_box, star_generator)
Beispiel #10
0
def getLensedView(params_or_sim):
    from mirage.views import LensView, AnimationController
    from mirage.engine import getVisualEngine
    from mirage.util import Vec2D
    from mirage.parameters import AnimationSimulation
    anim = None
    if isinstance(params_or_sim, AnimationSimulation):
        anim = params_or_sim
        params = params_or_sim.parameters
    else:
        params = params_or_sim
        sp = Vec2D(0.0, 0.0, 'arcsec')
        vel = Vec2D(0, 0, 'arcsec/s')
        anim = AnimationSimulation(params, sp, vel)
    eng = getVisualEngine(params)
    controller = AnimationController(anim, eng)
    eng.update_parameters(params)
    view = LensView("Lens View")
    view.connect_runner(controller)
    return view
Beispiel #11
0
 def on_release(self, event):
     if event.button != 3: return
     start = self.press
     if self._grabbed_quasar:
         xpress, ypress = event.xdata, event.ydata
         sim = self._controller_ref.simulation
         loc = Vec2D(xpress, ypress, self.controller.unit)
         self._controller_ref.query_location(loc, blocking=True)
         self._grabbed_quasar = False
     else:
         end = event.xdata, event.ydata
         if not start or not end: return
         self.press = None
         sim = self._controller_ref.simulation
         pos_unit = sim.start_position.unit
         vel_unit = sim.velocity.unit
         self.line.set_xdata([0, 0])
         self.line.set_ydata([0, 0])
         sv = Vec2D(start[0], start[1], pos_unit)
         vel = Vec2D(end[0] - start[0], end[1] - start[1], vel_unit)
         sim.update(start_position=sv, velocity=vel / 20)
Beispiel #12
0
 def on_motion(self, event):
     'on motion we will move the rect if the mouse is over us'
     if self.press is None: return
     if event.inaxes != self._imgAx or event.button != 3: return
     xpress, ypress = event.xdata, event.ydata
     if self._grabbed_quasar:
         sim = self._controller_ref.simulation
         loc = Vec2D(xpress, ypress, self.controller.unit)
         self._controller_ref.query_location(loc)
     else:
         self.line.set_xdata([xpress, event.xdata])
         self.line.set_ydata([ypress, event.ydata])
         self._fig.canvas.restore_region(self.background)
         self._imgAx.draw_artist(self.line)
         self._fig.canvas.blit(self._imgAx.bbox)
Beispiel #13
0
 def get_object(self,*args,**kwargs):
     from mirage.parameters import Simulation, ParametersError
     from mirage.util import Vec2D
     parameters = self._parameters_widget.get_object()
     if parameters:
         name = self.nameInput.text()
         desc = self.descriptionInput.toPlainText()
         tVar = self.varianceInput.toPlainText()
         trial_count = self.trialCountInput.value()
         special_parameters = []
         if self.mkMagMap.isChecked():
             # Making a magmap
             from mirage.parameters import MagnificationMapParameters
             mmRes = self.mmResolutionInput.value()
             mmRes = Vec2D(mmRes,mmRes)
             mm = MagnificationMapParameters(mmRes)
             special_parameters.append(mm)
         if self.mkLightCurves.isChecked():
             # Making light curves
             from mirage.parameters import LightCurvesParameters
             lcCount = self.lcCountInput.value()
             lcResolution = self.lcResolutionInput.value()
             lcResUnit = UserInputWidget.unitFromString(self.lcResolutionUnit.currentText()[2:],
                 parameters.quasar.r_g, parameters.theta_E)
             lcResolution = lcResolution/lcResUnit
             lcSeed = self.lcSeed.value()
             lcp = LightCurvesParameters(lcCount,lcResolution,lcSeed)
             special_parameters.append(lcp)
         sim = Simulation(parameters,name,desc,trial_count,tVar)
         for sp in special_parameters:
             sim.add_result(sp)
         try:
             #This varifies that the trial variance code is valid code.
             i = 0
             for i in range(sim.num_trials):
                 sim.set_trial(i)
                 sim.parameters
             return sim
         except ParametersError as e:
             UserInputWidget.warn_user("Error raised trying to produce parameters for trial %d." % i)
         except SyntaxError as e:
             UserInputWidget.warn_user("Trial Variance Input was not valid Python.")
         except:
             UserInputWidget.warn_user("Unknown error encountered in trial variance input. Please validate and try again.")
         return None
Beispiel #14
0
 def to_macroParams(self, pixels=Vec2D(2000, 2000)):
     region_dims = zero_vector(
         'arcsec') + self.einstein_radius.to('arcsec') * 2.0
     new_region = PixelRegion(zero_vector('arcsec'), region_dims, pixels)
     params = Parameters(self.quasar, self.lens, new_region)
     return params
Beispiel #15
0
 def from_json(cls, js):
     return cls(Vec2D.from_json(js['caustic_resolution']))
Beispiel #16
0
 def from_json(cls, js):
     return cls(Vec2D.from_json(js['magmap_resolution']))