astropy / astroplan

Observation planning package for astronomers – maintainer @bmorris3
https://astroplan.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
198 stars 109 forks source link

Can't plot star_rise_time #500

Closed mirosaide closed 3 years ago

mirosaide commented 3 years ago

I have calculated the set and rise of a star from different locations on earth and I would like to plot the set and rise of the star against random values of a given range, when I tried:

import astropy.units as u from astropy.time import Time from astropy.coordinates import SkyCoord, EarthLocation, AltAz from astroplan import download_IERS_A download_IERS_A from astroplan import Observer, FixedTarget

time = Time("2020-11-12 11:00:00",format='iso')

target = SkyCoord.from_name("Barnard's Star")

Location = Observer(latitude=cities[:,0]*u.deg, longitude=cities[:,1]*u.deg)
star_rise_time = Location.target_rise_time(time, target, which='next')
star_set_time = Location.target_set_time(time, target, which='next')

data = np.random.randint(2,50,size=2013)
plt.scatter(star_rise_time,data)

I am getting the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: float() argument must be a string or a number, not 'Time'

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-11-547411dc0262> in <module>
      1 data = np.random.randint(2,50,size=2013)
----> 2 plt.plot(star_rise_time,data)

~/.local/lib/python3.7/site-packages/matplotlib/pyplot.py in plot(scalex, scaley, data, *args, **kwargs)
   2761     return gca().plot(
   2762         *args, scalex=scalex, scaley=scaley, **({"data": data} if data
-> 2763         is not None else {}), **kwargs)
   2764 
   2765 

~/.local/lib/python3.7/site-packages/matplotlib/axes/_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
   1646         lines = [*self._get_lines(*args, data=data, **kwargs)]
   1647         for line in lines:
-> 1648             self.add_line(line)
   1649         self._request_autoscale_view(scalex=scalex, scaley=scaley)
   1650         return lines

~/.local/lib/python3.7/site-packages/matplotlib/axes/_base.py in add_line(self, line)
   1848             line.set_clip_path(self.patch)
   1849 
-> 1850         self._update_line_limits(line)
   1851         if not line.get_label():
   1852             line.set_label('_line%d' % len(self.lines))

~/.local/lib/python3.7/site-packages/matplotlib/axes/_base.py in _update_line_limits(self, line)
   1870         Figures out the data limit of the given line, updating self.dataLim.
   1871         """
-> 1872         path = line.get_path()
   1873         if path.vertices.size == 0:
   1874             return

~/.local/lib/python3.7/site-packages/matplotlib/lines.py in get_path(self)
   1025         """
   1026         if self._invalidy or self._invalidx:
-> 1027             self.recache()
   1028         return self._path
   1029 

~/.local/lib/python3.7/site-packages/matplotlib/lines.py in recache(self, always)
    668         if always or self._invalidx:
    669             xconv = self.convert_xunits(self._xorig)
--> 670             x = _to_unmasked_float_array(xconv).ravel()
    671         else:
    672             x = self._x

~/.local/lib/python3.7/site-packages/matplotlib/cbook/__init__.py in _to_unmasked_float_array(x)
   1313     """
   1314     if hasattr(x, 'mask'):
-> 1315         return np.ma.asarray(x, float).filled(np.nan)
   1316     else:
   1317         return np.asarray(x, float)

~/.local/lib/python3.7/site-packages/numpy/ma/core.py in asarray(a, dtype, order)
   7847     order = order or 'C'
   7848     return masked_array(a, dtype=dtype, copy=False, keep_mask=True,
-> 7849                         subok=False, order=order)
   7850 
   7851 

~/.local/lib/python3.7/site-packages/numpy/ma/core.py in __new__(cls, data, mask, dtype, copy, subok, ndmin, fill_value, keep_mask, hard_mask, shrink, order, **options)
   2793         # Process data.
   2794         _data = np.array(data, dtype=dtype, copy=copy,
-> 2795                          order=order, subok=True, ndmin=ndmin)
   2796         _baseclass = getattr(data, '_baseclass', type(_data))
   2797         # Check that we're not erasing the mask.

ValueError: setting an array element with a sequence.

Thanks in advance!

bmorris3 commented 3 years ago

Hi,

This is not an astroplan problem, so I'm going to close this issue, but I'm happy to help you figure out how to make your plot! Could you explain what you're trying to do a bit more?

The following snippet:

data = np.random.randint(2,50,size=2013)
plt.scatter(star_rise_time,data)

will generate a vector of length 2013 points called data. star_rise_time is a single astropy Time object. I think you're getting this error because (1) you can't plot a scalar time object against a vector numpy array (2) you should convert the Time object to a numerical time, by calling star_rise_time.jd, for example.

mirosaide commented 3 years ago

Hi, Thanks for your feedback,

I am trying to plot the rise and set time with respect to the value of the power transmitted by each location on earth when the star set and rise.

I have the locations in terms of latitude and longitude, the target ('star'), and the time of the year which I want to get the set and rise.

I will attach the code.

Ramiro Caisse Saide MPhil/PhD Research Student Department of Physics University of Mauritius Contact Number: +258 845672884

Brett M. Morris notifications@github.com escreveu no dia segunda, 1/02/2021 à(s) 08:44:

Hi,

This is not an astroplan problem, so I'm going to close this issue, but I'm happy to help you figure out how to make your plot! Could you explain what you're trying to do a bit more?

The following snippet:

data = np.random.randint(2,50,size=2013) plt.scatter(star_rise_time,data)

will generate a vector of length 2013 points called data. star_rise_time is a single astropy Time object. I think you're getting this error because (1) you can't plot a scalar time object against a vector numpy array (2) you should convert the Time object to a numerical time, by calling star_rise_time.jd, for example.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/astropy/astroplan/issues/500#issuecomment-770613316, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJZIERI4OW4MKMILMVL6UMTS4ZETHANCNFSM4W3X26FQ .