WSL/SLF GitLab Repository
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
snow-hydrology
SnowQM
Commits
4c128b5c
Commit
4c128b5c
authored
Jun 10, 2022
by
Adrien Michel
Browse files
Cleaning
parent
50344bcf
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/quantile_application.cpp
View file @
4c128b5c
...
...
@@ -38,7 +38,7 @@ bool getFileContent(const std::string fileName,
// Check number of lines
const
size_t
row_counts
=
std
::
count
(
std
::
istreambuf_iterator
<
char
>
(
file
),
std
::
istreambuf_iterator
<
char
>
(),
'\n'
);
std
::
istreambuf_iterator
<
char
>
(),
'\n'
);
if
(
row_counts
!=
nrows
)
{
return
false
;
}
...
...
@@ -110,55 +110,55 @@ Rcpp::NumericVector applyQMCpp(const Rcpp::NumericMatrix swe,
continue
;
}
if
(
omp_get_thread_num
()
==
0
)
{
// only in master thread!
if
(
omp_get_thread_num
()
==
0
){
// only in master thread!
if
(
check_interrupt
())
{
interrupt
=
true
;
continue
;
}
}
// Read QM files
std
::
vector
<
std
::
vector
<
double
>>
sourcePDF
;
if
(
!
getFileContent
(
sourcePath
+
"/quantiles_"
+
std
::
to_string
(
xCoords_cpp
[
p
])
+
"_"
+
std
::
to_string
(
yCoords_cpp
[
p
])
+
".txt"
,
sourcePDF
,
num_doys
)){
file_io_error
=
true
;
continue
;
}
std
::
vector
<
std
::
vector
<
double
>>
targetPDF
;
if
(
!
getFileContent
(
targetPath
+
"/quantiles_"
+
std
::
to_string
(
xCoords_cpp
[
p
])
+
"_"
+
std
::
to_string
(
yCoords_cpp
[
p
])
+
".txt"
,
targetPDF
,
num_doys
)){
file_io_error
=
true
;
continue
;
}
for
(
size_t
d
=
0
;
d
<
num_doys
;
++
d
){
if
(
sourcePDF
[
d
].
size
()
!=
targetPDF
[
d
].
size
())
{
// Read QM files
std
::
vector
<
std
::
vector
<
double
>>
sourcePDF
;
if
(
!
getFileContent
(
sourcePath
+
"/quantiles_"
+
std
::
to_string
(
xCoords_cpp
[
p
])
+
"_"
+
std
::
to_string
(
yCoords_cpp
[
p
])
+
".txt"
,
sourcePDF
,
num_doys
)){
file_io_error
=
true
;
continue
;
}
std
::
vector
<
std
::
vector
<
double
>>
targetPDF
;
if
(
!
getFileContent
(
targetPath
+
"/quantiles_"
+
std
::
to_string
(
xCoords_cpp
[
p
])
+
"_"
+
std
::
to_string
(
yCoords_cpp
[
p
])
+
".txt"
,
targetPDF
,
num_doys
)){
file_io_error
=
true
;
continue
;
}
}
for
(
size_t
d
=
0
;
d
<
doyArray_cpp
.
size
();
++
d
)
{
const
size_t
doy
(
doyArray_cpp
[
d
]
-
1
);
double
&
target
=
swe_cpp
[
p
+
(
d
)
*
num_pixels
];
auto
lower
=
std
::
upper_bound
(
sourcePDF
[
doy
].
begin
(),
sourcePDF
[
doy
].
end
(),
target
);
size_t
quantile
=
std
::
distance
(
sourcePDF
[
doy
].
begin
(),
lower
);
//Apply the -1 correction and lower bound
// Here quantiles are 0...100, in R 1...101
quantile
=
(
quantile
<=
1
)
?
1
:
quantile
-
1
;
quantile
=
(
quantile
>=
(
sourcePDF
[
doy
].
size
()
-
1
))
?
sourcePDF
[
doy
].
size
()
-
2
:
quantile
;
if
(
sourcePDF
[
doy
][
quantile
]
==
0
&&
targetPDF
[
doy
][
quantile
]
>
0
)
{
target
=
d
>
0
?
swe_cpp
[
p
+
(
d
-
1
)
*
num_pixels
]
/
2
:
0
;
for
(
size_t
d
=
0
;
d
<
num_doys
;
++
d
){
if
(
sourcePDF
[
d
].
size
()
!=
targetPDF
[
d
].
size
())
{
file_io_error
=
true
;
continue
;
}
}
else
{
target
+=
targetPDF
[
doy
][
quantile
]
-
sourcePDF
[
doy
][
quantile
];
for
(
size_t
d
=
0
;
d
<
doyArray_cpp
.
size
();
++
d
)
{
const
size_t
doy
(
doyArray_cpp
[
d
]
-
1
);
double
&
target
=
swe_cpp
[
p
+
(
d
)
*
num_pixels
];
auto
lower
=
std
::
upper_bound
(
sourcePDF
[
doy
].
begin
(),
sourcePDF
[
doy
].
end
(),
target
);
size_t
quantile
=
std
::
distance
(
sourcePDF
[
doy
].
begin
(),
lower
);
//Apply the -1 correction and lower bound
// Here quantiles are 0...100, in R 1...101
quantile
=
(
quantile
<=
1
)
?
1
:
quantile
-
1
;
quantile
=
(
quantile
>=
(
sourcePDF
[
doy
].
size
()
-
1
))
?
sourcePDF
[
doy
].
size
()
-
2
:
quantile
;
if
(
sourcePDF
[
doy
][
quantile
]
==
0
&&
targetPDF
[
doy
][
quantile
]
>
0
)
{
target
=
d
>
0
?
swe_cpp
[
p
+
(
d
-
1
)
*
num_pixels
]
/
2
:
0
;
}
else
{
target
+=
targetPDF
[
doy
][
quantile
]
-
sourcePDF
[
doy
][
quantile
];
}
// Set a lower limit on SWE
target
=
target
>
0.0005
?
target
:
0
;
}
// Set a lower limit on SWE
target
=
target
>
0.0005
?
target
:
0
;
}
}
if
(
interrupt
)
{
throw
interrupt_exception
(
"[E] The computation was interrupted by user"
);
...
...
@@ -167,4 +167,4 @@ Rcpp::NumericVector applyQMCpp(const Rcpp::NumericMatrix swe,
throw
interrupt_exception
(
"[E] Problem reading QM files, either files do not exist, they do not match the right dimensions, or they are ill formated"
);
}
return
Rcpp
::
wrap
(
swe_cpp
);
}
\ No newline at end of file
}
src/spatial_correlation.cpp
View file @
4c128b5c
...
...
@@ -47,20 +47,17 @@ Rcpp::List spatialCorrelationCpp(const Rcpp::NumericVector x_coords,
std
::
vector
<
std
::
vector
<
size_t
>
>
out_cpp
(
size
);
#if defined(_OPENMP)
#pragma omp parallel num_threads(ncores) shared(size, x_coords_cpp, y_coords_cpp, dist_threshold, out_cpp)
#pragma omp for
#endif
for
(
size_t
i
=
0
;
i
<
size
;
++
i
){
//Check for interrupt
if
(
interrupt
)
{
continue
;
}
#if defined(_OPENMP)
if
(
omp_get_thread_num
()
==
0
)
// only in master thread!
#endif
if
(
check_interrupt
())
{
interrupt
=
true
;
if
(
omp_get_thread_num
()
==
0
){
// only in master thread!
if
(
check_interrupt
())
{
interrupt
=
true
;
}
}
std
::
vector
<
double
>
x_dist
(
size
);
std
::
vector
<
double
>
y_dist
(
size
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment