<commit_before>/* Copyright 2014-2015. The Regents of the University of California.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 *
 * Authors:
 * 2012, 2015 <NAME> <<EMAIL>>
 */

#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <complex.h>
#include <stdio.h>
#include <math.h>
#include <getopt.h>

#include "num/multind.h"

#include "misc/mmio.h"
#include "misc/misc.h"
#include "misc/mri.h"


static void usage(const char* name, FILE* fd)
{
	fprintf(fd, "Usage: %s [-h] [-r] <output>\n", name);
}


static void help(void)
{
	printf( "\n"
		"Computes k-space trajectories.\n"
		"\n"
		"-x x\treadout samples\n"
		"-y y\tphase encoding lines\n"
		"-a a\tacceleration\n"
		"-r\tradial\n"
		"-G\tgolden angle\n"
		"-h\thelp\n");
}


int main(int argc, char* argv[])
{
	int X = 128;
	int Y = 128;
	int accel = 1;
	bool radial = false;
	bool golden = false;
	int c;

	while (-1 != (c = getopt(argc, argv, "x:y:a:rGh"))) {

		switch (c) {

		case 'x':
			X = atoi(optarg);
			break;

		case 'y':
			Y = atoi(optarg);
			break;

		case 'a':
			accel = atoi(optarg);
			break;

		case 'G':
			golden = true;
			radial = true;
			break;

		case 'r':
			radial = true;
			break;

		case 'h':
			usage(argv[0], stdout);
			help();
			exit(0);

		default:
			usage(argv[0], stderr);
			exit(1);
		}
	}

	if (argc - optind != 1) {

		usage(argv[0], stderr);
		exit(1);
	}

	int N = X * Y / accel;
	long dims[3] = { 3, X, Y / accel };
	complex float* samples = create_cfl(argv[optind + 0], 3, dims);


	int p = 0;
	for (int j = 0; j < Y; j += accel) {
		for (int i = 0; i < X; i++) {

			if (radial) {

				double golden_angle = 3. - sqrtf(5.);
				double base = golden ? ((2. - golden_angle) / 2.) : (1. / (float)Y);
				double angle = M_PI * (float)j * base;

				samples[p * 3 + 0] = ((float)i + 0.5 - (float)X / 2.) * sin(angle);
				samples[p * 3 + 1] = ((float)i + 0.5 - (float)X / 2.) * cos(angle);
				samples[p * 3 + 2] = 0.;

			} else {

				samples[p * 3 + 0] = (i - X / 2);
				samples[p * 3 + 1] = (j - Y / 2);
				samples[p * 3 + 2] = 0;
			}

			p++;
		}
	}
	assert(p == N - 0);

	unmap_cfl(3, dims, samples);
	exit(0);
}


<commit_msg>add some options or radial trajectories<commit_after>/* Copyright 2014-2015. The Regents of the University of California.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 *
 * Authors:
 * 2012, 2015 <NAME> <<EMAIL>>
 */

#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
#include <complex.h>
#include <stdio.h>
#include <math.h>
#include <getopt.h>

#include "num/multind.h"

#include "misc/mmio.h"
#include "misc/misc.h"
#include "misc/mri.h"


static void usage(const char* name, FILE* fd)
{
	fprintf(fd, "Usage: %s [-h] [-r] <output>\n", name);
}


static void help(void)
{
	printf( "\n"
		"Computes k-space trajectories.\n"
		"\n"
		"-x x\treadout samples\n"
		"-y y\tphase encoding lines\n"
		"-a a\tacceleration\n"
		"-t t\tturns\n"
		"-r\tradial\n"
		"-G\tgolden-ratio sampling\n"
		"-D\tdouble base angle\n"
		"-h\thelp\n");
}


static int remap(int all, int turns, int n)
{
	int spt = all / turns;
	return (n % spt) * turns + n / spt;
}

int main(int argc, char* argv[])
{
	int X = 128;
	int Y = 128;
	int accel = 1;
	bool radial = false;
	bool golden = false;
	bool dbl = false;
	int c;
	int turns = 1;

	while (-1 != (c = getopt(argc, argv, "x:y:a:t:rDGh"))) {

		switch (c) {

		case 'x':
			X = atoi(optarg);
			break;

		case 'y':
			Y = atoi(optarg);
			break;

		case 'a':
			accel = atoi(optarg);
			break;

		case 'G':
			golden = true;
			radial = true;
			break;

		case 'D':
			dbl = true;
		case 'r':
			radial = true;
			break;

		case 't':
			turns = atoi(optarg);
			break;

		case 'h':
			usage(argv[0], stdout);
			help();
			exit(0);

		default:
			usage(argv[0], stderr);
			exit(1);
		}
	}

	if (argc - optind != 1) {

		usage(argv[0], stderr);
		exit(1);
	}

	int N = X * Y / accel;
	long dims[3] = { 3, X, Y / accel };
	complex float* samples = create_cfl(argv[optind + 0], 3, dims);


	int p = 0;
	for (int j = 0; j < Y; j += accel) {
		for (int i = 0; i < X; i++) {

			if (radial) {

				/* golden-ratio sampling
				 *
				 * <NAME>, <NAME>, <NAME>, <NAME>, <NAME>.
				 * An optimal radial profile order based on the Golden Ratio
				 * for time-resolved MRI. IEEE TMI 26:68--76 (2007)
				 */

				double golden_angle = 3. - sqrtf(5.);
				double base = golden ? ((2. - golden_angle) / 2.) : (1. / (float)Y);
				double angle = M_PI * (float)remap(Y, turns, j) * (dbl ? 2. : 1.) * base;

				samples[p * 3 + 0] = ((float)i + 0.5 - (float)X / 2.) * sin(angle);
				samples[p * 3 + 1] = ((float)i + 0.5 - (float)X / 2.) * cos(angle);
				samples[p * 3 + 2] = 0.;

			} else {

				samples[p * 3 + 0] = (i - X / 2);
				samples[p * 3 + 1] = (j - Y / 2);
				samples[p * 3 + 2] = 0;
			}

			p++;
		}
	}
	assert(p == N - 0);

	unmap_cfl(3, dims, samples);
	exit(0);
}



{'fraction_non_alphanumeric': 0.1920937624155741, 'fraction_numerical': 0.029598728645212555, 'mean_word_length': 2.4772099447513813, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '852119', 'n_tokens_mistral': 2523, 'n_tokens_neox': 2101, 'n_words': 610}