source: trunk/src/file_Tbcorr_daily.py @ 694

Last change on this file since 694 was 694, checked in by llmlod, 8 years ago

new chaine

File size: 4.0 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4# import
5from pylab import *
6import glob
7from datetime import date
8from useCorrTb_daily import *
9import itertools as it
10from multiprocessing import Pool
11from functools import partial
12import matplotlib.gridspec as gridspec
13import time
14
15rep_fic='/homedata/mleduc/CorrTb/'
16### Satellite, Instrument, Produit Level, Channel
17sat  = ['M02','M01','N19','N18','N16','N15']
18inst = ['MHS','MHS','MHS','MHS','AMSUB','AMSUB']
19lvl  = 'L1C'
20ch   = ['B1','B2','B3','B4','B5']
21### Period
22dmin = date(2008,5,1)
23dmax = date(2008,5,3)
24# Zone
25#LS = -1.
26#LN = 4.
27#LS = 7.
28#LN = 12.
29#LW = -10.
30#LE = 5.
31
32# New Grid
33resol = .5
34latvec = arange(-34.5,34.6,resol)
35lonvec = arange(-180.,179.76,resol)
36
37# number of processes
38npr = 10
39
40for day in rrule(DAILY,dtstart=dmin,until=dmax):
41    print day
42    ### File list
43    repday = [day.strftime('%Y_%m_%d')]#[ff.strftime('%Y_%m_%d') for ff in rrule(DAILY,dtstart=day+relativedelta(days=-1),until=day+relativedelta(days=+1))]
44    repsat = [ii+ss for ii,ss in zip(inst,sat)]
45    fname = hstack([glob.glob('/bdd/AMSU-1C/%s/L1C/*/%s/*.L1C'%(reps,repd)) for reps,repd in it.product(repsat,repday)])
46
47    ### Read files (in parallel with Pool)
48    pool = Pool(processes=npr) 
49    res = pool.map(partial(applycorr2orb,lonvec=lonvec,latvec=latvec,ch=ch),fname)
50    pool.close()
51    pool.join()
52
53    print 'Join'
54    tbcorr, tobs, satvec = [dstack([proc[var] for proc in res if size(proc[var])]) for var in xrange(3)]
55    del res
56
57    # Sort ??? sur le temps ???
58    isort = argsort(nanmean(tobs.squeeze(),axis=0))
59    tbcorr = tbcorr[:,:,isort]
60    tobs = tobs.squeeze()[:,isort]
61    satvec = satvec.squeeze()[isort]
62
63    # Satellite/Instrument identification
64    satdef = SatName()
65    satnum = satdef.get_satnum(satvec.squeeze())
66
67    ### Fillvalue
68    tbcorr[isnan(tbcorr)] = -99.99
69
70    ### Save in netcdf file
71    print 'Save in nc'
72    nsat = satvec.size
73    nlon = lonvec.size
74    nlat = latvec.size
75    torig = date(day.year,1,1)
76    for cc, ich in enumerate(ch):
77        # Output file name
78        output = '%sTbCorr_AMSUMHS_%s_%3.2fdeg_%s.nc'%(rep_fic,ich,resol,day.strftime('%Y%m%d'))
79        # Creation du fichier   
80        ncfile = netCDF4.Dataset(output,'w',format='NETCDF4_CLASSIC')
81        # Definition des dimensions
82        ncfile.createDimension('lon',nlon)
83        ncfile.createDimension('lat',nlat)
84        ncfile.createDimension('satellite',nsat)
85       
86        # Creation des variables dimensions
87        lons = ncfile.createVariable('lon',dtype('float32').char,('lon',))
88        lons.long_name    = 'Longitude'
89        lons.units        = 'degrees_east'
90        lons.actual_range = '%4.2f,%4.2f'%(lonvec.min(),lonvec.max())
91        lons[:]           = lonvec
92   
93        lats = ncfile.createVariable('lat',dtype('float32').char,('lat',))
94        lats.long_name    = 'Latitude'
95        lats.units        = 'degrees_north'
96        lats.actual_range = '%4.2f,%4.2f'%(latvec.min(),latvec.max())
97        lats[:]           = latvec
98
99        sats = ncfile.createVariable('satellite',dtype('int16').char,('satellite',))
100        sats.long_name    = 'Satellite'
101        sats.description  = [str(num)+' = '+ns +', ' for num,ns in zip(satdef.satnum,satdef.satname)]
102        sats[:]           = satnum
103
104        # Creation variable
105        dates = ncfile.createVariable('time',dtype('float').char,('lat','lon','satellite',))
106        dates.long_name   = 'Time'
107        dates.units       = 'hours since %s'%torig.strftime('%Y-%m-%d %H:%M:%S')
108        #dates[:]          = (fix((tobs-date2num(torig))*24.*100)/100.).reshape(nlat,nlon,nsat)
109        dates[:]          = ((tobs-date2num(torig))*24.).reshape(nlat,nlon,nsat)
110
111        sclfactor = .01
112        tbfinal = ncfile.createVariable('tbcorr',dtype('int16').char,('lat','lon','satellite',))
113        tbfinal.description  = 'Corrected Tb of channel %s'%ich
114        tbfinal.units        = 'Kelvin'
115        tbfinal.scale_factor = sclfactor
116        tbfinal._Fillvalue   = -9999.
117        tbfinal[:]           = tbcorr[cc,:,:].reshape(nlat,nlon,nsat)
118
119        # Fermeture du fichier
120        ncfile.close()
121        print output+' created'
122 
Note: See TracBrowser for help on using the repository browser.