HajimeKawahara / exojax

🐈 Automatic differentiable spectrum modeling of exoplanets/brown dwarfs using JAX, compatible with NumPyro and JAXopt
http://secondearths.sakura.ne.jp/exojax/
MIT License
45 stars 14 forks source link

How to connect DataFrame in a common API to ExoJAX #256

Closed HajimeKawahara closed 1 year ago

HajimeKawahara commented 2 years ago
HajimeKawahara commented 2 years ago

Let's discuss in the discussion? @erwanp @ykawashima @chonma0ctopus

HajimeKawahara commented 2 years ago

@erwanp

Hello! Sorry for long silence. I have been busy the past few months as I moved from University of Tokyo to JAXA/ISAS (change my institution in your slide). Anyway, I manage to start a common API issue.

Currently, I am trying to use fetch_exomol as an interface (here)

        dataframe = fetch_exomol(self.simple_molecule_name,
                                 database=self.database,
                                 local_databases=self.path)

But I am wondering how we should call pf (partition function) info. Sofar we used exomolapi.read_pf in exojax. (here)

        # load pf
        pf = exomolapi.read_pf(self.pf_file)
        self.gQT = jnp.array(pf['QT'].to_numpy())  # grid QT
        self.T_gQT = jnp.array(pf['T'].to_numpy())  # T forgrid QT
        self.QTref = np.array(self.QT_interp(Tref))
        self.QTtyp = np.array(self.QT_interp(self.Ttyp))

I'd like to hear your opinion.

erwanp commented 2 years ago

Hello, congrats on the move ! Our lab worked with Kazuhisa Fujita-sama at JAXA, if you happen to meet him.

--

Side note, I think you shouldn't use fetch_exomol() directly. It includes some RADIS specific features, such as storing databases in ~/.radisdb or registering them in radis.json (which is useful, but should not be required by Exojax). Also, it renames columns in a RADIS-specific format. Instead, I suggest you use the underlying class from the common API, MdbExomol

--

For Partition Functions, I used a RADIS-specific mdb.to_partition_function_tabulator() function, which generates PartFuncExoMol, basically just an interpolator which returns np.interp(T, self.T_range, self.Q_range)

I think you should keep on using the ExoJax syntax you showed above. T_gQT, qGT can be retrieved from the MdbExoMol object :

  mdb = MdbExomol(
      local_path,
      molecule=molecule,
      name=databank_name,
      local_databases=local_databases,
      nurange=[
          load_wavenum_min if load_wavenum_min is not None else 0.0,
          load_wavenum_max if load_wavenum_max is not None else np.inf,
      ],
      engine=engine,
      cache=cache,
      skip_optional_data=skip_optional_data,
  )
#...
T_gQT, gQT = mdb.T_gQT, mdb.gQT

(link to common-api branch)

HajimeKawahara commented 2 years ago

Hello @erwanp,

Thanks a lot. I see. Then, first, I will try to wrap radis.api.exomol.MdbExomol in exojax.spec.api.MdbExomol. I think, in near future, maybe we should directly call radis.api.exomol.MdbExomol but now, I feel the wrapping is more safe.

erwanp commented 2 years ago

Yes, agreed. These API will take some time before they reach their final form. Even after you call radis.api.exomol.MdbExomol I'd suggest to Inherit() and Subclass the Radis class so you can easily override anything at anytime if needed (without having to require any RADIS update).

So in exojax/spec/api

from radis.api.exomol import MdbExomol 

class MdbExoMol(MdbExomol):
    ... 
HajimeKawahara commented 2 years ago

@erwanp

I think I managed to connect radis/api/exomolapi.py (working at common-api branch) to exojax/spec/api.py (working at radisapi branch) for ExoMol.

tests in ExoJAX

tests in radis

Before I move on HITEMP, I'd like you to make sure this is the right direction. I found, for HITEMP unlike ExoMol, MdbExomol like class does not exist in radis yet. Instead, I found HITEMPDatabaseManager. What are your thoughts on how to connect radis HITEMP API to ExoJAX?

erwanp commented 2 years ago

Hello ! HITEMPDatabaseManager inherits from DatabaseManager, similarly to MdBExomol. Therefore, HITEMPDatabaseManager will play the same role as MdBExomol in the API.

So it should be fairly easy to just duplicate the changes, unless you see a problem I missed ?

HajimeKawahara commented 2 years ago

OK, then, I will try to implement it the same way as mdbExomol 😃 Thanks!

HajimeKawahara commented 2 years ago

@erwanp Hello! I have a question on hapi in radis. It looks that the installation of radis automatically installs hapi. Is it correct? If true, how does it work?

HajimeKawahara commented 2 years ago

@erwanp Sorry to keep asking questions. What is the main reason for implementing hitranapi and hitempapi separately? Maybe data format?

erwanp commented 2 years ago

Many parts are common, but the download is different. And Hitran has more columns than the default ones, we currently have a project https://github.com/radis/radis/pull/495 to automatically include the broadening coefficients of non-air species. This is a Hitran only feature.

erwanp commented 2 years ago

@erwanp Hello! I have a question on hapi in radis. It looks that the installation of radis automatically installs hapi. Is it correct? If true, how does it work?

Hapi is pip installable. The pip package name is hitran-api https://github.com/radis/radis/blob/develop/environment.yml

HajimeKawahara commented 2 years ago

Hapi is pip installable. The pip package name is hitran-api

Thanks! Oh really. I did not notice that.

Many parts are common, but the download is different. And Hitran has more columns than the default ones, we currently have a project https://github.com/radis/radis/pull/495 to automatically include the broadening coefficients of non-air species. This is a Hitran only feature.

I see. So, it's presumably better to have separate moldbs in ExoJAX too.

HajimeKawahara commented 1 year ago

309 removed the old moldb. So, now ExoJAX officially determined to use radis.api as I/O of ExoMol, HITRAN, and HITEMP.