Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cornish_pasdy
Manage
Activity
Members
Labels
Plan
Issues
18
Issue boards
Milestones
Wiki
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CRNS
cornish_pasdy
Commits
1ff37b26
Commit
1ff37b26
authored
5 years ago
by
Martin Schrön
Browse files
Options
Downloads
Patches
Plain Diff
Collected some general functions into lib/PASDY
parent
23474bb8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/CORN.py
+1
-0
1 addition, 0 deletions
lib/CORN.py
lib/PASDY.py
+109
-0
109 additions, 0 deletions
lib/PASDY.py
with
110 additions
and
0 deletions
lib/CORN.py
0 → 100644
+
1
−
0
View file @
1ff37b26
import
CORN
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/PASDY.py
0 → 100644
+
109
−
0
View file @
1ff37b26
import
PASDY
# General functions
## Flushed print
##
_orig_print
=
print
def
print_flush
(
*
args
,
**
kwargs
):
_orig_print
(
*
args
,
flush
=
True
,
**
kwargs
)
## System calls
##
### Launch a file using its corresponding default application
### Usage: execute('file.pdf')
###
def
execute
(
file
):
import
subprocess
,
os
,
platform
file
=
os
.
path
.
abspath
(
file
)
if
platform
.
system
()
==
'
Darwin
'
:
# macOS
subprocess
.
call
((
'
open
'
,
file
))
elif
platform
.
system
()
==
'
Windows
'
:
# Windows
os
.
startfile
(
file
)
else
:
# linux variants
subprocess
.
call
((
'
xdg-open
'
,
file
))
## Definition shortcuts
##
### If a: convert(a), else b
###
def
ifdef
(
a
,
b
,
convert
=
float
):
if
not
a
:
return
(
b
)
else
:
return
(
convert
(
a
))
## Arrays
##
### Split str by comma
### Append some NaNs
###
def
xsplit
(
s
,
range
=
0
,
type
=
str
):
a
=
np
.
array
(
s
.
replace
(
'
,
'
,
'
'
).
split
(),
dtype
=
type
)
# fill up with NaNs
for
i
in
np
.
arange
(
range
-
len
(
a
)):
a
=
np
.
append
(
a
,
np
.
nan
)
return
(
a
)
## Strings
##
### Chomp
###
def
chomp
(
x
):
if
x
.
endswith
(
"
\r\n
"
):
return
x
[:
-
2
]
if
x
.
endswith
(
"
\n
"
)
or
x
.
endswith
(
"
\r
"
):
return
x
[:
-
1
]
return
(
x
)
## Input
##
### yes/no <-> Boolean
###
def
yesno2bool
(
s
):
s
=
s
.
lower
()
if
s
==
'
yes
'
or
s
==
'
y
'
:
return
(
True
)
else
:
return
(
False
)
###
def
bool2yesno
(
boo
):
if
boo
:
return
(
'
yes
'
)
else
:
return
(
'
no
'
)
## Output
##
### Print newly created file name and size
###
def
file_save_msg
(
file
,
name
=
'
File
'
,
end
=
''
):
size
=
os
.
stat
(
file
).
st_size
if
size
<
1024
:
sizestr
=
"
%.0f Bytes
"
%
(
size
)
elif
size
<
1024
**
2
:
sizestr
=
"
%.0f KB
"
%
(
size
/
1024
)
else
:
sizestr
=
"
%.1f MB
"
%
(
size
/
1024
/
1024
)
print
(
"
%s saved to %s (%s)
"
%
(
name
,
file
,
sizestr
),
end
=
end
)
# Spatial functions
## Distance
##
### use x nearest neighbors for averaging
### find k closest lat/lon to every lat/lon coordinates
###
def
distance
(
pointA
,
pointB
):
return
sqrt
((
pointB
[
0
]
-
pointA
[
0
])
**
2
+
(
pointB
[
1
]
-
pointA
[
1
])
**
2
)
## Coordinate conversion
##
### recalculate strange coordinates to proper decimals
###
def
deg100min2dec
(
coord
):
coord
=
coord
/
100
deg
=
np
.
floor
(
coord
)
minute
=
(
coord
-
deg
)
/
0.6
dec
=
deg
+
minute
return
(
dec
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment