databtlType.py 9.7 KB
import xlrd
from netCDF4 import Dataset
import numpy as np
import pandas as pd
import os, os.path
import glob
import testbtl as tb
from classe_variable import variable
"""creation des attributs pour les variables dans le fichier btl """
"""les codes"""
def mescodebtl():
    code1=('Fichier','Latitude','Longitude','unique','Date','PrDM','PRES_SDEV','TEMP','TE90_SDEV','Sal00','Date','Time',"CNTR","nCNTR","Sigma-t00","FlECO-AFL","Ph","pH",'Upoly0','Upoly1','Sbeox0ML/L','CStarTr0','Par','TEMP_RT','SECC')
    code2=('Q_TEMP','Sal','Q_PSAL','OXY_','Q_OXY',"CHL_","Q_CHL","PHA_","Q_PHA",'NOx_','Q_NOx','TEMP_','TEMP_QC')
    code3=('Salinity','Oxygen',"Si","PO4",'NOx','Silicates','Si_',"Nitrates")
    res=list(code1)
    res.extend(list(code2))
    res.extend(list(code3))
    return res
def mesgf3code(code):
    a={}
    for j in code:
        a[creerLaVariable(j).getgf3()]=j
    return a
def mescodegf3(l,code):
    return l[code]
"""les attributs des variables  """
def creerLaVariable(code):
    if code=="Fichier":
        return variable('Filename','none','CTD','Fichier','(none)',1,0,'filename: CTD')
    elif code=="Latitude":
        return variable('latitude','degrees','CTD','Latitude','LATD',1,5,'latitude: CTD')
    elif code=="Longitute":
        return variable('longitude','degrees','CTD','Longitute','LOND',1,5,'longitude: CTD')
    elif code=="unique":
        return variable('uniquesample number', 'none','CTD','unique','IDEN',1,0,'unique sample number')
    elif code=="zbouteille":
        return variable('pressure depth of the water sample','db','CTD','zbouteille','PRES',1,1,'nominal or exact water sample depth')
    elif code=="Date":
        return variable('GMT date of the water sample', 'none','CTD','Date','UNKN',1,0,'date: CTD')
    elif code=="Time":
        return variable( 'GMT time of the water sample', 'none','CTD','Time','UNKN',1,0,'time: CTD')
    elif code=="PrDM":
        return variable('CTD pressure', 'db','CTD','PrDM','PRES',1,1,'pressure: CTD')
    elif code=="TEMP":
        return variable('CTD temperature ITS-90', 'deg C','CTD','TE90','TE090C',1,2,'temperature: CTD')
    elif code=="TE90_SDEV":
        return variable('CTD standard deviation temperature', 'deg C','CTD','TE90_SDEV','SDEV',1,3,'standard deviation temperature: CTD')
    elif code=="Salinity":
        return variable('bottle sample salinity PSS-78', 'PSU','labo','PSAL_BS','PSAL',1,2,'')
    elif code=="Si":
        d='silicate content: Strickland and Parsons (1972)'+\
          '\nsilicate content: American Public Health Association (1989)'+\
            '\nsilicate content: AA3; Strickland and Parsons (1972)'+\
                '\nsilicate content: not corrected for salinity'+\
                    '\nsilicate content: unknown method.'+\
                        '\nsilicate content: Strickland and Parsons (1968)'+\
                            '\nsilicate content: Strain & Clement.1996.Can Data Rep Fish Aquat Sci 1004'
        return variable('bottle sample silicate (SIO4-SI) content', 'mmol/m**3','labo','Si_','SLCA',1,2,d)
    elif code=="Si_":
        d='silicate content: Strickland and Parsons (1972)'+\
          '\nsilicate content: American Public Health Association (1989)'+\
            '\nsilicate content: AA3; Strickland and Parsons (1972)'+\
                '\nsilicate content: not corrected for salinity'+\
                    '\nsilicate content: unknown method.'+\
                        '\nsilicate content: Strickland and Parsons (1968)'+\
                            '\nsilicate content: Strain & Clement.1996.Can Data Rep Fish Aquat Sci 1004'
        return variable('bottle sample silicate (SIO4-SI) content', 'mmol/m**3','labo','Si_','SLCA',1,2,d)
    elif code=="Silicates":
        d='silicate content: Strickland and Parsons (1972)'+\
          '\nsilicate content: American Public Health Association (1989)'+\
            '\nsilicate content: AA3; Strickland and Parsons (1972)'+\
                '\nsilicate content: not corrected for salinity'+\
                    '\nsilicate content: unknown method.'+\
                        '\nsilicate content: Strickland and Parsons (1968)'+\
                            '\nsilicate content: Strain & Clement.1996.Can Data Rep Fish Aquat Sci 1004'
        return variable('bottle sample silicate (SIO4-SI) content', 'mmol/m**3','labo','Si_','SLCA',1,2,d)
    elif code=="PO4":
        return variable('bottle sample phosphate (PO4-P) content', 'mmol/m**3','labo','PO4_','PHOS',1,2,'')
    elif code=="Sal00":
        return variable('CTD salinity PSS-78', 'PSU','CTD','Sal00','PSAL_01',1,2,'salinity: CTD')
    elif code=="CNTR":
        return variable('scan number','none','CTD','CNTR','CNTR',1,0,'scan number: CTD')
    elif code=="nCNTR":
        return variable('number of scans averaged','none','CTD','nCNTR','NUM_',1,0,'number of scans averaged: CTD')
    elif code=="PRES_SDEV":
        return variable('CTD standard deviation pressure','db','CTD','PRES_SDEV','SDEV',1,2,'standard deviation pressure: CTD')
    elif code=='Sigma-t00':
        return variable('CTD sigma-t','kg/m**3','CTD','Sigma-t00','SIGT',1,2,'sigma-t: CTD')
    elif code=="FlECO-AFL":
        return variable('CTD fluorescence','mg/m**3','CTD','FlECO-AFL','FLOR',1,3,'fluorescence: CTD')
    elif code=="Ph":
        return variable('CTD Ph','SI','CTD','Ph','PHPH',1,2,'Ph: CTD')
    elif code=='Upoly0':
        return variable('CTD nitrate','microM','CTD','Upoly0','NTRA_01',1,2,'nitrate: CTD')
    elif code=='Upoly1':
        return variable('CTD nitrate','microM','CTD','Upoly1','NTRA_02',1,2,'nitrate: CTD')
    elif code=='Sbeox0ML/L':
        return variable('CTD oxygen','ml/l','CTD','Sbeox0ML/L','DOXY',1,3,'oxygen: CTD')
    elif code=='pH':
        return variable('bottle sample pH','NBS scale','labo','pH','pHT_',1,4,'pH: calculated in situ value, Strickland & Parsons 1972 (NBS scale) pH: calculated in situ value, Lewis & Wallace 1998 (NBS scale) used for CTD calibration and comparison with old datasets pH: unknown method')
    elif code=='CStarTr0':
        return variable('CTD transmissivity','%','CTD','CStarTr0','TRAN',1,1,'transmissivity: CTD')
    elif code=='Par':
        return variable('CTD irradiance (PAR)','ueinsteins/s/m**2','CTD', 'Par','PSAR',1,3,'water column PAR (photosynthetically active radiation): CTD')
    elif code=='TEMP_RT':
        return variable('reversing thermometer temperature ITS-90','deg C','terrain','TEMP_RT','TE90T',1,4,'reversing thermometer measurement')
    elif code=='Q_TEMP':
        return variable('quality flag temperature','(none)','terrain','Q_TEMP','QQQQ',1,0,'quality flag of temperature')
    elif code=='SECC':
        return variable('secchi depth','m','terrain','SECC','SECC',1,0,'secchi depth measurement')
    elif code=='Sal':
        return variable('bottle sample salinity PSS-78','PSU','labo','Sal','PSAL_02',1,2,'autoSAL salinity measurement')
    elif code=='Q_PSAL':
        return variable('quality flag of bottle sample salinity','(none)', 'labo','Q_PSAL','PSAL_QC',1,0,'quality flag of bottle sample salinity')
    elif code=='OXY_':
        return variable('bottle sample oxygen','ml/l', 'labo','OXY_','DOXY_02',1,3,'Winkler dissolved oxygen titration method: Carpenter (1965) and Carrit and Carpenter (1966)')
    elif code=='Oxygen':
        return variable('bottle sample oxygen','ml/l', 'labo','OXY_','DOXY_02',1,3,'Winkler dissolved oxygen titration method: Carpenter (1965) and Carrit and Carpenter (1966)')
    elif code=='Q_OXY':
        return variable('quality flag of bottle sample oxygen','(none)', 'labo','Q_OXY','DOXY_QC',1,0,'quality flag of bottle sample oxygen ')
    elif code=='CHL_':
        return variable('bottle sample chlorophyll content','mg/m**3', 'labo','CHL_','CPHL',1,2,'chlorophyll-a content: fluorometric method of Holm-Hansen ')
    elif code=="Q_CHL":
        return variable( 'quality flag of bottle sample chlorophyll content','(none)', 'labo','Q_CHL','CPHL_QC',1,0,'quality flag of bottle sample chlorophyll content')
    elif code=='PHA_':
        return variable('bottle sample phaeopigment content','mg/m**3', 'labo','PHA_','PHA_',1,2,'phaeopigment content: fluorometric method of Holm-Hansen, Lorenzen,')
    elif code=='Q_PHA':
        return variable('quality flag of bottle sample phaeopigment content','mg/m**3', 'labo','Q_PHA','PHA_QC',1,2,'quality flag of bottle sample phaeopigment content')
    elif code=='NOx':
        return variable('bottle sample nitrate (NO3-N) + nitrite (NO2-N) content','mmol/m**3', 'labo','NOx_','NTRZ',1,2,'nitrate content')
    elif code=='NOx_':
        return variable('bottle sample nitrate (NO3-N) + nitrite (NO2-N) content','mmol/m**3', 'labo','NOx_','NTRZ',1,2,'nitrate content')
    elif code=='Nitrates':
        return variable('bottle sample nitrate (NO3-N) + nitrite (NO2-N) content','mmol/m**3', 'labo','NOx_','NTRZ',1,2,'nitrate content')
    elif code=='Q_NOx':
        return variable('quality flag of bottle sample nitrate','(none)', 'labo','Q_NOx','NTRZ_QC',1,0,'quality flag of bottle ')
    elif code=='TEMP_':
        return variable('water temperature','deg C','terrain','TEMP_','TEMP',1,4,'temperature measurement, unknown method')
    elif code=='Q_TEMP':
        return variable('quality flag of water temperature','(none)','terrain','Q_TEMP','TEMP_QC',1,0,'quality flag water temperature')
    elif code=='mission':
        return variable('mission','(none)','terrain','mission','mission',1,0,'quality')
    elif code=='bottle':
        return variable('mission','(none)','terrain','bottle','bottle',1,0,'quality')
    elif code=='cast':
        return variable('mission','(none)','terrain','cast','cast',1,0,'quality')
    elif code=='date':
        return variable('mission','(none)','terrain','date','date',1,0,'quality')
    elif code=='time':
        return variable('mission','(none)','terrain','time','time',1,0,'quality')
    else:
        return 0