skyfielders / python-skyfield

Elegant astronomy for Python
MIT License
1.42k stars 213 forks source link

Compute the solar altitude and azimuth obeserved from the mars #877

Open muyunl opened 1 year ago

muyunl commented 1 year ago

Hi, I am learning to use skyfield recently, it is really a nice tool, and I got a problem now. I'm trying to compute the solar altitude and azimuth obeserved from the mars, and I find an official examples about the moon:

  pc = PlanetaryConstants()
  pc.read_text(load('moon_080317.tf'))
  pc.read_text(load('pck00008.tpc'))
  pc.read_binary(load('moon_pa_de421_1900-2050.bpc'))

  aristarchus = moon + pc.build_latlon_degrees(frame, 26.3, -46.8)
  apparent = aristarchus.at(t).observe(earth).apparent()
  alt, az, distance = apparent.altaz()

So, I‘m trying to bulid reference frames of mars, like this:

      self.pc = PlanetaryConstants()
      self.pc.read_text(load(r"./configs/mars2020/m2020.tf"))
      self.pc.read_text(load(r"./configs/mars2020/pck00010.tpc"))
      self.pc.read_text(load(r"./configs/mars2020/mars_iau2000_v1.tpc"))
      self.frame = self.pc.build_frame_named("M2020_TOPO")

but I get an error: ** ValueError: unknown planetary constant 'FRAME_M2020_TOPO' You should either use this object's .read_text() method to load an additional ".tf" PCK text file that defines the missing name, or manually provide a value by adding the name and value to the this object's .assignments dictionary.

I find the frame name in the m2020.tf file which is in https://naif.jpl.nasa.gov/pub/naif/MARS2020/kernels/fk/m2020.tf. image

Can you offer me some advice to fix the problem or how can I compute the solar altitude obeserved from mars?

brandon-rhodes commented 1 year ago

Good afternoon! The m2020.tf file that you mention doesn't seem to contain the reference frame you need. If you read through it, it says that the M2020_TOPO frame is somewhere else:

   Currently an instance of this frame specific for a particular target
   landing site is defined in a separate FK named according to the
   m2020_tp_III_iau2000_vX.tf pattern, when III is the site ID and V is
   the file version.

Now, it's quite possible that Skyfield hasn't implemented that kind of frame yet, and that you'll get an error when you try using it; but you can at least try, by finding the file mentioned above, and trying to load it with Skyfield before asking Skyfield to use the frame. Let me know what happens when you try!