Exemple #1
0
    def __init__(self, parameters=None, coords=None):
        self._parameters = PixelLensingModelParameters(parameters)
        self._coords = None
        if coords is not None:
            self._coords = Coordinates(coords)

        self._datasets = []
Exemple #2
0
 def _set_coords(self, coords=None, ra=None, dec=None):
     """Set the coordinates and raise errors if applicable."""
     self._coords = None
     if (coords is not None) or (ra is not None) or (dec is not None):
         # Check for errors and if none, set the coordinates
         warnings.warn(
             'coords will be deprecated in future. There is no reason ' +
             'to tie this to a given dataset', FutureWarning)
         coords_msg = 'Must specify both or neither of ra and dec'
         # ...using coords keyword
         if coords is not None:
             self._coords = Coordinates(coords)
         # ...using ra, dec keywords
         if ra is not None:
             if dec is not None:
                 self._coords = Coordinates(ra, dec)
             else:
                 raise AttributeError(coords_msg)
         else:
             if ra is not None:
                 raise AttributeError(coords_msg)
Exemple #3
0
    def _update_coords(self, coords=None):
        """Set the coordinates as a SkyCoord object"""
        self._coords = Coordinates(coords)

        if self._model is not None:
            self._model.coords = self._coords

        # We run the command below with try, because _update_coords() is called
        # by _set_datasets before self._datasets is set.
        try:
            for dataset in self._datasets:
                dataset.coords = self._coords
        except Exception:
            pass
Exemple #4
0
    def __init__(self,
                 times,
                 parameters,
                 parallax=None,
                 coords=None,
                 satellite_skycoord=None,
                 earth_coords=None):
        # Set times
        if isinstance(times, np.ndarray):
            self.times = times
        elif isinstance(times, (list, tuple)):
            self.times = np.array(times)
        else:
            self.times = np.array([times])

        # Check for ModelParameters and set.
        if isinstance(parameters, ModelParameters):
            self.parameters = parameters
        else:
            m = 'parameters is a required and must be a ModelParameters object'
            raise TypeError(m)

        # Set parallax values
        self.parallax = {
            'earth_orbital': False,
            'satellite': False,
            'topocentric': False
        }
        if parallax is not None:
            for (key, value) in parallax.items():
                self.parallax[key] = value

        if coords is None or isinstance(coords, Coordinates):
            self.coords = coords
        else:
            self.coords = Coordinates(coords)
        self.satellite_skycoord = satellite_skycoord
        if earth_coords is not None:
            raise NotImplementedError(
                "The earth_coords needed for " +
                "topocentric parallax is not implemented yet")
        self.earth_coords = None

        # Calculate trajectory
        self.get_xy()
Exemple #5
0
 def coords(self, new_value):
     self._coords = Coordinates(new_value)
Exemple #6
0
    def __init__(self,
                 data_list=None,
                 file_name=None,
                 phot_fmt="mag",
                 chi2_fmt="flux",
                 coords=None,
                 ra=None,
                 dec=None,
                 ephemerides_file=None,
                 add_2450000=False,
                 add_2460000=False,
                 bandpass=None,
                 bad=None,
                 good=None,
                 plot_properties=None,
                 **kwargs):

        # Initialize some variables
        self._n_epochs = None
        self._horizons = None
        self._satellite_skycoord = None

        self._init_keys = {'add245': add_2450000, 'add246': add_2460000}
        self._limb_darkening_weights = None
        self.bandpass = bandpass
        self._chi2_fmt = chi2_fmt

        # Set the coords (if applicable)...
        coords_msg = 'Must specify both or neither of ra and dec'
        self._coords = None
        # ...using coords keyword
        if coords is not None:
            self._coords = Coordinates(coords)
        # ...using ra, dec keywords
        if ra is not None:
            if dec is not None:
                self._coords = Coordinates(ra, dec)
            else:
                raise AttributeError(coords_msg)
        else:
            if ra is not None:
                raise AttributeError(coords_msg)

        # Plot properties
        if plot_properties is None:
            plot_properties = {}
        self.plot_properties = plot_properties

        # Import the photometry...
        if data_list is not None and file_name is not None:
            raise ValueError(
                'MulensData cannot be initialized with both data_list and ' +
                'file_name. Choose one or the other.')
        elif data_list is not None:
            # ...from an array
            if len(kwargs) > 0:
                raise ValueError('data_list and kwargs cannot be both set')
            if len(data_list) != 3:
                try:
                    msg0 = "\n" + str(data_list) + "\n"
                except Exception:
                    msg0 = ""
                msg = (msg0 + "\n" +
                       'MulensData was initiated with data_list of length ' +
                       '{:}, while length of 3 is expected (i.e. time, mag ' +
                       'or flux, and uncertainty).')
                raise ValueError(msg.format(len(data_list)))
            (vector_1, vector_2, vector_3) = list(data_list)
            self._initialize(phot_fmt,
                             time=np.array(vector_1),
                             brightness=np.array(vector_2),
                             err_brightness=np.array(vector_3),
                             coords=self._coords)
        elif file_name is not None:
            # ...from a file
            usecols = kwargs.pop('usecols', (0, 1, 2))
            if not exists(file_name):
                raise FileNotFoundError(file_name)
            try:
                (vector_1, vector_2, vector_3) = np.loadtxt(fname=file_name,
                                                            unpack=True,
                                                            usecols=usecols,
                                                            **kwargs)
            except Exception:
                print("kwargs passed to np.loadtxt():")
                print(kwargs)
                print("usecols =", usecols)
                print("File:", file_name)
                raise
            self._initialize(phot_fmt,
                             time=vector_1,
                             brightness=vector_2,
                             err_brightness=vector_3,
                             coords=self._coords)

            # check if data label specified, if not use file_name
            if 'label' not in self.plot_properties.keys():
                if file_name is not None:
                    self.plot_properties['label'] = basename(file_name)
                else:
                    self.plot_properties['label'] = 'a dataset'
        else:
            raise ValueError('MulensData cannot be initialized with ' +
                             'data_list or file_name')

        if bad is not None and good is not None:
            raise ValueError('Provide bad or good, but not both')
        elif bad is not None:
            self.bad = bad
        elif good is not None:
            self.good = good
        else:
            self.bad = self.n_epochs * [False]

        # Set up satellite properties (if applicable)
        self._ephemerides_file = ephemerides_file