@@ -33,7 +33,7 @@ def __init__(self, context, MCsteps=1000, parallel_cores=0):
3333 self .plot = Plotting (context )
3434 self .context = context
3535
36- def calibrate_l1a (self , measurandstring , dataset_l0 , dataset_l0_bla ):
36+ def calibrate_l1a (self , measurandstring , dataset_l0 , dataset_l0_bla , swir = False ):
3737 if measurandstring != "radiance" and measurandstring != "irradiance" :
3838 self .context .logger .error ("the measurandstring needs to be either 'radiance' or 'irradiance" )
3939 exit ()
@@ -42,14 +42,25 @@ def calibrate_l1a(self, measurandstring, dataset_l0, dataset_l0_bla):
4242 self .context .get_config_value ("measurement_function_calibrate" ))
4343 input_vars = calibrate_function .get_argument_names ()
4444
45- calibration_data , wavids = self .prepare_calibration_data (measurandstring )
45+ calibration_data , wavids = self .prepare_calibration_data (measurandstring , swir )
4646 dataset_l0 ,dataset_l0_bla = self .preprocess_l0 (dataset_l0 ,dataset_l0_bla ,wavids )
4747 dataset_l1a = self .templ .l1a_template_from_l0_dataset (measurandstring , dataset_l0 )
48- input_qty_l1a = self .find_input (input_vars , dataset_l0 , dataset_l0_bla , calibration_data )
49- u_random_input_qty_l1a = self .find_u_random_input (input_vars , dataset_l0 , calibration_data )
50- u_systematic_input_qty_l1a = self .find_u_systematic_input (input_vars , dataset_l0 , calibration_data )
51- dataset_l1a = self .process_measurement_function (measurandstring , dataset_l1a , calibrate_function .function ,
52- input_qty_l1a , u_random_input_qty_l1a , u_systematic_input_qty_l1a )
48+ input_qty = self .find_input (input_vars , dataset_l0 , dataset_l0_bla , calibration_data )
49+ u_random_input_qty = self .find_u_random_input (input_vars , dataset_l0 , calibration_data )
50+ u_systematic_input_qty_indep ,u_systematic_input_qty_corr ,\
51+ cov_systematic_input_qty_indep ,cov_systematic_input_qty_corr = self .find_u_systematic_input (input_vars , dataset_l0 , calibration_data )
52+
53+ dataset_l1a = self .process_measurement_function (measurandstring , dataset_l1a ,
54+ calibrate_function .function ,
55+ input_qty ,
56+ u_random_input_qty ,
57+ u_systematic_input_qty_indep ,
58+ u_systematic_input_qty_corr ,
59+ cov_systematic_input_qty_indep ,
60+ cov_systematic_input_qty_corr )
61+ if swir :
62+ dataset_l1a .attrs ['product_name' ]= dataset_l1a .attrs ['product_name' ]+ "_SWIR"
63+
5364 if self .context .get_config_value ("write_l1a" ):
5465 self .writer .write (dataset_l1a , overwrite = True )
5566
@@ -58,7 +69,7 @@ def calibrate_l1a(self, measurandstring, dataset_l0, dataset_l0_bla):
5869
5970 return dataset_l1a
6071
61- def prepare_calibration_data (self ,measurandstring ):
72+ def prepare_calibration_data (self ,measurandstring , swir = False ):
6273 hypstar = self .context .get_config_value ("hypstar_cal_number" )
6374 directory = self .context .get_config_value ("calibration_directory" )
6475 caldates = [os .path .basename (path ) for path in glob .glob
@@ -69,27 +80,31 @@ def prepare_calibration_data(self,measurandstring):
6980 "\\ hypstar_" + str (hypstar )+ "_nonlin_corr_coefs_*.dat" )):
7081 non_linear_cals = np .genfromtxt (f )
7182
83+ if swir :
84+ sensortag = "swir"
85+ else :
86+ sensortag = "vnir"
7287
7388 if measurandstring == "radiance" :
7489 for f in glob .glob (os .path .join (directory ,
7590 "hypstar_" + str (hypstar )+ "/radiometric/" + str (
7691 caldate )+ "/hypstar_" + str (
77- hypstar )+ "_radcal_L_*_vnir .dat" )):
92+ hypstar )+ "_radcal_L_*_%s .dat" % ( sensortag ) )):
7893 gains = np .genfromtxt (f )
79- wavids = [int (gains [0 ,0 ]),int (gains [- 1 ,0 ])+ 1 ]
94+ wavids = [int (gains [0 ,0 ])- 1 ,int (gains [- 1 ,0 ])]
8095 else :
8196 for f in glob .glob (os .path .join (directory ,
8297 "hypstar_" + str (hypstar )+ "/radiometric/" + str (
8398 caldate )+ "/hypstar_" + str (
84- hypstar )+ "_radcal_E_*_vnir .dat" )):
99+ hypstar )+ "_radcal_E_*_%s .dat" % ( sensortag ) )):
85100 gains = np .genfromtxt (f )
86- wavids = [int (gains [0 ,0 ]),int (gains [- 1 ,0 ])+ 1 ]
101+ wavids = [int (gains [0 ,0 ])- 1 ,int (gains [- 1 ,0 ])]
87102
88103
89104 calibration_data = {}
90105 calibration_data ["gains" ] = gains [:,2 ]
91106 calibration_data ["u_random_gains" ] = None
92- calibration_data ["u_systematic_gains " ] = gains [:,2 ]* (gains [:,6 ]** 2 +
107+ calibration_data ["u_systematic_indep_gains " ] = gains [:,2 ]* (gains [:,6 ]** 2 +
93108 gains [:,7 ]** 2 + gains [:,8 ]** 2 + gains [:,9 ]** 2 + gains [:,10 ]** 2 + gains [:,11 ]** 2 +
94109 gains [:,12 ]** 2 + gains [:,13 ]** 2 + gains [:,14 ]** 2 + gains [:,15 ]** 2 +
95110 gains [:,16 ]** 2 + gains [:,17 ]** 2 + gains [:,19 ]** 2 )** 0.5 / 100
@@ -106,10 +121,10 @@ def prepare_calibration_data(self,measurandstring):
106121 cov_filament = punpy .convert_corr_to_cov (np .ones ((len (gains [:,2 ]),len (gains [:,2 ]))),
107122 gains [:,2 ]* (gains [:,6 ]** 2 )** 0.5 / 100 )
108123
109- calibration_data ["cov_systematic_gains " ] = cov_diag + cov_other + cov_full + cov_filament
124+ calibration_data ["cov_systematic_indep_gains " ] = cov_diag + cov_other + cov_full + cov_filament
110125
111126
112- calibration_data ["u_cosystematic_gains " ] = gains [:,2 ]* (gains [:,4 ]** 2 +
127+ calibration_data ["u_systematic_corr_rad_irr_gains " ] = gains [:,2 ]* (gains [:,4 ]** 2 +
113128 gains [:,5 ]** 2 + gains [:,18 ]** 2 )** 0.5 / 100
114129
115130 cov_other = punpy .convert_corr_to_cov (np .eye (len (gains [:,2 ])),gains [:,2 ]* (
@@ -119,7 +134,7 @@ def prepare_calibration_data(self,measurandstring):
119134 np .ones ((len (gains [:,2 ]),len (gains [:,2 ]))),
120135 gains [:,2 ]* (gains [:,5 ]** 2 )** 0.5 / 100 )
121136
122- calibration_data ["cov_cosystematic_gains " ] = cov_other + cov_filament
137+ calibration_data ["cov_systematic_corr_rad_irr_gains " ] = cov_other + cov_filament
123138
124139 calibration_data ["non_linearity_coefficients" ] = non_linear_cals [:,0 ]
125140 calibration_data ["u_random_non_linearity_coefficients" ] = None
@@ -193,21 +208,29 @@ def find_u_systematic_input(self, variables, dataset, ancillary_dataset):
193208 :return:
194209 :rtype:
195210 """
196- inputs = []
197- covs = []
211+ inputs_indep = []
212+ covs_indep = []
213+ inputs_corr = []
214+ covs_corr = []
198215 for var in variables :
199216 try :
200- inputs .append (dataset ["u_systematic_" + var ].values )
201- covs .append (punpy .convert_corr_to_cov (dataset ["corr_systematic_" + var ].values ,dataset ["u_systematic_" + var ].values ))
217+ inputs_indep .append (dataset ["u_systematic_" + var ].values )
218+ covs_indep .append (punpy .convert_corr_to_cov (dataset ["corr_systematic_" + var ].values ,dataset ["u_systematic_" + var ].values ))
202219 except :
203220 try :
204- inputs .append (ancillary_dataset ["u_systematic_" + var ])
205- covs .append (ancillary_dataset ["cov_systematic_" + var ])
221+ inputs_indep .append (ancillary_dataset ["u_systematic_indep_" + var ])
222+ covs_indep .append (ancillary_dataset ["cov_systematic_indep_" + var ])
206223 except :
207- inputs .append (None )
208- covs .append (None )
224+ inputs_indep .append (None )
225+ covs_indep .append (None )
226+ try :
227+ inputs_corr .append (ancillary_dataset ["u_systematic_corr_rad_irr_" + var ])
228+ covs_corr .append (ancillary_dataset ["cov_systematic_corr_rad_irr_" + var ])
229+ except :
230+ inputs_corr .append (None )
231+ covs_corr .append (None )
209232
210- return inputs
233+ return inputs_indep , inputs_corr , covs_indep , covs_corr
211234
212235 def preprocess_l0 (self , datasetl0 , datasetl0_bla , wavids ):
213236 """
@@ -306,7 +329,10 @@ def sigma_clip(self,values,tolerance=0.01,median=True,sigma_thresh=3.0):
306329
307330 def process_measurement_function (self , measurandstring , dataset , measurement_function , input_quantities ,
308331 u_random_input_quantities ,
309- u_systematic_input_quantities ):
332+ u_systematic_input_quantities_indep ,
333+ u_systematic_input_quantities_corr ,
334+ cov_systematic_input_quantities_indep ,
335+ cov_systematic_input_quantities_corr ):
310336 datashape = input_quantities [0 ].shape
311337 for i in range (len (input_quantities )):
312338 if len (input_quantities [i ].shape ) < len (datashape ):
@@ -318,24 +344,33 @@ def process_measurement_function(self, measurandstring, dataset, measurement_fun
318344 if u_random_input_quantities [i ] is not None :
319345 if len (u_random_input_quantities [i ].shape ) < len (datashape ):
320346 u_random_input_quantities [i ] = np .tile (u_random_input_quantities [i ], (datashape [1 ], 1 )).T
321- if u_systematic_input_quantities [i ] is not None :
322- if len (u_systematic_input_quantities [i ].shape ) < len (datashape ):
323- u_systematic_input_quantities [i ] = np .tile (u_systematic_input_quantities [i ], (datashape [1 ], 1 )).T
347+ if u_systematic_input_quantities_indep [i ] is not None :
348+ if len (u_systematic_input_quantities_indep [i ].shape ) < len (datashape ):
349+ u_systematic_input_quantities_indep [i ] = np .tile (u_systematic_input_quantities_indep [i ], (datashape [1 ], 1 )).T
350+ if u_systematic_input_quantities_corr [i ] is not None :
351+ if len (u_systematic_input_quantities_corr [i ].shape ) < len (datashape ):
352+ u_systematic_input_quantities_corr [i ] = np .tile (u_systematic_input_quantities_corr [i ], (datashape [1 ], 1 )).T
324353
325354 measurand = measurement_function (* input_quantities )
326355 with warnings .catch_warnings ():
327356 warnings .simplefilter ("ignore" )
328357 u_random_measurand = self .prop .propagate_random (measurement_function , input_quantities ,
329358 u_random_input_quantities ,repeat_dims = 1 )
330- u_systematic_measurand , corr_systematic_measurand = self .prop .propagate_systematic (measurement_function ,
331- input_quantities ,
332- u_systematic_input_quantities ,cov_x = ['rand' ]* len (u_systematic_input_quantities ),
333- return_corr = True ,
334- repeat_dims = 1 ,corr_axis = 0 )
359+ u_syst_measurand_indep ,corr_syst_measurand_indep = self .prop .propagate_systematic (
360+ measurement_function ,input_quantities ,u_systematic_input_quantities_indep ,
361+ cov_x = cov_systematic_input_quantities_indep ,return_corr = True ,
362+ repeat_dims = 1 ,corr_axis = 0 )
363+ u_syst_measurand_corr ,corr_syst_measurand_corr = self .prop .propagate_systematic (
364+ measurement_function ,input_quantities ,u_systematic_input_quantities_corr ,
365+ cov_x = cov_systematic_input_quantities_corr ,return_corr = True ,
366+ repeat_dims = 1 ,corr_axis = 0 )
367+
335368 dataset [measurandstring ].values = measurand
336369 dataset ["u_random_" + measurandstring ].values = u_random_measurand
337- dataset ["u_systematic_" + measurandstring ].values = u_systematic_measurand
370+ dataset ["u_systematic_indep_" + measurandstring ].values = u_syst_measurand_indep
371+ dataset ["u_systematic_corr_rad_irr_" + measurandstring ].values = u_syst_measurand_corr
338372 dataset ["corr_random_" + measurandstring ].values = np .eye (len (u_random_measurand ))
339- dataset ["corr_systematic_" + measurandstring ].values = corr_systematic_measurand
373+ dataset ["corr_systematic_indep_" + measurandstring ].values = corr_syst_measurand_indep
374+ dataset ["corr_systematic_corr_rad_irr_" + measurandstring ].values = corr_syst_measurand_corr
340375
341376 return dataset
0 commit comments