Generating Sequential File Names with Mathematica

One common task when outputting scientific computation results, figures, etc. is the need to include numbers in a file name. For example, including leading zeros in a name can ensure that the files are ordered sequentially when you list the directory contents. If the numerical values correspond to real numbers (as opposed to integers) you may want to include decimals after the decimal point.

The function below generates a name that starts with the string “T_” and then includes a left and right zero padded number at the end of the file name.

BuildNameForPeriod[period_, n_] := 
 Module[{}, 
  "T_" <> StringTake[ToString[NumberForm[period, {n, 2}, 
       NumberPadding -> {"0", "0"}]], -n]
 ]

You can test it with

Table[BuildNameForPeriod[i,6],{i,0,200,5}]

which produces the output

{T_000.00,T_005.00,T_010.00,T_015.00,T_020.00,T_025.00,
T_030.00,T_035.00,T_040.00,T_045.00,T_050.00,T_055.00,
T_060.00,T_065.00,T_070.00,T_075.00,T_080.00,T_085.00,
T_090.00,T_095.00,T_100.00,T_105.00,T_110.00,T_115.00,
T_120.00,T_125.00,T_130.00,T_135.00,T_140.00,T_145.00,
T_150.00,T_155.00,T_160.00,T_165.00,T_170.00,T_175.00,
T_180.00,T_185.00,T_190.00,T_195.00,T_200.00}

Of course there ought to be an easier way (and probably is), but this seems to work.

Don’t Study Large Earthquakes with Mathematica’s EarthquakeData

Mathematica contains information on earthquakes that is accessible using the built-in EarthquakeData function. The function includes useful search approaches that allow users to select earthquakes by magnitude, depth, date, etc. The geographic selection tools are particularly useful – you can select earthquakes by geographic regions, polygons, distance from a reference location, etc.

Unfortunately, something is wrong with the data. The earthquake information are not what most earthquake seismologists would agree is accurate. I have not combed through their entire data set, but the Wolfram data seem to have a problem with at least earthquake magnitudes. Although magnitude is the most commonly quoted estimate of an earthquake size, it is not a quantity easy for nonspecialists to understand and to package for general use.

The development of earthquake magnitude scales has a complex history because observational seismology developed before the firm theoretical basis of faulting and earthquakes was established. Many magnitudes may be associated with a large earthquake and not all are of equal value or even accurately reflect the size of the earthquake. Seismologists continue to measure and use a suite of magnitudes because that’s how we can compare old and new earthquakes.

The data for large earthquakes returned by the EarthquakeData command are inaccurate. I emailed Wolfram several years ago to describe problems I saw on Wolfram Alpha and they responded, but serious, obvious problems remain.  This is not a big deal to me, I use Mathematica to analyze and display earthquake data often, but I never use Mathematica’s data. But two things concern me: (1) Do all the data included with Mathematica suffer from such substantial errors (I don’t think so, but I wouldn’t know the details); (2) I worry about students exploring earthquakes on their own who perform calculations with the Mathematica’s data and who then are disappointed and discouraged that the effort was wasted because the input was flawed.

In the following, I evaluate some of the EarthquakeData information for large earthquakes. Problems appear quickly.

A simple search for a list of great earthquakes

Great earthquakes are earthquakes with magnitudes greater than or equal to 8.0. Mathematica makes searching for earthquakes with a minimum magnitude convenient. The search results are a list earthquake entities that contain properties related to each earthquake in the list. Since we know much more about recent earthquakes than historical events, some properties for the older events may be missing.

Here is an example query to get a list of all great earthquakes in the Wolfram data base.

(* Select earthquakes with magnitudes greater than or equal to 8.0 *)
eqs = EarthquakeData[All, 8.0];
Print["Returned " <> ToString[Length[eqs]] <> " earthquake entities."]

Continue reading