Skip to content

Instantly share code, notes, and snippets.

@stageipsl
Created June 26, 2014 12:00
Show Gist options
  • Save stageipsl/89be5601be973ae9fe30 to your computer and use it in GitHub Desktop.
Save stageipsl/89be5601be973ae9fe30 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import goccp as go
import numpy as np
from netCDF4 import Dataset
from numpy import dtype
def ecr_cdf(sortie,flag, alt_max, lg, lt, ti,alt):
ncfile = Dataset(sortie+'.nc','w')
u,v = np.shape(flag)
#Flag
ncfile.createDimension('x',u)
ncfile.createDimension('y',v)
flags = ncfile.createVariable('flags',dtype('int32').char,('x','y'))
flags[:] = flag
#altitude extinction
alt_max_extinction = ncfile.createVariable('alt_max_extinction',dtype('float32').char,('x'))
alt_max_extinction[:] = alt_max
#longitude
longitude = ncfile.createVariable('longitude',dtype('float32').char,('x'))
longitude[:] = lg
#latitude
latitude = ncfile.createVariable('latitude',dtype('float32').char,('x'))
latitude[:] = lt
#temps
time = ncfile.createVariable('time',dtype('float32').char,('x'))
time[:] = ti
#altitude
altitude = ncfile.createVariable('altitude',dtype('float32').char,('y'))
altitude[:] = alt
ncfile.close()
print '*** OK !', 'sortie : ', sortie+'.nc'
fichier="/bdd/CFMIP/CFMIP_OBS_LOCAL/GOCCP/instant_SR_CR_DR/grid_L40/2013/201308/night/instant_SR_CR_DR_2013-08-24T23-19-30ZN_night_CFMIP2_2.70.nc"
#faire le cas general
choix = input("Flags d'un fichier en particulier ou d'un dossier ? ( 1 = dossier | 2 = fichier ) ")
while (choix != 1) and (choix != 2) :
print "nouvelle tentative"
choix = input("Flags d'un fichier en particulier ou d'un dossier ? ( 1 = dossier | 2 = fichier ) ")
print choix
if choix == 1:
mois = raw_input("entrez le mois :")
annee = raw_input("entrez l'annee :")
path = "/bdd/CFMIP/CFMIP_OBS_LOCAL/GOCCP/instant_SR_CR_DR/grid_L40/"
path += str(annee) +'/'+str(annee)+str(mois)+"/night/"
nbr_fichier,liste = go.lecture_dossier(path)
for i in range(0, nbr_fichier):
print '[',i,'/',nbr_fichier,']'
fil = path + liste[i]
print fil
lg, lt, ti, atb,alt, sol_alt, SR = go.extraction(fil)
flag = go.flag_orbite(alt,SR,sol_alt)
alt_max = go.alt_max_orbite(alt,SR,sol_alt)
sortie = 'flag_vf_' + liste[i][17:36]
ecr_cdf(sortie,flag, alt_max, lg, lt, ti,alt)
#np.savez(sortie, flag, alt_max, lg, lt, ti)
#go.affiche_flag_lot(lg, lt, flag,alt,sol_alt,sortie)
print '\n'
if choix == 2:
fil = raw_input("chemin du fichier")
lg, lt, ti, atb,alt, sol_alt, SR = go.extraction(fil)
flag = go.flag_orbite(alt,SR,sol_alt)
sortie = 'SR_orbite_VF_'+ fil[99:110]
alt_max = go.alt_max_orbite(alt,SR,sol_alt)
ecr_cdf(sortie,flag, alt_max, lg, lt, ti,alt)
#np.savez(sortie, flag, alt_max, lg, lt, ti)
#go.affiche_flag(lg, lt, flag,alt,sol_alt,path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment