Commit 54cf39fd authored by Jérôme Colin's avatar Jérôme Colin

Initial commit

parents
WL_b1,RSR_b1
0.350000000000,0.000261041000
0.360000000000,0.000221131000
0.370000000000,0.000150339000
0.380000000000,0.000092296100
0.390000000000,0.000069387200
0.400000000000,0.000103704000
0.410000000000,0.000085449200
0.420000000000,0.000037792400
0.430000000000,0.000030190100
0.440000000000,0.000030418300
0.450000000000,0.000031239300
0.460000000000,0.000041568300
0.470000000000,0.000027899700
0.480000000000,0.000028752000
0.490000000000,0.000027873400
0.500000000000,0.000021380000
0.510000000000,0.000011830600
0.520000000000,0.000017469800
0.530000000000,0.000019211800
0.540000000000,0.000018956300
0.550000000000,0.000022947300
0.560000000000,0.000018128200
0.570000000000,0.000072908700
0.570200000000,0.000073177100
0.573210000000,0.000078989000
0.575210000000,0.000082355900
0.578200000000,0.000078484900
0.580200000000,0.000085802600
0.583190000000,0.000049778800
0.585200000000,0.000040101200
0.588200000000,0.000063677700
0.590190000000,0.000068710600
0.593190000000,0.000092010900
0.595210000000,0.000111932000
0.598210000000,0.000071535200
0.600210000000,0.000060229800
0.605200000000,0.000119795000
0.608200000000,0.000348286000
0.610190000000,0.001191450000
0.613210000000,0.005569600000
0.615210000000,0.025965500000
0.618190000000,0.146929000000
0.620210000000,0.367228000000
0.623190000000,0.684460000000
0.625200000000,0.724822000000
0.628200000000,0.727771000000
0.630190000000,0.733656000000
0.633210000000,0.745276000000
0.635200000000,0.753959000000
0.638190000000,0.768836000000
0.640190000000,0.774306000000
0.643200000000,0.790446000000
0.645190000000,0.813292000000
0.648190000000,0.868503000000
0.650210000000,0.904408000000
0.653210000000,0.965654000000
0.655190000000,0.990801000000
0.658200000000,1.000000000000
0.660210000000,0.946519000000
0.663190000000,0.816125000000
0.665190000000,0.730804000000
0.668200000000,0.546438000000
0.670200000000,0.383817000000
0.673190000000,0.164949000000
0.675210000000,0.087927700000
0.678210000000,0.031048600000
0.680200000000,0.015782500000
0.683210000000,0.004662540000
0.685200000000,0.002262840000
0.688190000000,0.000843440000
0.690210000000,0.000467935000
0.693190000000,0.000182585000
0.695200000000,0.000107413000
0.698210000000,0.000076398900
0.700190000000,0.000083030000
0.703210000000,0.000114591000
0.705200000000,0.000106094000
0.710200000000,0.000077446900
0.713200000000,0.000100684000
0.715200000000,0.000109653000
0.718190000000,0.000120549000
0.720190000000,0.000127597000
0.730000000000,0.000021384000
0.740000000000,0.000028792400
0.750000000000,0.000022613000
0.760000000000,0.000038898200
0.770000000000,0.000032166400
0.780000000000,0.000039417300
0.790000000000,0.000049382700
0.800000000000,0.000056807200
0.810000000000,0.000066929200
0.820000000000,0.000118165000
0.830000000000,0.000064532800
0.840000000000,0.000151329000
0.850000000000,0.000230796000
0.860000000000,0.000197672000
0.870000000000,0.000163882000
0.880000000000,0.000053324200
0.890000000000,0.000063514800
0.900000000000,0.000051357000
0.910000000000,0.000064465100
0.920000000000,0.000035058700
0.930000000000,0.000034434600
0.940000000000,0.000033221700
0.950000000000,0.000077597500
0.960000000000,0.000088794900
0.970000000000,0.000139009000
0.980000000000,0.000047952700
0.990000000000,0.000033837700
1.000000000000,0.000032747100
1.010000000000,0.000041217900
1.020000000000,0.000059301600
1.030000000000,0.000061260800
1.040000000000,0.000053602900
1.050000000000,0.000060621500
1.060000000000,0.000072620800
1.070000000000,0.000070336500
1.080000000000,0.000078958800
1.090000000000,0.000092393100
1.100000000000,0.000126032000
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
NAME
rsr_resampler
VERSION
20180731_03
SYNOPSIS
rsr_resampler <INPUT> <FROM> <TO> <STEP>
where
<INPUT> must be two column spectral response function
in ASCII, one line header, '.' decimal separator, ',' field separator
<FROM> is the lower bound of the resampling range in micrometers
<TO> is the upper bound of the resampling range in micrometers
and <STEP> must be a float value refering to the output sampling step
in micrometers
EXAMPLE
python rsr_resampler.py demo.rsr 0.3 2.6 0.001
COMPUTER LANGUAGE
Python 3.6, with Numpy 1.14, Scipy 1.1, Pandas 0.23
Coding style (as much as possible...):
http://legacy.python.org/dev/peps/pep-0008/#overriding-principle
DESCRIPTION
Purpose: resampling a spectral response function regardless of the
initial gaps, ordering and/or duplicates in the input file.
AUTHORS
Jerome COLIN & Laure ROUPIOZ
ICube Laboratory, CNRS
300 boulevard S. Brant
CS 10413
67412 ILLKIRCH Cedex
FRANCE
Contact: j.colin@unistra.fr
DISCLAIMER
This code is provided "as is" and with no guarantee. The author disclaim
any liability for direct or consequential damages resulting from your
use of this code.
"""
import sys
import getopt
import numpy as np
from scipy import interpolate
import pandas as pd
def main():
# parse command line options
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
except getopt.error as msg:
print(msg)
print("for help use --help")
sys.exit(2)
# process options
for o, a in opts:
if o in ("-h", "--help"):
print(__doc__)
sys.exit(0)
# process arguments
try:
process(args[0],args[1],args[2],args[3])
except(IndexError):
print("ERROR: invalid number of argument. Try --help")
sys.exit(2)
def process(filename,from_wl,to_wl,step_wl):
# Try opening the file
try:
df = pd.read_csv(filename,header=0,names=['wlc','rsr'])
except(FileNotFoundError):
print(("ERROR: file {} not found...").format(filename))
sys.exit(1)
# Defining the output sampling
try:
if from_wl >= to_wl:
print("ERROR: FROM must be smaller than TO !")
sys.exit(2)
output_sampling = np.arange(float(from_wl),float(to_wl)+float(step_wl),float(step_wl))
except(ValueError):
print("ERROR: the FROM, TO and STEP arguments must be floating point numbers !")
sys.exit(2)
except(ZeroDivisionError):
print("ERROR: the STEP argument must be non-zero numbers !")
sys.exit(2)
# Extract non-null values of RSR for band
subset_df = df.loc[df['wlc'].notnull(), ['wlc','rsr']]
# Reordering & removing duplicates
subset_df = subset_df.sort_values(by=['wlc'])
subset_df = subset_df.drop_duplicates()
# Compute a spline function of RSR on the subset
tck, fp, ier, msg = interpolate.splrep(subset_df['wlc'].values, subset_df['rsr'].values, k=3, s=0, full_output=1)
print(("INFO: {}, code {}").format(msg, ier))
# Compute values for the full range
new_rsr = interpolate.splev(output_sampling, tck, der=0, ext=0)
# Clean-up new_rsr where input response is null
new_rsr[output_sampling<subset_df['wlc'].values.min()] = 0
new_rsr[output_sampling>subset_df['wlc'].values.max()] = 0
# Write to outfile
outfile = filename[:-4]+"_resampled.csv"
with open(outfile,"w") as f:
f.write("'wlc','rsr'\n")
for i in range(len(output_sampling)):
f.write(("%6.3f, %12.6f \n") % (output_sampling[i],new_rsr[i]))
# Done, printing completition message
print(("COMPLETE: resampled {} in range [{}:{}] at step {} micrometers to {}").format(filename,from_wl,to_wl,step_wl,outfile))
if __name__ == "__main__":
main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment