natashabatalha / picaso

A Planetary Intensity Code for Atmospheric Spectroscopy Observations
https://natashabatalha.github.io/picaso
GNU General Public License v3.0
66 stars 41 forks source link

sqlite query for single ptid is throwing an error #1

Closed ramanakumars closed 5 years ago

ramanakumars commented 5 years ago

It seems that when there is only one unique p-t index in the opacity database, the index value gets formatted as tuple causing an error in the query.

Should the ind_pt query also have a special case similar to the molecule query, like:

unique_ptind = np.unique(ind_pt)

if len(unique_ptind)==1:
        query_ptid = """ptid= '{}' """.format(str(unique_ptind[0]))
else:
        query_ptid = 'ptid in '+str(tuple(unique_ptind))

cur.execute("""SELECT molecule,ptid,opacity
            FROM molecular
            {}
            AND {}""".format(query_mol, query_ptid))
natashabatalha commented 5 years ago

Can you show me what you are inputting for case.atmosphere() and the exact error? Is this for isothermal atmospheres?

ramanakumars commented 5 years ago

I'm using a profile from a GCM output. Here is the .tp file I use as input for the atmosphere: nep_base.tp.txt

This is the error I get:

  File "/usr/local/lib/python3.6/dist-packages/picaso/optics.py", line 708, in get_opacities
    AND ptid in {}""".format(query_mol, str(tuple(np.unique(ind_pt)))))
sqlite3.OperationalError: near ")": syntax error

This is the output when I print out the query:

SELECT molecule,ptid,opacity FROM molecular WHERE molecule= 'CH4' AND ptid in (521,)

This is the script that I use:

import numpy as np
import pandas as pd
import astropy.units as u
import os

#picaso
from picaso import justdoit as jdi 
from picaso import justplotit as jpi

import matplotlib.pyplot as plt

opacity2 = jdi.opannection()
base_case = jdi.inputs()

#phase angle 
base_case.phase_angle(0) #radians

#define gravity
base_case.gravity(gravity=11, gravity_unit=u.Unit('m/(s**2)')) #any astropy units available

#define star 
base_case.star(opacity2, 5700., 0, 4.0) #opacity db, pysynphot database, temp, metallicity, logg

base_case.atmosphere(filename="nep_base.tp", delim_whitespace=True)

base_atmo = np.loadtxt('nep_base.tp', skiprows=1)

## get the top and bot indices of the cloud
## (for debug)
cpt = np.argmin((base_atmo[:,0]-1.)**2.)
cpb = np.argmin((base_atmo[:,0]-6.)**2.)

base_case.clouds(g0=[0.1], w0=[0.96], opd=[3.], p = [3.], dp=[3])

wno_base, alb_base = base_case.spectrum(opacity2)
natashabatalha commented 5 years ago

Ah thanks for sending this. There shouldn't be a len(unique_ptind)==1: because someone should always be submitting a run with different pressures. I found what bug was causing this issue though. It was pulling incorrect pressures. Do a git pull and make sure the issue is gone.

ramanakumars commented 5 years ago

Perfect! It works without an error now, thanks!

I did notice with the new install that there was an error in the setup for build_3d_input.py, where you have

 from .justdoit import 

Should there be a * after the import? The install still worked, but the error was gone when I added the *.

natashabatalha commented 5 years ago

Fixed that and did a mini release. Thanks!