testbtl.py 3.95 KB
from seabird.cnv import fCNV
from seabird import netcdf
import numpy
from datetime import date
from datetime import datetime
import pandas as pd
from datetime import datetime, timedelta
from netCDF4 import num2date, date2num
#profile = fCNV("/home/BUREAUTIQUE/thib0010/Bureau/QO/CTD/1702001.btl")

#print(profile.attributes) # It will return the header, as a dictionary.

#print(profile.keys()) # It will list the available variables.
#Sal00'
#print(profile["Par"].attributes)
def alldata(filename):
    return fCNV(filename)
"""toutes """
def mesvariable(filename):
    a=[]
    j=0
    profile = fCNV(filename)
    mesvar=profile.keys()
    for i in mesvar:
        a.append(profile[i])
        j=j+1
    return a
"""Les valeurs par leur nom et leur indice """

def recupvaleur(filename):
    a=mesvariable(filename)
    liste={}
    for i in a:
        liste[i.attributes["name"],i.attributes["id"]]=i
    return liste
"""Les valeurs par leur indice 0 pour bottle position"""

def recupvaleurindice(filename):
    a=mesvariable(filename)
    liste={}
    for i in a:
        liste[i.attributes["id"]]=i
    return liste
"""Les valeurs par leur nom """

def recupvaleurname(filename):
    a=mesvariable(filename)
    liste={}
    for i in a:
        liste[i.attributes["name"]]=i
    liste=pd.DataFrame.from_dict(liste,dtype=float)
    return liste
"""date + time format"""
def recupdatetime(filename):
    res=[]
    i=0
    madate=recupvaleurindice(filename)[1]
    matemps=recupvaleurindice(filename)[2]
    while i<len(madate):
        res.append(datetime.combine(madate[i],matemps[i]))
        i=i+1
    return res
"""time dermier minute depuis 1980-01-01 00:00:00 """

def recupvaleurtime(filename):
    res=recupdatetime(filename)
    tstart=[]
    datetampon=pd.to_datetime("1980-01-01 00:00:00")
    for i in res:
        tstart.append(divmod((i-datetampon).total_seconds(),60)[0])
    return tstart
"""ajouter une colonne pour le format datetime de chaque bouteille """

def adddatetimecol(filename):
    a=recupvaleurindice(filename)
    c=len(a)
    b={}
    b=a
    tstart=recupvaleurtime(filename)
    b[c]=tstart
    b=pd.DataFrame.from_dict(b)
    return b
""" les valeurs pour les bouteilles """
def addnumpy(filename):
    a=adddatetimecol(filename)
    b=[]
    for i in a.values():
        b.append(i)
    return numpy.array(b),len(numpy.array(b)[0]),len(numpy.array(b))
"""recup les donnees pour chaque bouteille """

def databouteille(filename,numbouteille):
    z=[]
    dataa={}
    f=0
    a=adddatetimecol(filename)
    b,c,d=addnumpy(filename)
    e=recupvaleurname(filename)
    for i in e.keys():
        if i not in ("bottle","time","date"):
            z.append(i)
    z.append("datetime")
    bou=list(b[0,0:c])
    for i,j in enumerate(bou):
        if int(j)==numbouteille:
            m=list(b[3:d,i])
        else:
            k=1
    for i in m :
        dataa[z[f]]=i
        f=f+1
    return dataa
def recupEntete(filename):
    profile=alldata(filename)
    entete=profile.attributes
    return entete
"""recup LATITUDE """
def recupLatitude(filename):
    entete=recupEntete(filename)
    return entete["LATITUDE"]
"""recup Longitute """
def recupLong(filename):
    entete=recupEntete(filename)
    return entete["LONGITUDE"]
"""recup time dermier minute depuis 1980-01-01 00:00:00"""
def recupTims(filename):
    entete=recupEntete(filename)
    t=entete["datetime"]
    return t
def recupTimeS(filename):
    entete=recupEntete(filename)
    t=entete["datetime"]
    datetampon=pd.to_datetime("1980-01-01 00:00:00")

    tstart=divmod((t-datetampon).total_seconds(),60)[0]
    return tstart
#d=recupvaleurindice("/home/BUREAUTIQUE/thib0010/Bureau/QO/CTD/1702001.btl")[1][0]
#d=datetime.combine(d, datetime.min.time())
#print(databouteille("/home/BUREAUTIQUE/thib0010/Bureau/QO/CTD/1702001.btl",2))
#print(recupvaleurname("/home/BUREAUTIQUE/thib0010/Bureau/QO/CTD/1702001.btl")["bottle"])
#print(alldata("/home/BUREAUTIQUE/thib0010/Bureau/QO/CTD/1702001.btl").keys())
#print(a[0].attributes["name"])