Commit 0a368797 authored by Michele Maris's avatar Michele Maris
Browse files

u replaced py files

parent 66e1a10c
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
from .modelDb import *
from .artecs_map import *
"""
   .. #include:: ../../README.md
"""

from .tap import EXOP_TAP as exop_pubblic_tap

from .artecs_map import *

from .modelDb import *

+111 −13
Original line number Diff line number Diff line
class artecs_map :
   def __init__(self,filename) :
   """
A class to handle a temperature map from ARTECS.

It reads the artecs_map from a fits file.

   >>> AMAP=artecs_map("artecs_map.fits")

Keywords in the map are returned as members of the class or using the method "parameter".

Example:

   >>> AMAP.temp 

returns the temperature map,

   >>> AMAP.parameter('temp')
   
returns the temperature map.


   >>> AMAP.shape

returns the shape of the map (rows, columns)


   """
   @property 
   def filename(self) :
      """ parameter: the filename """
      return self._filename
   
   @property 
   def p(self) :
      """ the fits file pointer, normally closed.
      """
      return self._p
   
   @property 
   def lst_lat(self) :
      """ list of latitude bands """
      return self._lst_lat
   
   @property 
   def lst_year(self) :
      """ list of time intervals """
      return self._lst_year

   @property 
   def shape(self) :
      """ the shape of the 2D maps """
      return self._shape
   
   @property 
   def TMGLOB(self) :
      """ the mean surface temperature """
      return self._TMGLOB
   
   def __init__(self,filename,closeFits=True,verbose=False) :
      """ To instantiate the class pass the filename from which to load the Temperature map
      
      >Keywords: 
      
      >>`verbose`: if True verbose output
      
      >>`closeFits`: if True the fits file is closed after reading
      """
      import numpy
      try :
         import pyfits
      except :
         from astropy.io import fits as pyfits
      self.filename=filename
      self.p=pyfits.open(filename)
      self._filename=filename
      self._p=pyfits.open(filename)
      self._key=[]
      self._value=[]
      self._descr=[]
@@ -22,26 +87,59 @@ class artecs_map :
               self._value.append('\n'.join(self.p[0].header['COMMENT']))
               self._descr.append(None)
               mkd=False
      
      #: N of year intervals
      self.N=self.parameter('N')
      
      #: NS number of latitude bands
      self.NS=self.parameter('NS')
      self.shape=(self.NS,self.N)
      
      #: the shape
      self._shape=(self.NS,self.N)
     
      self.year=self.p[1].data['year']
      self.lat=self.p[1].data['lat']
      self.temp=self.p[1].data['temp']      
      self.year.shape=self.shape
      self.lat.shape=self.shape
      self.temp.shape=self.shape
      self.TMGLOB=self.temp.mean()
      self.p.close()
      self.lst_lat=self.lat[0]
      self.lst_year=self.year[:,0].T
   def keys(self) : 
      
      #: the mean surfscr temperature
      self._TMGLOB=self.temp.mean()

      self._lst_lat=self.lat[0]
      self._lst_year=self.year[:,0].T

      if verbose :
         print('Successfully opened and readed ',filename)
         
      if closeFits :
         self._p.close()
         if verbose :
            print('fits file closed ',filename)
         
      
   def keys(self,maps=False) : 
      """
returns the list of quantities in the map
      
Keywords: 

>`maps` (default False), if True returns just the list of of elements which are 2D maps
      """
      if maps : 
         return ['year','lat','temp']
      else :
         return self._key
   def has_key(self,key) : 
      """True if required `key` is in the map"""
      return key in self._key
   def parameter(self,key) :
      """returns a parameter from the fits file from its `key'"""
      return self._value[self._key.index(key)]
   def description(self,key) :
      """returns the description of a parameter in the fits file from its `key'"""
      return self._descr[self._key.index(key)]
   def bilinear_interpolation(self,lat,year) :
      pass
   #def bilinear_interpolation(self,lat,year) :
      #"""returns bilinear interpolation of the map (not implemeted yet) """
      #raise Exception(
+16 −0
Original line number Diff line number Diff line
"""
   **DEPRECATED** 
"""

class modelDb :
   """
   **DEPRECATED** 
   
Class to handle a local version of the ARTECS DB.

It takes in input a csv file generated from a query of ARTECS and saved in csv format.

See the example in the introductory page.

This module is kept for compatibility with early releases of py_artecs, but it is not maintained so its use is DEPRECATED.

   """
   def __init__(self,project_name,project_path,csv_name,Verbose=True,csv_sep='!',csv_comment='#',csv_index_col='index',figures_path='png',filterBad=True,new=False,query=None) :
      import time
      from collections import OrderedDict
+19 −19
Original line number Diff line number Diff line
__DESCRIPTION__="""
By M.Maris 1.1 - 2019 Nov 15 - 

TAP services for ARTECS

By M.Maris 1.1 - 2019 Nov 15 - 
Ported to python3
Needs pyvo 

Tap service for artecs


Example:
import artecs
atap=artecs.exop_pubblic_tap()
   >>> import artecs
   >>> atap=artecs.exop_pubblic_tap()
   
atap.EXPLAIN()
atap.keys()
   >>> atap.EXPLAIN()
   
   >>> atap.keys()

tab=atap.search('(0.7 <= SMA) and (SMA <=3.)')

tab.FO_CONST.unique()
   >>> tab=atap.search('(0.7 <= SMA) and (SMA <=3.)')

tab.to_csv('/tmp/pippo.csv',sep=' ')

MAP=atap.get_map(tab.URL[0])
   >>> tab.FO_CONST.unique()

   >>> tab.to_csv('/tmp/pippo.csv',sep=' ')

   >>> MAP=atap.get_map(tab.URL[0])

"""

@@ -41,9 +41,9 @@ except :

class EXOP_TAP :
   def __init__(self,tap_url="http://archives.ia2.inaf.it/vo/tap/exo",table_name="exo.EXO",temporary_files_path='/tmp') :
      import pyvo
      #import pyvo
      #
      #creates empty object
      #creates empty instantiation
      self._empty()
      #
      self._temporary_files_path=temporary_files_path+'/' if temporary_files_path!='' and temporary_files_path!=None else ''
@@ -76,6 +76,7 @@ class EXOP_TAP :
      self._download_success=None
   #
   def _get_field_description(self) :
      """ gets description of fields """
      self.adql_search('SELECT TOP 1 * FROM '+self._table_name)
      self._field_description=self._search_result.fielddescs
      self._field_names=self._search_result.fieldnames
@@ -90,7 +91,7 @@ class EXOP_TAP :
      return this in self._field_names
   #
   def __include__(self,this) :
      """this in object"""
      """this is an object"""
      return this in self._field_names
   #
   def success(self) : 
@@ -98,7 +99,7 @@ class EXOP_TAP :
      return self._search_success==True
   #
   def clean(self) :
      """cleans information from last search"""
      """clean information from last search"""
      self._search_success=None
      self._search_result=None
   #
@@ -145,7 +146,7 @@ class EXOP_TAP :
         return self._search_result.table.to_pandas()
   #
   def get_map(self,_URL,outfile=None) :
      """gets a map """
      """gets a map from an URL"""
      import numpy as np
      import time
      from .artecs_map import artecs_map
@@ -218,7 +219,7 @@ class EXOP_TAP :
      self.get_map(URL,outfile=_o)
   # 
   def EXPLAIN(self) :
      """print a short introduction on the query language"""
      """print a short introduction on the ADQL query language"""
      print ("""
ADQL = Astronomical Data Query Language

@@ -262,4 +263,3 @@ Tutorials:

""")