Save GIF with Animation package {R} - r

I would like to save a set of maps as gif with the animation package. I produce these maps for different years through a function I created. The function works.
However, I don't manage to save the output as a gif. This is what I coded:
i<- 1
saveGIF(
for(i in 1955:1957)
multiplePlots(i),
interval = .65,
movie.name = "test.gif",
img.name="test",
convert = "convert"
)
The error is the following (copy-pasted from the console, I hope it helps):
Executing:
""C:\Program Files\ImageMagick-6.9.3-Q16\convert.exe" -loop 0 -delay 65 test1.png test2.png test3.png "test.gif""
convert.exe: unable to load module `C:\Program Files\ImageMagick-6.9.3-Q16\modules\coders\IM_MOD_RL_PNG_.dll': Le module spécifié est introuvable.
# error/module.c/OpenModule/1300.
convert.exe: no decode delegate for this image format `PNG' # error/constitute.c/ReadImage/501.
convert.exe: unable to load module `C:\Program Files\ImageMagick-6.9.3-Q16\modules\coders\IM_MOD_RL_PNG_.dll': Le module spécifié est introuvable.
# error/module.c/OpenModule/1300.
convert.exe: no decode delegate for this image format `PNG' # error/constitute.c/ReadImage/501.
convert.exe: unable to load module `C:\Program Files\ImageMagick-6.9.3-Q16\modules\coders\IM_MOD_RL_PNG_.dll': Le module spécifié est introuvable.
# error/module.c/OpenModule/1300.
convert.exe: no decode delegate for this image format `PNG' # error/constitute.c/ReadImage/501.
convert.exe: no images defined `test.gif' # error/convert.c/ConvertImageCommand/3252.
an error occurred in the conversion... see Notes in ?im.convert
[1] FALSE
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c ""C:\Program Files\ImageMagick-6.9.3-Q16\convert.exe" -loop 0 -delay 65 test1.png test2.png test3.png "test.gif""' had status 1
2: In cmd.fun(convert) :
'""C:\Program Files\ImageMagick-6.9.3-Q16\convert.exe" -loop 0 -delay 65 test1.png test2.png test3.png "test.gif""' execution failed with error code 1
3: running command '""C:\Program Files\ImageMagick-6.9.3-Q16\convert.exe" -loop 0 -delay 65 test1.png test2.png test3.png "test.gif""' had status 127
4: In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="test.gif": Le fichier spécifié est introuvable
In case you are wondering, I have ImageMagick installed.
Many thanks.

Related

Extracting RIFF data from both .wav and .flac files

Wave files can contain unofficial metadata, such as Sampler Chunk - "smpl":
https://sites.google.com/site/musicgapi/technical-documents/wav-file-format#smpl
These are used for audio looping players and samplers avoiding to loading multiple samples.
I have one such file here:
https://github.com/studiorack/basic-harmonica/blob/bf42d5bab7470cc201e3c4b6dee7925b19db6bff/samples/harmonica_1.wav
and a flac file converted using the official flac command line tool:
flac harmonica_1.wav --keep-foreign-metadata
https://github.com/studiorack/basic-harmonica/blob/main/samples/harmonica_1.flac
When running these tools I can confirm the metadata exists in each file:
https://hexfiend.com
However I do see a different in the number of bytes (I believe as flac has riff inserted in multiple places)
I can also convert the .flac file back to .wav and it is the same size, and contains the metadata: flac harmonica_1.flac --keep-foreign-metadata
When using other tools I can read the data:
$ sndfile-info har.wav
smpl : 60
Manufacturer : 0
Product : 0
Period : 20833 nsec
Midi Note : 64
Pitch Fract. : 0
SMPTE Format : 0
SMPTE Offset : 00:00:00 00
Loop Count : 1
Cue ID : 131072 Type : 0 Start : 12707 End : 47221 Fraction : 0 Count : 0
Sampler Data : 0
https://linux.die.net/man/1/sndfile-info
This only works for .wav files. There is a feature request for libsndfile to support 'smpl' in flac files:
https://github.com/libsndfile/libsndfile/issues/59
$ metaflac ./har.flac --list
smpl<aQ#�1u�METADATA block #7
type: 2 (APPLICATION)
is last: false
length: 20
application ID: 72696666
data contents:
https://xiph.org/flac
However as you can see the result returned are different. I would like a both .wav and .flac RIFF 'smpl' data to be returned in the same format, so I can verify the results match.
https://exiftool.org appears to be tool to do that. But it also produced inconsistent results between .wav and .flac:
$ exiftool -a -G1 -s ./har.wav
[ExifTool] ExifToolVersion : 12.42
[System] FileName : har.wav
[System] Directory : .
[System] FileSize : 95 kB
[System] FileModifyDate : 2022:10:11 21:16:37-07:00
[System] FileAccessDate : 2022:10:15 14:39:46-07:00
[System] FileInodeChangeDate : 2022:10:15 14:39:50-07:00
[System] FilePermissions : -rw-r--r--
[File] FileType : WAV
[File] FileTypeExtension : wav
[File] MIMEType : audio/x-wav
[RIFF] Encoding : Microsoft PCM
[RIFF] NumChannels : 1
[RIFF] SampleRate : 48000
[RIFF] AvgBytesPerSec : 96000
[RIFF] BitsPerSample : 16
[RIFF] Manufacturer : 0
[RIFF] Product : 0
[RIFF] SamplePeriod : 20833
[RIFF] MIDIUnityNote : 64
[RIFF] MIDIPitchFraction : 0
[RIFF] SMPTEFormat : none
[RIFF] SMPTEOffset : 00:00:00:00
[RIFF] NumSampleLoops : 1
[RIFF] SamplerDataLen : 0
[RIFF] SamplerData : (Binary data 20 bytes, use -b option to extract)
[RIFF] UnshiftedNote : 64
[RIFF] FineTune : 0
[RIFF] Gain : 0
[RIFF] LowNote : 0
[RIFF] HighNote : 127
[RIFF] LowVelocity : 0
[RIFF] HighVelocity : 127
[RIFF] Comment : Recorded on 7/10/2022 in Edison.
[RIFF] Software : FL Studio 20
[Composite] Duration : 0.99 s
and for flac
$ exiftool -a -G1 -s ./har.flac
[ExifTool] ExifToolVersion : 12.42
[System] FileName : har.flac
[System] Directory : .
[System] FileSize : 83 kB
[System] FileModifyDate : 2022:10:11 20:59:37-07:00
[System] FileAccessDate : 2022:10:15 14:44:12-07:00
[System] FileInodeChangeDate : 2022:10:15 14:42:26-07:00
[System] FilePermissions : -rw-r--r--
[File] FileType : FLAC
[File] FileTypeExtension : flac
[File] MIMEType : audio/flac
[FLAC] BlockSizeMin : 4096
[FLAC] BlockSizeMax : 4096
[FLAC] FrameSizeMin : 3442
[FLAC] FrameSizeMax : 6514
[FLAC] SampleRate : 48000
[FLAC] Channels : 1
[FLAC] BitsPerSample : 16
[FLAC] TotalSamples : 47222
[FLAC] MD5Signature : f89646c0d3056ec38c3e33ca79299253
[Vorbis] Vendor : reference libFLAC 1.4.1 20220922
[Composite] Duration : 0.98 s
How can I read this data consistently regardless of .flac or .wav file?
I was helped by the creator of exiftool here:
https://exiftool.org/forum/index.php?topic=14064.0
In short flac riff blocks were stored in a custom metadata format which exiftool could parse but needed a custom .ExifTool_config file
The creator added the necessary changes in a commit:
https://github.com/exiftool/exiftool/commit/5c2467fa6cdb38233793884e80cee9abf4da48e6#diff-0c24c6846e8207ad8d090e564fdc366dad6386f2ef7c51eea5aa0d72d970ff11
The latest release of ExifTool 12.49 now parses .wav and .flac loop data!
"Decode 'riff' metadata blocks in FLAC audio files"
https://exiftool.org/history.html
Usage:
exiftool ./har.wav
exiftool ./har.flac
Output:
Encoding : Microsoft PCM
Num Channels : 1
Sample Rate : 48000
Avg Bytes Per Sec : 96000
Bits Per Sample : 16
Manufacturer : 0
Product : 0
Sample Period : 20833
MIDI Unity Note : 64
MIDI Pitch Fraction : 0
SMPTE Format : none
SMPTE Offset : 00:00:00:00
Num Sample Loops : 1
Sampler Data Len : 0
Sampler Data : (Binary data 20 bytes, use -b option to extract)
Unshifted Note : 64
Fine Tune : 0
Gain : 0
Low Note : 0
High Note : 127
Low Velocity : 0
High Velocity : 127
Acidizer Flags : One shot
Root Note : High C
Beats : 2
Meter : 4/4
Tempo : 0
Comment : Recorded on 7/10/2022 in Edison.
Software : FL Studio 20
Duration : 0.87 s

CrossReferencing error; how can fix it in metboAnalystR?

I try to enrich my metabolite with MetboAnalystR and then when i want to Cross-reference list of compounds against libraries,
I faced with the error. This is my code:
tmp.vec <- c("L-Alanine", "Hexadecanoic acid", "L-Phenylalanine", "O-Propanoylcarnitine", "L-Methionine",
"L-Palmitoylcarnitine", "Triacylglycerol")
mSet<-InitDataObjects("conc", "msetora", FALSE)
mSet<-Setup.MapData(mSet, tmp.vec)
mSet<-CrossReferencing(mSet, "name")
In the last code, I get this error:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:21 --:--:-- 0
curl: (28) Failed to connect to www.metaboanalyst.ca port 443 after 21166 ms: Timed out
[1] "Download unsucceful. Ensure that curl is downloaded on your computer."
[1] "Attempting to re-try download using libcurl..."
trying URL 'https://www.metaboanalyst.ca/resources/libs/compound_db.qs'
Error in download.file(lib.url, destfile = filenm, method = "libcurl") :
cannot open URL 'https://www.metaboanalyst.ca/resources/libs/compound_db.qs'
In addition: Warning message:
In download.file(lib.url, destfile = filenm, method = "libcurl") :
URL 'https://www.metaboanalyst.ca/resources/libs/compound_db.qs': Timeout of 60 seconds was reached
what should I do for solving?
thank you for helping

"End Of File" Error While Converting ASCII to GRD

I am trying to run a FORTRAN program (with gfortran) where I convert an ASCII file to a GRD file. I'm expecting the program to read a text file and then output a grd file.
After running the program, I am getting the following error message:
Fortran runtime error: End of file
Below are the files that I am working with:
Terminal Commands:
gfortran ascii2grd.f90
./a.out
FORTRAN Program:
!PROGRAM TO CONVERT ASCII TO GRD
program ascii2grd
parameter(nx=25,ny=23,np=1)
real u(nx,ny,np),temp1(nx,ny)
open(2,file='/home/weather/test.grd',
form='unformatted',access='direct',recl=nx*ny*4)
open(1,file='/home/weather/out.dat')
do k=1,np
read(1,*)((u(j,i,k),j=1,nx),i=1,ny)
10 continue
enddo
rec=1
do kk=1,np
write(2,rec=irec)((u(j,i,kk),j=1,nx),i=1,ny)
write(*,*)'Processing...'
irec=irec+1
enddo
write(*,*)'Done!'
stop
end
Sample from out.dat
999.000000
11.1000004
999.000000
999.000000
16.7000008
999.000000
14.6000004
999.000000
999.000000
999.000000

Execution halted error in R

I run hicpipe tools and it returns this error during execution. Its error was:
Rsge temp files: tmp/Rsge.test_cluster.binned.*
Error in if (trace) cat("Running locally \n") :
argument is of length zero
Calls: compute.total.counts -> model.predict.split -> sge.parRapply
Execution halted
Error: error in total_expected_counts_wrapper.r
Execution halted
make[1]: *** [/home/dashti/hicpipe/output/test_cluster/test_cluster.nm]
Error 1
make[1]: Leaving directory `/home/dashti/hicpipe'
make: *** [all] Error 1
It was run a Rscript code in below:
Rscript R/total_expected_counts_wrapper.r /home/dashti/hicpipe/output/test_cluster/test_cluster /home/dashti/hicpipe/models/map_len_gc.mdl trans 1e+06 0 200
Code of total_expected_counts_wrapper.r is :
options(warn=1)
# get script name
all.args = commandArgs(F)
fn.arg = "--file="
script.name = sub(fn.arg, "", all.args[grep(fn.arg, all.args)])
args = commandArgs(T)
if (length(args) == 1) {
cat(sprintf("usage: %s <input prefix> <model file> <filter> <cis.threshold> <use cluster> <max jobs on cluster>\n",
script.name))
q(status=1)
}
ifn.prefix = args[1]
model.ifn = args[2]
filter = args[3]
cis.threshold = as.numeric(args[4])
cluster = (args[5] == "1")
max.njobs = as.numeric(args[6])
mtable = read.delim(model.ifn)
mfields = mtable$field
maxvals = mtable$size
if (cluster) {
cat("Using Sun Grid Engine cluster\n")
} else {
cat("Not using Sun Grid Engine cluster, running sequentially on local machine\n")
}
source("R/model_predict.r")
compute.total.counts(prefix=ifn.prefix, cluster=cluster, max.njobs=max.njobs, ofields=mfields, max.vals=maxvals, filter=filter, cis.threshold=cis.threshold)
q(status=0)
What should I do? I see other .R files but I cannot find any trace variable in them. I send an E-mail to authors but I do not receive any response.
source("R/model_predict.r")
In model_predict.r, Rsge library is loaded
173 library(Rsge)
174 sge.options(sge.save.global=F)
175 sge.prefix = paste("tmp/Rsge.", get.short.fn(fends.fn), ".", sep="")
176 cat(sprintf("Rsge temp files: %s*\n", sge.prefix))
177 sge.options(sge.file.prefix=sge.prefix)
178
179 result = sge.parRapply(ranges, model.predict, lib.dir=lib.dir,
180 njobs=njobs, join.method=c, cluster=cluster,
181 fends.fn=fends.fn, log.dir=log.dir,
182 prior=prior, mfields=mfields, mfields.maxvals=mfields.maxvals, mfields.fns=mfields.fns,
183 filter=filter, cis.threshold=cis.threshold, ofields.x=ofields.x, ofields.y=ofields.y,
184 function.savelist=c("get.short.fn", "get.ofield.args"))
185 if (class(result) == "list" && class(result[[1]]) == "try-error")
186 return (-1)
and it seems that Rsge does not work properly.
I workarounded by editing Rsge/sge.parApply.R code
(set value of variables equal to Rsge/sge.optionR)
and reinstalling Rsge.
1
2 # $Id: sge.parRapply.R,v 1.2 2006/12/15 15:21:23 kuhna03 Exp $
3
4 sge.apply <- function(X, MARGIN, FUN, ...,
5 join.method=cbind,
6 njobs,
7 batch.size=options('sge.block.size'),
8 packages=NULL,
9 global.savelist=NULL,
10 function.savelist=NULL,
11 cluster=options('sge.use.cluster'),
12 #trace=options('sge.trace'),
13 trace=TRUE,
14 #debug=options('sge.debug'),
15 debug=FALSE,
16 file.prefix=options('sge.file.prefix')
17 ) {

How can i make a python file run another which is not in same directory?

This is my code...I have tried many solutions given on stackoverflow but i am not able to run another python file which is not in same directory
f.py
import os
print "Start..."
file='"C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical
Session on R\Session II - Regression\run.py"'
os.system('python file ')
print "Done"
Output:
Fatal error: cannot open file 'file': No such file or directory
run.py
import os
print "Start..."
files=r'"C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical
Session on R\Session II - Regression\decisionTree.R"'
os.system('Rscript '+files)
print "Done"
I get the desired result when i run run.py.
Output:
C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical Session
on R\
Session II - Regression>python r.py
Start...
START
elapsed
0.17
Step 1: Library Inclusion
Step 2: Variable Declaration[1]
[1] "regressionDataSet.csv"
Step 3: Data Loading RMSD
irNumber
14395 1.167 5364.27 4616.64
15435 2.500 25468.10 475274.00 -
8739 4.039 5921.03 7071.89
11586 0.000 14192.70 75413.00
13765 0.000 17432.40 245147.00 -
10087 3.814 7333.51 26580.70
[1] 16382
[1] "RMSD" "Area"
[5] "SS" "ResidueLeng
Step 4: Counting dataset[1] 1638
Step 5: Choose Target Variable[1
Step 6: Choose Inputs Variable[1
"SS"
[5] "ResidueLength" "PairNumber"
[1] 6
Step 7: Select training dataset
th PairNumber RMSD
14395 5364.27 4616.64 -696.
15435 25468.10 475274.00 -10600.
8739 5921.03 7071.89 -1658.
11586 14192.70 75413.00 -7939.
13765 17432.40 245147.00 -10885.
10087 7333.51 26580.70 -2746.
[1] 8191
Step 8: Select testing dataset
PairNumber RMSD
10216 20510.40 254178.0 44500.0
2385 9981.42 28499.0 -4789.0
1886 21107.10 192443.0 -4860.0
13684 17765.00 76543.0 -8164.0
10319 6308.91 10287.3 -3370.0
13088 5844.34 11139.7 -1879.7
[1] 8192
Step 9: Model Building -> decis
ength + PairNumber
n= 8191
node), split, n, deviance, yval
* denotes terminal node
1) root 8191 23819.88000 2.364
2) Energy< -6161.885 1592 4
4) ResidueLength< 387.5 74
8) Energy< -7785.3 262
9) Energy>=-7785.3 481
5) ResidueLength>=387.5 84
10) Energy< -12910.5 173
11) Energy>=-12910.5 676
22) ResidueLength< 467.
44) ResidueLength>=39
45) ResidueLength< 39
23) ResidueLength>=467.
3) Energy>=-6161.885 6599 17
6) SS< 21.5 1584 3795.813
7) SS>=21.5 5015 13126.850
14) Energy< -3971.125 163
28) ResidueLength< 192.
29) ResidueLength>=192.
58) ResidueLength< 26
116) Energy< -4680.5
117) Energy>=-4680.5
59) ResidueLength>=26
15) Energy>=-3971.125 337
30) Area< 8601.98 1655
60) Energy< -2933.36
61) Energy>=-2933.36
31) Area>=8601.98 1721
Step 10: Prediction using -> de
13684 10319 13088
3.24618361 0.51722167 3.10727318
Step 11: Extracting Actual[1] 3.
Step 12: Model Evaluation[1] 0.5
[1] 0.25
[1] 1.19
[1] 48.19
elapsed
0.53
null device
1
modelName r R rm
elapsed decisionTree 0.5 0.25 1.
Step 13: Writing to file
Step 14: Saving the Model -> dec
Done
Total Time Taken: 0.53 secDone
But i get the following error when i run it through f.py
Error:
Start...
Start...
START
elapsed
0.18
Step 1: Library Inclusion
Step 2: Variable Declaration[1] "decisionTree"
[1] "regressionDataSet.csv"
Step 3: Data LoadingError in file(file, "rt") : cannot open the connec
Calls: read.csv -> read.table -> file
In addition: Warning message:
In file(file, "rt") :
cannot open file 'regressionDataSet.csv': No such file or directory
Put an r in front of your file path, so that the backslashes \ don't escape strings where you don't want them to be escaped (see also this question).
Secondly os.system('python file') will literally execute python file, your variable isn't being used.
Also make sure there's no linebreak your file path (just one long line).
import os
print "Start..."
folder = r'C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical Session on R\Session II - Regression'
file= r'"{}\run.py"'.format(folder)
os.chdir(folder)
os.system('python '+file)
print "Done"

Resources